mirror of https://github.com/buggins/dlangui.git
settings improvements
This commit is contained in:
parent
176759910c
commit
f841c401fd
|
@ -80,6 +80,23 @@ class SettingsFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int limitInt(long value, int minvalue, int maxvalue) {
|
||||||
|
if (value < minvalue)
|
||||||
|
return minvalue;
|
||||||
|
else if (value > maxvalue)
|
||||||
|
return maxvalue;
|
||||||
|
return cast(int)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string limitString(string value, const string[] values) {
|
||||||
|
assert(values.length > 0);
|
||||||
|
foreach(v; values)
|
||||||
|
if (v.equal(value))
|
||||||
|
return value;
|
||||||
|
return values[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@property bool loaded() {
|
@property bool loaded() {
|
||||||
return _loaded;
|
return _loaded;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +240,6 @@ final class Setting {
|
||||||
_changed = changed;
|
_changed = changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// array
|
/// array
|
||||||
private static struct SettingArray {
|
private static struct SettingArray {
|
||||||
Setting[] list;
|
Setting[] list;
|
||||||
|
|
|
@ -270,6 +270,31 @@ class ExecutableFileNameEditItem : SettingsItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PathNameEditItem : 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);
|
||||||
|
DirEditLine ed = new DirEditLine(_id ~ "-path-edit");
|
||||||
|
ed.addFilter(FileFilterEntry(UIString("All files"d), "*.*"));
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// settings page - item of settings tree, can edit several settings
|
/// settings page - item of settings tree, can edit several settings
|
||||||
class SettingsPage {
|
class SettingsPage {
|
||||||
protected SettingsPage _parent;
|
protected SettingsPage _parent;
|
||||||
|
@ -348,6 +373,13 @@ class SettingsPage {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// add EditLine to edit filename
|
||||||
|
PathNameEditItem addDirNameEdit(string id, UIString label, string defaultValue = "") {
|
||||||
|
PathNameEditItem res = new PathNameEditItem(id, label, defaultValue);
|
||||||
|
addItem(res);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/// add EditLine to edit executable file name
|
/// add EditLine to edit executable file name
|
||||||
ExecutableFileNameEditItem addExecutableFileNameEdit(string id, UIString label, string defaultValue = "") {
|
ExecutableFileNameEditItem addExecutableFileNameEdit(string id, UIString label, string defaultValue = "") {
|
||||||
ExecutableFileNameEditItem res = new ExecutableFileNameEditItem(id, label, defaultValue);
|
ExecutableFileNameEditItem res = new ExecutableFileNameEditItem(id, label, defaultValue);
|
||||||
|
|
Loading…
Reference in New Issue