From 94ad83796ed7ca4b44c2919355bc90fc280b660f Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 10 Dec 2015 11:04:32 +0300 Subject: [PATCH] settings --- dlangide_msvc.visualdproj | 3 + src/dlangide/ui/settings.d | 201 +++------------------ src/dlangide/workspace/idesettings.d | 179 ++++++++++++++++++ src/dlangide/workspace/projectsettings.d | 51 ++++++ src/dlangide/workspace/workspacesettings.d | 20 ++ 5 files changed, 276 insertions(+), 178 deletions(-) create mode 100644 src/dlangide/workspace/idesettings.d create mode 100644 src/dlangide/workspace/projectsettings.d create mode 100644 src/dlangide/workspace/workspacesettings.d diff --git a/dlangide_msvc.visualdproj b/dlangide_msvc.visualdproj index 196a207..aa1b3fe 100644 --- a/dlangide_msvc.visualdproj +++ b/dlangide_msvc.visualdproj @@ -463,8 +463,11 @@ + + + diff --git a/src/dlangide/ui/settings.d b/src/dlangide/ui/settings.d index cf13431..84a93ae 100644 --- a/src/dlangide/ui/settings.d +++ b/src/dlangide/ui/settings.d @@ -6,184 +6,9 @@ import dlangui.graphics.fonts; import dlangui.widgets.lists; import dlangui.dialogs.settingsdialog; - -const AVAILABLE_THEMES = ["ide_theme_default", "ide_theme_dark"]; -const AVAILABLE_LANGUAGES = ["en", "ru", "es"]; - -class IDESettings : SettingsFile { - - this(string filename) { - super(filename); - } - - override void updateDefaults() { - Setting ed = editorSettings(); - ed.setBooleanDef("useSpacesForTabs", true); - ed.setIntegerDef("tabSize", 4); - ed.setBooleanDef("smartIndents", true); - ed.setBooleanDef("smartIndentsAfterPaste", true); - Setting ui = uiSettings(); - ui.setStringDef("theme", "ide_theme_default"); - ui.setStringDef("language", "en"); - ui.setIntegerDef("hintingMode", 1); - ui.setIntegerDef("minAntialiasedFontSize", 0); - ui.setFloatingDef("fontGamma", 0.8); - debuggerSettings.setStringDef("executable", "gdb"); - terminalSettings.setStringDef("executable", "xterm"); - dubSettings.setStringDef("executable", "dub"); - dubSettings.setStringDef("additional_params", ""); - dmdToolchainSettings.setStringDef("executable", "dmd"); - ldcToolchainSettings.setStringDef("executable", "ldc2"); - gdcToolchainSettings.setStringDef("executable", "gdc"); - } - - /// override to do something after loading - e.g. set defaults - override void afterLoad() { - } - - @property Setting editorSettings() { - Setting res = _setting.objectByPath("editors/textEditor", true); - return res; - } - - @property Setting uiSettings() { - Setting res = _setting.objectByPath("interface", true); - return res; - } - - @property Setting debuggerSettings() { - Setting res = _setting.objectByPath("dlang/debugger", true); - return res; - } - - @property Setting terminalSettings() { - Setting res = _setting.objectByPath("dlang/terminal", true); - return res; - } - - @property Setting dubSettings() { - Setting res = _setting.objectByPath("dlang/dub", true); - return res; - } - - @property Setting dmdToolchainSettings() { - Setting res = _setting.objectByPath("dlang/toolchains/dmd", true); - return res; - } - - @property Setting ldcToolchainSettings() { - Setting res = _setting.objectByPath("dlang/toolchains/ldc", true); - return res; - } - - @property Setting gdcToolchainSettings() { - Setting res = _setting.objectByPath("dlang/toolchains/gdc", true); - return res; - } - - 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]; - } - - /// theme - @property string uiTheme() { - return limitString(uiSettings.getString("theme", "ide_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); - } - /// text editor setting, true if need to insert spaces instead of tabs - @property IDESettings useSpacesForTabs(bool v) { - editorSettings.setBoolean("useSpacesForTabs", v); - return this; - } - - /// text editor setting, true if need to insert spaces instead of tabs - @property int tabSize() { - return limitInt(editorSettings.getInteger("tabSize", 4), 1, 16); - } - /// text editor setting, true if need to insert spaces instead of tabs - @property IDESettings tabSize(int v) { - editorSettings.setInteger("tabSize", limitInt(v, 1, 16)); - return this; - } - - /// true if smart indents are enabled - @property bool smartIndents() { return editorSettings.getBoolean("smartIndents", true); } - /// set smart indents enabled flag - @property IDESettings smartIndents(bool enabled) { editorSettings.setBoolean("smartIndents", enabled); return this; } - - /// true if smart indents are enabled - @property bool smartIndentsAfterPaste() { return editorSettings.getBoolean("smartIndentsAfterPaste", true); } - /// set smart indents enabled flag - @property IDESettings smartIndentsAfterPaste(bool enabled) { editorSettings.setBoolean("smartIndentsAfterPaste", enabled); return this; } - - @property double fontGamma() { - double gamma = uiSettings.getFloating("fontGamma", 1.0); - if (gamma >= 0.5 && gamma <= 2.0) - return gamma; - return 1.0; - } - - @property HintingMode hintingMode() { - long mode = uiSettings.getInteger("hintingMode", HintingMode.Normal); - if (mode >= HintingMode.Normal && mode <= HintingMode.Light) - return cast(HintingMode)mode; - return HintingMode.Normal; - } - - @property int minAntialiasedFontSize() { - long sz = uiSettings.getInteger("minAntialiasedFontSize", 0); - if (sz >= 0) - return cast(int)sz; - return 0; - } - - @property string debuggerExecutable() { - return debuggerSettings.getString("executable", "gdb"); - } - - @property string terminalExecutable() { - return terminalSettings.getString("executable", "xterm"); - } - - @property string dubExecutable() { - return dubSettings.getString("executable", "dub"); - } - - @property string dubAdditionalParams() { - return dubSettings.getString("additional_params", ""); - } -} +public import dlangide.workspace.projectsettings; +public import dlangide.workspace.idesettings; +public import dlangide.workspace.workspacesettings; /// create DlangIDE settings pages tree SettingsPage createSettingsPages() { @@ -253,3 +78,23 @@ SettingsPage createSettingsPages() { StringListValue(2000, "2.0 "d)]); return res; } + +/// create DlangIDE settings pages tree +SettingsPage createProjectSettingsPages() { + SettingsPage res = new SettingsPage("", UIString(""d)); + SettingsPage build = res.addChild("build", UIString("Build"d)); + build.addStringComboBox("build/toolchain", UIString("Toolchain"d), [ + StringListValue("default", "Default"d), + StringListValue("dmd", "DMD"d), + StringListValue("ldc", "LDC"d), + StringListValue("gdc", "GDC"d)]); + build.addStringComboBox("build/arch", UIString("Architecture"d), [ + StringListValue("default", "Default"d), + StringListValue("x86", "x86"d), + StringListValue("x86_64", "x86_6"d)]); + SettingsPage dbg = res.addChild("debug", UIString("Run and Debug"d)); + dbg.addStringEdit("debug/run_args", UIString("Command line args"d), ""); + dbg.addDirNameEdit("debug/working_dir", UIString("Working directory"d), ""); + dbg.addCheckbox("debug/external_console", UIString("Run in external console"d), true); + return res; +} diff --git a/src/dlangide/workspace/idesettings.d b/src/dlangide/workspace/idesettings.d new file mode 100644 index 0000000..424dc11 --- /dev/null +++ b/src/dlangide/workspace/idesettings.d @@ -0,0 +1,179 @@ +module dlangide.workspace.idesettings; + +import dlangui.core.settings; +import dlangui.core.i18n; +import dlangui.graphics.fonts; + +const AVAILABLE_THEMES = ["ide_theme_default", "ide_theme_dark"]; +const AVAILABLE_LANGUAGES = ["en", "ru", "es"]; + +class IDESettings : SettingsFile { + + this(string filename) { + super(filename); + } + + override void updateDefaults() { + Setting ed = editorSettings(); + ed.setBooleanDef("useSpacesForTabs", true); + ed.setIntegerDef("tabSize", 4); + ed.setBooleanDef("smartIndents", true); + ed.setBooleanDef("smartIndentsAfterPaste", true); + Setting ui = uiSettings(); + ui.setStringDef("theme", "ide_theme_default"); + ui.setStringDef("language", "en"); + ui.setIntegerDef("hintingMode", 1); + ui.setIntegerDef("minAntialiasedFontSize", 0); + ui.setFloatingDef("fontGamma", 0.8); + debuggerSettings.setStringDef("executable", "gdb"); + terminalSettings.setStringDef("executable", "xterm"); + dubSettings.setStringDef("executable", "dub"); + dubSettings.setStringDef("additional_params", ""); + dmdToolchainSettings.setStringDef("executable", "dmd"); + ldcToolchainSettings.setStringDef("executable", "ldc2"); + gdcToolchainSettings.setStringDef("executable", "gdc"); + } + + /// override to do something after loading - e.g. set defaults + override void afterLoad() { + } + + @property Setting editorSettings() { + Setting res = _setting.objectByPath("editors/textEditor", true); + return res; + } + + @property Setting uiSettings() { + Setting res = _setting.objectByPath("interface", true); + return res; + } + + @property Setting debuggerSettings() { + Setting res = _setting.objectByPath("dlang/debugger", true); + return res; + } + + @property Setting terminalSettings() { + Setting res = _setting.objectByPath("dlang/terminal", true); + return res; + } + + @property Setting dubSettings() { + Setting res = _setting.objectByPath("dlang/dub", true); + return res; + } + + @property Setting dmdToolchainSettings() { + Setting res = _setting.objectByPath("dlang/toolchains/dmd", true); + return res; + } + + @property Setting ldcToolchainSettings() { + Setting res = _setting.objectByPath("dlang/toolchains/ldc", true); + return res; + } + + @property Setting gdcToolchainSettings() { + Setting res = _setting.objectByPath("dlang/toolchains/gdc", true); + return res; + } + + /// theme + @property string uiTheme() { + return limitString(uiSettings.getString("theme", "ide_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); + } + /// text editor setting, true if need to insert spaces instead of tabs + @property IDESettings useSpacesForTabs(bool v) { + editorSettings.setBoolean("useSpacesForTabs", v); + return this; + } + + /// text editor setting, true if need to insert spaces instead of tabs + @property int tabSize() { + return limitInt(editorSettings.getInteger("tabSize", 4), 1, 16); + } + /// text editor setting, true if need to insert spaces instead of tabs + @property IDESettings tabSize(int v) { + editorSettings.setInteger("tabSize", limitInt(v, 1, 16)); + return this; + } + + /// true if smart indents are enabled + @property bool smartIndents() { return editorSettings.getBoolean("smartIndents", true); } + /// set smart indents enabled flag + @property IDESettings smartIndents(bool enabled) { editorSettings.setBoolean("smartIndents", enabled); return this; } + + /// true if smart indents are enabled + @property bool smartIndentsAfterPaste() { return editorSettings.getBoolean("smartIndentsAfterPaste", true); } + /// set smart indents enabled flag + @property IDESettings smartIndentsAfterPaste(bool enabled) { editorSettings.setBoolean("smartIndentsAfterPaste", enabled); return this; } + + @property double fontGamma() { + double gamma = uiSettings.getFloating("fontGamma", 1.0); + if (gamma >= 0.5 && gamma <= 2.0) + return gamma; + return 1.0; + } + + @property HintingMode hintingMode() { + long mode = uiSettings.getInteger("hintingMode", HintingMode.Normal); + if (mode >= HintingMode.Normal && mode <= HintingMode.Light) + return cast(HintingMode)mode; + return HintingMode.Normal; + } + + @property int minAntialiasedFontSize() { + long sz = uiSettings.getInteger("minAntialiasedFontSize", 0); + if (sz >= 0) + return cast(int)sz; + return 0; + } + + @property string debuggerExecutable() { + return debuggerSettings.getString("executable", "gdb"); + } + + @property string terminalExecutable() { + return terminalSettings.getString("executable", "xterm"); + } + + @property string dubExecutable() { + return dubSettings.getString("executable", "dub"); + } + + @property string dubAdditionalParams() { + return dubSettings.getString("additional_params", ""); + } + + string getToolchainSettings(string toolchainName) { + if (toolchainName.equal("dmd")) + return dmdToolchainSettings.getString("executable", "dmd"); + if (toolchainName.equal("gdc")) + return dmdToolchainSettings.getString("executable", "gdc"); + if (toolchainName.equal("ldc")) + return dmdToolchainSettings.getString("executable", "ldc2"); + return null; + } + +} + diff --git a/src/dlangide/workspace/projectsettings.d b/src/dlangide/workspace/projectsettings.d new file mode 100644 index 0000000..de8fa18 --- /dev/null +++ b/src/dlangide/workspace/projectsettings.d @@ -0,0 +1,51 @@ +module dlangide.workspace.projectsettings; + +import dlangui.core.settings; +import dlangui.core.i18n; + +import dlangide.workspace.idesettings; + +const AVAILABLE_TOOLCHAINS = ["default", "dmd", "ldc", "gdc"]; +const AVAILABLE_ARCH = ["default", "x86", "x86_64"]; + +class ProjectSettings : SettingsFile { + + this(string filename) { + super(filename); + } + + /// override to do something after loading - e.g. set defaults + override void afterLoad() { + } + + override void updateDefaults() { + Setting build = buildSettings(); + build.setStringDef("toolchain", "default"); + build.setStringDef("arch", "default"); + Setting dbg = debugSettings(); + dbg.setBooleanDef("external_console", true); + } + + @property Setting buildSettings() { + Setting res = _setting.objectByPath("build", true); + return res; + } + + @property Setting debugSettings() { + Setting res = _setting.objectByPath("debug", true); + return res; + } + + string getToolchain(IDESettings idesettings) { + string cfg = buildSettings.getString("toolchain"); + return idesettings.getToolchainSettings(cfg); + } + + string getArch(IDESettings idesettings) { + string cfg = buildSettings.getString("arch"); + if (cfg.equal("default")) + return null; + return cfg; + } +} + diff --git a/src/dlangide/workspace/workspacesettings.d b/src/dlangide/workspace/workspacesettings.d new file mode 100644 index 0000000..ec6a1da --- /dev/null +++ b/src/dlangide/workspace/workspacesettings.d @@ -0,0 +1,20 @@ +module dlangide.workspace.workspacesettings; + +import dlangui.core.settings; +import dlangui.core.i18n; + +class WorkspaceSettings : SettingsFile { + + this(string filename) { + super(filename); + } + + /// override to do something after loading - e.g. set defaults + override void afterLoad() { + } + + override void updateDefaults() { + } + +} +