1 module dlangide.ui.settings;
2 
3 import dlangui.core.settings;
4 import dlangui.core.i18n;
5 import dlangui.graphics.fonts;
6 import dlangui.widgets.lists;
7 import dlangui.dialogs.settingsdialog;
8 
9 public import dlangide.workspace.projectsettings;
10 public import dlangide.workspace.idesettings;
11 public import dlangide.workspace.workspacesettings;
12 
13 StringListValue[] createFaceList(bool monospaceFirst) {
14     StringListValue[] faces;
15     faces.assumeSafeAppend();
16     faces ~= StringListValue("Default", "OPTION_DEFAULT"c);
17     import dlangui.graphics.fonts;
18     import std.utf : toUTF32;
19     FontFaceProps[] allFaces = FontManager.instance.getFaces();
20     import std.algorithm.sorting : sort;
21     auto fontCompMonospaceFirst = function(ref FontFaceProps a, ref FontFaceProps b) {
22         if (a.family == FontFamily.MonoSpace && b.family != FontFamily.MonoSpace)
23             return -1;
24         if (a.family != FontFamily.MonoSpace && b.family == FontFamily.MonoSpace)
25             return 1;
26         if (a.face < b.face)
27             return -1;
28         if (a.face > b.face)
29             return 1;
30         return 0;
31     };
32     auto fontComp = function(ref FontFaceProps a, ref FontFaceProps b) {
33         if (a.face < b.face)
34             return -1;
35         if (a.face > b.face)
36             return 1;
37         return 0;
38     };
39     //auto sorted = allFaces.sort!((a, b) => (a.family == FontFamily.MonoSpace && b.family != FontFamily.MonoSpace) || (a.face < b.face));
40     auto sorted = sort!((a, b) => (monospaceFirst ? fontCompMonospaceFirst(a, b) : fontComp(a, b)) < 0)(allFaces);
41 
42     //allFaces = allFaces.sort!((a, b) => a.family == FontFamily.MonoSpace && b.family == FontFamily.MonoSpace || a.face < b.face);
43     //for (int i = 0; i < allFaces.length; i++) {
44     foreach (face; sorted) {
45         if (face.family == FontFamily.MonoSpace)
46             faces ~= StringListValue(face.face, "*"d ~ toUTF32(face.face));
47         else
48             faces ~= StringListValue(face.face, toUTF32(face.face));
49     }
50     return faces;
51 }
52 
53 StringListValue[] createIntValueList(int[] values, dstring suffix = ""d) {
54     import std.conv : to;
55     StringListValue[] res;
56     res.assumeSafeAppend();
57     foreach(n; values) {
58         res ~= StringListValue(n, to!dstring(n) ~ suffix);
59     }
60     return res;
61 }
62 
63 /// create DlangIDE settings pages tree
64 SettingsPage createSettingsPages() {
65     // Root page
66     SettingsPage res = new SettingsPage("", UIString.fromRaw(""d));
67 
68     // UI settings page
69     SettingsPage ui = res.addChild("interface", UIString.fromId("OPTION_INTERFACE"c));
70     ui.addStringComboBox("interface/theme", UIString.fromId("OPTION_THEME"c), [
71             StringListValue("ide_theme_default", "OPTION_DEFAULT"c), 
72             StringListValue("ide_theme_dark", "OPTION_DARK"c)]);
73     ui.addStringComboBox("interface/language", UIString.fromId("OPTION_LANGUAGE"c), [
74             StringListValue("en", "MENU_VIEW_LANGUAGE_EN"c), 
75             StringListValue("ru", "MENU_VIEW_LANGUAGE_RU"c), 
76             StringListValue("es", "MENU_VIEW_LANGUAGE_ES"c),
77 	    StringListValue("cs", "MENU_VIEW_LANGUAGE_CS"c)]);
78 
79     // UI font faces
80     ui.addStringComboBox("interface/uiFontFace", UIString.fromId("OPTION_FONT_FACE"c), 
81                       createFaceList(false));
82     ui.addIntComboBox("interface/uiFontSize", UIString.fromId("OPTION_FONT_SIZE"c), 
83                       createIntValueList([6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,30,32]));
84 
85 
86     ui.addIntComboBox("interface/hintingMode", UIString.fromId("OPTION_FONT_HINTING"c), [StringListValue(0, "OPTION_FONT_HINTING_NORMAL"c), 
87                 StringListValue(1, "OPTION_FONT_HINTING_FORCE"c), 
88                 StringListValue(2, "OPTION_FONT_HINTING_DISABLED"c), StringListValue(3, "OPTION_FONT_HINTING_LIGHT"c)]);
89     ui.addIntComboBox("interface/minAntialiasedFontSize", UIString.fromId("OPTION_FONT_ANTIALIASING"c), 
90                       [StringListValue(0, "OPTION_FONT_ANTIALIASING_ALWAYS_ON"c), 
91                       StringListValue(12, "12"d), 
92                       StringListValue(14, "14"d), 
93                       StringListValue(16, "16"d), 
94                       StringListValue(20, "20"d), 
95                       StringListValue(24, "24"d), 
96                       StringListValue(32, "32"d), 
97                       StringListValue(48, "48"d), 
98                       StringListValue(255, "OPTION_FONT_ANTIALIASING_ALWAYS_OFF"c)]);
99     ui.addFloatComboBox("interface/fontGamma", UIString.fromId("OPTION_FONT_GAMMA"c), 
100                    [
101                     StringListValue(500,  "0.5   "d),
102                     StringListValue(600,  "0.6   "d),
103                     StringListValue(700,  "0.7   "d),
104                     StringListValue(800,  "0.8   "d),
105                     StringListValue(850,  "0.85  "d),
106                     StringListValue(900,  "0.9   "d),
107                     StringListValue(950,  "0.95  "d),
108                     StringListValue(1000, "1.0   "d),
109                     StringListValue(1050, "1.05  "d),
110                     StringListValue(1100, "1.1   "d), 
111                     StringListValue(1150, "1.15  "d), 
112                     StringListValue(1200, "1.2   "d), 
113                     StringListValue(1250, "1.25  "d), 
114                     StringListValue(1300, "1.3   "d), 
115                     StringListValue(1400, "1.4   "d), 
116                     StringListValue(1500, "1.5   "d), 
117                     StringListValue(1700, "1.7   "d), 
118                     StringListValue(2000, "2.0   "d)]);
119 
120     SettingsPage ed = res.addChild("editors", UIString.fromId("OPTION_EDITORS"c));
121     SettingsPage texted = ed.addChild("editors/textEditor", UIString.fromId("OPTION_TEXT_EDITORS"c));
122 
123     // editor font faces
124     texted.addStringComboBox("editors/textEditor/fontFace", UIString.fromId("OPTION_FONT_FACE"c), createFaceList(true));
125     texted.addIntComboBox("editors/textEditor/fontSize", UIString.fromId("OPTION_FONT_SIZE"c),
126                       createIntValueList([6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,30,32]));
127 
128     texted.addNumberEdit("editors/textEditor/tabSize", UIString.fromId("OPTION_TAB"c), 1, 16, 4);
129     texted.addCheckbox("editors/textEditor/useSpacesForTabs", UIString.fromId("OPTION_USE_SPACES"c));
130     texted.addCheckbox("editors/textEditor/smartIndents", UIString.fromId("OPTION_SMART_INDENTS"c));
131     texted.addCheckbox("editors/textEditor/smartIndentsAfterPaste", UIString.fromId("OPTION_SMART_INDENTS_PASTE"c));
132     texted.addCheckbox("editors/textEditor/showWhiteSpaceMarks", UIString.fromId("OPTION_SHOW_SPACES"c));
133     texted.addCheckbox("editors/textEditor/showTabPositionMarks", UIString.fromId("OPTION_SHOW_TABS"c));
134 
135     // Common page
136     SettingsPage common = res.addChild("common", UIString.fromId("OPTION_COMMON"c));
137     common.addCheckbox("common/autoOpenLastProject", UIString.fromId("OPTION_AUTO_OPEN_LAST_PROJECT"c));
138 
139 
140     SettingsPage dlang = res.addChild("dlang", UIString.fromRaw("D"d));
141     SettingsPage dub = dlang.addChild("dlang/dub", UIString.fromRaw("DUB"d));
142     dub.addExecutableFileNameEdit("dlang/dub/executable", UIString.fromId("OPTION_DUB_EXECUTABLE"c), "dub");
143     dub.addStringEdit("dlang/dub/additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), "");
144     SettingsPage rdmd = dlang.addChild("dlang/rdmd", UIString.fromRaw("rdmd"d));
145     rdmd.addExecutableFileNameEdit("dlang/rdmd/executable", UIString.fromId("OPTION_RDMD_EXECUTABLE"c), "rdmd");
146     rdmd.addStringEdit("dlang/rdmd/additional_params", UIString.fromId("OPTION_RDMD_ADDITIONAL_PARAMS"c), "");
147     SettingsPage ddebug = dlang.addChild("dlang/debugger", UIString.fromId("OPTION_DEBUGGER"c));
148     version (Windows) {
149         ddebug.addExecutableFileNameEdit("dlang/debugger/executable", UIString.fromId("OPTION_DEBUGGER_EXECUTABLE"c), "gdb");
150     } else {
151         ddebug.addExecutableFileNameEdit("dlang/debugger/executable", UIString.fromId("OPTION_DEBUGGER_EXECUTABLE"c), "mago-mi");
152     }
153     SettingsPage terminal = dlang.addChild("dlang/terminal", UIString.fromId("OPTION_TERMINAL"c));
154     terminal.addExecutableFileNameEdit("dlang/terminal/executable", UIString.fromId("OPTION_TERMINAL_EXECUTABLE"c), "xterm");
155 
156     SettingsPage toolchains = dlang.addChild("dlang/toolchains", UIString.fromId("OPTION_TOOLCHANS"c));
157     SettingsPage dmdtoolchain = toolchains.addChild("dlang/toolchains/dmd", UIString.fromRaw("DMD"d));
158     dmdtoolchain.addExecutableFileNameEdit("dlang/toolchains/dmd/executable", UIString.fromId("OPTION_DMD_EXECUTABLE"c), "dmd");
159     dmdtoolchain.addStringEdit("dlang/toolchains/dmd/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), "");
160     SettingsPage ldctoolchain = toolchains.addChild("dlang/toolchains/ldc", UIString.fromRaw("LDC"d));
161     ldctoolchain.addExecutableFileNameEdit("dlang/toolchains/ldc/executable", UIString.fromId("OPTION_LDC2_EXECUTABLE"c), "ldc2");
162     ldctoolchain.addStringEdit("dlang/toolchains/ldc/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), "");
163     SettingsPage ldmdtoolchain = toolchains.addChild("dlang/toolchains/ldmd", UIString.fromRaw("LDMD"d));
164     ldmdtoolchain.addExecutableFileNameEdit("dlang/toolchains/ldmd/executable", UIString.fromId("OPTION_LDMD2_EXECUTABLE"c), "ldmd2");
165     ldmdtoolchain.addStringEdit("dlang/toolchains/ldmd/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), "");
166     SettingsPage gdctoolchain = toolchains.addChild("dlang/toolchains/gdc", UIString.fromRaw("GDC"d));
167     gdctoolchain.addExecutableFileNameEdit("dlang/toolchains/gdc/executable", UIString.fromId("OPTION_GDC_EXECUTABLE"c), "gdc");
168     gdctoolchain.addStringEdit("dlang/toolchains/gdc/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), "");
169 
170     return res;
171 }
172 
173 /// create DlangIDE settings pages tree
174 SettingsPage createProjectSettingsPages() {
175     SettingsPage res = new SettingsPage("", UIString.fromRaw(""d));
176 
177     SettingsPage build = res.addChild("build", UIString.fromRaw("Build"d));
178     build.addStringComboBox("build/toolchain", UIString.fromRaw("Toolchain"d), [
179             StringListValue("default", "Default"d), 
180             StringListValue("dmd", "DMD"d), 
181             StringListValue("ldc", "LDC"d), 
182             StringListValue("ldmd", "LDMD"d), 
183             StringListValue("gdc", "GDC"d)]);
184     build.addStringComboBox("build/arch", UIString.fromRaw("Architecture"d), [
185             StringListValue("default", "Default"d), 
186             StringListValue("x86", "x86"d), 
187             StringListValue("x86_64", "x86_64"d),
188             StringListValue("arm", "arm"d),
189             StringListValue("arm64", "arm64"d),
190     ]);
191     build.addCheckbox("build/verbose", UIString.fromRaw("Verbose"d), true);
192     build.addStringEdit("build/dub_additional_params", UIString.fromRaw("DUB additional params"d), "");
193 
194     SettingsPage dbg = res.addChild("debug", UIString.fromRaw("Run and Debug"d));
195     dbg.addStringEdit("debug/run_args", UIString.fromRaw("Command line args"d), "");
196     dbg.addDirNameEdit("debug/working_dir", UIString.fromRaw("Working directory"d), "");
197     dbg.addCheckbox("debug/external_console", UIString.fromRaw("Run in external console"d), false);
198 
199     return res;
200 }