editor_settings.cpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  1. /*************************************************************************/
  2. /* editor_settings.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_settings.h"
  31. #include "core/io/certs_compressed.gen.h"
  32. #include "core/io/compression.h"
  33. #include "core/io/config_file.h"
  34. #include "core/io/file_access_memory.h"
  35. #include "core/io/ip.h"
  36. #include "core/io/resource_loader.h"
  37. #include "core/io/resource_saver.h"
  38. #include "core/io/translation_loader_po.h"
  39. #include "core/os/dir_access.h"
  40. #include "core/os/file_access.h"
  41. #include "core/os/keyboard.h"
  42. #include "core/os/os.h"
  43. #include "core/project_settings.h"
  44. #include "core/version.h"
  45. #include "editor/doc_translations.gen.h"
  46. #include "editor/editor_node.h"
  47. #include "editor/editor_translations.gen.h"
  48. #include "scene/main/node.h"
  49. #include "scene/main/scene_tree.h"
  50. #include "scene/main/viewport.h"
  51. // PRIVATE METHODS
  52. Ref<EditorSettings> EditorSettings::singleton = NULL;
  53. // Properties
  54. bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
  55. _THREAD_SAFE_METHOD_
  56. bool changed = _set_only(p_name, p_value);
  57. if (changed) {
  58. emit_signal("settings_changed");
  59. }
  60. return true;
  61. }
  62. bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
  63. _THREAD_SAFE_METHOD_
  64. if (p_name.operator String() == "shortcuts") {
  65. Array arr = p_value;
  66. ERR_FAIL_COND_V(arr.size() && arr.size() & 1, true);
  67. for (int i = 0; i < arr.size(); i += 2) {
  68. String name = arr[i];
  69. Ref<InputEvent> shortcut = arr[i + 1];
  70. Ref<ShortCut> sc;
  71. sc.instance();
  72. sc->set_shortcut(shortcut);
  73. add_shortcut(name, sc);
  74. }
  75. return false;
  76. }
  77. bool changed = false;
  78. if (p_value.get_type() == Variant::NIL) {
  79. if (props.has(p_name)) {
  80. props.erase(p_name);
  81. changed = true;
  82. }
  83. } else {
  84. if (props.has(p_name)) {
  85. if (p_value != props[p_name].variant) {
  86. props[p_name].variant = p_value;
  87. changed = true;
  88. }
  89. } else {
  90. props[p_name] = VariantContainer(p_value, last_order++);
  91. changed = true;
  92. }
  93. if (save_changed_setting) {
  94. if (!props[p_name].save) {
  95. props[p_name].save = true;
  96. changed = true;
  97. }
  98. }
  99. }
  100. return changed;
  101. }
  102. bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
  103. _THREAD_SAFE_METHOD_
  104. if (p_name.operator String() == "shortcuts") {
  105. Array arr;
  106. for (const Map<String, Ref<ShortCut>>::Element *E = shortcuts.front(); E; E = E->next()) {
  107. Ref<ShortCut> sc = E->get();
  108. if (optimize_save) {
  109. if (!sc->has_meta("original")) {
  110. continue; //this came from settings but is not any longer used
  111. }
  112. Ref<InputEvent> original = sc->get_meta("original");
  113. if (sc->is_shortcut(original) || (original.is_null() && sc->get_shortcut().is_null()))
  114. continue; //not changed from default, don't save
  115. }
  116. arr.push_back(E->key());
  117. arr.push_back(sc->get_shortcut());
  118. }
  119. r_ret = arr;
  120. return true;
  121. }
  122. const VariantContainer *v = props.getptr(p_name);
  123. if (!v) {
  124. WARN_PRINT("EditorSettings::_get - Property not found: " + String(p_name));
  125. return false;
  126. }
  127. r_ret = v->variant;
  128. return true;
  129. }
  130. void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value) {
  131. set(p_name, p_value);
  132. props[p_name].initial = p_value;
  133. props[p_name].has_default_value = true;
  134. }
  135. struct _EVCSort {
  136. String name;
  137. Variant::Type type;
  138. int order;
  139. bool save;
  140. bool restart_if_changed;
  141. bool operator<(const _EVCSort &p_vcs) const { return order < p_vcs.order; }
  142. };
  143. void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
  144. _THREAD_SAFE_METHOD_
  145. const String *k = NULL;
  146. Set<_EVCSort> vclist;
  147. while ((k = props.next(k))) {
  148. const VariantContainer *v = props.getptr(*k);
  149. if (v->hide_from_editor)
  150. continue;
  151. _EVCSort vc;
  152. vc.name = *k;
  153. vc.order = v->order;
  154. vc.type = v->variant.get_type();
  155. vc.save = v->save;
  156. /*if (vc.save) { this should be implemented, but lets do after 3.1 is out.
  157. if (v->initial.get_type() != Variant::NIL && v->initial == v->variant) {
  158. vc.save = false;
  159. }
  160. }*/
  161. vc.restart_if_changed = v->restart_if_changed;
  162. vclist.insert(vc);
  163. }
  164. for (Set<_EVCSort>::Element *E = vclist.front(); E; E = E->next()) {
  165. int pinfo = 0;
  166. if (E->get().save || !optimize_save) {
  167. pinfo |= PROPERTY_USAGE_STORAGE;
  168. }
  169. if (!E->get().name.begins_with("_") && !E->get().name.begins_with("projects/")) {
  170. pinfo |= PROPERTY_USAGE_EDITOR;
  171. } else {
  172. pinfo |= PROPERTY_USAGE_STORAGE; //hiddens must always be saved
  173. }
  174. PropertyInfo pi(E->get().type, E->get().name);
  175. pi.usage = pinfo;
  176. if (hints.has(E->get().name))
  177. pi = hints[E->get().name];
  178. if (E->get().restart_if_changed) {
  179. pi.usage |= PROPERTY_USAGE_RESTART_IF_CHANGED;
  180. }
  181. p_list->push_back(pi);
  182. }
  183. p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
  184. }
  185. void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
  186. ERR_FAIL_COND(!p_info.has("name"));
  187. ERR_FAIL_COND(!p_info.has("type"));
  188. PropertyInfo pinfo;
  189. pinfo.name = p_info["name"];
  190. ERR_FAIL_COND(!props.has(pinfo.name));
  191. pinfo.type = Variant::Type(p_info["type"].operator int());
  192. ERR_FAIL_INDEX(pinfo.type, Variant::VARIANT_MAX);
  193. if (p_info.has("hint"))
  194. pinfo.hint = PropertyHint(p_info["hint"].operator int());
  195. if (p_info.has("hint_string"))
  196. pinfo.hint_string = p_info["hint_string"];
  197. add_property_hint(pinfo);
  198. }
  199. // Default configs
  200. bool EditorSettings::has_default_value(const String &p_setting) const {
  201. _THREAD_SAFE_METHOD_
  202. if (!props.has(p_setting))
  203. return false;
  204. return props[p_setting].has_default_value;
  205. }
  206. void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
  207. _THREAD_SAFE_METHOD_
  208. /* Languages */
  209. {
  210. String lang_hint = "en";
  211. String host_lang = OS::get_singleton()->get_locale();
  212. host_lang = TranslationServer::standardize_locale(host_lang);
  213. // Some locales are not properly supported currently in Godot due to lack of font shaping
  214. // (e.g. Arabic or Hindi), so even though we have work in progress translations for them,
  215. // we skip them as they don't render properly. (GH-28577)
  216. const Vector<String> locales_to_skip = String("ar,bn,fa,he,hi,ml,si,ta,te,ur").split(",");
  217. String best;
  218. EditorTranslationList *etl = _editor_translations;
  219. while (etl->data) {
  220. const String &locale = etl->lang;
  221. // Skip locales which we can't render properly (see above comment).
  222. // Test against language code without regional variants (e.g. ur_PK).
  223. String lang_code = locale.get_slice("_", 0);
  224. if (locales_to_skip.find(lang_code) != -1) {
  225. etl++;
  226. continue;
  227. }
  228. lang_hint += ",";
  229. lang_hint += locale;
  230. if (host_lang == locale) {
  231. best = locale;
  232. }
  233. if (best == String() && host_lang.begins_with(locale)) {
  234. best = locale;
  235. }
  236. etl++;
  237. }
  238. if (best == String()) {
  239. best = "en";
  240. }
  241. _initial_set("interface/editor/editor_language", best);
  242. set_restart_if_changed("interface/editor/editor_language", true);
  243. hints["interface/editor/editor_language"] = PropertyInfo(Variant::STRING, "interface/editor/editor_language", PROPERTY_HINT_ENUM, lang_hint, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  244. }
  245. /* Interface */
  246. // Editor
  247. _initial_set("interface/editor/display_scale", 0);
  248. hints["interface/editor/display_scale"] = PropertyInfo(Variant::INT, "interface/editor/display_scale", PROPERTY_HINT_ENUM, "Auto,75%,100%,125%,150%,175%,200%,Custom", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  249. _initial_set("interface/editor/custom_display_scale", 1.0f);
  250. hints["interface/editor/custom_display_scale"] = PropertyInfo(Variant::FLOAT, "interface/editor/custom_display_scale", PROPERTY_HINT_RANGE, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  251. _initial_set("interface/editor/main_font_size", 14);
  252. hints["interface/editor/main_font_size"] = PropertyInfo(Variant::INT, "interface/editor/main_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  253. _initial_set("interface/editor/code_font_size", 14);
  254. hints["interface/editor/code_font_size"] = PropertyInfo(Variant::INT, "interface/editor/code_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT);
  255. _initial_set("interface/editor/font_antialiased", true);
  256. _initial_set("interface/editor/font_hinting", 0);
  257. hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "Auto,None,Light,Normal", PROPERTY_USAGE_DEFAULT);
  258. _initial_set("interface/editor/main_font", "");
  259. hints["interface/editor/main_font"] = PropertyInfo(Variant::STRING, "interface/editor/main_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT);
  260. _initial_set("interface/editor/main_font_bold", "");
  261. hints["interface/editor/main_font_bold"] = PropertyInfo(Variant::STRING, "interface/editor/main_font_bold", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT);
  262. _initial_set("interface/editor/code_font", "");
  263. hints["interface/editor/code_font"] = PropertyInfo(Variant::STRING, "interface/editor/code_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT);
  264. _initial_set("interface/editor/dim_editor_on_dialog_popup", true);
  265. _initial_set("interface/editor/low_processor_mode_sleep_usec", 6900); // ~144 FPS
  266. hints["interface/editor/low_processor_mode_sleep_usec"] = PropertyInfo(Variant::FLOAT, "interface/editor/low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  267. _initial_set("interface/editor/unfocused_low_processor_mode_sleep_usec", 50000); // 20 FPS
  268. hints["interface/editor/unfocused_low_processor_mode_sleep_usec"] = PropertyInfo(Variant::FLOAT, "interface/editor/unfocused_low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  269. _initial_set("interface/editor/separate_distraction_mode", false);
  270. _initial_set("interface/editor/automatically_open_screenshots", true);
  271. _initial_set("interface/editor/hide_console_window", false);
  272. _initial_set("interface/editor/save_each_scene_on_quit", true); // Regression
  273. _initial_set("interface/editor/quit_confirmation", true);
  274. // Theme
  275. _initial_set("interface/theme/preset", "Default");
  276. hints["interface/theme/preset"] = PropertyInfo(Variant::STRING, "interface/theme/preset", PROPERTY_HINT_ENUM, "Default,Alien,Arc,Godot 2,Grey,Light,Solarized (Dark),Solarized (Light),Custom", PROPERTY_USAGE_DEFAULT);
  277. _initial_set("interface/theme/icon_and_font_color", 0);
  278. hints["interface/theme/icon_and_font_color"] = PropertyInfo(Variant::INT, "interface/theme/icon_and_font_color", PROPERTY_HINT_ENUM, "Auto,Dark,Light", PROPERTY_USAGE_DEFAULT);
  279. _initial_set("interface/theme/base_color", Color(0.2, 0.23, 0.31));
  280. hints["interface/theme/base_color"] = PropertyInfo(Variant::COLOR, "interface/theme/base_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
  281. _initial_set("interface/theme/accent_color", Color(0.41, 0.61, 0.91));
  282. hints["interface/theme/accent_color"] = PropertyInfo(Variant::COLOR, "interface/theme/accent_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT);
  283. _initial_set("interface/theme/contrast", 0.25);
  284. hints["interface/theme/contrast"] = PropertyInfo(Variant::FLOAT, "interface/theme/contrast", PROPERTY_HINT_RANGE, "0.01, 1, 0.01");
  285. _initial_set("interface/theme/relationship_line_opacity", 0.1);
  286. hints["interface/theme/relationship_line_opacity"] = PropertyInfo(Variant::FLOAT, "interface/theme/relationship_line_opacity", PROPERTY_HINT_RANGE, "0.00, 1, 0.01");
  287. _initial_set("interface/theme/highlight_tabs", false);
  288. _initial_set("interface/theme/border_size", 1);
  289. _initial_set("interface/theme/use_graph_node_headers", false);
  290. hints["interface/theme/border_size"] = PropertyInfo(Variant::INT, "interface/theme/border_size", PROPERTY_HINT_RANGE, "0,2,1", PROPERTY_USAGE_DEFAULT);
  291. _initial_set("interface/theme/additional_spacing", 0);
  292. hints["interface/theme/additional_spacing"] = PropertyInfo(Variant::FLOAT, "interface/theme/additional_spacing", PROPERTY_HINT_RANGE, "0,5,0.1", PROPERTY_USAGE_DEFAULT);
  293. _initial_set("interface/theme/custom_theme", "");
  294. hints["interface/theme/custom_theme"] = PropertyInfo(Variant::STRING, "interface/theme/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT);
  295. // Scene tabs
  296. _initial_set("interface/scene_tabs/show_extension", false);
  297. _initial_set("interface/scene_tabs/show_thumbnail_on_hover", true);
  298. _initial_set("interface/scene_tabs/resize_if_many_tabs", true);
  299. _initial_set("interface/scene_tabs/minimum_width", 50);
  300. hints["interface/scene_tabs/minimum_width"] = PropertyInfo(Variant::INT, "interface/scene_tabs/minimum_width", PROPERTY_HINT_RANGE, "50,500,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  301. _initial_set("interface/scene_tabs/show_script_button", false);
  302. /* Filesystem */
  303. // Directories
  304. _initial_set("filesystem/directories/autoscan_project_path", "");
  305. hints["filesystem/directories/autoscan_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/autoscan_project_path", PROPERTY_HINT_GLOBAL_DIR);
  306. _initial_set("filesystem/directories/default_project_path", OS::get_singleton()->has_environment("HOME") ? OS::get_singleton()->get_environment("HOME") : OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS));
  307. hints["filesystem/directories/default_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/default_project_path", PROPERTY_HINT_GLOBAL_DIR);
  308. // On save
  309. _initial_set("filesystem/on_save/compress_binary_resources", true);
  310. _initial_set("filesystem/on_save/safe_save_on_backup_then_rename", true);
  311. // File dialog
  312. _initial_set("filesystem/file_dialog/show_hidden_files", false);
  313. _initial_set("filesystem/file_dialog/display_mode", 0);
  314. hints["filesystem/file_dialog/display_mode"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List");
  315. _initial_set("filesystem/file_dialog/thumbnail_size", 64);
  316. hints["filesystem/file_dialog/thumbnail_size"] = PropertyInfo(Variant::INT, "filesystem/file_dialog/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16");
  317. // Import
  318. _initial_set("filesystem/import/pvrtc_texture_tool", "");
  319. #ifdef WINDOWS_ENABLED
  320. hints["filesystem/import/pvrtc_texture_tool"] = PropertyInfo(Variant::STRING, "filesystem/import/pvrtc_texture_tool", PROPERTY_HINT_GLOBAL_FILE, "*.exe");
  321. #else
  322. hints["filesystem/import/pvrtc_texture_tool"] = PropertyInfo(Variant::STRING, "filesystem/import/pvrtc_texture_tool", PROPERTY_HINT_GLOBAL_FILE, "");
  323. #endif
  324. _initial_set("filesystem/import/pvrtc_fast_conversion", false);
  325. /* Docks */
  326. // SceneTree
  327. _initial_set("docks/scene_tree/start_create_dialog_fully_expanded", false);
  328. // FileSystem
  329. _initial_set("docks/filesystem/thumbnail_size", 64);
  330. hints["docks/filesystem/thumbnail_size"] = PropertyInfo(Variant::INT, "docks/filesystem/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16");
  331. _initial_set("docks/filesystem/always_show_folders", true);
  332. // Property editor
  333. _initial_set("docks/property_editor/auto_refresh_interval", 0.3);
  334. /* Text editor */
  335. // Theme
  336. _initial_set("text_editor/theme/color_theme", "Adaptive");
  337. hints["text_editor/theme/color_theme"] = PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, "Adaptive,Default,Custom");
  338. _initial_set("text_editor/theme/line_spacing", 6);
  339. hints["text_editor/theme/line_spacing"] = PropertyInfo(Variant::INT, "text_editor/theme/line_spacing", PROPERTY_HINT_RANGE, "0,50,1");
  340. _load_default_text_editor_theme();
  341. // Highlighting
  342. _initial_set("text_editor/highlighting/syntax_highlighting", true);
  343. _initial_set("text_editor/highlighting/highlight_all_occurrences", true);
  344. _initial_set("text_editor/highlighting/highlight_current_line", true);
  345. _initial_set("text_editor/highlighting/highlight_type_safe_lines", true);
  346. // Indent
  347. _initial_set("text_editor/indent/type", 0);
  348. hints["text_editor/indent/type"] = PropertyInfo(Variant::INT, "text_editor/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces");
  349. _initial_set("text_editor/indent/size", 4);
  350. hints["text_editor/indent/size"] = PropertyInfo(Variant::INT, "text_editor/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes.
  351. _initial_set("text_editor/indent/auto_indent", true);
  352. _initial_set("text_editor/indent/convert_indent_on_save", true);
  353. _initial_set("text_editor/indent/draw_tabs", true);
  354. _initial_set("text_editor/indent/draw_spaces", false);
  355. // Navigation
  356. _initial_set("text_editor/navigation/smooth_scrolling", true);
  357. _initial_set("text_editor/navigation/v_scroll_speed", 80);
  358. _initial_set("text_editor/navigation/show_minimap", true);
  359. _initial_set("text_editor/navigation/minimap_width", 80);
  360. hints["text_editor/navigation/minimap_width"] = PropertyInfo(Variant::INT, "text_editor/navigation/minimap_width", PROPERTY_HINT_RANGE, "50,250,1");
  361. // Appearance
  362. _initial_set("text_editor/appearance/show_line_numbers", true);
  363. _initial_set("text_editor/appearance/line_numbers_zero_padded", false);
  364. _initial_set("text_editor/appearance/show_bookmark_gutter", true);
  365. _initial_set("text_editor/appearance/show_breakpoint_gutter", true);
  366. _initial_set("text_editor/appearance/show_info_gutter", true);
  367. _initial_set("text_editor/appearance/code_folding", true);
  368. _initial_set("text_editor/appearance/word_wrap", false);
  369. _initial_set("text_editor/appearance/show_line_length_guidelines", true);
  370. _initial_set("text_editor/appearance/line_length_guideline_soft_column", 80);
  371. hints["text_editor/appearance/line_length_guideline_soft_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_soft_column", PROPERTY_HINT_RANGE, "20, 160, 1");
  372. _initial_set("text_editor/appearance/line_length_guideline_hard_column", 100);
  373. hints["text_editor/appearance/line_length_guideline_hard_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_hard_column", PROPERTY_HINT_RANGE, "20, 160, 1");
  374. // Script list
  375. _initial_set("text_editor/script_list/show_members_overview", true);
  376. // Files
  377. _initial_set("text_editor/files/trim_trailing_whitespace_on_save", false);
  378. _initial_set("text_editor/files/autosave_interval_secs", 0);
  379. _initial_set("text_editor/files/restore_scripts_on_load", true);
  380. // Tools
  381. _initial_set("text_editor/tools/create_signal_callbacks", true);
  382. _initial_set("text_editor/tools/sort_members_outline_alphabetically", false);
  383. // Cursor
  384. _initial_set("text_editor/cursor/scroll_past_end_of_file", false);
  385. _initial_set("text_editor/cursor/block_caret", false);
  386. _initial_set("text_editor/cursor/caret_blink", true);
  387. _initial_set("text_editor/cursor/caret_blink_speed", 0.5);
  388. hints["text_editor/cursor/caret_blink_speed"] = PropertyInfo(Variant::FLOAT, "text_editor/cursor/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.01");
  389. _initial_set("text_editor/cursor/right_click_moves_caret", true);
  390. // Completion
  391. _initial_set("text_editor/completion/idle_parse_delay", 2.0);
  392. hints["text_editor/completion/idle_parse_delay"] = PropertyInfo(Variant::FLOAT, "text_editor/completion/idle_parse_delay", PROPERTY_HINT_RANGE, "0.1, 10, 0.01");
  393. _initial_set("text_editor/completion/auto_brace_complete", true);
  394. _initial_set("text_editor/completion/code_complete_delay", 0.3);
  395. hints["text_editor/completion/code_complete_delay"] = PropertyInfo(Variant::FLOAT, "text_editor/completion/code_complete_delay", PROPERTY_HINT_RANGE, "0.01, 5, 0.01");
  396. _initial_set("text_editor/completion/put_callhint_tooltip_below_current_line", true);
  397. _initial_set("text_editor/completion/callhint_tooltip_offset", Vector2());
  398. _initial_set("text_editor/completion/complete_file_paths", true);
  399. _initial_set("text_editor/completion/add_type_hints", false);
  400. _initial_set("text_editor/completion/use_single_quotes", false);
  401. // Help
  402. _initial_set("text_editor/help/show_help_index", true);
  403. _initial_set("text_editor/help/help_font_size", 15);
  404. hints["text_editor/help/help_font_size"] = PropertyInfo(Variant::INT, "text_editor/help/help_font_size", PROPERTY_HINT_RANGE, "8,48,1");
  405. _initial_set("text_editor/help/help_source_font_size", 14);
  406. hints["text_editor/help/help_source_font_size"] = PropertyInfo(Variant::INT, "text_editor/help/help_source_font_size", PROPERTY_HINT_RANGE, "8,48,1");
  407. _initial_set("text_editor/help/help_title_font_size", 23);
  408. hints["text_editor/help/help_title_font_size"] = PropertyInfo(Variant::INT, "text_editor/help/help_title_font_size", PROPERTY_HINT_RANGE, "8,48,1");
  409. /* Editors */
  410. // GridMap
  411. _initial_set("editors/grid_map/pick_distance", 5000.0);
  412. // 3D
  413. _initial_set("editors/3d/primary_grid_color", Color(0.56, 0.56, 0.56));
  414. hints["editors/3d/primary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/primary_grid_color", PROPERTY_HINT_COLOR_NO_ALPHA, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  415. _initial_set("editors/3d/secondary_grid_color", Color(0.38, 0.38, 0.38));
  416. hints["editors/3d/secondary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/secondary_grid_color", PROPERTY_HINT_COLOR_NO_ALPHA, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  417. _initial_set("editors/3d/grid_size", 50);
  418. hints["editors/3d/grid_size"] = PropertyInfo(Variant::INT, "editors/3d/grid_size", PROPERTY_HINT_RANGE, "1,500,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  419. _initial_set("editors/3d/primary_grid_steps", 10);
  420. hints["editors/3d/primary_grid_steps"] = PropertyInfo(Variant::INT, "editors/3d/primary_grid_steps", PROPERTY_HINT_RANGE, "1,100,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
  421. _initial_set("editors/3d/default_fov", 70.0);
  422. _initial_set("editors/3d/default_z_near", 0.05);
  423. _initial_set("editors/3d/default_z_far", 500.0);
  424. // 3D: Navigation
  425. _initial_set("editors/3d/navigation/navigation_scheme", 0);
  426. _initial_set("editors/3d/navigation/invert_y_axis", false);
  427. hints["editors/3d/navigation/navigation_scheme"] = PropertyInfo(Variant::INT, "editors/3d/navigation/navigation_scheme", PROPERTY_HINT_ENUM, "Godot,Maya,Modo");
  428. _initial_set("editors/3d/navigation/zoom_style", 0);
  429. hints["editors/3d/navigation/zoom_style"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_style", PROPERTY_HINT_ENUM, "Vertical, Horizontal");
  430. _initial_set("editors/3d/navigation/emulate_3_button_mouse", false);
  431. _initial_set("editors/3d/navigation/orbit_modifier", 0);
  432. hints["editors/3d/navigation/orbit_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/orbit_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  433. _initial_set("editors/3d/navigation/pan_modifier", 1);
  434. hints["editors/3d/navigation/pan_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/pan_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  435. _initial_set("editors/3d/navigation/zoom_modifier", 4);
  436. hints["editors/3d/navigation/zoom_modifier"] = PropertyInfo(Variant::INT, "editors/3d/navigation/zoom_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  437. _initial_set("editors/3d/navigation/warped_mouse_panning", true);
  438. // 3D: Navigation feel
  439. _initial_set("editors/3d/navigation_feel/orbit_sensitivity", 0.4);
  440. hints["editors/3d/navigation_feel/orbit_sensitivity"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/orbit_sensitivity", PROPERTY_HINT_RANGE, "0.0, 2, 0.01");
  441. _initial_set("editors/3d/navigation_feel/orbit_inertia", 0.05);
  442. hints["editors/3d/navigation_feel/orbit_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  443. _initial_set("editors/3d/navigation_feel/translation_inertia", 0.15);
  444. hints["editors/3d/navigation_feel/translation_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  445. _initial_set("editors/3d/navigation_feel/zoom_inertia", 0.075);
  446. hints["editors/3d/navigation_feel/zoom_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/zoom_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  447. _initial_set("editors/3d/navigation_feel/manipulation_orbit_inertia", 0.075);
  448. hints["editors/3d/navigation_feel/manipulation_orbit_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/manipulation_orbit_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  449. _initial_set("editors/3d/navigation_feel/manipulation_translation_inertia", 0.075);
  450. hints["editors/3d/navigation_feel/manipulation_translation_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/navigation_feel/manipulation_translation_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  451. // 3D: Freelook
  452. _initial_set("editors/3d/freelook/freelook_inertia", 0.1);
  453. hints["editors/3d/freelook/freelook_inertia"] = PropertyInfo(Variant::FLOAT, "editors/3d/freelook/freelook_inertia", PROPERTY_HINT_RANGE, "0.0, 1, 0.01");
  454. _initial_set("editors/3d/freelook/freelook_base_speed", 5.0);
  455. hints["editors/3d/freelook/freelook_base_speed"] = PropertyInfo(Variant::FLOAT, "editors/3d/freelook/freelook_base_speed", PROPERTY_HINT_RANGE, "0.0, 10, 0.01");
  456. _initial_set("editors/3d/freelook/freelook_activation_modifier", 0);
  457. hints["editors/3d/freelook/freelook_activation_modifier"] = PropertyInfo(Variant::INT, "editors/3d/freelook/freelook_activation_modifier", PROPERTY_HINT_ENUM, "None,Shift,Alt,Meta,Ctrl");
  458. _initial_set("editors/3d/freelook/freelook_speed_zoom_link", false);
  459. // 2D
  460. _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07));
  461. _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8));
  462. _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1));
  463. _initial_set("editors/2d/bone_width", 5);
  464. _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.9));
  465. _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.9));
  466. _initial_set("editors/2d/bone_selected_color", Color(0.9, 0.45, 0.45, 0.9));
  467. _initial_set("editors/2d/bone_ik_color", Color(0.9, 0.9, 0.45, 0.9));
  468. _initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35));
  469. _initial_set("editors/2d/bone_outline_size", 2);
  470. _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4));
  471. _initial_set("editors/2d/constrain_editor_view", true);
  472. _initial_set("editors/2d/warped_mouse_panning", true);
  473. _initial_set("editors/2d/simple_panning", false);
  474. _initial_set("editors/2d/scroll_to_pan", false);
  475. _initial_set("editors/2d/pan_speed", 20);
  476. // Polygon editor
  477. _initial_set("editors/poly_editor/point_grab_radius", 8);
  478. _initial_set("editors/poly_editor/show_previous_outline", true);
  479. // Animation
  480. _initial_set("editors/animation/autorename_animation_tracks", true);
  481. _initial_set("editors/animation/confirm_insert_track", true);
  482. _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0));
  483. _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0));
  484. /* Run */
  485. // Window placement
  486. _initial_set("run/window_placement/rect", 1);
  487. hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen");
  488. String screen_hints = "Same as Editor,Previous Monitor,Next Monitor";
  489. for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) {
  490. screen_hints += ",Monitor " + itos(i + 1);
  491. }
  492. _initial_set("run/window_placement/rect_custom_position", Vector2());
  493. _initial_set("run/window_placement/screen", 0);
  494. hints["run/window_placement/screen"] = PropertyInfo(Variant::INT, "run/window_placement/screen", PROPERTY_HINT_ENUM, screen_hints);
  495. // Auto save
  496. _initial_set("run/auto_save/save_before_running", true);
  497. // Output
  498. _initial_set("run/output/font_size", 13);
  499. hints["run/output/font_size"] = PropertyInfo(Variant::INT, "run/output/font_size", PROPERTY_HINT_RANGE, "8,48,1");
  500. _initial_set("run/output/always_clear_output_on_play", true);
  501. _initial_set("run/output/always_open_output_on_play", true);
  502. _initial_set("run/output/always_close_output_on_stop", false);
  503. /* Network */
  504. // Debug
  505. _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network
  506. _initial_set("network/debug/remote_port", 6007);
  507. hints["network/debug/remote_port"] = PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1");
  508. // SSL
  509. _initial_set("network/ssl/editor_ssl_certificates", _SYSTEM_CERTS_PATH);
  510. hints["network/ssl/editor_ssl_certificates"] = PropertyInfo(Variant::STRING, "network/ssl/editor_ssl_certificates", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem");
  511. /* Extra config */
  512. _initial_set("project_manager/sorting_order", 0);
  513. hints["project_manager/sorting_order"] = PropertyInfo(Variant::INT, "project_manager/sorting_order", PROPERTY_HINT_ENUM, "Name,Path,Last Edited");
  514. if (p_extra_config.is_valid()) {
  515. if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) {
  516. Vector<String> list = p_extra_config->get_value("init_projects", "list");
  517. for (int i = 0; i < list.size(); i++) {
  518. String name = list[i].replace("/", "::");
  519. set("projects/" + name, list[i]);
  520. };
  521. };
  522. if (p_extra_config->has_section("presets")) {
  523. List<String> keys;
  524. p_extra_config->get_section_keys("presets", &keys);
  525. for (List<String>::Element *E = keys.front(); E; E = E->next()) {
  526. String key = E->get();
  527. Variant val = p_extra_config->get_value("presets", key);
  528. set(key, val);
  529. };
  530. };
  531. };
  532. }
  533. void EditorSettings::_load_default_text_editor_theme() {
  534. bool dark_theme = is_dark_theme();
  535. _initial_set("text_editor/highlighting/symbol_color", Color(0.73, 0.87, 1.0));
  536. _initial_set("text_editor/highlighting/keyword_color", Color(1.0, 1.0, 0.7));
  537. _initial_set("text_editor/highlighting/base_type_color", Color(0.64, 1.0, 0.83));
  538. _initial_set("text_editor/highlighting/engine_type_color", Color(0.51, 0.83, 1.0));
  539. _initial_set("text_editor/highlighting/user_type_color", Color(0.42, 0.67, 0.93));
  540. _initial_set("text_editor/highlighting/comment_color", Color(0.4, 0.4, 0.4));
  541. _initial_set("text_editor/highlighting/string_color", Color(0.94, 0.43, 0.75));
  542. _initial_set("text_editor/highlighting/background_color", dark_theme ? Color(0.0, 0.0, 0.0, 0.23) : Color(0.2, 0.23, 0.31));
  543. _initial_set("text_editor/highlighting/completion_background_color", Color(0.17, 0.16, 0.2));
  544. _initial_set("text_editor/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27));
  545. _initial_set("text_editor/highlighting/completion_existing_color", Color(0.13, 0.87, 0.87, 0.87));
  546. _initial_set("text_editor/highlighting/completion_scroll_color", Color(1, 1, 1));
  547. _initial_set("text_editor/highlighting/completion_font_color", Color(0.67, 0.67, 0.67));
  548. _initial_set("text_editor/highlighting/text_color", Color(0.67, 0.67, 0.67));
  549. _initial_set("text_editor/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4));
  550. _initial_set("text_editor/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6));
  551. _initial_set("text_editor/highlighting/caret_color", Color(0.67, 0.67, 0.67));
  552. _initial_set("text_editor/highlighting/caret_background_color", Color(0, 0, 0));
  553. _initial_set("text_editor/highlighting/text_selected_color", Color(0, 0, 0));
  554. _initial_set("text_editor/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35));
  555. _initial_set("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2));
  556. _initial_set("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15));
  557. _initial_set("text_editor/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1));
  558. _initial_set("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15));
  559. _initial_set("text_editor/highlighting/number_color", Color(0.92, 0.58, 0.2));
  560. _initial_set("text_editor/highlighting/function_color", Color(0.4, 0.64, 0.81));
  561. _initial_set("text_editor/highlighting/member_variable_color", Color(0.9, 0.31, 0.35));
  562. _initial_set("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4));
  563. _initial_set("text_editor/highlighting/bookmark_color", Color(0.08, 0.49, 0.98));
  564. _initial_set("text_editor/highlighting/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2));
  565. _initial_set("text_editor/highlighting/executing_line_color", Color(0.2, 0.8, 0.2, 0.4));
  566. _initial_set("text_editor/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8));
  567. _initial_set("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1));
  568. _initial_set("text_editor/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38));
  569. }
  570. bool EditorSettings::_save_text_editor_theme(String p_file) {
  571. String theme_section = "color_theme";
  572. Ref<ConfigFile> cf = memnew(ConfigFile); // hex is better?
  573. List<String> keys;
  574. props.get_key_list(&keys);
  575. keys.sort();
  576. for (const List<String>::Element *E = keys.front(); E; E = E->next()) {
  577. const String &key = E->get();
  578. if (key.begins_with("text_editor/highlighting/") && key.find("color") >= 0) {
  579. cf->set_value(theme_section, key.replace("text_editor/highlighting/", ""), ((Color)props[key].variant).to_html());
  580. }
  581. }
  582. Error err = cf->save(p_file);
  583. return err == OK;
  584. }
  585. bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) {
  586. return p_theme_name == "default" || p_theme_name == "adaptive" || p_theme_name == "custom";
  587. }
  588. static Dictionary _get_builtin_script_templates() {
  589. Dictionary templates;
  590. // No Comments
  591. templates["no_comments.gd"] =
  592. "extends %BASE%\n"
  593. "\n"
  594. "\n"
  595. "func _ready()%VOID_RETURN%:\n"
  596. "%TS%pass\n";
  597. // Empty
  598. templates["empty.gd"] =
  599. "extends %BASE%"
  600. "\n"
  601. "\n";
  602. return templates;
  603. }
  604. static void _create_script_templates(const String &p_path) {
  605. Dictionary templates = _get_builtin_script_templates();
  606. List<Variant> keys;
  607. templates.get_key_list(&keys);
  608. FileAccess *file = FileAccess::create(FileAccess::ACCESS_FILESYSTEM);
  609. DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  610. dir->change_dir(p_path);
  611. for (int i = 0; i < keys.size(); i++) {
  612. if (!dir->file_exists(keys[i])) {
  613. Error err = file->reopen(p_path.plus_file((String)keys[i]), FileAccess::WRITE);
  614. ERR_FAIL_COND(err != OK);
  615. file->store_string(templates[keys[i]]);
  616. file->close();
  617. }
  618. }
  619. memdelete(dir);
  620. memdelete(file);
  621. }
  622. // PUBLIC METHODS
  623. EditorSettings *EditorSettings::get_singleton() {
  624. return singleton.ptr();
  625. }
  626. void EditorSettings::create() {
  627. if (singleton.ptr())
  628. return; //pointless
  629. DirAccess *dir = NULL;
  630. String data_path;
  631. String data_dir;
  632. String config_path;
  633. String config_dir;
  634. String cache_path;
  635. String cache_dir;
  636. Ref<ConfigFile> extra_config = memnew(ConfigFile);
  637. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir();
  638. DirAccess *d = DirAccess::create_for_path(exe_path);
  639. bool self_contained = false;
  640. if (d->file_exists(exe_path + "/._sc_")) {
  641. self_contained = true;
  642. Error err = extra_config->load(exe_path + "/._sc_");
  643. if (err != OK) {
  644. ERR_PRINT("Can't load config from path '" + exe_path + "/._sc_'.");
  645. }
  646. } else if (d->file_exists(exe_path + "/_sc_")) {
  647. self_contained = true;
  648. Error err = extra_config->load(exe_path + "/_sc_");
  649. if (err != OK) {
  650. ERR_PRINT("Can't load config from path '" + exe_path + "/_sc_'.");
  651. }
  652. }
  653. memdelete(d);
  654. if (self_contained) {
  655. // editor is self contained, all in same folder
  656. data_path = exe_path;
  657. data_dir = data_path.plus_file("editor_data");
  658. config_path = exe_path;
  659. config_dir = data_dir;
  660. cache_path = exe_path;
  661. cache_dir = data_dir.plus_file("cache");
  662. } else {
  663. // Typically XDG_DATA_HOME or %APPDATA%
  664. data_path = OS::get_singleton()->get_data_path();
  665. data_dir = data_path.plus_file(OS::get_singleton()->get_godot_dir_name());
  666. // Can be different from data_path e.g. on Linux or macOS
  667. config_path = OS::get_singleton()->get_config_path();
  668. config_dir = config_path.plus_file(OS::get_singleton()->get_godot_dir_name());
  669. // Can be different from above paths, otherwise a subfolder of data_dir
  670. cache_path = OS::get_singleton()->get_cache_path();
  671. if (cache_path == data_path) {
  672. cache_dir = data_dir.plus_file("cache");
  673. } else {
  674. cache_dir = cache_path.plus_file(OS::get_singleton()->get_godot_dir_name());
  675. }
  676. }
  677. ClassDB::register_class<EditorSettings>(); //otherwise it can't be unserialized
  678. String config_file_path;
  679. if (data_path != "" && config_path != "" && cache_path != "") {
  680. // Validate/create data dir and subdirectories
  681. dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  682. if (dir->change_dir(data_dir) != OK) {
  683. dir->make_dir_recursive(data_dir);
  684. if (dir->change_dir(data_dir) != OK) {
  685. ERR_PRINT("Cannot create data directory!");
  686. memdelete(dir);
  687. goto fail;
  688. }
  689. }
  690. if (dir->change_dir("templates") != OK) {
  691. dir->make_dir("templates");
  692. } else {
  693. dir->change_dir("..");
  694. }
  695. // Validate/create cache dir
  696. if (dir->change_dir(cache_dir) != OK) {
  697. dir->make_dir_recursive(cache_dir);
  698. if (dir->change_dir(cache_dir) != OK) {
  699. ERR_PRINT("Cannot create cache directory!");
  700. memdelete(dir);
  701. goto fail;
  702. }
  703. }
  704. // Validate/create config dir and subdirectories
  705. if (dir->change_dir(config_dir) != OK) {
  706. dir->make_dir_recursive(config_dir);
  707. if (dir->change_dir(config_dir) != OK) {
  708. ERR_PRINT("Cannot create config directory!");
  709. memdelete(dir);
  710. goto fail;
  711. }
  712. }
  713. if (dir->change_dir("text_editor_themes") != OK) {
  714. dir->make_dir("text_editor_themes");
  715. } else {
  716. dir->change_dir("..");
  717. }
  718. if (dir->change_dir("script_templates") != OK) {
  719. dir->make_dir("script_templates");
  720. } else {
  721. dir->change_dir("..");
  722. }
  723. if (dir->change_dir("feature_profiles") != OK) {
  724. dir->make_dir("feature_profiles");
  725. } else {
  726. dir->change_dir("..");
  727. }
  728. _create_script_templates(dir->get_current_dir().plus_file("script_templates"));
  729. if (dir->change_dir("projects") != OK) {
  730. dir->make_dir("projects");
  731. } else {
  732. dir->change_dir("..");
  733. }
  734. // Validate/create project-specific config dir
  735. dir->change_dir("projects");
  736. String project_config_dir = ProjectSettings::get_singleton()->get_resource_path();
  737. if (project_config_dir.ends_with("/"))
  738. project_config_dir = config_path.substr(0, project_config_dir.size() - 1);
  739. project_config_dir = project_config_dir.get_file() + "-" + project_config_dir.md5_text();
  740. if (dir->change_dir(project_config_dir) != OK) {
  741. dir->make_dir(project_config_dir);
  742. } else {
  743. dir->change_dir("..");
  744. }
  745. dir->change_dir("..");
  746. // Validate editor config file
  747. String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres";
  748. config_file_path = config_dir.plus_file(config_file_name);
  749. if (!dir->file_exists(config_file_name)) {
  750. goto fail;
  751. }
  752. memdelete(dir);
  753. singleton = ResourceLoader::load(config_file_path, "EditorSettings");
  754. if (singleton.is_null()) {
  755. WARN_PRINT("Could not open config file.");
  756. goto fail;
  757. }
  758. singleton->save_changed_setting = true;
  759. singleton->config_file_path = config_file_path;
  760. singleton->project_config_dir = project_config_dir;
  761. singleton->settings_dir = config_dir;
  762. singleton->data_dir = data_dir;
  763. singleton->cache_dir = cache_dir;
  764. print_verbose("EditorSettings: Load OK!");
  765. singleton->setup_language();
  766. singleton->setup_network();
  767. singleton->load_favorites();
  768. singleton->list_text_editor_themes();
  769. return;
  770. }
  771. fail:
  772. // patch init projects
  773. if (extra_config->has_section("init_projects")) {
  774. Vector<String> list = extra_config->get_value("init_projects", "list");
  775. for (int i = 0; i < list.size(); i++) {
  776. list.write[i] = exe_path.plus_file(list[i]);
  777. };
  778. extra_config->set_value("init_projects", "list", list);
  779. };
  780. singleton = Ref<EditorSettings>(memnew(EditorSettings));
  781. singleton->save_changed_setting = true;
  782. singleton->config_file_path = config_file_path;
  783. singleton->settings_dir = config_dir;
  784. singleton->data_dir = data_dir;
  785. singleton->cache_dir = cache_dir;
  786. singleton->_load_defaults(extra_config);
  787. singleton->setup_language();
  788. singleton->setup_network();
  789. singleton->list_text_editor_themes();
  790. }
  791. void EditorSettings::setup_language() {
  792. String lang = get("interface/editor/editor_language");
  793. if (lang == "en")
  794. return; // Default, nothing to do.
  795. // Load editor translation for configured/detected locale.
  796. EditorTranslationList *etl = _editor_translations;
  797. while (etl->data) {
  798. if (etl->lang == lang) {
  799. Vector<uint8_t> data;
  800. data.resize(etl->uncomp_size);
  801. Compression::decompress(data.ptrw(), etl->uncomp_size, etl->data, etl->comp_size, Compression::MODE_DEFLATE);
  802. FileAccessMemory *fa = memnew(FileAccessMemory);
  803. fa->open_custom(data.ptr(), data.size());
  804. Ref<Translation> tr = TranslationLoaderPO::load_translation(fa);
  805. if (tr.is_valid()) {
  806. tr->set_locale(etl->lang);
  807. TranslationServer::get_singleton()->set_tool_translation(tr);
  808. break;
  809. }
  810. }
  811. etl++;
  812. }
  813. // Load class reference translation.
  814. DocTranslationList *dtl = _doc_translations;
  815. while (dtl->data) {
  816. if (dtl->lang == lang) {
  817. Vector<uint8_t> data;
  818. data.resize(dtl->uncomp_size);
  819. Compression::decompress(data.ptrw(), dtl->uncomp_size, dtl->data, dtl->comp_size, Compression::MODE_DEFLATE);
  820. FileAccessMemory *fa = memnew(FileAccessMemory);
  821. fa->open_custom(data.ptr(), data.size());
  822. Ref<Translation> tr = TranslationLoaderPO::load_translation(fa);
  823. if (tr.is_valid()) {
  824. tr->set_locale(dtl->lang);
  825. TranslationServer::get_singleton()->set_doc_translation(tr);
  826. break;
  827. }
  828. }
  829. dtl++;
  830. }
  831. }
  832. void EditorSettings::setup_network() {
  833. List<IP_Address> local_ip;
  834. IP::get_singleton()->get_local_addresses(&local_ip);
  835. String hint;
  836. String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
  837. String selected = "127.0.0.1";
  838. // Check that current remote_host is a valid interface address and populate hints.
  839. for (List<IP_Address>::Element *E = local_ip.front(); E; E = E->next()) {
  840. String ip = E->get();
  841. // link-local IPv6 addresses don't work, skipping them
  842. if (ip.begins_with("fe80:0:0:0:")) // fe80::/64
  843. continue;
  844. // Same goes for IPv4 link-local (APIPA) addresses.
  845. if (ip.begins_with("169.254.")) // 169.254.0.0/16
  846. continue;
  847. // Select current IP (found)
  848. if (ip == current)
  849. selected = ip;
  850. if (hint != "")
  851. hint += ",";
  852. hint += ip;
  853. }
  854. // Add hints with valid IP addresses to remote_host property.
  855. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint));
  856. // Fix potentially invalid remote_host due to network change.
  857. set("network/debug/remote_host", selected);
  858. }
  859. void EditorSettings::save() {
  860. //_THREAD_SAFE_METHOD_
  861. if (!singleton.ptr())
  862. return;
  863. if (singleton->config_file_path == "") {
  864. ERR_PRINT("Cannot save EditorSettings config, no valid path");
  865. return;
  866. }
  867. Error err = ResourceSaver::save(singleton->config_file_path, singleton);
  868. if (err != OK) {
  869. ERR_PRINT("Error saving editor settings to " + singleton->config_file_path);
  870. } else {
  871. print_verbose("EditorSettings: Save OK!");
  872. }
  873. }
  874. void EditorSettings::destroy() {
  875. if (!singleton.ptr())
  876. return;
  877. save();
  878. singleton = Ref<EditorSettings>();
  879. }
  880. void EditorSettings::set_optimize_save(bool p_optimize) {
  881. optimize_save = p_optimize;
  882. }
  883. // Properties
  884. void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
  885. _THREAD_SAFE_METHOD_
  886. set(p_setting, p_value);
  887. }
  888. Variant EditorSettings::get_setting(const String &p_setting) const {
  889. _THREAD_SAFE_METHOD_
  890. return get(p_setting);
  891. }
  892. bool EditorSettings::has_setting(const String &p_setting) const {
  893. _THREAD_SAFE_METHOD_
  894. return props.has(p_setting);
  895. }
  896. void EditorSettings::erase(const String &p_setting) {
  897. _THREAD_SAFE_METHOD_
  898. props.erase(p_setting);
  899. }
  900. void EditorSettings::raise_order(const String &p_setting) {
  901. _THREAD_SAFE_METHOD_
  902. ERR_FAIL_COND(!props.has(p_setting));
  903. props[p_setting].order = ++last_order;
  904. }
  905. void EditorSettings::set_restart_if_changed(const StringName &p_setting, bool p_restart) {
  906. _THREAD_SAFE_METHOD_
  907. if (!props.has(p_setting))
  908. return;
  909. props[p_setting].restart_if_changed = p_restart;
  910. }
  911. void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current) {
  912. _THREAD_SAFE_METHOD_
  913. if (!props.has(p_setting))
  914. return;
  915. props[p_setting].initial = p_value;
  916. props[p_setting].has_default_value = true;
  917. if (p_update_current) {
  918. set(p_setting, p_value);
  919. }
  920. }
  921. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed) {
  922. Variant ret = p_default;
  923. if (EditorSettings::get_singleton()->has_setting(p_setting)) {
  924. ret = EditorSettings::get_singleton()->get(p_setting);
  925. } else {
  926. EditorSettings::get_singleton()->set_manually(p_setting, p_default);
  927. EditorSettings::get_singleton()->set_restart_if_changed(p_setting, p_restart_if_changed);
  928. }
  929. if (!EditorSettings::get_singleton()->has_default_value(p_setting)) {
  930. EditorSettings::get_singleton()->set_initial_value(p_setting, p_default);
  931. }
  932. return ret;
  933. }
  934. Variant _EDITOR_GET(const String &p_setting) {
  935. ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has_setting(p_setting), Variant());
  936. return EditorSettings::get_singleton()->get(p_setting);
  937. }
  938. bool EditorSettings::property_can_revert(const String &p_setting) {
  939. if (!props.has(p_setting))
  940. return false;
  941. if (!props[p_setting].has_default_value)
  942. return false;
  943. return props[p_setting].initial != props[p_setting].variant;
  944. }
  945. Variant EditorSettings::property_get_revert(const String &p_setting) {
  946. if (!props.has(p_setting) || !props[p_setting].has_default_value)
  947. return Variant();
  948. return props[p_setting].initial;
  949. }
  950. void EditorSettings::add_property_hint(const PropertyInfo &p_hint) {
  951. _THREAD_SAFE_METHOD_
  952. hints[p_hint.name] = p_hint;
  953. }
  954. // Data directories
  955. String EditorSettings::get_data_dir() const {
  956. return data_dir;
  957. }
  958. String EditorSettings::get_templates_dir() const {
  959. return get_data_dir().plus_file("templates");
  960. }
  961. // Config directories
  962. String EditorSettings::get_settings_dir() const {
  963. return settings_dir;
  964. }
  965. String EditorSettings::get_project_settings_dir() const {
  966. return get_settings_dir().plus_file("projects").plus_file(project_config_dir);
  967. }
  968. String EditorSettings::get_text_editor_themes_dir() const {
  969. return get_settings_dir().plus_file("text_editor_themes");
  970. }
  971. String EditorSettings::get_script_templates_dir() const {
  972. return get_settings_dir().plus_file("script_templates");
  973. }
  974. String EditorSettings::get_project_script_templates_dir() const {
  975. return ProjectSettings::get_singleton()->get("editor/script_templates_search_path");
  976. }
  977. // Cache directory
  978. String EditorSettings::get_cache_dir() const {
  979. return cache_dir;
  980. }
  981. String EditorSettings::get_feature_profiles_dir() const {
  982. return get_settings_dir().plus_file("feature_profiles");
  983. }
  984. // Metadata
  985. void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) {
  986. Ref<ConfigFile> cf = memnew(ConfigFile);
  987. String path = get_project_settings_dir().plus_file("project_metadata.cfg");
  988. Error err;
  989. err = cf->load(path);
  990. ERR_FAIL_COND_MSG(err != OK && err != ERR_FILE_NOT_FOUND, "Cannot load editor settings from file '" + path + "'.");
  991. cf->set_value(p_section, p_key, p_data);
  992. err = cf->save(path);
  993. ERR_FAIL_COND_MSG(err != OK, "Cannot save editor settings to file '" + path + "'.");
  994. }
  995. Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const {
  996. Ref<ConfigFile> cf = memnew(ConfigFile);
  997. String path = get_project_settings_dir().plus_file("project_metadata.cfg");
  998. Error err = cf->load(path);
  999. if (err != OK) {
  1000. return p_default;
  1001. }
  1002. return cf->get_value(p_section, p_key, p_default);
  1003. }
  1004. void EditorSettings::set_favorites(const Vector<String> &p_favorites) {
  1005. favorites = p_favorites;
  1006. FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::WRITE);
  1007. if (f) {
  1008. for (int i = 0; i < favorites.size(); i++)
  1009. f->store_line(favorites[i]);
  1010. memdelete(f);
  1011. }
  1012. }
  1013. Vector<String> EditorSettings::get_favorites() const {
  1014. return favorites;
  1015. }
  1016. void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) {
  1017. recent_dirs = p_recent_dirs;
  1018. FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::WRITE);
  1019. if (f) {
  1020. for (int i = 0; i < recent_dirs.size(); i++)
  1021. f->store_line(recent_dirs[i]);
  1022. memdelete(f);
  1023. }
  1024. }
  1025. Vector<String> EditorSettings::get_recent_dirs() const {
  1026. return recent_dirs;
  1027. }
  1028. void EditorSettings::load_favorites() {
  1029. FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorites"), FileAccess::READ);
  1030. if (f) {
  1031. String line = f->get_line().strip_edges();
  1032. while (line != "") {
  1033. favorites.push_back(line);
  1034. line = f->get_line().strip_edges();
  1035. }
  1036. memdelete(f);
  1037. }
  1038. f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::READ);
  1039. if (f) {
  1040. String line = f->get_line().strip_edges();
  1041. while (line != "") {
  1042. recent_dirs.push_back(line);
  1043. line = f->get_line().strip_edges();
  1044. }
  1045. memdelete(f);
  1046. }
  1047. }
  1048. bool EditorSettings::is_dark_theme() {
  1049. int AUTO_COLOR = 0;
  1050. int LIGHT_COLOR = 2;
  1051. Color base_color = get("interface/theme/base_color");
  1052. int icon_font_color_setting = get("interface/theme/icon_and_font_color");
  1053. return (icon_font_color_setting == AUTO_COLOR && ((base_color.r + base_color.g + base_color.b) / 3.0) < 0.5) || icon_font_color_setting == LIGHT_COLOR;
  1054. }
  1055. void EditorSettings::list_text_editor_themes() {
  1056. String themes = "Adaptive,Default,Custom";
  1057. DirAccess *d = DirAccess::open(get_text_editor_themes_dir());
  1058. if (d) {
  1059. List<String> custom_themes;
  1060. d->list_dir_begin();
  1061. String file = d->get_next();
  1062. while (file != String()) {
  1063. if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) {
  1064. custom_themes.push_back(file.get_basename());
  1065. }
  1066. file = d->get_next();
  1067. }
  1068. d->list_dir_end();
  1069. memdelete(d);
  1070. custom_themes.sort();
  1071. for (List<String>::Element *E = custom_themes.front(); E; E = E->next()) {
  1072. themes += "," + E->get();
  1073. }
  1074. }
  1075. add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
  1076. }
  1077. void EditorSettings::load_text_editor_theme() {
  1078. String p_file = get("text_editor/theme/color_theme");
  1079. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1080. if (p_file == "Default") {
  1081. _load_default_text_editor_theme();
  1082. }
  1083. return; // sorry for "Settings changed" console spam
  1084. }
  1085. String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet");
  1086. Ref<ConfigFile> cf = memnew(ConfigFile);
  1087. Error err = cf->load(theme_path);
  1088. if (err != OK) {
  1089. return;
  1090. }
  1091. List<String> keys;
  1092. cf->get_section_keys("color_theme", &keys);
  1093. for (List<String>::Element *E = keys.front(); E; E = E->next()) {
  1094. String key = E->get();
  1095. String val = cf->get_value("color_theme", key);
  1096. // don't load if it's not already there!
  1097. if (has_setting("text_editor/highlighting/" + key)) {
  1098. // make sure it is actually a color
  1099. if (val.is_valid_html_color() && key.find("color") >= 0) {
  1100. props["text_editor/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam
  1101. }
  1102. }
  1103. }
  1104. emit_signal("settings_changed");
  1105. // if it doesn't load just use what is currently loaded
  1106. }
  1107. bool EditorSettings::import_text_editor_theme(String p_file) {
  1108. if (!p_file.ends_with(".tet")) {
  1109. return false;
  1110. } else {
  1111. if (p_file.get_file().to_lower() == "default.tet") {
  1112. return false;
  1113. }
  1114. DirAccess *d = DirAccess::open(get_text_editor_themes_dir());
  1115. if (d) {
  1116. d->copy(p_file, get_text_editor_themes_dir().plus_file(p_file.get_file()));
  1117. memdelete(d);
  1118. return true;
  1119. }
  1120. }
  1121. return false;
  1122. }
  1123. bool EditorSettings::save_text_editor_theme() {
  1124. String p_file = get("text_editor/theme/color_theme");
  1125. if (_is_default_text_editor_theme(p_file.get_file().to_lower())) {
  1126. return false;
  1127. }
  1128. String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet");
  1129. return _save_text_editor_theme(theme_path);
  1130. }
  1131. bool EditorSettings::save_text_editor_theme_as(String p_file) {
  1132. if (!p_file.ends_with(".tet")) {
  1133. p_file += ".tet";
  1134. }
  1135. if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) {
  1136. return false;
  1137. }
  1138. if (_save_text_editor_theme(p_file)) {
  1139. // switch to theme is saved in the theme directory
  1140. list_text_editor_themes();
  1141. String theme_name = p_file.substr(0, p_file.length() - 4).get_file();
  1142. if (p_file.get_base_dir() == get_text_editor_themes_dir()) {
  1143. _initial_set("text_editor/theme/color_theme", theme_name);
  1144. load_text_editor_theme();
  1145. }
  1146. return true;
  1147. }
  1148. return false;
  1149. }
  1150. bool EditorSettings::is_default_text_editor_theme() {
  1151. String p_file = get("text_editor/theme/color_theme");
  1152. return _is_default_text_editor_theme(p_file.get_file().to_lower());
  1153. }
  1154. Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) {
  1155. Vector<String> templates;
  1156. String template_dir = get_script_templates_dir();
  1157. if (!p_custom_path.empty()) {
  1158. template_dir = p_custom_path;
  1159. }
  1160. DirAccess *d = DirAccess::open(template_dir);
  1161. if (d) {
  1162. d->list_dir_begin();
  1163. String file = d->get_next();
  1164. while (file != String()) {
  1165. if (file.get_extension() == p_extension) {
  1166. templates.push_back(file.get_basename());
  1167. }
  1168. file = d->get_next();
  1169. }
  1170. d->list_dir_end();
  1171. memdelete(d);
  1172. }
  1173. return templates;
  1174. }
  1175. String EditorSettings::get_editor_layouts_config() const {
  1176. return get_settings_dir().plus_file("editor_layouts.cfg");
  1177. }
  1178. // Shortcuts
  1179. void EditorSettings::add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut) {
  1180. shortcuts[p_name] = p_shortcut;
  1181. }
  1182. bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
  1183. const Map<String, Ref<ShortCut>>::Element *E = shortcuts.find(p_name);
  1184. ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");
  1185. return E->get()->is_shortcut(p_event);
  1186. }
  1187. Ref<ShortCut> EditorSettings::get_shortcut(const String &p_name) const {
  1188. const Map<String, Ref<ShortCut>>::Element *E = shortcuts.find(p_name);
  1189. if (!E)
  1190. return Ref<ShortCut>();
  1191. return E->get();
  1192. }
  1193. void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
  1194. for (const Map<String, Ref<ShortCut>>::Element *E = shortcuts.front(); E; E = E->next()) {
  1195. r_shortcuts->push_back(E->key());
  1196. }
  1197. }
  1198. Ref<ShortCut> ED_GET_SHORTCUT(const String &p_path) {
  1199. if (!EditorSettings::get_singleton()) {
  1200. return NULL;
  1201. }
  1202. Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1203. ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path + ".");
  1204. return sc;
  1205. }
  1206. struct ShortCutMapping {
  1207. const char *path;
  1208. uint32_t keycode;
  1209. };
  1210. Ref<ShortCut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode) {
  1211. #ifdef OSX_ENABLED
  1212. // Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
  1213. if (p_keycode == KEY_DELETE) {
  1214. p_keycode = KEY_MASK_CMD | KEY_BACKSPACE;
  1215. }
  1216. #endif
  1217. Ref<InputEventKey> ie;
  1218. if (p_keycode) {
  1219. ie.instance();
  1220. ie->set_unicode(p_keycode & KEY_CODE_MASK);
  1221. ie->set_keycode(p_keycode & KEY_CODE_MASK);
  1222. ie->set_shift(bool(p_keycode & KEY_MASK_SHIFT));
  1223. ie->set_alt(bool(p_keycode & KEY_MASK_ALT));
  1224. ie->set_control(bool(p_keycode & KEY_MASK_CTRL));
  1225. ie->set_metakey(bool(p_keycode & KEY_MASK_META));
  1226. }
  1227. if (!EditorSettings::get_singleton()) {
  1228. Ref<ShortCut> sc;
  1229. sc.instance();
  1230. sc->set_name(p_name);
  1231. sc->set_shortcut(ie);
  1232. sc->set_meta("original", ie);
  1233. return sc;
  1234. }
  1235. Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
  1236. if (sc.is_valid()) {
  1237. sc->set_name(p_name); //keep name (the ones that come from disk have no name)
  1238. sc->set_meta("original", ie); //to compare against changes
  1239. return sc;
  1240. }
  1241. sc.instance();
  1242. sc->set_name(p_name);
  1243. sc->set_shortcut(ie);
  1244. sc->set_meta("original", ie); //to compare against changes
  1245. EditorSettings::get_singleton()->add_shortcut(p_path, sc);
  1246. return sc;
  1247. }
  1248. void EditorSettings::notify_changes() {
  1249. _THREAD_SAFE_METHOD_
  1250. SceneTree *sml = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
  1251. if (!sml) {
  1252. return;
  1253. }
  1254. Node *root = sml->get_root()->get_child(0);
  1255. if (!root) {
  1256. return;
  1257. }
  1258. root->propagate_notification(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1259. }
  1260. void EditorSettings::_bind_methods() {
  1261. ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
  1262. ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
  1263. ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
  1264. ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
  1265. ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value", "update_current"), &EditorSettings::set_initial_value);
  1266. ClassDB::bind_method(D_METHOD("property_can_revert", "name"), &EditorSettings::property_can_revert);
  1267. ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &EditorSettings::property_get_revert);
  1268. ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind);
  1269. ClassDB::bind_method(D_METHOD("get_settings_dir"), &EditorSettings::get_settings_dir);
  1270. ClassDB::bind_method(D_METHOD("get_project_settings_dir"), &EditorSettings::get_project_settings_dir);
  1271. ClassDB::bind_method(D_METHOD("set_project_metadata", "section", "key", "data"), &EditorSettings::set_project_metadata);
  1272. ClassDB::bind_method(D_METHOD("get_project_metadata", "section", "key", "default"), &EditorSettings::get_project_metadata, DEFVAL(Variant()));
  1273. ClassDB::bind_method(D_METHOD("set_favorites", "dirs"), &EditorSettings::set_favorites);
  1274. ClassDB::bind_method(D_METHOD("get_favorites"), &EditorSettings::get_favorites);
  1275. ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
  1276. ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
  1277. ADD_SIGNAL(MethodInfo("settings_changed"));
  1278. BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
  1279. }
  1280. EditorSettings::EditorSettings() {
  1281. last_order = 0;
  1282. optimize_save = true;
  1283. save_changed_setting = true;
  1284. _load_defaults();
  1285. }
  1286. EditorSettings::~EditorSettings() {
  1287. }