editor_settings.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*************************************************************************/
  2. /* editor_settings.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. #ifndef EDITOR_SETTINGS_H
  31. #define EDITOR_SETTINGS_H
  32. #include "object.h"
  33. #include "core/io/config_file.h"
  34. #include "os/thread_safe.h"
  35. #include "resource.h"
  36. #include "scene/gui/shortcut.h"
  37. #include "translation.h"
  38. class EditorPlugin;
  39. class EditorSettings : public Resource {
  40. GDCLASS(EditorSettings, Resource);
  41. private:
  42. _THREAD_SAFE_CLASS_
  43. public:
  44. struct Plugin {
  45. EditorPlugin *instance;
  46. String path;
  47. String name;
  48. String author;
  49. String version;
  50. String description;
  51. bool installs;
  52. String script;
  53. Vector<String> install_files;
  54. };
  55. private:
  56. struct VariantContainer {
  57. int order;
  58. Variant variant;
  59. Variant initial;
  60. bool hide_from_editor;
  61. bool save;
  62. VariantContainer() {
  63. order = 0;
  64. hide_from_editor = false;
  65. save = false;
  66. }
  67. VariantContainer(const Variant &p_variant, int p_order) {
  68. variant = p_variant;
  69. order = p_order;
  70. hide_from_editor = false;
  71. }
  72. };
  73. static Ref<EditorSettings> singleton;
  74. HashMap<String, PropertyInfo> hints;
  75. HashMap<String, VariantContainer> props;
  76. int last_order;
  77. Ref<Resource> clipboard;
  78. Vector<Ref<Translation> > translations;
  79. Map<String, Ref<ShortCut> > shortcuts;
  80. String resource_path;
  81. String config_file_path;
  82. String settings_path;
  83. String project_config_path;
  84. Vector<String> favorite_dirs;
  85. Vector<String> recent_dirs;
  86. bool save_changed_setting;
  87. bool optimize_save; //do not save stuff that came from config but was not set from engine
  88. bool _set(const StringName &p_name, const Variant &p_value, bool p_emit_signal = true);
  89. bool _get(const StringName &p_name, Variant &r_ret) const;
  90. void _initial_set(const StringName &p_name, const Variant &p_value);
  91. void _get_property_list(List<PropertyInfo> *p_list) const;
  92. void _add_property_info_bind(const Dictionary &p_info);
  93. void _load_defaults(Ref<ConfigFile> p_extra_config = NULL);
  94. void _load_default_text_editor_theme();
  95. bool _save_text_editor_theme(String p_file);
  96. protected:
  97. static void _bind_methods();
  98. public:
  99. enum {
  100. NOTIFICATION_EDITOR_SETTINGS_CHANGED = 10000
  101. };
  102. static EditorSettings *get_singleton();
  103. static void create();
  104. void setup_language();
  105. void setup_network();
  106. static void save();
  107. static void destroy();
  108. void set_optimize_save(bool p_optimize);
  109. void set_setting(const String &p_setting, const Variant &p_value);
  110. Variant get_setting(const String &p_setting) const;
  111. bool has_setting(const String &p_setting) const;
  112. void erase(const String &p_setting);
  113. void raise_order(const String &p_setting);
  114. void set_initial_value(const StringName &p_setting, const Variant &p_value);
  115. void set_manually(const StringName &p_setting, const Variant &p_value, bool p_emit_signal = false) {
  116. _set(p_setting, p_value, p_emit_signal);
  117. }
  118. bool property_can_revert(const String &p_setting);
  119. Variant property_get_revert(const String &p_setting);
  120. void add_property_hint(const PropertyInfo &p_hint);
  121. void set_resource_clipboard(const Ref<Resource> &p_resource) { clipboard = p_resource; }
  122. Ref<Resource> get_resource_clipboard() const { return clipboard; }
  123. String get_settings_path() const;
  124. String get_project_settings_path() const;
  125. void set_project_metadata(const String &p_section, const String &p_key, Variant p_data);
  126. Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default);
  127. void set_favorite_dirs(const Vector<String> &p_favorites_dirs);
  128. Vector<String> get_favorite_dirs() const;
  129. void set_recent_dirs(const Vector<String> &p_recent_dirs);
  130. Vector<String> get_recent_dirs() const;
  131. void load_favorites();
  132. void list_text_editor_themes();
  133. void load_text_editor_theme();
  134. bool import_text_editor_theme(String p_file);
  135. bool save_text_editor_theme();
  136. bool save_text_editor_theme_as(String p_file);
  137. Vector<String> get_script_templates(const String &p_extension);
  138. void add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut);
  139. bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const;
  140. Ref<ShortCut> get_shortcut(const String &p_name) const;
  141. void get_shortcut_list(List<String> *r_shortcuts);
  142. void notify_changes();
  143. EditorSettings();
  144. ~EditorSettings();
  145. };
  146. //not a macro any longer
  147. #define EDITOR_DEF(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val))
  148. Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default);
  149. #define EDITOR_GET(m_var) _EDITOR_GET(m_var)
  150. Variant _EDITOR_GET(const String &p_setting);
  151. #define ED_IS_SHORTCUT(p_name, p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name, p_ev))
  152. Ref<ShortCut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode = 0);
  153. Ref<ShortCut> ED_GET_SHORTCUT(const String &p_path);
  154. #endif // EDITOR_SETTINGS_H