mirror of https://github.com/buggins/dlangui.git
settings dialog support
This commit is contained in:
parent
042c675431
commit
e654035492
|
@ -57,6 +57,12 @@ class SettingsFile {
|
||||||
protected bool _loaded;
|
protected bool _loaded;
|
||||||
|
|
||||||
@property Setting setting() { return _setting; }
|
@property Setting setting() { return _setting; }
|
||||||
|
@property Setting copySettings() {
|
||||||
|
return _setting.clone();
|
||||||
|
}
|
||||||
|
@property void applySettings(Setting settings) {
|
||||||
|
_setting.apply(settings);
|
||||||
|
}
|
||||||
alias setting this;
|
alias setting this;
|
||||||
|
|
||||||
/// create settings file object; if filename is provided, attempts to load settings from file
|
/// create settings file object; if filename is provided, attempts to load settings from file
|
||||||
|
@ -241,6 +247,13 @@ final class Setting {
|
||||||
@property int length() {
|
@property int length() {
|
||||||
return cast(int)list.length;
|
return cast(int)list.length;
|
||||||
}
|
}
|
||||||
|
/// deep copy
|
||||||
|
void copyFrom(ref SettingArray v) {
|
||||||
|
list.length = v.list.length;
|
||||||
|
for(int i = 0; i < v.list.length; i++) {
|
||||||
|
list[i] = v.list[i].clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ordered map
|
/// ordered map
|
||||||
|
@ -315,6 +328,16 @@ final class Setting {
|
||||||
@property int length() {
|
@property int length() {
|
||||||
return cast(int)list.length;
|
return cast(int)list.length;
|
||||||
}
|
}
|
||||||
|
/// deep copy
|
||||||
|
void copyFrom(SettingMap * v) {
|
||||||
|
list.length = v.list.length;
|
||||||
|
for(int i = 0; i < v.list.length; i++) {
|
||||||
|
list[i] = v.list[i].clone();
|
||||||
|
}
|
||||||
|
destroy(map);
|
||||||
|
foreach(key, value; v.map)
|
||||||
|
map[key] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -374,6 +397,45 @@ final class Setting {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void apply(Setting settings) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// deep copy of settings
|
||||||
|
Setting clone() {
|
||||||
|
Setting res = new Setting();
|
||||||
|
res.clear(_type);
|
||||||
|
final switch(_type) with(SettingType) {
|
||||||
|
case STRING:
|
||||||
|
res._store.str = _store.str;
|
||||||
|
break;
|
||||||
|
case ARRAY:
|
||||||
|
res._store.array.copyFrom(_store.array);
|
||||||
|
break;
|
||||||
|
case OBJECT:
|
||||||
|
if (_store.map) {
|
||||||
|
res._store.map = new SettingMap();
|
||||||
|
res._store.map.copyFrom(_store.map);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case INTEGER:
|
||||||
|
res._store.integer = _store.integer;
|
||||||
|
break;
|
||||||
|
case UINTEGER:
|
||||||
|
res._store.uinteger = _store.uinteger;
|
||||||
|
break;
|
||||||
|
case FLOAT:
|
||||||
|
res._store.floating = _store.floating;
|
||||||
|
break;
|
||||||
|
case TRUE:
|
||||||
|
case FALSE:
|
||||||
|
case NULL:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
res._changed = false;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// read as string value
|
/// read as string value
|
||||||
@property inout(string) str() inout {
|
@property inout(string) str() inout {
|
||||||
final switch(_type) with(SettingType) {
|
final switch(_type) with(SettingType) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import dlangui.core.events;
|
||||||
import dlangui.core.i18n;
|
import dlangui.core.i18n;
|
||||||
import dlangui.core.stdaction;
|
import dlangui.core.stdaction;
|
||||||
import dlangui.core.files;
|
import dlangui.core.files;
|
||||||
import dlangui.core.settings;
|
public import dlangui.core.settings;
|
||||||
import dlangui.widgets.controls;
|
import dlangui.widgets.controls;
|
||||||
import dlangui.widgets.lists;
|
import dlangui.widgets.lists;
|
||||||
import dlangui.widgets.layouts;
|
import dlangui.widgets.layouts;
|
||||||
|
@ -22,6 +22,7 @@ private import std.utf;
|
||||||
private import std.conv : to;
|
private import std.conv : to;
|
||||||
private import std.array : split;
|
private import std.array : split;
|
||||||
|
|
||||||
|
/// item on settings page
|
||||||
class SettingsItem {
|
class SettingsItem {
|
||||||
protected string _id;
|
protected string _id;
|
||||||
protected UIString _label;
|
protected UIString _label;
|
||||||
|
@ -40,20 +41,27 @@ class SettingsItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// items shows checkbox
|
/// checkbox setting
|
||||||
class CheckboxItem : SettingsItem {
|
class CheckboxItem : SettingsItem {
|
||||||
this(string id, UIString label) {
|
private bool _inverse;
|
||||||
|
this(string id, UIString label, bool inverse = false) {
|
||||||
super(id, label);
|
super(id, label);
|
||||||
|
_inverse = inverse;
|
||||||
}
|
}
|
||||||
/// create setting widget
|
/// create setting widget
|
||||||
override Widget createWidget(Setting settings) {
|
override Widget createWidget(Setting settings) {
|
||||||
CheckBox res = new CheckBox(_id, _label);
|
CheckBox res = new CheckBox(_id, _label);
|
||||||
Setting setting = settings.settingByPath(_id, SettingType.FALSE);
|
Setting setting = settings.settingByPath(_id, SettingType.FALSE);
|
||||||
res.checked = setting.boolean;
|
res.checked = setting.boolean ^ _inverse;
|
||||||
|
res.onCheckChangeListener = delegate(Widget source, bool checked) {
|
||||||
|
setting.boolean = checked ^ _inverse;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// settings page - item of settings tree, can edit several settings
|
||||||
class SettingsPage {
|
class SettingsPage {
|
||||||
protected SettingsPage _parent;
|
protected SettingsPage _parent;
|
||||||
protected ObjectList!SettingsPage _children;
|
protected ObjectList!SettingsPage _children;
|
||||||
|
@ -78,9 +86,14 @@ class SettingsPage {
|
||||||
return _children[index];
|
return _children[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void addChild(SettingsPage item) {
|
SettingsPage addChild(SettingsPage item) {
|
||||||
_children.add(item);
|
_children.add(item);
|
||||||
item._parent = this;
|
item._parent = this;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsPage addChild(string id, UIString label) {
|
||||||
|
return addChild(new SettingsPage(id, label));
|
||||||
}
|
}
|
||||||
|
|
||||||
@property int itemCount() {
|
@property int itemCount() {
|
||||||
|
@ -92,9 +105,17 @@ class SettingsPage {
|
||||||
return _items[index];
|
return _items[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void addItem(SettingsItem item) {
|
SettingsItem addItem(SettingsItem item) {
|
||||||
_items.add(item);
|
_items.add(item);
|
||||||
item._page = this;
|
item._page = this;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// add checkbox (boolean value) for setting
|
||||||
|
CheckboxItem addCheckbox(string id, UIString label, bool inverse = false) {
|
||||||
|
CheckboxItem res = new CheckboxItem(id, label, inverse);
|
||||||
|
addItem(res);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// create page widget (default implementation creates empty page)
|
/// create page widget (default implementation creates empty page)
|
||||||
|
@ -110,7 +131,7 @@ class SettingsPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem createTreeItem() {
|
TreeItem createTreeItem() {
|
||||||
return null;
|
return new TreeItem(_id, _label);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -118,10 +139,10 @@ class SettingsPage {
|
||||||
class SettingsDialog : Dialog {
|
class SettingsDialog : Dialog {
|
||||||
protected TreeWidget _tree;
|
protected TreeWidget _tree;
|
||||||
protected FrameLayout _frame;
|
protected FrameLayout _frame;
|
||||||
protected SettingsFile _settings;
|
protected Setting _settings;
|
||||||
protected SettingsPage _layout;
|
protected SettingsPage _layout;
|
||||||
|
|
||||||
this(UIString caption, Window parent, SettingsFile settings, SettingsPage layout) {
|
this(UIString caption, Window parent, Setting settings, SettingsPage layout) {
|
||||||
super(caption, parent, DialogFlag.Modal | DialogFlag.Resizable | DialogFlag.Popup);
|
super(caption, parent, DialogFlag.Modal | DialogFlag.Resizable | DialogFlag.Popup);
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
_layout = layout;
|
_layout = layout;
|
||||||
|
@ -152,10 +173,18 @@ class SettingsDialog : Dialog {
|
||||||
minWidth(600).minHeight(400);
|
minWidth(600).minHeight(400);
|
||||||
_tree = new TreeWidget("prop_tree");
|
_tree = new TreeWidget("prop_tree");
|
||||||
_tree.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT);
|
_tree.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
|
_tree.minHeight(200).minWidth(100);
|
||||||
_tree.selectionListener = &onTreeItemSelected;
|
_tree.selectionListener = &onTreeItemSelected;
|
||||||
_tree.fontSize = 16;
|
_tree.fontSize = 16;
|
||||||
_frame = new FrameLayout("prop_pages");
|
_frame = new FrameLayout("prop_pages");
|
||||||
|
_frame.minHeight(200).minWidth(100);
|
||||||
createControls(_layout, _tree.items);
|
createControls(_layout, _tree.items);
|
||||||
|
HorizontalLayout content = new HorizontalLayout("settings_dlg_content");
|
||||||
|
content.addChild(_tree);
|
||||||
|
content.addChild(_frame);
|
||||||
|
content.layoutHeight(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
|
addChild(content);
|
||||||
|
addChild(createButtonsPanel([ACTION_APPLY, ACTION_CANCEL], 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
ACTION_OK=Ok
|
ACTION_OK=Ok
|
||||||
ACTION_CANCEL=Cancel
|
ACTION_CANCEL=Cancel
|
||||||
ACTION_YES=Yes
|
ACTION_YES=Yes
|
||||||
|
ACTION_APPLY=Apply
|
||||||
ACTION_NO=No
|
ACTION_NO=No
|
||||||
ACTION_CLOSE=Close
|
ACTION_CLOSE=Close
|
||||||
ACTION_ABORT=Abort
|
ACTION_ABORT=Abort
|
||||||
|
|
Loading…
Reference in New Issue