editor_settings.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**************************************************************************/
  2. /* editor_settings.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #ifndef EDITOR_SETTINGS_H
  31. #define EDITOR_SETTINGS_H
  32. #include "core/io/config_file.h"
  33. #include "core/io/resource.h"
  34. #include "core/os/thread_safe.h"
  35. #include "core/templates/rb_set.h"
  36. class EditorPlugin;
  37. class InputEvent;
  38. class Shortcut;
  39. class EditorSettings : public Resource {
  40. GDCLASS(EditorSettings, Resource);
  41. _THREAD_SAFE_CLASS_
  42. public:
  43. struct Plugin {
  44. EditorPlugin *instance = nullptr;
  45. String path;
  46. String name;
  47. String author;
  48. String version;
  49. String description;
  50. bool installs = false;
  51. String script;
  52. Vector<String> install_files;
  53. };
  54. private:
  55. struct VariantContainer {
  56. int order = 0;
  57. Variant variant;
  58. Variant initial;
  59. bool has_default_value = false;
  60. bool hide_from_editor = false;
  61. bool save = false;
  62. bool restart_if_changed = false;
  63. VariantContainer() {}
  64. VariantContainer(const Variant &p_variant, int p_order) :
  65. order(p_order),
  66. variant(p_variant) {
  67. }
  68. };
  69. static Ref<EditorSettings> singleton;
  70. HashSet<String> changed_settings;
  71. HashMap<String, PropertyInfo> hints;
  72. HashMap<String, VariantContainer> props;
  73. int last_order;
  74. Ref<Resource> clipboard;
  75. mutable HashMap<String, Ref<Shortcut>> shortcuts;
  76. HashMap<String, List<Ref<InputEvent>>> builtin_action_overrides;
  77. Vector<String> favorites;
  78. Vector<String> recent_dirs;
  79. bool save_changed_setting = true;
  80. bool optimize_save = true; //do not save stuff that came from config but was not set from engine
  81. bool _set(const StringName &p_name, const Variant &p_value);
  82. bool _set_only(const StringName &p_name, const Variant &p_value);
  83. bool _get(const StringName &p_name, Variant &r_ret) const;
  84. void _initial_set(const StringName &p_name, const Variant &p_value);
  85. void _get_property_list(List<PropertyInfo> *p_list) const;
  86. void _add_property_info_bind(const Dictionary &p_info);
  87. bool _property_can_revert(const StringName &p_name) const;
  88. bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
  89. void _load_defaults(Ref<ConfigFile> p_extra_config = Ref<ConfigFile>());
  90. void _load_godot2_text_editor_theme();
  91. bool _save_text_editor_theme(String p_file);
  92. bool _is_default_text_editor_theme(String p_theme_name);
  93. protected:
  94. static void _bind_methods();
  95. public:
  96. enum {
  97. NOTIFICATION_EDITOR_SETTINGS_CHANGED = 10000
  98. };
  99. static EditorSettings *get_singleton();
  100. static void create();
  101. void setup_language();
  102. void setup_network();
  103. static void save();
  104. static void destroy();
  105. void set_optimize_save(bool p_optimize);
  106. bool has_default_value(const String &p_setting) const;
  107. void set_setting(const String &p_setting, const Variant &p_value);
  108. Variant get_setting(const String &p_setting) const;
  109. bool has_setting(const String &p_setting) const;
  110. void erase(const String &p_setting);
  111. void raise_order(const String &p_setting);
  112. void set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current = false);
  113. void set_restart_if_changed(const StringName &p_setting, bool p_restart);
  114. void set_manually(const StringName &p_setting, const Variant &p_value, bool p_emit_signal = false) {
  115. if (p_emit_signal) {
  116. _set(p_setting, p_value);
  117. } else {
  118. _set_only(p_setting, p_value);
  119. }
  120. }
  121. void add_property_hint(const PropertyInfo &p_hint);
  122. PackedStringArray get_changed_settings() const;
  123. bool check_changed_settings_in_group(const String &p_setting_prefix) const;
  124. void mark_setting_changed(const String &p_setting);
  125. void set_resource_clipboard(const Ref<Resource> &p_resource) { clipboard = p_resource; }
  126. Ref<Resource> get_resource_clipboard() const { return clipboard; }
  127. void set_project_metadata(const String &p_section, const String &p_key, Variant p_data);
  128. Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const;
  129. void set_favorites(const Vector<String> &p_favorites);
  130. Vector<String> get_favorites() const;
  131. void set_recent_dirs(const Vector<String> &p_recent_dirs);
  132. Vector<String> get_recent_dirs() const;
  133. void load_favorites_and_recent_dirs();
  134. bool is_dark_theme();
  135. void list_text_editor_themes();
  136. void load_text_editor_theme();
  137. bool import_text_editor_theme(String p_file);
  138. bool save_text_editor_theme();
  139. bool save_text_editor_theme_as(String p_file);
  140. bool is_default_text_editor_theme();
  141. Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String());
  142. String get_editor_layouts_config() const;
  143. float get_auto_display_scale() const;
  144. void _add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut);
  145. void add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut);
  146. bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const;
  147. Ref<Shortcut> get_shortcut(const String &p_name) const;
  148. void get_shortcut_list(List<String> *r_shortcuts);
  149. void set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events);
  150. const Array get_builtin_action_overrides(const String &p_name) const;
  151. void notify_changes();
  152. EditorSettings();
  153. ~EditorSettings();
  154. };
  155. //not a macro any longer
  156. #define EDITOR_DEF(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val))
  157. #define EDITOR_DEF_RST(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val), true)
  158. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed = false);
  159. #define EDITOR_GET(m_var) _EDITOR_GET(m_var)
  160. Variant _EDITOR_GET(const String &p_setting);
  161. #define ED_IS_SHORTCUT(p_name, p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name, p_ev))
  162. Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode = Key::NONE, bool p_physical = false);
  163. Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical = false);
  164. void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode = Key::NONE, bool p_physical = false);
  165. void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical = false);
  166. Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path);
  167. #endif // EDITOR_SETTINGS_H