more settings

This commit is contained in:
Vadim Lopatin 2015-02-17 17:54:23 +03:00
parent 7778bd3ecf
commit 6dd4ac7fe6
1 changed files with 40 additions and 0 deletions

View File

@ -2,6 +2,10 @@ module dlangide.ui.settings;
import dlangui.core.settings;
const AVAILABLE_THEMES = ["theme_default", "theme_dark"];
const AVAILABLE_LANGUAGES = ["en", "ru"];
class IDESettings : SettingsFile {
this(string filename) {
@ -12,6 +16,9 @@ class IDESettings : SettingsFile {
Setting ed = editorSettings();
ed.setBooleanDef("useSpacesForTabs", true);
ed.setIntegerDef("tabSize", 4);
Setting ui = uiSettings();
ui.setStringDef("theme", "theme_default");
ui.setStringDef("language", "en");
}
/// override to do something after loading - e.g. set defaults
@ -23,6 +30,11 @@ class IDESettings : SettingsFile {
return res;
}
@property Setting uiSettings() {
Setting res = _setting.objectByPath("interface", true);
return res;
}
static int limitInt(long value, int minvalue, int maxvalue) {
if (value < minvalue)
return minvalue;
@ -31,6 +43,34 @@ class IDESettings : SettingsFile {
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];
}
/// theme
@property string uiTheme() {
return limitString(uiSettings.getString("theme", "theme_default"), AVAILABLE_THEMES);
}
/// theme
@property IDESettings uiTheme(string v) {
uiSettings.setString("theme", limitString(v, AVAILABLE_THEMES));
return this;
}
/// language
@property string uiLanguage() {
return limitString(uiSettings.getString("language", "en"), AVAILABLE_LANGUAGES);
}
/// language
@property IDESettings uiLanguage(string v) {
uiSettings.setString("language", limitString(v, AVAILABLE_LANGUAGES));
return this;
}
/// text editor setting, true if need to insert spaces instead of tabs
@property bool useSpacesForTabs() {
return editorSettings.getBoolean("useSpacesForTabs", true);