浏览代码

Merge pull request #109619 from aaronp64/theme_editor_name_change

`ThemeEditor` fix to show filename for new/renamed files
Thaddeus Crews 3 周之前
父节点
当前提交
4854c0447b
共有 2 个文件被更改,包括 24 次插入1 次删除
  1. 21 1
      editor/scene/gui/theme_editor_plugin.cpp
  2. 3 0
      editor/scene/gui/theme_editor_plugin.h

+ 21 - 1
editor/scene/gui/theme_editor_plugin.cpp

@@ -31,6 +31,7 @@
 #include "theme_editor_plugin.h"
 #include "theme_editor_plugin.h"
 
 
 #include "editor/doc/editor_help.h"
 #include "editor/doc/editor_help.h"
+#include "editor/docks/filesystem_dock.h"
 #include "editor/docks/inspector_dock.h"
 #include "editor/docks/inspector_dock.h"
 #include "editor/editor_node.h"
 #include "editor/editor_node.h"
 #include "editor/editor_string_names.h"
 #include "editor/editor_string_names.h"
@@ -3710,7 +3711,7 @@ void ThemeEditor::edit(const Ref<Theme> &p_theme) {
 	}
 	}
 
 
 	if (theme.is_valid()) {
 	if (theme.is_valid()) {
-		theme_name->set_text(TTR("Theme:") + " " + theme->get_path().get_file());
+		_update_theme_name(theme->get_path().get_file());
 	}
 	}
 }
 }
 
 
@@ -3749,6 +3750,23 @@ void ThemeEditor::_scene_closed(const String &p_path) {
 	}
 	}
 }
 }
 
 
+void ThemeEditor::_resource_saved(const Ref<Resource> &p_resource) {
+	if (theme.is_valid() && theme == p_resource) {
+		_update_theme_name(theme->get_path().get_file());
+	}
+}
+
+void ThemeEditor::_files_moved(const String &p_old_path, const String &p_new_path) {
+	// Theme's path may not have been updated to new path yet - need to check both old and new.
+	if (theme.is_valid() && (theme->get_path() == p_old_path || theme->get_path() == p_new_path)) {
+		_update_theme_name(p_new_path.get_file());
+	}
+}
+
+void ThemeEditor::_update_theme_name(const String &p_name) {
+	theme_name->set_text(TTR("Theme:") + " " + p_name);
+}
+
 void ThemeEditor::_add_preview_button_cbk() {
 void ThemeEditor::_add_preview_button_cbk() {
 	preview_scene_dialog->popup_file_dialog();
 	preview_scene_dialog->popup_file_dialog();
 }
 }
@@ -3879,6 +3897,8 @@ void ThemeEditor::_notification(int p_what) {
 	switch (p_what) {
 	switch (p_what) {
 		case NOTIFICATION_READY: {
 		case NOTIFICATION_READY: {
 			EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ThemeEditor::_scene_closed));
 			EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ThemeEditor::_scene_closed));
+			EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ThemeEditor::_resource_saved));
+			FileSystemDock::get_singleton()->connect("files_moved", callable_mp(this, &ThemeEditor::_files_moved));
 		} break;
 		} break;
 
 
 		case NOTIFICATION_THEME_CHANGED: {
 		case NOTIFICATION_THEME_CHANGED: {

+ 3 - 0
editor/scene/gui/theme_editor_plugin.h

@@ -454,6 +454,9 @@ class ThemeEditor : public VBoxContainer {
 	void _theme_edit_button_cbk();
 	void _theme_edit_button_cbk();
 	void _theme_close_button_cbk();
 	void _theme_close_button_cbk();
 	void _scene_closed(const String &p_path);
 	void _scene_closed(const String &p_path);
+	void _resource_saved(const Ref<Resource> &p_resource);
+	void _files_moved(const String &p_old_path, const String &p_new_path);
+	void _update_theme_name(const String &p_name);
 
 
 	void _add_preview_button_cbk();
 	void _add_preview_button_cbk();
 	void _preview_scene_dialog_cbk(const String &p_path);
 	void _preview_scene_dialog_cbk(const String &p_path);