summaryrefslogtreecommitdiffstats
path: root/editor/editor_command_palette.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-09-25 17:18:33 +0200
committerRémi Verschelde <rverschelde@gmail.com>2023-09-25 17:18:33 +0200
commitf0a980840f77d464bc14c1d1966865413853d703 (patch)
tree59308600f7bc90d6ee87cc390c0c36389761eb03 /editor/editor_command_palette.cpp
parent8ddf73c74dfa6ca51462a4721d77ba84e813b51a (diff)
parent9f0b8c0a705e608868ac952976ef70f773a03bbd (diff)
downloadredot-engine-f0a980840f77d464bc14c1d1966865413853d703.tar.gz
Merge pull request #82194 from KoBeWi/your_command_failed._Good_luck_finding_out_why
Add call validation to CommandPalette
Diffstat (limited to 'editor/editor_command_palette.cpp')
-rw-r--r--editor/editor_command_palette.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp
index 18a251a306..da970980eb 100644
--- a/editor/editor_command_palette.cpp
+++ b/editor/editor_command_palette.cpp
@@ -34,6 +34,7 @@
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
+#include "editor/gui/editor_toaster.h"
#include "scene/gui/control.h"
#include "scene/gui/tree.h"
@@ -184,10 +185,10 @@ void EditorCommandPalette::_sbox_input(const Ref<InputEvent> &p_ie) {
void EditorCommandPalette::_confirmed() {
TreeItem *selected_option = search_options->get_selected();
- String command_key = selected_option != nullptr ? selected_option->get_metadata(0) : "";
+ const String command_key = selected_option != nullptr ? selected_option->get_metadata(0) : "";
if (!command_key.is_empty()) {
hide();
- execute_command(command_key);
+ callable_mp(this, &EditorCommandPalette::execute_command).call_deferred(command_key);
}
}
@@ -248,11 +249,19 @@ void EditorCommandPalette::_add_command(String p_command_name, String p_key_name
commands[p_key_name] = command;
}
-void EditorCommandPalette::execute_command(String &p_command_key) {
+void EditorCommandPalette::execute_command(const String &p_command_key) {
ERR_FAIL_COND_MSG(!commands.has(p_command_key), p_command_key + " not found.");
commands[p_command_key].last_used = OS::get_singleton()->get_unix_time();
- commands[p_command_key].callable.call_deferred();
_save_history();
+
+ Variant ret;
+ Callable::CallError ce;
+ const Callable &callable = commands[p_command_key].callable;
+ callable.callp(nullptr, 0, ret, ce);
+
+ if (ce.error != Callable::CallError::CALL_OK) {
+ EditorToaster::get_singleton()->popup_str(vformat(TTR("Failed to execute command \"%s\":\n%s."), p_command_key, Variant::get_callable_error_text(callable, nullptr, 0, ce)), EditorToaster::SEVERITY_ERROR);
+ }
}
void EditorCommandPalette::register_shortcuts_as_command() {