Skip to content

Commit

Permalink
CraterCrashGH-89 On rename, notify user if new name already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Feb 2, 2024
1 parent fe8a393 commit e34c057
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/editor/script_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ void OrchestratorScriptViewSection::_notification(int p_what)
_confirm->set_title("Please confirm...");
_confirm->connect("confirmed", callable_mp(this, &OrchestratorScriptViewSection::_on_remove_confirmed));
add_child(_confirm);

_notify = memnew(AcceptDialog);
_notify->set_title("Message");
add_child(_notify);
}
else if (p_what == NOTIFICATION_THEME_CHANGED)
{
Expand Down Expand Up @@ -183,6 +187,13 @@ void OrchestratorScriptViewSection::_toggle()
_tree->set_visible(_expanded);
}

void OrchestratorScriptViewSection::_show_notification(const String& p_message)
{
_notify->set_text(p_message);
_notify->reset_size();
_notify->popup_centered();
}

void OrchestratorScriptViewSection::_confirm_removal(TreeItem* p_item)
{
_confirm->set_text(_get_remove_confirm_text(p_item));
Expand Down Expand Up @@ -494,6 +505,12 @@ void OrchestratorScriptViewGraphsSection::_handle_item_activated(TreeItem* p_ite

void OrchestratorScriptViewGraphsSection::_handle_item_renamed(const String& p_old_name, const String& p_new_name)
{
if (_get_existing_names().has(p_new_name))
{
_show_notification("A graph with the name '" + p_new_name + "' already exists.");
return;
}

_script->rename_graph(p_old_name, p_new_name);
emit_signal("graph_renamed", p_old_name, p_new_name);

Expand Down Expand Up @@ -689,6 +706,12 @@ void OrchestratorScriptViewFunctionsSection::_handle_item_activated(TreeItem* p_

void OrchestratorScriptViewFunctionsSection::_handle_item_renamed(const String& p_old_name, const String& p_new_name)
{
if (_get_existing_names().has(p_new_name))
{
_show_notification("A function with the name '" + p_new_name + "' already exists.");
return;
}

_script->rename_function(p_old_name, p_new_name);
emit_signal("graph_renamed", p_old_name, p_new_name);

Expand Down Expand Up @@ -923,6 +946,12 @@ void OrchestratorScriptViewVariablesSection::_handle_item_activated(TreeItem* p_

void OrchestratorScriptViewVariablesSection::_handle_item_renamed(const String& p_old_name, const String& p_new_name)
{
if (_get_existing_names().has(p_new_name))
{
_show_notification("A variable with the name '" + p_new_name + "' already exists.");
return;
}

_script->rename_variable(p_old_name, p_new_name);
update();
}
Expand Down Expand Up @@ -1093,6 +1122,12 @@ void OrchestratorScriptViewSignalsSection::_handle_item_activated(TreeItem* p_it

void OrchestratorScriptViewSignalsSection::_handle_item_renamed(const String& p_old_name, const String& p_new_name)
{
if (_get_existing_names().has(p_new_name))
{
_show_notification("A signal with the name '" + p_new_name + "' already exists.");
return;
}

_script->rename_custom_user_signal(p_old_name, p_new_name);
update();
}
Expand Down
5 changes: 5 additions & 0 deletions src/editor/script_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class OrchestratorScriptViewSection : public VBoxContainer
Button* _collapse_button{ nullptr }; //! The collapse button
PopupMenu* _context_menu{ nullptr }; //! Context menu
ConfirmationDialog* _confirm{ nullptr }; //! Confirmation dialog
AcceptDialog* _notify{ nullptr }; //! Notification dialog
bool _expanded{ true }; //! Whether the section is currently expanded
bool _theme_changing{ false }; //! Whether the theme is being changed

Expand All @@ -61,6 +62,10 @@ class OrchestratorScriptViewSection : public VBoxContainer
/// Toggles the visbility of the tree control.
void _toggle();

/// Notifies the user of a message.
/// @param p_message the text to notify
void _show_notification(const String& p_message);

/// Presents the user a dialog, confirming the removal of the tree item.
/// @param p_item the item to be removed, should not be null
void _confirm_removal(TreeItem* p_item);
Expand Down

0 comments on commit e34c057

Please sign in to comment.