Skip to content

Commit

Permalink
Add copy to toast notification
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydensipe committed Nov 3, 2024
1 parent c6c464c commit c5079b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion editor/gui/editor_toaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,15 @@ 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->set_focus_mode(FOCUS_NONE);
copy_button->connect(SceneStringName(pressed), callable_mp(this, &EditorToaster::copy).bind(panel));
copy_button->connect(SceneStringName(theme_changed), callable_mp(this, &EditorToaster::_copy_button_theme_changed).bind(copy_button));
hbox_container->add_child(copy_button);

Button *close_button = memnew(Button);
close_button->set_flat(true);
close_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
Expand Down Expand Up @@ -495,6 +502,18 @@ void EditorToaster::_close_button_theme_changed(Control *p_close_button) {
}
}

void EditorToaster::copy(Control *p_control) {
ERR_FAIL_COND(!toasts.has(p_control));
DisplayServer::get_singleton()->clipboard_set(toasts[p_control].message);
}

void EditorToaster::_copy_button_theme_changed(Control *p_copy_button) {
Button *copy_button = Object::cast_to<Button>(p_copy_button);
if (copy_button) {
copy_button->set_button_icon(get_editor_theme_icon(SNAME("ActionCopy")));
}
}

EditorToaster *EditorToaster::get_singleton() {
return singleton;
}
Expand Down
2 changes: 2 additions & 0 deletions editor/gui/editor_toaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class EditorToaster : public HBoxContainer {
void _repop_old();
void _popup_str(const String &p_message, Severity p_severity, const String &p_tooltip);
void _close_button_theme_changed(Control *p_close_button);
void _copy_button_theme_changed(Control *p_copy_button);

protected:
static EditorToaster *singleton;
Expand All @@ -114,6 +115,7 @@ class EditorToaster : public HBoxContainer {
Control *popup(Control *p_control, Severity p_severity = SEVERITY_INFO, double p_time = 0.0, const String &p_tooltip = String());
void popup_str(const String &p_message, Severity p_severity = SEVERITY_INFO, const String &p_tooltip = String());
void close(Control *p_control);
void copy(Control *p_control);

EditorToaster();
~EditorToaster();
Expand Down

0 comments on commit c5079b7

Please sign in to comment.