Merge pull request #260 from default0/file_dialog_tweaks

File dialog tweaks
This commit is contained in:
Vadim Lopatin 2016-05-10 09:59:10 +04:00
commit 806742c848
1 changed files with 21 additions and 13 deletions

View File

@ -115,6 +115,8 @@ class FileDialog : Dialog, CustomGridCellAdapter {
protected bool _isOpenDialog; protected bool _isOpenDialog;
protected bool _showHiddenFiles;
protected string[string] _filetypeIcons; protected string[string] _filetypeIcons;
this(UIString caption, Window parent, Action action = null, uint fileDialogFlags = DialogFlag.Modal | DialogFlag.Resizable | FileDialogFlag.FileMustExist) { this(UIString caption, Window parent, Action action = null, uint fileDialogFlags = DialogFlag.Modal | DialogFlag.Resizable | FileDialogFlag.FileMustExist) {
@ -159,6 +161,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
_filterIndex = index; _filterIndex = index;
} }
/// the path to the directory whose files should be displayed
@property string path() { @property string path() {
return _path; return _path;
} }
@ -167,6 +170,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
_path = s; _path = s;
} }
/// the name of the file or directory that is currently selected
@property string filename() { @property string filename() {
return _filename; return _filename;
} }
@ -175,6 +179,14 @@ class FileDialog : Dialog, CustomGridCellAdapter {
_filename = s; _filename = s;
} }
@property bool showHiddenFiles() {
return _showHiddenFiles;
}
@property void showHiddenFiles(bool b) {
_showHiddenFiles = b;
}
/// return currently selected filter value - array of patterns like ["*.txt", "*.rtf"] /// return currently selected filter value - array of patterns like ["*.txt", "*.rtf"]
@property string[] selectedFilter() { @property string[] selectedFilter() {
if (_filterIndex >= 0 && _filterIndex < _filters.length) if (_filterIndex >= 0 && _filterIndex < _filters.length)
@ -200,7 +212,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
dir = buildNormalizedPath(dir); dir = buildNormalizedPath(dir);
Log.d("FileDialog.openDirectory(", dir, ")"); Log.d("FileDialog.openDirectory(", dir, ")");
_fileList.rows = 0; _fileList.rows = 0;
if (!listDirectory(dir, true, true, false, selectedFilter, _entries, executableFilterSelected)) if (!listDirectory(dir, true, true, _showHiddenFiles, selectedFilter, _entries, executableFilterSelected))
return false; return false;
_path = dir; _path = dir;
_isRoot = isRoot(dir); _isRoot = isRoot(dir);
@ -338,12 +350,8 @@ class FileDialog : Dialog, CustomGridCellAdapter {
DirEntry e = _entries[index]; DirEntry e = _entries[index];
string fname = e.name; string fname = e.name;
_edFilename.text = toUTF32(baseName(fname)); _edFilename.text = toUTF32(baseName(fname));
if (e.isDir) {
_filename = "";
} else if (e.isFile) {
_filename = fname; _filename = fname;
} }
}
protected void createAndEnterDirectory(string name) { protected void createAndEnterDirectory(string name) {
string newdir = buildNormalizedPath(_path, name); string newdir = buildNormalizedPath(_path, name);
@ -374,14 +382,14 @@ class FileDialog : Dialog, CustomGridCellAdapter {
return true; return true;
} }
if (action.id == StandardAction.Open || action.id == StandardAction.OpenDirectory || action.id == StandardAction.Save) { if (action.id == StandardAction.Open || action.id == StandardAction.OpenDirectory || action.id == StandardAction.Save) {
if (_filename.length > 0 || action.id == StandardAction.OpenDirectory) { if (_filename.length > 0) {
Action result = _action; Action result = _action;
if (action.id == StandardAction.OpenDirectory)
result.stringParam = _path;
else
result.stringParam = _filename; result.stringParam = _filename;
// success if either selected dir & has to open dir or if selected file
if (action.id == StandardAction.OpenDirectory && isDir(_filename) || isFile(_filename)) {
close(result); close(result);
return true; return true;
}
} else if (_filename.length == 0){ } else if (_filename.length == 0){
auto row = _fileList.row(); auto row = _fileList.row();
onItemActivated(row); onItemActivated(row);