Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit def5a04

Browse files
committedOct 4, 2024
Merge pull request godotengine#97543 from KoBeWi/to_edit_or_not_to_edit
Fix closing Theme Editor not actually closing it
2 parents e5688f5 + 66d2b0f commit def5a04

7 files changed

+30
-68
lines changed
 

‎editor/editor_node.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,7 @@ void EditorNode::hide_unused_editors(const Object *p_editing_owner) {
23902390
// This is to sweep properties that were removed from the inspector.
23912391
List<ObjectID> to_remove;
23922392
for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
2393-
const Object *context = ObjectDB::get_instance(kv.key);
2393+
Object *context = ObjectDB::get_instance(kv.key);
23942394
if (context) {
23952395
// In case of self-owning plugins, they are disabled here if they can auto hide.
23962396
const EditorPlugin *self_owning = Object::cast_to<EditorPlugin>(context);
@@ -2399,7 +2399,7 @@ void EditorNode::hide_unused_editors(const Object *p_editing_owner) {
23992399
}
24002400
}
24012401

2402-
if (!context) {
2402+
if (!context || context->call(SNAME("_should_stop_editing"))) {
24032403
to_remove.push_back(kv.key);
24042404
for (EditorPlugin *plugin : kv.value) {
24052405
if (plugin->can_auto_hide()) {

‎editor/editor_properties.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3179,6 +3179,10 @@ void EditorPropertyResource::_update_preferred_shader() {
31793179
}
31803180
}
31813181

3182+
bool EditorPropertyResource::_should_stop_editing() const {
3183+
return !resource_picker->is_toggle_pressed();
3184+
}
3185+
31823186
void EditorPropertyResource::_viewport_selected(const NodePath &p_path) {
31833187
Node *to_node = get_node(p_path);
31843188
if (!Object::cast_to<Viewport>(to_node)) {
@@ -3361,6 +3365,10 @@ void EditorPropertyResource::_notification(int p_what) {
33613365
}
33623366
}
33633367

3368+
void EditorPropertyResource::_bind_methods() {
3369+
ClassDB::bind_method(D_METHOD("_should_stop_editing"), &EditorPropertyResource::_should_stop_editing);
3370+
}
3371+
33643372
EditorPropertyResource::EditorPropertyResource() {
33653373
use_sub_inspector = bool(EDITOR_GET("interface/inspector/open_resources_in_current_inspector"));
33663374
has_borders = true;

‎editor/editor_properties.h

+2
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,12 @@ class EditorPropertyResource : public EditorProperty {
683683

684684
void _open_editor_pressed();
685685
void _update_preferred_shader();
686+
bool _should_stop_editing() const;
686687

687688
protected:
688689
virtual void _set_read_only(bool p_read_only) override;
689690
void _notification(int p_what);
691+
static void _bind_methods();
690692

691693
public:
692694
virtual void update_property() override;

‎editor/editor_resource_picker.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,10 @@ void EditorResourcePicker::set_toggle_pressed(bool p_pressed) {
949949
assign_button->set_pressed(p_pressed);
950950
}
951951

952+
bool EditorResourcePicker::is_toggle_pressed() const {
953+
return assign_button->is_pressed();
954+
}
955+
952956
void EditorResourcePicker::set_editable(bool p_editable) {
953957
editable = p_editable;
954958
assign_button->set_disabled(!editable && !edited_resource.is_valid());

‎editor/editor_resource_picker.h

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class EditorResourcePicker : public HBoxContainer {
135135
void set_toggle_mode(bool p_enable);
136136
bool is_toggle_mode() const;
137137
void set_toggle_pressed(bool p_pressed);
138+
bool is_toggle_pressed() const;
138139

139140
void set_editable(bool p_editable);
140141
bool is_editable() const;

‎editor/plugins/theme_editor_plugin.cpp

+12-66
Original file line numberDiff line numberDiff line change
@@ -3596,6 +3596,13 @@ void ThemeEditor::_theme_close_button_cbk() {
35963596
}
35973597
}
35983598

3599+
void ThemeEditor::_scene_closed(const String &p_path) {
3600+
if (theme.is_valid() && theme->is_built_in() && theme->get_path().get_slice("::", 0) == p_path) {
3601+
theme = Ref<Theme>();
3602+
EditorNode::get_singleton()->hide_unused_editors(plugin);
3603+
}
3604+
}
3605+
35993606
void ThemeEditor::_add_preview_button_cbk() {
36003607
preview_scene_dialog->popup_file_dialog();
36013608
}
@@ -3679,7 +3686,10 @@ void ThemeEditor::_preview_control_picked(String p_class_name) {
36793686

36803687
void ThemeEditor::_notification(int p_what) {
36813688
switch (p_what) {
3682-
case NOTIFICATION_ENTER_TREE:
3689+
case NOTIFICATION_READY: {
3690+
EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ThemeEditor::_scene_closed));
3691+
} break;
3692+
36833693
case NOTIFICATION_THEME_CHANGED: {
36843694
preview_tabs->add_theme_style_override("tab_selected", get_theme_stylebox(SNAME("ThemeEditorPreviewFG"), EditorStringName(EditorStyles)));
36853695
preview_tabs->add_theme_style_override("tab_unselected", get_theme_stylebox(SNAME("ThemeEditorPreviewBG"), EditorStringName(EditorStyles)));
@@ -3807,71 +3817,7 @@ void ThemeEditorPlugin::make_visible(bool p_visible) {
38073817
}
38083818

38093819
bool ThemeEditorPlugin::can_auto_hide() const {
3810-
Ref<Theme> edited_theme = theme_editor->theme;
3811-
if (edited_theme.is_null()) {
3812-
return true;
3813-
}
3814-
3815-
Ref<Resource> edited_resource = Ref<Resource>(InspectorDock::get_inspector_singleton()->get_next_edited_object());
3816-
if (edited_resource.is_null()) {
3817-
return true;
3818-
}
3819-
3820-
// Don't hide if edited resource used by this theme.
3821-
Ref<StyleBox> sbox = edited_resource;
3822-
if (sbox.is_valid()) {
3823-
List<StringName> type_list;
3824-
edited_theme->get_stylebox_type_list(&type_list);
3825-
3826-
for (const StringName &E : type_list) {
3827-
List<StringName> list;
3828-
edited_theme->get_stylebox_list(E, &list);
3829-
3830-
for (const StringName &F : list) {
3831-
if (edited_theme->get_stylebox(F, E) == sbox) {
3832-
return false;
3833-
}
3834-
}
3835-
}
3836-
return true;
3837-
}
3838-
3839-
Ref<Texture2D> tex = edited_resource;
3840-
if (tex.is_valid()) {
3841-
List<StringName> type_list;
3842-
edited_theme->get_icon_type_list(&type_list);
3843-
3844-
for (const StringName &E : type_list) {
3845-
List<StringName> list;
3846-
edited_theme->get_icon_list(E, &list);
3847-
3848-
for (const StringName &F : list) {
3849-
if (edited_theme->get_icon(F, E) == tex) {
3850-
return false;
3851-
}
3852-
}
3853-
}
3854-
return true;
3855-
}
3856-
3857-
Ref<Font> fnt = edited_resource;
3858-
if (fnt.is_valid()) {
3859-
List<StringName> type_list;
3860-
edited_theme->get_font_type_list(&type_list);
3861-
3862-
for (const StringName &E : type_list) {
3863-
List<StringName> list;
3864-
edited_theme->get_font_list(E, &list);
3865-
3866-
for (const StringName &F : list) {
3867-
if (edited_theme->get_font(F, E) == fnt) {
3868-
return false;
3869-
}
3870-
}
3871-
}
3872-
return true;
3873-
}
3874-
return true;
3820+
return theme_editor->theme.is_null();
38753821
}
38763822

38773823
ThemeEditorPlugin::ThemeEditorPlugin() {

‎editor/plugins/theme_editor_plugin.h

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ class ThemeEditor : public VBoxContainer {
445445
void _theme_save_button_cbk(bool p_save_as);
446446
void _theme_edit_button_cbk();
447447
void _theme_close_button_cbk();
448+
void _scene_closed(const String &p_path);
448449

449450
void _add_preview_button_cbk();
450451
void _preview_scene_dialog_cbk(const String &p_path);

0 commit comments

Comments
 (0)
Please sign in to comment.