editor_feature_profile.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**************************************************************************/
  2. /* editor_feature_profile.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_FEATURE_PROFILE_H
  31. #define EDITOR_FEATURE_PROFILE_H
  32. #include "core/io/file_access.h"
  33. #include "core/object/ref_counted.h"
  34. #include "editor/editor_help.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/separator.h"
  38. #include "scene/gui/split_container.h"
  39. #include "scene/gui/tree.h"
  40. class EditorFileDialog;
  41. class EditorFeatureProfile : public RefCounted {
  42. GDCLASS(EditorFeatureProfile, RefCounted);
  43. public:
  44. enum Feature {
  45. FEATURE_3D,
  46. FEATURE_SCRIPT,
  47. FEATURE_ASSET_LIB,
  48. FEATURE_SCENE_TREE,
  49. FEATURE_NODE_DOCK,
  50. FEATURE_FILESYSTEM_DOCK,
  51. FEATURE_IMPORT_DOCK,
  52. FEATURE_HISTORY_DOCK,
  53. FEATURE_MAX
  54. };
  55. private:
  56. HashSet<StringName> disabled_classes;
  57. HashSet<StringName> disabled_editors;
  58. HashMap<StringName, HashSet<StringName>> disabled_properties;
  59. HashSet<StringName> collapsed_classes;
  60. bool features_disabled[FEATURE_MAX];
  61. static const char *feature_names[FEATURE_MAX];
  62. static const char *feature_descriptions[FEATURE_MAX];
  63. static const char *feature_identifiers[FEATURE_MAX];
  64. String _get_feature_name(Feature p_feature) { return get_feature_name(p_feature); }
  65. protected:
  66. static void _bind_methods();
  67. public:
  68. void set_disable_class(const StringName &p_class, bool p_disabled);
  69. bool is_class_disabled(const StringName &p_class) const;
  70. void set_disable_class_editor(const StringName &p_class, bool p_disabled);
  71. bool is_class_editor_disabled(const StringName &p_class) const;
  72. void set_disable_class_property(const StringName &p_class, const StringName &p_property, bool p_disabled);
  73. bool is_class_property_disabled(const StringName &p_class, const StringName &p_property) const;
  74. bool has_class_properties_disabled(const StringName &p_class) const;
  75. void set_item_collapsed(const StringName &p_class, bool p_collapsed);
  76. bool is_item_collapsed(const StringName &p_class) const;
  77. void set_disable_feature(Feature p_feature, bool p_disable);
  78. bool is_feature_disabled(Feature p_feature) const;
  79. Error save_to_file(const String &p_path);
  80. Error load_from_file(const String &p_path);
  81. static String get_feature_name(Feature p_feature);
  82. static String get_feature_description(Feature p_feature);
  83. EditorFeatureProfile();
  84. };
  85. VARIANT_ENUM_CAST(EditorFeatureProfile::Feature)
  86. class EditorFeatureProfileManager : public AcceptDialog {
  87. GDCLASS(EditorFeatureProfileManager, AcceptDialog);
  88. enum Action {
  89. PROFILE_CLEAR,
  90. PROFILE_SET,
  91. PROFILE_IMPORT,
  92. PROFILE_EXPORT,
  93. PROFILE_NEW,
  94. PROFILE_ERASE,
  95. PROFILE_MAX
  96. };
  97. enum ClassOptions {
  98. CLASS_OPTION_DISABLE_EDITOR
  99. };
  100. ConfirmationDialog *erase_profile_dialog = nullptr;
  101. ConfirmationDialog *new_profile_dialog = nullptr;
  102. LineEdit *new_profile_name = nullptr;
  103. LineEdit *current_profile_name = nullptr;
  104. OptionButton *profile_list = nullptr;
  105. Button *profile_actions[PROFILE_MAX];
  106. HSplitContainer *h_split = nullptr;
  107. VBoxContainer *class_list_vbc = nullptr;
  108. Tree *class_list = nullptr;
  109. VBoxContainer *property_list_vbc = nullptr;
  110. Tree *property_list = nullptr;
  111. EditorHelpBit *description_bit = nullptr;
  112. Label *no_profile_selected_help = nullptr;
  113. EditorFileDialog *import_profiles = nullptr;
  114. EditorFileDialog *export_profile = nullptr;
  115. void _profile_action(int p_action);
  116. void _profile_selected(int p_what);
  117. void _hide_requested();
  118. String current_profile;
  119. void _update_profile_list(const String &p_select_profile = String());
  120. void _update_selected_profile();
  121. void _fill_classes_from(TreeItem *p_parent, const String &p_class, const String &p_selected);
  122. Ref<EditorFeatureProfile> current;
  123. Ref<EditorFeatureProfile> edited;
  124. void _erase_selected_profile();
  125. void _create_new_profile();
  126. String _get_selected_profile();
  127. void _import_profiles(const Vector<String> &p_paths);
  128. void _export_profile(const String &p_path);
  129. bool updating_features = false;
  130. void _class_list_item_selected();
  131. void _class_list_item_edited();
  132. void _class_list_item_collapsed(Object *p_item);
  133. void _property_item_edited();
  134. void _save_and_update();
  135. Timer *update_timer = nullptr;
  136. void _emit_current_profile_changed();
  137. static EditorFeatureProfileManager *singleton;
  138. protected:
  139. static void _bind_methods();
  140. void _notification(int p_what);
  141. public:
  142. Ref<EditorFeatureProfile> get_current_profile();
  143. String get_current_profile_name() const;
  144. void set_current_profile(const String &p_profile_name, bool p_validate_profile);
  145. void notify_changed();
  146. static EditorFeatureProfileManager *get_singleton() { return singleton; }
  147. EditorFeatureProfileManager();
  148. };
  149. #endif // EDITOR_FEATURE_PROFILE_H