mirror of https://github.com/buggins/dlangui.git
settings dialog improvements
This commit is contained in:
parent
9b73a5447c
commit
176759910c
|
@ -187,7 +187,7 @@ bool filterFilename(string filename, string[] filters) {
|
|||
|
||||
Returns true if directory exists and listed successfully, false otherwise.
|
||||
*/
|
||||
bool listDirectory(string dir, bool includeDirs, bool includeFiles, bool showHiddenFiles, string[] filters, ref DirEntry[] entries) {
|
||||
bool listDirectory(string dir, bool includeDirs, bool includeFiles, bool showHiddenFiles, string[] filters, ref DirEntry[] entries, bool showExecutables = false) {
|
||||
|
||||
entries.length = 0;
|
||||
|
||||
|
@ -216,9 +216,23 @@ bool listDirectory(string dir, bool includeDirs, bool includeFiles, bool showHid
|
|||
foreach(DirEntry e; dirs)
|
||||
entries ~= e;
|
||||
if (includeFiles)
|
||||
foreach(DirEntry e; files)
|
||||
if (filterFilename(e.name, filters))
|
||||
foreach(DirEntry e; files) {
|
||||
bool passed = false;
|
||||
if (showExecutables) {
|
||||
version(Windows) {
|
||||
passed = e.name.endsWith(".exe") || e.name.endsWith(".EXE")
|
||||
|| e.name.endsWith(".cmd") || e.name.endsWith(".CMD")
|
||||
|| e.name.endsWith(".bat") || e.name.endsWith(".BAT");
|
||||
} else version (posix) {
|
||||
// execute permission for others
|
||||
passed = (e.attributes & 1) != 0;
|
||||
}
|
||||
} else {
|
||||
passed = filterFilename(e.name, filters);
|
||||
}
|
||||
if (passed)
|
||||
entries ~= e;
|
||||
}
|
||||
return true;
|
||||
} catch (FileException e) {
|
||||
return false;
|
||||
|
|
|
@ -69,14 +69,20 @@ enum FileDialogFlag : uint {
|
|||
struct FileFilterEntry {
|
||||
UIString label;
|
||||
string[] filter;
|
||||
this(UIString displayLabel, string filterList) {
|
||||
bool executableOnly;
|
||||
this(UIString displayLabel, string filterList, bool executableOnly = false) {
|
||||
label = displayLabel;
|
||||
if (filterList.length)
|
||||
filter = split(filterList, ";");
|
||||
this.executableOnly = executableOnly;
|
||||
}
|
||||
}
|
||||
|
||||
__gshared bool SHOW_FILE_DIALOG_IN_POPUP = true;
|
||||
version (Windows) {
|
||||
__gshared bool SHOW_FILE_DIALOG_IN_POPUP = true;
|
||||
} else {
|
||||
__gshared bool SHOW_FILE_DIALOG_IN_POPUP = false;
|
||||
}
|
||||
|
||||
/// File open / save dialog
|
||||
class FileDialog : Dialog, CustomGridCellAdapter {
|
||||
|
@ -165,6 +171,12 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
|||
return null;
|
||||
}
|
||||
|
||||
@property bool executableFilterSelected() {
|
||||
if (_filterIndex >= 0 && _filterIndex < _filters.length)
|
||||
return _filters[_filterIndex].executableOnly;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected bool upLevel() {
|
||||
return openDirectory(parentDir(_path), _path);
|
||||
}
|
||||
|
@ -177,7 +189,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
|||
dir = buildNormalizedPath(dir);
|
||||
Log.d("FileDialog.openDirectory(", dir, ")");
|
||||
_fileList.rows = 0;
|
||||
if (!listDirectory(dir, true, true, false, selectedFilter, _entries))
|
||||
if (!listDirectory(dir, true, true, false, selectedFilter, _entries, executableFilterSelected))
|
||||
return false;
|
||||
_path = dir;
|
||||
_isRoot = isRoot(dir);
|
||||
|
|
|
@ -73,7 +73,7 @@ class StringComboBoxItem : SettingsItem {
|
|||
override Widget[] createWidgets(Setting settings) {
|
||||
TextWidget lbl = new TextWidget(_id ~ "-label", _label);
|
||||
ComboBox cb = new ComboBox(_id, _items);
|
||||
//cb.minWidth = 100;
|
||||
cb.minWidth = 200;
|
||||
Setting setting = settings.settingByPath(_id, SettingType.STRING);
|
||||
string itemId = setting.str;
|
||||
int index = -1;
|
||||
|
@ -105,7 +105,7 @@ class IntComboBoxItem : SettingsItem {
|
|||
override Widget[] createWidgets(Setting settings) {
|
||||
TextWidget lbl = new TextWidget(_id ~ "-label", _label);
|
||||
ComboBox cb = new ComboBox(_id, _items);
|
||||
//cb.minWidth = 100;
|
||||
cb.minWidth = 100;
|
||||
Setting setting = settings.settingByPath(_id, SettingType.INTEGER);
|
||||
long itemId = setting.integer;
|
||||
int index = -1;
|
||||
|
@ -139,7 +139,7 @@ class FloatComboBoxItem : SettingsItem {
|
|||
override Widget[] createWidgets(Setting settings) {
|
||||
TextWidget lbl = new TextWidget(_id ~ "-label", _label);
|
||||
ComboBox cb = new ComboBox(_id, _items);
|
||||
//cb.minWidth = 100;
|
||||
cb.minWidth = 100;
|
||||
Setting setting = settings.settingByPath(_id, SettingType.FLOAT);
|
||||
long itemId = cast(long)(setting.floating * _divider);
|
||||
int index = -1;
|
||||
|
@ -174,6 +174,7 @@ class NumberEditItem : SettingsItem {
|
|||
override Widget[] createWidgets(Setting settings) {
|
||||
TextWidget lbl = new TextWidget(_id ~ "-label", _label);
|
||||
EditLine ed = new EditLine(_id ~ "-edit", _label);
|
||||
ed.minWidth = 100;
|
||||
Setting setting = settings.settingByPath(_id, SettingType.INTEGER);
|
||||
int n = cast(int)setting.integerDef(_defaultValue);
|
||||
if (_minValue != int.max && n < _minValue)
|
||||
|
@ -206,7 +207,57 @@ class StringEditItem : SettingsItem {
|
|||
/// create setting widget
|
||||
override Widget[] createWidgets(Setting settings) {
|
||||
TextWidget lbl = new TextWidget(_id ~ "-label", _label);
|
||||
EditLine ed = new EditLine(_id ~ "-edit", _label);
|
||||
EditLine ed = new EditLine(_id ~ "-edit");
|
||||
ed.minWidth = 200;
|
||||
Setting setting = settings.settingByPath(_id, SettingType.STRING);
|
||||
string value = setting.strDef(_defaultValue);
|
||||
setting.str = value;
|
||||
ed.text = toUTF32(value);
|
||||
ed.contentChange = delegate(EditableContent content) {
|
||||
string value = toUTF8(content.text);
|
||||
setting.str = value;
|
||||
};
|
||||
return [lbl, ed];
|
||||
}
|
||||
}
|
||||
|
||||
class FileNameEditItem : SettingsItem {
|
||||
string _defaultValue;
|
||||
this(string id, UIString label, string defaultValue) {
|
||||
super(id, label);
|
||||
_defaultValue = defaultValue;
|
||||
}
|
||||
/// create setting widget
|
||||
override Widget[] createWidgets(Setting settings) {
|
||||
import dlangui.dialogs.filedlg;
|
||||
TextWidget lbl = new TextWidget(_id ~ "-label", _label);
|
||||
FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit");
|
||||
ed.minWidth = 200;
|
||||
Setting setting = settings.settingByPath(_id, SettingType.STRING);
|
||||
string value = setting.strDef(_defaultValue);
|
||||
setting.str = value;
|
||||
ed.text = toUTF32(value);
|
||||
ed.contentChange = delegate(EditableContent content) {
|
||||
string value = toUTF8(content.text);
|
||||
setting.str = value;
|
||||
};
|
||||
return [lbl, ed];
|
||||
}
|
||||
}
|
||||
|
||||
class ExecutableFileNameEditItem : SettingsItem {
|
||||
string _defaultValue;
|
||||
this(string id, UIString label, string defaultValue) {
|
||||
super(id, label);
|
||||
_defaultValue = defaultValue;
|
||||
}
|
||||
/// create setting widget
|
||||
override Widget[] createWidgets(Setting settings) {
|
||||
import dlangui.dialogs.filedlg;
|
||||
TextWidget lbl = new TextWidget(_id ~ "-label", _label);
|
||||
FileNameEditLine ed = new FileNameEditLine(_id ~ "-filename-edit");
|
||||
ed.addFilter(FileFilterEntry(UIString("Executable files"d), "*.exe", true));
|
||||
ed.minWidth = 200;
|
||||
Setting setting = settings.settingByPath(_id, SettingType.STRING);
|
||||
string value = setting.strDef(_defaultValue);
|
||||
setting.str = value;
|
||||
|
@ -290,6 +341,20 @@ class SettingsPage {
|
|||
return res;
|
||||
}
|
||||
|
||||
/// add EditLine to edit filename
|
||||
FileNameEditItem addFileNameEdit(string id, UIString label, string defaultValue = "") {
|
||||
FileNameEditItem res = new FileNameEditItem(id, label, defaultValue);
|
||||
addItem(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// add EditLine to edit executable file name
|
||||
ExecutableFileNameEditItem addExecutableFileNameEdit(string id, UIString label, string defaultValue = "") {
|
||||
ExecutableFileNameEditItem res = new ExecutableFileNameEditItem(id, label, defaultValue);
|
||||
addItem(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
StringComboBoxItem addStringComboBox(string id, UIString label, StringListValue[] items) {
|
||||
StringComboBoxItem res = new StringComboBoxItem(id, label, items);
|
||||
addItem(res);
|
||||
|
|
Loading…
Reference in New Issue