Skip to content

Commit bb02ab2

Browse files
committed
Merge pull request #107436 from timothyqiu/action-button-icon
Fix some inspector action buttons not updating icon when theme changes
2 parents dd129b6 + 5593ac4 commit bb02ab2

16 files changed

+48
-121
lines changed

editor/inspector/editor_inspector.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@
5757
#include "scene/resources/style_box_flat.h"
5858
#include "scene/scene_string_names.h"
5959

60+
void EditorInspectorActionButton::_notification(int p_what) {
61+
switch (p_what) {
62+
case NOTIFICATION_THEME_CHANGED: {
63+
set_button_icon(get_editor_theme_icon(icon_name));
64+
} break;
65+
}
66+
}
67+
68+
EditorInspectorActionButton::EditorInspectorActionButton(const String &p_text, const StringName &p_icon_name) {
69+
icon_name = p_icon_name;
70+
set_text(p_text);
71+
set_theme_type_variation(SNAME("InspectorActionButton"));
72+
set_h_size_flags(SIZE_SHRINK_CENTER);
73+
}
74+
6075
bool EditorInspector::_property_path_matches(const String &p_property_path, const String &p_filter, EditorPropertyNameProcessor::Style p_style) {
6176
if (p_property_path.containsn(p_filter)) {
6277
return true;
@@ -3164,8 +3179,6 @@ void EditorInspectorArray::_notification(int p_what) {
31643179
ae.erase->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
31653180
}
31663181
}
3167-
3168-
add_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
31693182
} break;
31703183

31713184
case NOTIFICATION_DRAG_BEGIN: {
@@ -3256,7 +3269,7 @@ EditorInspectorArray::EditorInspectorArray(bool p_read_only) {
32563269
elements_vbox->add_theme_constant_override("separation", 0);
32573270
vbox->add_child(elements_vbox);
32583271

3259-
add_button = EditorInspector::create_inspector_action_button(TTR("Add Element"));
3272+
add_button = memnew(EditorInspectorActionButton(TTRC("Add Element"), SNAME("Add")));
32603273
add_button->connect(SceneStringName(pressed), callable_mp(this, &EditorInspectorArray::_add_button_pressed));
32613274
add_button->set_disabled(read_only);
32623275
vbox->add_child(add_button);
@@ -3513,14 +3526,6 @@ void EditorInspector::cleanup_plugins() {
35133526
inspector_plugin_count = 0;
35143527
}
35153528

3516-
Button *EditorInspector::create_inspector_action_button(const String &p_text) {
3517-
Button *button = memnew(Button);
3518-
button->set_text(p_text);
3519-
button->set_theme_type_variation(SNAME("InspectorActionButton"));
3520-
button->set_h_size_flags(SIZE_SHRINK_CENTER);
3521-
return button;
3522-
}
3523-
35243529
bool EditorInspector::is_main_editor_inspector() const {
35253530
return InspectorDock::get_singleton() && InspectorDock::get_inspector_singleton() == this;
35263531
}
@@ -4611,8 +4616,7 @@ void EditorInspector::update_tree() {
46114616
spacer->set_custom_minimum_size(Size2(0, 4) * EDSCALE);
46124617
main_vbox->add_child(spacer);
46134618

4614-
Button *add_md = EditorInspector::create_inspector_action_button(TTR("Add Metadata"));
4615-
add_md->set_button_icon(theme_cache.icon_add);
4619+
Button *add_md = memnew(EditorInspectorActionButton(TTRC("Add Metadata"), SNAME("Add")));
46164620
add_md->connect(SceneStringName(pressed), callable_mp(this, &EditorInspector::_show_add_meta_dialog));
46174621
main_vbox->add_child(add_md);
46184622
if (all_read_only) {

editor/inspector/editor_inspector.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232

3333
#include "editor/inspector/editor_property_name_processor.h"
3434
#include "scene/gui/box_container.h"
35+
#include "scene/gui/button.h"
3536
#include "scene/gui/panel_container.h"
3637
#include "scene/gui/scroll_container.h"
3738

3839
class AddMetadataDialog;
3940
class AcceptDialog;
40-
class Button;
4141
class ConfirmationDialog;
4242
class EditorInspector;
4343
class EditorValidationPanel;
@@ -57,6 +57,18 @@ class EditorPropertyRevert {
5757
static bool can_property_revert(Object *p_object, const StringName &p_property, const Variant *p_custom_current_value = nullptr);
5858
};
5959

60+
class EditorInspectorActionButton : public Button {
61+
GDCLASS(EditorInspectorActionButton, Button);
62+
63+
StringName icon_name;
64+
65+
protected:
66+
void _notification(int p_what);
67+
68+
public:
69+
EditorInspectorActionButton(const String &p_text, const StringName &p_icon_name);
70+
};
71+
6072
class EditorProperty : public Container {
6173
GDCLASS(EditorProperty, Container);
6274

@@ -765,7 +777,6 @@ class EditorInspector : public ScrollContainer {
765777
static void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
766778
static void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
767779
static void cleanup_plugins();
768-
static Button *create_inspector_action_button(const String &p_text);
769780

770781
static EditorProperty *instantiate_property_editor(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false);
771782

editor/inspector/editor_properties_array_dict.cpp

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,7 @@ void EditorPropertyArray::update_property() {
456456
property_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
457457
vbox->add_child(property_vbox);
458458

459-
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Element"));
460-
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
459+
button_add_item = memnew(EditorInspectorActionButton(TTRC("Add Element"), SNAME("Add")));
461460
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_add_element));
462461
button_add_item->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyArray::_button_add_item_draw));
463462
SET_DRAG_FORWARDING_CD(button_add_item, EditorPropertyArray);
@@ -750,12 +749,6 @@ Node *EditorPropertyArray::get_base_node() {
750749

751750
void EditorPropertyArray::_notification(int p_what) {
752751
switch (p_what) {
753-
case NOTIFICATION_THEME_CHANGED: {
754-
if (button_add_item) {
755-
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
756-
}
757-
} break;
758-
759752
case NOTIFICATION_DRAG_BEGIN: {
760753
if (is_visible_in_tree()) {
761754
if (_is_drop_valid(get_viewport()->gui_get_drag_data())) {
@@ -1305,8 +1298,7 @@ void EditorPropertyDictionary::update_property() {
13051298
_create_new_property_slot(EditorPropertyDictionaryObject::NEW_KEY_INDEX);
13061299
_create_new_property_slot(EditorPropertyDictionaryObject::NEW_VALUE_INDEX);
13071300

1308-
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Key/Value Pair"));
1309-
button_add_item->set_button_icon(get_theme_icon(SNAME("Add"), EditorStringName(EditorIcons)));
1301+
button_add_item = memnew(EditorInspectorActionButton(TTRC("Add Key/Value Pair"), SNAME("Add")));
13101302
button_add_item->set_disabled(is_read_only());
13111303
button_add_item->set_accessibility_name(TTRC("Add"));
13121304
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyDictionary::_add_key_value));
@@ -1454,7 +1446,6 @@ void EditorPropertyDictionary::_notification(int p_what) {
14541446
switch (p_what) {
14551447
case NOTIFICATION_THEME_CHANGED: {
14561448
if (button_add_item) {
1457-
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
14581449
add_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("DictionaryAddItem")));
14591450
}
14601451
} break;
@@ -1661,9 +1652,8 @@ void EditorPropertyLocalizableString::update_property() {
16611652
}
16621653

16631654
if (page_index == max_page) {
1664-
button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Translation"));
1655+
button_add_item = memnew(EditorInspectorActionButton(TTRC("Add Translation"), SNAME("Add")));
16651656
button_add_item->set_accessibility_name(TTRC("Add Translation"));
1666-
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
16671657
button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyLocalizableString::_add_locale_popup));
16681658
property_vbox->add_child(button_add_item);
16691659
}
@@ -1684,16 +1674,6 @@ void EditorPropertyLocalizableString::_object_id_selected(const StringName &p_pr
16841674
emit_signal(SNAME("object_id_selected"), p_property, p_id);
16851675
}
16861676

1687-
void EditorPropertyLocalizableString::_notification(int p_what) {
1688-
switch (p_what) {
1689-
case NOTIFICATION_THEME_CHANGED: {
1690-
if (button_add_item) {
1691-
button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add")));
1692-
}
1693-
} break;
1694-
}
1695-
}
1696-
16971677
void EditorPropertyLocalizableString::_edit_pressed() {
16981678
Variant prop_val = get_edited_property_value();
16991679
if (prop_val.get_type() == Variant::NIL && edit->is_pressed()) {

editor/inspector/editor_properties_array_dict.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,6 @@ class EditorPropertyLocalizableString : public EditorProperty {
295295
void _add_locale(const String &p_locale);
296296
void _object_id_selected(const StringName &p_property, ObjectID p_id);
297297

298-
protected:
299-
void _notification(int p_what);
300-
301298
public:
302299
virtual void update_property() override;
303300
EditorPropertyLocalizableString();

editor/inspector/input_event_editor_plugin.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
#include "editor/settings/event_listener_line_edit.h"
3535
#include "editor/settings/input_event_configuration_dialog.h"
3636

37-
void InputEventConfigContainer::_notification(int p_what) {
38-
switch (p_what) {
39-
case NOTIFICATION_THEME_CHANGED: {
40-
open_config_button->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
41-
} break;
42-
}
43-
}
44-
4537
void InputEventConfigContainer::_configure_pressed() {
4638
config_dialog->popup_and_configure(input_event);
4739
}
@@ -134,7 +126,7 @@ InputEventConfigContainer::InputEventConfigContainer() {
134126
input_event_text->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
135127
add_child(input_event_text);
136128

137-
open_config_button = EditorInspector::create_inspector_action_button(TTR("Configure"));
129+
EditorInspectorActionButton *open_config_button = memnew(EditorInspectorActionButton(TTRC("Configure"), SNAME("Edit")));
138130
open_config_button->connect(SceneStringName(pressed), callable_mp(this, &InputEventConfigContainer::_configure_pressed));
139131
add_child(open_config_button);
140132

editor/inspector/input_event_editor_plugin.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class InputEventConfigContainer : public VBoxContainer {
3838
GDCLASS(InputEventConfigContainer, VBoxContainer);
3939

4040
Label *input_event_text = nullptr;
41-
Button *open_config_button = nullptr;
4241

4342
Ref<InputEvent> input_event;
4443
InputEventConfigurationDialog *config_dialog = nullptr;
@@ -48,9 +47,6 @@ class InputEventConfigContainer : public VBoxContainer {
4847

4948
void _event_changed();
5049

51-
protected:
52-
void _notification(int p_what);
53-
5450
public:
5551
void set_event(const Ref<InputEvent> &p_event);
5652

editor/inspector/tool_button_editor_plugin.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030

3131
#include "tool_button_editor_plugin.h"
3232

33-
#include "scene/gui/button.h"
34-
35-
void EditorInspectorToolButtonPlugin::_update_action_icon(Button *p_action_button, const String &p_action_icon) {
36-
p_action_button->set_button_icon(p_action_button->get_editor_theme_icon(p_action_icon));
37-
}
38-
3933
void EditorInspectorToolButtonPlugin::_call_action(const Variant &p_object, const StringName &p_property) {
4034
Object *object = p_object.get_validated_object();
4135
ERR_FAIL_NULL_MSG(object, vformat(R"(Failed to get property "%s" on a previously freed instance.)", p_property));
@@ -65,10 +59,9 @@ bool EditorInspectorToolButtonPlugin::parse_property(Object *p_object, const Var
6559
const String &hint_text = splits[0]; // Safe since `splits` cannot be empty.
6660
const String &hint_icon = splits.size() > 1 ? splits[1] : "Callable";
6761

68-
Button *action_button = EditorInspector::create_inspector_action_button(hint_text);
62+
EditorInspectorActionButton *action_button = memnew(EditorInspectorActionButton(hint_text, hint_icon));
6963
action_button->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED);
7064
action_button->set_disabled(p_usage & PROPERTY_USAGE_READ_ONLY);
71-
action_button->connect(SceneStringName(theme_changed), callable_mp(this, &EditorInspectorToolButtonPlugin::_update_action_icon).bind(action_button, hint_icon));
7265
action_button->connect(SceneStringName(pressed), callable_mp(this, &EditorInspectorToolButtonPlugin::_call_action).bind(p_object, p_path));
7366

7467
add_custom_control(action_button);

editor/inspector/tool_button_editor_plugin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
class EditorInspectorToolButtonPlugin : public EditorInspectorPlugin {
3737
GDCLASS(EditorInspectorToolButtonPlugin, EditorInspectorPlugin);
3838

39-
void _update_action_icon(Button *p_action_button, const String &p_action_icon);
4039
void _call_action(const Variant &p_object, const StringName &p_property);
4140

4241
public:

editor/scene/3d/skeleton_3d_editor_plugin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void BonePropertiesEditor::create_editors() {
106106
meta_section->setup("bone_meta", TTR("Bone Metadata"), this, Color(.0f, .0f, .0f), true);
107107
section->get_vbox()->add_child(meta_section);
108108

109-
add_metadata_button = EditorInspector::create_inspector_action_button(TTR("Add Bone Metadata"));
109+
EditorInspectorActionButton *add_metadata_button = memnew(EditorInspectorActionButton(TTRC("Add Bone Metadata"), SNAME("Add")));
110110
add_metadata_button->connect(SceneStringName(pressed), callable_mp(this, &BonePropertiesEditor::_show_add_meta_dialog));
111111
section->get_vbox()->add_child(add_metadata_button);
112112

@@ -121,7 +121,6 @@ void BonePropertiesEditor::_notification(int p_what) {
121121
const Color section_color = get_theme_color(SNAME("prop_subsection"), EditorStringName(Editor));
122122
section->set_bg_color(section_color);
123123
rest_section->set_bg_color(section_color);
124-
add_metadata_button->set_button_icon(get_editor_theme_icon(SNAME("Add")));
125124
} break;
126125
}
127126
}

editor/scene/3d/skeleton_3d_editor_plugin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class BonePropertiesEditor : public VBoxContainer {
6565

6666
EditorInspectorSection *meta_section = nullptr;
6767
AddMetadataDialog *add_meta_dialog = nullptr;
68-
Button *add_metadata_button = nullptr;
6968

7069
Rect2 background_rects[5];
7170

0 commit comments

Comments
 (0)