Merge pull request #95343 from Giganzo/unique-name-dialog

Add ConfirmationDialog when clicking on % button in SceneTree
This commit is contained in:
Rémi Verschelde 2024-09-04 17:11:46 +02:00
commit de2f50777e
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 53 additions and 6 deletions

View File

@ -174,15 +174,40 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i
EditorDockManager::get_singleton()->focus_dock(NodeDock::get_singleton()); EditorDockManager::get_singleton()->focus_dock(NodeDock::get_singleton());
NodeDock::get_singleton()->show_groups(); NodeDock::get_singleton()->show_groups();
} else if (p_id == BUTTON_UNIQUE) { } else if (p_id == BUTTON_UNIQUE) {
undo_redo->create_action(TTR("Disable Scene Unique Name")); bool ask_before_revoking_unique_name = EDITOR_GET("docks/scene_tree/ask_before_revoking_unique_name");
undo_redo->add_do_method(n, "set_unique_name_in_owner", false); revoke_node = n;
undo_redo->add_undo_method(n, "set_unique_name_in_owner", true); if (ask_before_revoking_unique_name) {
undo_redo->add_do_method(this, "_update_tree"); String msg = vformat(TTR("Revoke unique name for node \"%s\"?"), n->get_name());
undo_redo->add_undo_method(this, "_update_tree"); ask_before_revoke_checkbox->set_pressed(false);
undo_redo->commit_action(); revoke_dialog_label->set_text(msg);
revoke_dialog->reset_size();
revoke_dialog->popup_centered();
} else {
_revoke_unique_name();
}
} }
} }
void SceneTreeEditor::_update_ask_before_revoking_unique_name() {
if (ask_before_revoke_checkbox->is_pressed()) {
EditorSettings::get_singleton()->set("docks/scene_tree/ask_before_revoking_unique_name", false);
ask_before_revoke_checkbox->set_pressed(false);
}
_revoke_unique_name();
}
void SceneTreeEditor::_revoke_unique_name() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Disable Scene Unique Name"));
undo_redo->add_do_method(revoke_node, "set_unique_name_in_owner", false);
undo_redo->add_undo_method(revoke_node, "set_unique_name_in_owner", true);
undo_redo->add_do_method(this, "_update_tree");
undo_redo->add_undo_method(this, "_update_tree");
undo_redo->commit_action();
}
void SceneTreeEditor::_toggle_visible(Node *p_node) { void SceneTreeEditor::_toggle_visible(Node *p_node) {
if (p_node->has_method("is_visible") && p_node->has_method("set_visible")) { if (p_node->has_method("is_visible") && p_node->has_method("set_visible")) {
bool v = bool(p_node->call("is_visible")); bool v = bool(p_node->call("is_visible"));
@ -1620,6 +1645,18 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope
update_node_tooltip_delay->set_one_shot(true); update_node_tooltip_delay->set_one_shot(true);
add_child(update_node_tooltip_delay); add_child(update_node_tooltip_delay);
revoke_dialog = memnew(ConfirmationDialog);
revoke_dialog->set_ok_button_text(TTR("Revoke"));
add_child(revoke_dialog);
revoke_dialog->connect(SceneStringName(confirmed), callable_mp(this, &SceneTreeEditor::_update_ask_before_revoking_unique_name));
VBoxContainer *vb = memnew(VBoxContainer);
revoke_dialog->add_child(vb);
revoke_dialog_label = memnew(Label);
vb->add_child(revoke_dialog_label);
ask_before_revoke_checkbox = memnew(CheckBox(TTR("Don't Ask Again")));
ask_before_revoke_checkbox->set_tooltip_text(TTR("This dialog can also be enabled/disabled in the Editor Settings: Docks > Scene Tree > Ask Before Revoking Unique Name."));
vb->add_child(ask_before_revoke_checkbox);
script_types = memnew(List<StringName>); script_types = memnew(List<StringName>);
ClassDB::get_inheriters_from_class("Script", script_types); ClassDB::get_inheriters_from_class("Script", script_types);
} }

View File

@ -31,6 +31,7 @@
#ifndef SCENE_TREE_EDITOR_H #ifndef SCENE_TREE_EDITOR_H
#define SCENE_TREE_EDITOR_H #define SCENE_TREE_EDITOR_H
#include "scene/gui/check_box.h"
#include "scene/gui/check_button.h" #include "scene/gui/check_button.h"
#include "scene/gui/dialogs.h" #include "scene/gui/dialogs.h"
#include "scene/gui/tree.h" #include "scene/gui/tree.h"
@ -68,6 +69,11 @@ class SceneTreeEditor : public Control {
AcceptDialog *error = nullptr; AcceptDialog *error = nullptr;
AcceptDialog *warning = nullptr; AcceptDialog *warning = nullptr;
ConfirmationDialog *revoke_dialog = nullptr;
Label *revoke_dialog_label = nullptr;
CheckBox *ask_before_revoke_checkbox = nullptr;
Node *revoke_node = nullptr;
bool auto_expand_selected = true; bool auto_expand_selected = true;
bool connect_to_script_mode = false; bool connect_to_script_mode = false;
bool connecting_signal = false; bool connecting_signal = false;
@ -144,6 +150,9 @@ class SceneTreeEditor : public Control {
Vector<StringName> valid_types; Vector<StringName> valid_types;
void _update_ask_before_revoking_unique_name();
void _revoke_unique_name();
public: public:
// Public for use with callable_mp. // Public for use with callable_mp.
void _update_tree(bool p_scroll_to_selected = false); void _update_tree(bool p_scroll_to_selected = false);

View File

@ -4655,6 +4655,7 @@ SceneTreeDock::SceneTreeDock(Node *p_scene_root, EditorSelection *p_editor_selec
EDITOR_DEF("interface/editors/show_scene_tree_root_selection", true); EDITOR_DEF("interface/editors/show_scene_tree_root_selection", true);
EDITOR_DEF("interface/editors/derive_script_globals_by_name", true); EDITOR_DEF("interface/editors/derive_script_globals_by_name", true);
EDITOR_DEF("docks/scene_tree/ask_before_deleting_related_animation_tracks", true); EDITOR_DEF("docks/scene_tree/ask_before_deleting_related_animation_tracks", true);
EDITOR_DEF("docks/scene_tree/ask_before_revoking_unique_name", true);
EDITOR_DEF("_use_favorites_root_selection", false); EDITOR_DEF("_use_favorites_root_selection", false);
Resource::_update_configuration_warning = _update_configuration_warning; Resource::_update_configuration_warning = _update_configuration_warning;