IDE settings, initial implementation

This commit is contained in:
Vadim Lopatin 2015-02-17 17:41:19 +03:00
parent 250ee0c224
commit 7778bd3ecf
4 changed files with 79 additions and 1 deletions

View File

@ -224,6 +224,7 @@
<File path="src\dlangide\ui\frame.d" />
<File path="src\dlangide\ui\homescreen.d" />
<File path="src\dlangide\ui\outputpanel.d" />
<File path="src\dlangide\ui\settings.d" />
<File path="src\dlangide\ui\wspanel.d" />
</Folder>
<Folder name="workspace">

View File

@ -13,6 +13,7 @@ import ddc.lexer.tokenizer;
import dlangide.workspace.workspace;
import dlangide.workspace.project;
import dlangide.ui.commands;
import dlangide.ui.settings;
import dlangide.tools.d.dsyntaxhighlighter;
import std.algorithm;
@ -41,6 +42,20 @@ class DSourceEdit : SourceEdit {
this() {
this("SRCEDIT");
}
protected IDESettings _settings;
@property DSourceEdit settings(IDESettings s) {
_settings = s;
return this;
}
@property IDESettings settings() {
return _settings;
}
void applySettings() {
if (!_settings)
return;
tabSize = _settings.tabSize;
useSpacesForTabs = _settings.useSpacesForTabs;
}
protected ProjectSourceFile _projectSourceFile;
@property ProjectSourceFile projectSourceFile() { return _projectSourceFile; }
/// load by filename

View File

@ -21,6 +21,7 @@ import dlangide.ui.wspanel;
import dlangide.ui.outputpanel;
import dlangide.ui.dsourceedit;
import dlangide.ui.homescreen;
import dlangide.ui.settings;
import dlangide.tools.d.dcdserver;
import dlangide.workspace.workspace;
import dlangide.workspace.project;
@ -66,6 +67,7 @@ class IDEFrame : AppFrame {
TabWidget _tabs;
EditorTool _editorTool;
DCDServer _dcdServer;
IDESettings _settings;
dstring frameWindowCaptionSuffix = "DLangIDE"d;
@ -81,7 +83,10 @@ class IDEFrame : AppFrame {
_appName = "dlangide";
_editorTool = new DEditorTool(this);
_dcdServer = new DCDServer();
_settings = new IDESettings(buildNormalizedPath(settingsDir, "settings.json"));
_settings.load();
_settings.updateDefaults();
_settings.save();
super.init();
}
@ -100,6 +105,9 @@ class IDEFrame : AppFrame {
return openSourceFile(file.filename, file, activate);
}
/// returns global IDE settings
@property IDESettings settings() { return _settings; }
///
bool onCompilerLogIssueClick(dstring filename, int line, int column)
{
@ -149,6 +157,7 @@ class IDEFrame : AppFrame {
TabItem tab = _tabs.tab(filename);
tab.objectParam = file;
editor.onModifiedStateChangeListener = &onModifiedStateChange;
editor.settings(settings).applySettings();
_tabs.selectTab(index, true);
} else {
destroy(editor);

View File

@ -0,0 +1,53 @@
module dlangide.ui.settings;
import dlangui.core.settings;
class IDESettings : SettingsFile {
this(string filename) {
super(filename);
}
override void updateDefaults() {
Setting ed = editorSettings();
ed.setBooleanDef("useSpacesForTabs", true);
ed.setIntegerDef("tabSize", 4);
}
/// 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;
}
static int limitInt(long value, int minvalue, int maxvalue) {
if (value < minvalue)
return minvalue;
else if (value > maxvalue)
return maxvalue;
return cast(int)value;
}
/// 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;
}
}