From d6011aa5e4b9a95398f580c5dd6216d24e9e6723 Mon Sep 17 00:00:00 2001 From: Cedric Schneider Date: Sat, 7 May 2016 22:56:22 +0200 Subject: [PATCH 1/2] FileDialog: Flag to show hidden files --- src/dlangui/dialogs/filedlg.d | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index 67d0f4b1..eef8b2f7 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -115,6 +115,8 @@ class FileDialog : Dialog, CustomGridCellAdapter { protected bool _isOpenDialog; + protected bool _showHiddenFiles; + protected string[string] _filetypeIcons; this(UIString caption, Window parent, Action action = null, uint fileDialogFlags = DialogFlag.Modal | DialogFlag.Resizable | FileDialogFlag.FileMustExist) { @@ -175,6 +177,14 @@ class FileDialog : Dialog, CustomGridCellAdapter { _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"] @property string[] selectedFilter() { if (_filterIndex >= 0 && _filterIndex < _filters.length) @@ -200,7 +210,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { dir = buildNormalizedPath(dir); Log.d("FileDialog.openDirectory(", dir, ")"); _fileList.rows = 0; - if (!listDirectory(dir, true, true, false, selectedFilter, _entries, executableFilterSelected)) + if (!listDirectory(dir, true, true, _showHiddenFiles, selectedFilter, _entries, executableFilterSelected)) return false; _path = dir; _isRoot = isRoot(dir); From da7a1df886f0865ec421158c244d083b88e9da6f Mon Sep 17 00:00:00 2001 From: Cedric Schneider Date: Sat, 7 May 2016 23:12:45 +0200 Subject: [PATCH 2/2] FileDialog: Improve directory selection If you select a directory but do not open it and then hit the "Select Directory" button to close the dialog the open path would be given as result instead of the selected directory. This change breaks backwards compatibility insofar that the "path" property you would use to access the selected path in OpenDirectory dialogs is no longer the path the user chose, but instead the parent directory of the path the user chose. --- src/dlangui/dialogs/filedlg.d | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index eef8b2f7..f24fab1b 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -161,6 +161,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { _filterIndex = index; } + /// the path to the directory whose files should be displayed @property string path() { return _path; } @@ -169,6 +170,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { _path = s; } + /// the name of the file or directory that is currently selected @property string filename() { return _filename; } @@ -348,11 +350,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { DirEntry e = _entries[index]; string fname = e.name; _edFilename.text = toUTF32(baseName(fname)); - if (e.isDir) { - _filename = ""; - } else if (e.isFile) { - _filename = fname; - } + _filename = fname; } protected void createAndEnterDirectory(string name) { @@ -384,14 +382,14 @@ class FileDialog : Dialog, CustomGridCellAdapter { return true; } 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; - if (action.id == StandardAction.OpenDirectory) - result.stringParam = _path; - else - result.stringParam = _filename; - close(result); - return true; + 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); + return true; + } } else if (_filename.length == 0){ auto row = _fileList.row(); onItemActivated(row);