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", UIString.fromId("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 import std.conv : to; 66 // Root page 67 SettingsPage res = new SettingsPage("", UIString.fromRaw(""d)); 68 69 // UI settings page 70 SettingsPage ui = res.addChild("interface", UIString.fromId("OPTION_INTERFACE"c)); 71 ui.addStringComboBox("interface/theme", UIString.fromId("OPTION_THEME"c), [ 72 StringListValue("ide_theme_default", "OPTION_DEFAULT"c), 73 StringListValue("ide_theme_dark", "OPTION_DARK"c)]); 74 ui.addStringComboBox("interface/language", UIString.fromId("OPTION_LANGUAGE"c), [ 75 StringListValue("en", "MENU_VIEW_LANGUAGE_EN"c), 76 StringListValue("ru", "MENU_VIEW_LANGUAGE_RU"c), 77 StringListValue("es", "MENU_VIEW_LANGUAGE_ES"c), 78 StringListValue("cs", "MENU_VIEW_LANGUAGE_CS"c)]); 79 80 // UI font faces 81 ui.addStringComboBox("interface/uiFontFace", UIString.fromId("OPTION_FONT_FACE"c), 82 createFaceList(false)); 83 ui.addIntComboBox("interface/uiFontSize", UIString.fromId("OPTION_FONT_SIZE"c), 84 createIntValueList([6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,30,32])); 85 86 87 ui.addIntComboBox("interface/hintingMode", UIString.fromId("OPTION_FONT_HINTING"c), [StringListValue(0, "OPTION_FONT_HINTING_NORMAL"c), 88 StringListValue(1, "OPTION_FONT_HINTING_FORCE"c), 89 StringListValue(2, "OPTION_FONT_HINTING_DISABLED"c), StringListValue(3, "OPTION_FONT_HINTING_LIGHT"c)]); 90 ui.addIntComboBox("interface/minAntialiasedFontSize", UIString.fromId("OPTION_FONT_ANTIALIASING"c), 91 [StringListValue(0, "OPTION_FONT_ANTIALIASING_ALWAYS_ON"c), 92 StringListValue(12, "12"d), 93 StringListValue(14, "14"d), 94 StringListValue(16, "16"d), 95 StringListValue(20, "20"d), 96 StringListValue(24, "24"d), 97 StringListValue(32, "32"d), 98 StringListValue(48, "48"d), 99 StringListValue(255, "OPTION_FONT_ANTIALIASING_ALWAYS_OFF"c)]); 100 ui.addFloatComboBox("interface/fontGamma", UIString.fromId("OPTION_FONT_GAMMA"c), 101 [ 102 StringListValue(500, "0.5 "d), 103 StringListValue(600, "0.6 "d), 104 StringListValue(700, "0.7 "d), 105 StringListValue(800, "0.8 "d), 106 StringListValue(850, "0.85 "d), 107 StringListValue(900, "0.9 "d), 108 StringListValue(950, "0.95 "d), 109 StringListValue(1000, "1.0 "d), 110 StringListValue(1050, "1.05 "d), 111 StringListValue(1100, "1.1 "d), 112 StringListValue(1150, "1.15 "d), 113 StringListValue(1200, "1.2 "d), 114 StringListValue(1250, "1.25 "d), 115 StringListValue(1300, "1.3 "d), 116 StringListValue(1400, "1.4 "d), 117 StringListValue(1500, "1.5 "d), 118 StringListValue(1700, "1.7 "d), 119 StringListValue(2000, "2.0 "d)]); 120 121 ui.addIntComboBox("interface/screenDpiOverride", UIString.fromId("OPTION_SCREEN_DPI_OVERRIDE"c), 122 [StringListValue(0, UIString.fromId("OPTION_SCREEN_DPI_OVERRIDE_NONE"c).value ~ " ("d ~ to!dstring(systemScreenDPI) ~ ")"d), 123 StringListValue(72, "72"d), 124 StringListValue(96, "96"d), 125 StringListValue(120, "120"d), 126 StringListValue(140, "140"d), 127 StringListValue(150, "150"d), 128 StringListValue(300, "300"d), 129 StringListValue(400, "400"d), 130 StringListValue(600, "600"d)]); 131 132 SettingsPage ed = res.addChild("editors", UIString.fromId("OPTION_EDITORS"c)); 133 SettingsPage texted = ed.addChild("editors/textEditor", UIString.fromId("OPTION_TEXT_EDITORS"c)); 134 135 // editor font faces 136 texted.addStringComboBox("editors/textEditor/fontFace", UIString.fromId("OPTION_FONT_FACE"c), createFaceList(true)); 137 texted.addIntComboBox("editors/textEditor/fontSize", UIString.fromId("OPTION_FONT_SIZE"c), 138 createIntValueList([6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,30,32])); 139 140 texted.addNumberEdit("editors/textEditor/tabSize", UIString.fromId("OPTION_TAB"c), 1, 16, 4); 141 texted.addCheckbox("editors/textEditor/useSpacesForTabs", UIString.fromId("OPTION_USE_SPACES"c)); 142 texted.addCheckbox("editors/textEditor/smartIndents", UIString.fromId("OPTION_SMART_INDENTS"c)); 143 texted.addCheckbox("editors/textEditor/smartIndentsAfterPaste", UIString.fromId("OPTION_SMART_INDENTS_PASTE"c)); 144 texted.addCheckbox("editors/textEditor/showWhiteSpaceMarks", UIString.fromId("OPTION_SHOW_SPACES"c)); 145 texted.addCheckbox("editors/textEditor/showTabPositionMarks", UIString.fromId("OPTION_SHOW_TABS"c)); 146 147 // Common page 148 SettingsPage common = res.addChild("common", UIString.fromId("OPTION_COMMON"c)); 149 common.addCheckbox("common/autoOpenLastProject", UIString.fromId("OPTION_AUTO_OPEN_LAST_PROJECT"c)); 150 151 152 SettingsPage dlang = res.addChild("dlang", UIString.fromRaw("D"d)); 153 SettingsPage dub = dlang.addChild("dlang/dub", UIString.fromRaw("DUB"d)); 154 dub.addExecutableFileNameEdit("dlang/dub/executable", UIString.fromId("OPTION_DUB_EXECUTABLE"c), "dub"); 155 dub.addStringEdit("dlang/dub/additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), ""); 156 SettingsPage rdmd = dlang.addChild("dlang/rdmd", UIString.fromRaw("rdmd"d)); 157 rdmd.addExecutableFileNameEdit("dlang/rdmd/executable", UIString.fromId("OPTION_RDMD_EXECUTABLE"c), "rdmd"); 158 rdmd.addStringEdit("dlang/rdmd/additional_params", UIString.fromId("OPTION_RDMD_ADDITIONAL_PARAMS"c), ""); 159 SettingsPage ddebug = dlang.addChild("dlang/debugger", UIString.fromId("OPTION_DEBUGGER"c)); 160 version (Windows) { 161 ddebug.addExecutableFileNameEdit("dlang/debugger/executable", UIString.fromId("OPTION_DEBUGGER_EXECUTABLE"c), "gdb"); 162 } else { 163 ddebug.addExecutableFileNameEdit("dlang/debugger/executable", UIString.fromId("OPTION_DEBUGGER_EXECUTABLE"c), "mago-mi"); 164 } 165 SettingsPage terminal = dlang.addChild("dlang/terminal", UIString.fromId("OPTION_TERMINAL"c)); 166 terminal.addExecutableFileNameEdit("dlang/terminal/executable", UIString.fromId("OPTION_TERMINAL_EXECUTABLE"c), "xterm"); 167 168 SettingsPage toolchains = dlang.addChild("dlang/toolchains", UIString.fromId("OPTION_TOOLCHAINS"c)); 169 SettingsPage dmdtoolchain = toolchains.addChild("dlang/toolchains/dmd", UIString.fromRaw("DMD"d)); 170 dmdtoolchain.addExecutableFileNameEdit("dlang/toolchains/dmd/executable", UIString.fromId("OPTION_DMD_EXECUTABLE"c), "dmd"); 171 dmdtoolchain.addStringEdit("dlang/toolchains/dmd/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), ""); 172 SettingsPage ldctoolchain = toolchains.addChild("dlang/toolchains/ldc", UIString.fromRaw("LDC"d)); 173 ldctoolchain.addExecutableFileNameEdit("dlang/toolchains/ldc/executable", UIString.fromId("OPTION_LDC2_EXECUTABLE"c), "ldc2"); 174 ldctoolchain.addStringEdit("dlang/toolchains/ldc/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), ""); 175 SettingsPage ldmdtoolchain = toolchains.addChild("dlang/toolchains/ldmd", UIString.fromRaw("LDMD"d)); 176 ldmdtoolchain.addExecutableFileNameEdit("dlang/toolchains/ldmd/executable", UIString.fromId("OPTION_LDMD2_EXECUTABLE"c), "ldmd2"); 177 ldmdtoolchain.addStringEdit("dlang/toolchains/ldmd/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), ""); 178 SettingsPage gdctoolchain = toolchains.addChild("dlang/toolchains/gdc", UIString.fromRaw("GDC"d)); 179 gdctoolchain.addExecutableFileNameEdit("dlang/toolchains/gdc/executable", UIString.fromId("OPTION_GDC_EXECUTABLE"c), "gdc"); 180 gdctoolchain.addStringEdit("dlang/toolchains/gdc/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), ""); 181 182 return res; 183 } 184 185 /// create DlangIDE settings pages tree 186 SettingsPage createProjectSettingsPages() { 187 SettingsPage res = new SettingsPage("", UIString.fromRaw(""d)); 188 189 SettingsPage build = res.addChild("build", UIString.fromId("OPTION_BUILD"c)); 190 build.addStringComboBox("build/toolchain", UIString.fromId("OPTION_TOOLCHAIN"c), [ 191 StringListValue("default", UIString.fromId("OPTION_DEFAULT"c)), 192 StringListValue("dmd", "DMD"d), 193 StringListValue("ldc", "LDC"d), 194 StringListValue("ldmd", "LDMD"d), 195 StringListValue("gdc", "GDC"d)]); 196 build.addStringComboBox("build/arch", UIString.fromId("OPTION_ARCHITECTURE"c), [ 197 StringListValue("default", UIString.fromId("OPTION_DEFAULT"c)), 198 StringListValue("x86", "x86"d), 199 StringListValue("x86_64", "x86_64"d), 200 StringListValue("arm", "arm"d), 201 StringListValue("arm64", "arm64"d), 202 ]); 203 build.addCheckbox("build/verbose", UIString.fromId("OPTION_VERBOSE"c), true); 204 build.addStringEdit("build/dub_additional_params", UIString.fromId("OPTION_DUB_ADDITIONAL_PARAMS"c), ""); 205 206 SettingsPage dbg = res.addChild("debug", UIString.fromId("OPTION_RUN_DEBUG"c)); 207 dbg.addStringEdit("debug/run_args", UIString.fromId("OPTION_COMMAND_LINE"c), ""); 208 dbg.addDirNameEdit("debug/working_dir", UIString.fromId("OPTION_WORKING_DIR"c), ""); 209 dbg.addCheckbox("debug/external_console", UIString.fromId("OPTION_RUN_IN_EXTERNAL_CONSOLE"c), false); 210 211 return res; 212 }