瀏覽代碼

Disable the OK button when no node is selected.

(cherry picked from commit 83d478ffcd12a77803b0646749c06eca14802d99)
Chia-Hsiang Cheng 3 年之前
父節點
當前提交
c9e59457e5
共有 2 個文件被更改,包括 10 次插入0 次删除
  1. 9 0
      editor/scene_tree_editor.cpp
  2. 1 0
      editor/scene_tree_editor.h

+ 9 - 0
editor/scene_tree_editor.cpp

@@ -1315,6 +1315,10 @@ void SceneTreeDialog::_select() {
 	}
 }
 
+void SceneTreeDialog::_selected_changed() {
+	get_ok()->set_disabled(!tree->get_selected());
+}
+
 void SceneTreeDialog::_filter_changed(const String &p_filter) {
 	tree->set_filter(p_filter);
 }
@@ -1322,6 +1326,7 @@ void SceneTreeDialog::_filter_changed(const String &p_filter) {
 void SceneTreeDialog::_bind_methods() {
 	ClassDB::bind_method("_select", &SceneTreeDialog::_select);
 	ClassDB::bind_method("_cancel", &SceneTreeDialog::_cancel);
+	ClassDB::bind_method(D_METHOD("_selected_changed"), &SceneTreeDialog::_selected_changed);
 	ClassDB::bind_method(D_METHOD("_filter_changed"), &SceneTreeDialog::_filter_changed);
 
 	ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::NODE_PATH, "path")));
@@ -1343,6 +1348,10 @@ SceneTreeDialog::SceneTreeDialog() {
 	tree->set_v_size_flags(SIZE_EXPAND_FILL);
 	tree->get_scene_tree()->connect("item_activated", this, "_select");
 	vbc->add_child(tree);
+
+	// Disable the OK button when no node is selected.
+	get_ok()->set_disabled(!tree->get_selected());
+	tree->connect("node_selected", this, "_selected_changed");
 }
 
 SceneTreeDialog::~SceneTreeDialog() {

+ 1 - 0
editor/scene_tree_editor.h

@@ -170,6 +170,7 @@ class SceneTreeDialog : public ConfirmationDialog {
 
 	void _select();
 	void _cancel();
+	void _selected_changed();
 	void _filter_changed(const String &p_filter);
 
 protected: