From 1dfe3d581d892f4b6d06e803994057407d44238e Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 3 Mar 2015 17:57:52 +0300 Subject: [PATCH] edit/preferences dialog, part 1 --- src/dlangide/ui/frame.d | 18 ++++++++++++++++++ src/dlangide/ui/settings.d | 17 +++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/dlangide/ui/frame.d b/src/dlangide/ui/frame.d index 3cc18f5..60a59ec 100644 --- a/src/dlangide/ui/frame.d +++ b/src/dlangide/ui/frame.d @@ -13,6 +13,7 @@ import dlangui.widgets.combobox; import dlangui.widgets.popup; import dlangui.dialogs.dialog; import dlangui.dialogs.filedlg; +import dlangui.dialogs.settingsdialog; import dlangui.core.stdaction; import dlangui.core.files; @@ -489,6 +490,8 @@ class IDEFrame : AppFrame { /// override to handle specific actions state (e.g. change enabled state for supported actions) override bool handleActionStateRequest(const Action a) { switch (a.id) { + case IDEActions.EditPreferences: + return true; case IDEActions.FileExit: case IDEActions.FileOpen: case IDEActions.WindowCloseAllDocuments: @@ -619,6 +622,9 @@ class IDEFrame : AppFrame { auto results = _editorTool.getCompletions(currentEditor, currentEditor.getCaretPosition); currentEditor.showCompletionPopup(results); return true; + case IDEActions.EditPreferences: + showPreferences(); + return true; default: return super.handleAction(a); } @@ -626,6 +632,18 @@ class IDEFrame : AppFrame { return false; } + void showPreferences() { + Setting s = _settings.copySettings(); + SettingsDialog dlg = new SettingsDialog(UIString("DlangIDE settings"d), window, s, createSettingsPages()); + dlg.onDialogResult = delegate(Dialog dlg, const Action result) { + if (result.id == ACTION_APPLY.id) { + _settings.applySettings(s); + _settings.save(); + } + }; + dlg.show(); + } + private bool loadProject(Project project) { if (!project.load()) { _logPanel.logLine("Cannot read project " ~ project.filename); diff --git a/src/dlangide/ui/settings.d b/src/dlangide/ui/settings.d index 0be6ba1..269a5e8 100644 --- a/src/dlangide/ui/settings.d +++ b/src/dlangide/ui/settings.d @@ -1,6 +1,8 @@ module dlangide.ui.settings; import dlangui.core.settings; +import dlangui.core.i18n; +import dlangui.dialogs.settingsdialog; const AVAILABLE_THEMES = ["theme_default", "theme_dark"]; @@ -103,3 +105,18 @@ class IDESettings : SettingsFile { /// set smart indents enabled flag @property IDESettings smartIndentsAfterPaste(bool enabled) { editorSettings.setBoolean("smartIndentsAfterPaste", enabled); return this; } } + +/// create DlangIDE settings pages tree +SettingsPage createSettingsPages() { + SettingsPage res = new SettingsPage("", UIString(""d)); + SettingsPage ed = res.addChild("editors", UIString("Editors"d)); + SettingsPage texted = ed.addChild("editors/textEditor", UIString("Text Editors"d)); + texted.addCheckbox("editors/textEditor/useSpacesForTabs", UIString("Use spaces for tabs"d)); + texted.addCheckbox("editors/textEditor/smartIndents", UIString("Smart indents"d)); + texted.addCheckbox("editors/textEditor/smartIndentsAfterPaste", UIString("Smart indent after paste"d)); + //ed.setIntegerDef("tabSize", 4); + SettingsPage ui = res.addChild("interface", UIString("Interface"d)); + //ui.setStringDef("theme", "theme_default"); + //ui.setStringDef("language", "en"); + return res; +}