Browse Source

Merge pull request #46593 from pycbouh/theme-editor-better-edit-ui

Refactor Edit Theme menu in Theme Editor
Rémi Verschelde 4 years ago
parent
commit
759b876b8a

File diff suppressed because it is too large
+ 0 - 0
editor/icons/FontSize.svg


File diff suppressed because it is too large
+ 0 - 0
editor/icons/ThemeRemoveAllItems.svg


File diff suppressed because it is too large
+ 0 - 0
editor/icons/ThemeRemoveCustomItems.svg


File diff suppressed because it is too large
+ 727 - 317
editor/plugins/theme_editor_plugin.cpp


+ 81 - 27
editor/plugins/theme_editor_plugin.h

@@ -41,6 +41,77 @@
 
 #include "editor/editor_node.h"
 
+class ThemeItemEditorDialog : public AcceptDialog {
+	GDCLASS(ThemeItemEditorDialog, AcceptDialog);
+
+	Ref<Theme> edited_theme;
+
+	ItemList *edit_type_list;
+	OptionButton *edit_add_class_options;
+	LineEdit *edit_add_custom_value;
+	String edited_item_type;
+
+	Button *edit_items_add_color;
+	Button *edit_items_add_constant;
+	Button *edit_items_add_font;
+	Button *edit_items_add_font_size;
+	Button *edit_items_add_icon;
+	Button *edit_items_add_stylebox;
+	Button *edit_items_remove_class;
+	Button *edit_items_remove_custom;
+	Button *edit_items_remove_all;
+	Tree *edit_items_tree;
+
+	enum ItemsTreeAction {
+		ITEMS_TREE_RENAME_ITEM,
+		ITEMS_TREE_REMOVE_ITEM,
+		ITEMS_TREE_REMOVE_DATA_TYPE,
+	};
+
+	ConfirmationDialog *edit_theme_item_dialog;
+	VBoxContainer *edit_theme_item_old_vb;
+	Label *theme_item_old_name;
+	LineEdit *theme_item_name;
+
+	enum ItemPopupMode {
+		CREATE_THEME_ITEM,
+		RENAME_THEME_ITEM,
+		ITEM_POPUP_MODE_MAX
+	};
+
+	ItemPopupMode item_popup_mode = ITEM_POPUP_MODE_MAX;
+	String edit_item_old_name;
+	Theme::DataType edit_item_data_type = Theme::DATA_TYPE_MAX;
+
+	void _dialog_about_to_show();
+	void _update_edit_types();
+	void _edited_type_selected(int p_item_idx);
+
+	void _update_edit_item_tree(String p_item_type);
+	void _item_tree_button_pressed(Object *p_item, int p_column, int p_id);
+
+	void _add_class_type_items();
+	void _add_custom_type();
+	void _add_theme_item(Theme::DataType p_data_type, String p_item_name, String p_item_type);
+	void _remove_data_type_items(Theme::DataType p_data_type, String p_item_type);
+	void _remove_class_items();
+	void _remove_custom_items();
+	void _remove_all_items();
+
+	void _open_add_theme_item_dialog(int p_data_type);
+	void _open_rename_theme_item_dialog(Theme::DataType p_data_type, String p_item_name);
+	void _confirm_edit_theme_item();
+	void _edit_theme_item_gui_input(const Ref<InputEvent> &p_event);
+
+protected:
+	void _notification(int p_what);
+
+public:
+	void set_edited_theme(const Ref<Theme> &p_theme);
+
+	ThemeItemEditorDialog();
+};
+
 class ThemeEditor : public VBoxContainer {
 	GDCLASS(ThemeEditor, VBoxContainer);
 
@@ -50,40 +121,23 @@ class ThemeEditor : public VBoxContainer {
 
 	EditorFileDialog *file_dialog;
 
-	double time_left;
-
-	MenuButton *theme_menu;
-	ConfirmationDialog *add_del_dialog;
-	HBoxContainer *type_hbc;
-	MenuButton *type_menu;
-	LineEdit *type_edit;
-	HBoxContainer *name_hbc;
-	MenuButton *name_menu;
-	LineEdit *name_edit;
-	OptionButton *type_select;
-	Label *type_select_label;
-	Label *name_select_label;
-
-	enum PopupMode {
-		POPUP_ADD,
-		POPUP_CLASS_ADD,
-		POPUP_REMOVE,
-		POPUP_CLASS_REMOVE,
+	double time_left = 0;
+
+	Button *theme_edit_button;
+	MenuButton *theme_create_menu;
+	ThemeItemEditorDialog *theme_edit_dialog;
+
+	enum CreatePopupMode {
 		POPUP_CREATE_EMPTY,
 		POPUP_CREATE_EDITOR_EMPTY,
-		POPUP_IMPORT_EDITOR_THEME
+		POPUP_IMPORT_EDITOR_THEME,
 	};
 
-	int popup_mode;
-
 	Tree *test_tree;
 
 	void _save_template_cbk(String fname);
-	void _dialog_cbk();
-	void _type_menu_cbk(int p_option);
-	void _name_menu_about_to_show();
-	void _name_menu_cbk(int p_option);
-	void _theme_menu_cbk(int p_option);
+	void _theme_edit_button_cbk();
+	void _theme_create_menu_cbk(int p_option);
 	void _propagate_redraw(Control *p_at);
 	void _refresh_interval();
 

+ 45 - 0
scene/resources/theme.cpp

@@ -508,6 +508,10 @@ bool Theme::has_icon(const StringName &p_name, const StringName &p_node_type) co
 	return (icon_map.has(p_node_type) && icon_map[p_node_type].has(p_name) && icon_map[p_node_type][p_name].is_valid());
 }
 
+bool Theme::has_icon_nocheck(const StringName &p_name, const StringName &p_node_type) const {
+	return (icon_map.has(p_node_type) && icon_map[p_node_type].has(p_name));
+}
+
 void Theme::rename_icon(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) {
 	ERR_FAIL_COND_MSG(!icon_map.has(p_node_type), "Cannot rename the icon '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist.");
 	ERR_FAIL_COND_MSG(icon_map[p_node_type].has(p_name), "Cannot rename the icon '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
@@ -592,6 +596,10 @@ bool Theme::has_stylebox(const StringName &p_name, const StringName &p_node_type
 	return (style_map.has(p_node_type) && style_map[p_node_type].has(p_name) && style_map[p_node_type][p_name].is_valid());
 }
 
+bool Theme::has_stylebox_nocheck(const StringName &p_name, const StringName &p_node_type) const {
+	return (style_map.has(p_node_type) && style_map[p_node_type].has(p_name));
+}
+
 void Theme::rename_stylebox(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) {
 	ERR_FAIL_COND_MSG(!style_map.has(p_node_type), "Cannot rename the stylebox '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist.");
 	ERR_FAIL_COND_MSG(style_map[p_node_type].has(p_name), "Cannot rename the stylebox '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
@@ -678,6 +686,10 @@ bool Theme::has_font(const StringName &p_name, const StringName &p_node_type) co
 	return ((font_map.has(p_node_type) && font_map[p_node_type].has(p_name) && font_map[p_node_type][p_name].is_valid()) || default_theme_font.is_valid());
 }
 
+bool Theme::has_font_nocheck(const StringName &p_name, const StringName &p_node_type) const {
+	return (font_map.has(p_node_type) && font_map[p_node_type].has(p_name));
+}
+
 void Theme::rename_font(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) {
 	ERR_FAIL_COND_MSG(!font_map.has(p_node_type), "Cannot rename the font '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist.");
 	ERR_FAIL_COND_MSG(font_map[p_node_type].has(p_name), "Cannot rename the font '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
@@ -755,6 +767,10 @@ bool Theme::has_font_size(const StringName &p_name, const StringName &p_node_typ
 	return ((font_size_map.has(p_node_type) && font_size_map[p_node_type].has(p_name) && (font_size_map[p_node_type][p_name] > 0)) || (default_theme_font_size > 0));
 }
 
+bool Theme::has_font_size_nocheck(const StringName &p_name, const StringName &p_node_type) const {
+	return (font_size_map.has(p_node_type) && font_size_map[p_node_type].has(p_name));
+}
+
 void Theme::rename_font_size(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) {
 	ERR_FAIL_COND_MSG(!font_size_map.has(p_node_type), "Cannot rename the font size '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist.");
 	ERR_FAIL_COND_MSG(font_size_map[p_node_type].has(p_name), "Cannot rename the font size '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
@@ -826,6 +842,10 @@ bool Theme::has_color(const StringName &p_name, const StringName &p_node_type) c
 	return (color_map.has(p_node_type) && color_map[p_node_type].has(p_name));
 }
 
+bool Theme::has_color_nocheck(const StringName &p_name, const StringName &p_node_type) const {
+	return (color_map.has(p_node_type) && color_map[p_node_type].has(p_name));
+}
+
 void Theme::rename_color(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) {
 	ERR_FAIL_COND_MSG(!color_map.has(p_node_type), "Cannot rename the color '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist.");
 	ERR_FAIL_COND_MSG(color_map[p_node_type].has(p_name), "Cannot rename the color '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
@@ -896,6 +916,10 @@ bool Theme::has_constant(const StringName &p_name, const StringName &p_node_type
 	return (constant_map.has(p_node_type) && constant_map[p_node_type].has(p_name));
 }
 
+bool Theme::has_constant_nocheck(const StringName &p_name, const StringName &p_node_type) const {
+	return (constant_map.has(p_node_type) && constant_map[p_node_type].has(p_name));
+}
+
 void Theme::rename_constant(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) {
 	ERR_FAIL_COND_MSG(!constant_map.has(p_node_type), "Cannot rename the constant '" + String(p_old_name) + "' because the node type '" + String(p_node_type) + "' does not exist.");
 	ERR_FAIL_COND_MSG(constant_map[p_node_type].has(p_name), "Cannot rename the constant '" + String(p_old_name) + "' because the new name '" + String(p_name) + "' already exists.");
@@ -1029,6 +1053,27 @@ bool Theme::has_theme_item(DataType p_data_type, const StringName &p_name, const
 	return false;
 }
 
+bool Theme::has_theme_item_nocheck(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const {
+	switch (p_data_type) {
+		case DATA_TYPE_COLOR:
+			return has_color_nocheck(p_name, p_node_type);
+		case DATA_TYPE_CONSTANT:
+			return has_constant_nocheck(p_name, p_node_type);
+		case DATA_TYPE_FONT:
+			return has_font_nocheck(p_name, p_node_type);
+		case DATA_TYPE_FONT_SIZE:
+			return has_font_size_nocheck(p_name, p_node_type);
+		case DATA_TYPE_ICON:
+			return has_icon_nocheck(p_name, p_node_type);
+		case DATA_TYPE_STYLEBOX:
+			return has_stylebox_nocheck(p_name, p_node_type);
+		case DATA_TYPE_MAX:
+			break; // Can't happen, but silences warning.
+	}
+
+	return false;
+}
+
 void Theme::rename_theme_item(DataType p_data_type, const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type) {
 	switch (p_data_type) {
 		case DATA_TYPE_COLOR:

+ 7 - 0
scene/resources/theme.h

@@ -119,6 +119,7 @@ public:
 	void set_icon(const StringName &p_name, const StringName &p_node_type, const Ref<Texture2D> &p_icon);
 	Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_node_type) const;
 	bool has_icon(const StringName &p_name, const StringName &p_node_type) const;
+	bool has_icon_nocheck(const StringName &p_name, const StringName &p_node_type) const;
 	void rename_icon(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type);
 	void clear_icon(const StringName &p_name, const StringName &p_node_type);
 	void get_icon_list(StringName p_node_type, List<StringName> *p_list) const;
@@ -128,6 +129,7 @@ public:
 	void set_stylebox(const StringName &p_name, const StringName &p_node_type, const Ref<StyleBox> &p_style);
 	Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_node_type) const;
 	bool has_stylebox(const StringName &p_name, const StringName &p_node_type) const;
+	bool has_stylebox_nocheck(const StringName &p_name, const StringName &p_node_type) const;
 	void rename_stylebox(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type);
 	void clear_stylebox(const StringName &p_name, const StringName &p_node_type);
 	void get_stylebox_list(StringName p_node_type, List<StringName> *p_list) const;
@@ -137,6 +139,7 @@ public:
 	void set_font(const StringName &p_name, const StringName &p_node_type, const Ref<Font> &p_font);
 	Ref<Font> get_font(const StringName &p_name, const StringName &p_node_type) const;
 	bool has_font(const StringName &p_name, const StringName &p_node_type) const;
+	bool has_font_nocheck(const StringName &p_name, const StringName &p_node_type) const;
 	void rename_font(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type);
 	void clear_font(const StringName &p_name, const StringName &p_node_type);
 	void get_font_list(StringName p_node_type, List<StringName> *p_list) const;
@@ -146,6 +149,7 @@ public:
 	void set_font_size(const StringName &p_name, const StringName &p_node_type, int p_font_size);
 	int get_font_size(const StringName &p_name, const StringName &p_node_type) const;
 	bool has_font_size(const StringName &p_name, const StringName &p_node_type) const;
+	bool has_font_size_nocheck(const StringName &p_name, const StringName &p_node_type) const;
 	void rename_font_size(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type);
 	void clear_font_size(const StringName &p_name, const StringName &p_node_type);
 	void get_font_size_list(StringName p_node_type, List<StringName> *p_list) const;
@@ -155,6 +159,7 @@ public:
 	void set_color(const StringName &p_name, const StringName &p_node_type, const Color &p_color);
 	Color get_color(const StringName &p_name, const StringName &p_node_type) const;
 	bool has_color(const StringName &p_name, const StringName &p_node_type) const;
+	bool has_color_nocheck(const StringName &p_name, const StringName &p_node_type) const;
 	void rename_color(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type);
 	void clear_color(const StringName &p_name, const StringName &p_node_type);
 	void get_color_list(StringName p_node_type, List<StringName> *p_list) const;
@@ -164,6 +169,7 @@ public:
 	void set_constant(const StringName &p_name, const StringName &p_node_type, int p_constant);
 	int get_constant(const StringName &p_name, const StringName &p_node_type) const;
 	bool has_constant(const StringName &p_name, const StringName &p_node_type) const;
+	bool has_constant_nocheck(const StringName &p_name, const StringName &p_node_type) const;
 	void rename_constant(const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type);
 	void clear_constant(const StringName &p_name, const StringName &p_node_type);
 	void get_constant_list(StringName p_node_type, List<StringName> *p_list) const;
@@ -173,6 +179,7 @@ public:
 	void set_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type, const Variant &p_value);
 	Variant get_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const;
 	bool has_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const;
+	bool has_theme_item_nocheck(DataType p_data_type, const StringName &p_name, const StringName &p_node_type) const;
 	void rename_theme_item(DataType p_data_type, const StringName &p_old_name, const StringName &p_name, const StringName &p_node_type);
 	void clear_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_node_type);
 	void get_theme_item_list(DataType p_data_type, StringName p_node_type, List<StringName> *p_list) const;

Some files were not shown because too many files changed in this diff