From 81a7a2c50c6bb5930b6ea8aeb03c924f0b9b5479 Mon Sep 17 00:00:00 2001 From: Jayden Sipe Date: Sat, 2 Nov 2024 00:02:36 -0400 Subject: [PATCH] Add copy to toast notification --- editor/gui/editor_toaster.cpp | 16 +++++++++++++++- editor/gui/editor_toaster.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/editor/gui/editor_toaster.cpp b/editor/gui/editor_toaster.cpp index ff425ba65e1..60f02ccfd4a 100644 --- a/editor/gui/editor_toaster.cpp +++ b/editor/gui/editor_toaster.cpp @@ -371,13 +371,19 @@ Control *EditorToaster::popup(Control *p_control, Severity p_severity, double p_ p_control->set_h_size_flags(SIZE_EXPAND_FILL); hbox_container->add_child(p_control); - // Close button. + // Add buttons. if (p_time > 0.0) { + Button *copy_button = memnew(Button); + copy_button->set_flat(true); + copy_button->connect(SceneStringName(pressed), callable_mp(this, &EditorToaster::copy).bind(panel)); + hbox_container->add_child(copy_button); + Button *close_button = memnew(Button); close_button->set_flat(true); close_button->connect(SceneStringName(pressed), callable_mp(this, &EditorToaster::instant_close).bind(panel)); hbox_container->add_child(close_button); + toast.copy_button = copy_button; toast.close_button = close_button; } @@ -493,6 +499,9 @@ void EditorToaster::_toast_theme_changed(Control *p_control) { if (toast.close_button) { toast.close_button->set_button_icon(get_editor_theme_icon(SNAME("Close"))); } + if (toast.copy_button) { + toast.copy_button->set_button_icon(get_editor_theme_icon(SNAME("ActionCopy"))); + } } void EditorToaster::close(Control *p_control) { @@ -506,6 +515,11 @@ void EditorToaster::instant_close(Control *p_control) { p_control->set_modulate(Color(1, 1, 1, 0)); } +void EditorToaster::copy(Control *p_control) { + ERR_FAIL_COND(!toasts.has(p_control)); + DisplayServer::get_singleton()->clipboard_set(toasts[p_control].message); +} + void EditorToaster::_bind_methods() { ClassDB::bind_method(D_METHOD("push_toast", "message", "severity", "tooltip"), &EditorToaster::_popup_str, DEFVAL(EditorToaster::SEVERITY_INFO), DEFVAL(String())); diff --git a/editor/gui/editor_toaster.h b/editor/gui/editor_toaster.h index 0d0080945ea..467569f62b0 100644 --- a/editor/gui/editor_toaster.h +++ b/editor/gui/editor_toaster.h @@ -75,6 +75,7 @@ private: bool popped = false; // Buttons + Button *copy_button = nullptr; Button *close_button = nullptr; // Messages @@ -117,6 +118,7 @@ public: void popup_str(const String &p_message, Severity p_severity = SEVERITY_INFO, const String &p_tooltip = String()); void close(Control *p_control); void instant_close(Control *p_control); + void copy(Control *p_control); EditorToaster(); ~EditorToaster();