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