Skip to content

Commit 722d932

Browse files
committed
Expose toast notification methods
1 parent ec6a1c0 commit 722d932

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed

doc/classes/EditorInterface.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
[b]Note:[/b] When creating custom editor UI, prefer accessing theme items directly from your GUI nodes using the [code]get_theme_*[/code] methods.
118118
</description>
119119
</method>
120+
<method name="get_editor_toaster" qualifiers="const">
121+
<return type="EditorToaster" />
122+
<description>
123+
Returns the editor's [EditorToaster].
124+
</description>
125+
</method>
120126
<method name="get_editor_undo_redo" qualifiers="const">
121127
<return type="EditorUndoRedoManager" />
122128
<description>

doc/classes/EditorToaster.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="EditorToaster" inherits="HBoxContainer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
Manages toast notifications within the editor.
5+
</brief_description>
6+
<description>
7+
This object manages the functionality and display of toast notifications within the editor, ensuring timely and informative alerts are presented to users.
8+
[b]Note:[/b] This class shouldn't be instantiated directly. Instead, access the singleton using [method EditorInterface.get_editor_toaster].
9+
</description>
10+
<tutorials>
11+
</tutorials>
12+
<methods>
13+
<method name="push_toast">
14+
<return type="void" />
15+
<param index="0" name="message" type="String" />
16+
<param index="1" name="severity" type="int" enum="EditorToaster.Severity" default="0" />
17+
<param index="2" name="tooltip" type="String" default="&quot;&quot;" />
18+
<description>
19+
Pushes a toast notification to the editor for display.
20+
</description>
21+
</method>
22+
</methods>
23+
<constants>
24+
<constant name="SEVERITY_INFO" value="0" enum="Severity">
25+
Toast will display with an INFO severity.
26+
</constant>
27+
<constant name="SEVERITY_WARNING" value="1" enum="Severity">
28+
Toast will display with a WARNING severity and have a corresponding color.
29+
</constant>
30+
<constant name="SEVERITY_ERROR" value="2" enum="Severity">
31+
Toast will display with an ERROR severity and have a corresponding color.
32+
</constant>
33+
</constants>
34+
</class>

editor/editor_interface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "editor/gui/editor_quick_open_dialog.h"
4444
#include "editor/gui/editor_run_bar.h"
4545
#include "editor/gui/editor_scene_tabs.h"
46+
#include "editor/gui/editor_toaster.h"
4647
#include "editor/gui/scene_tree_editor.h"
4748
#include "editor/inspector_dock.h"
4849
#include "editor/plugins/node_3d_editor_plugin.h"
@@ -89,6 +90,10 @@ Ref<EditorSettings> EditorInterface::get_editor_settings() const {
8990
return EditorSettings::get_singleton();
9091
}
9192

93+
EditorToaster *EditorInterface::get_editor_toaster() const {
94+
return EditorToaster::get_singleton();
95+
}
96+
9297
EditorUndoRedoManager *EditorInterface::get_editor_undo_redo() const {
9398
return EditorUndoRedoManager::get_singleton();
9499
}
@@ -581,6 +586,7 @@ void EditorInterface::_bind_methods() {
581586
ClassDB::bind_method(D_METHOD("get_resource_previewer"), &EditorInterface::get_resource_previewer);
582587
ClassDB::bind_method(D_METHOD("get_selection"), &EditorInterface::get_selection);
583588
ClassDB::bind_method(D_METHOD("get_editor_settings"), &EditorInterface::get_editor_settings);
589+
ClassDB::bind_method(D_METHOD("get_editor_toaster"), &EditorInterface::get_editor_toaster);
584590
ClassDB::bind_method(D_METHOD("get_editor_undo_redo"), &EditorInterface::get_editor_undo_redo);
585591

586592
ClassDB::bind_method(D_METHOD("make_mesh_previews", "meshes", "preview_size"), &EditorInterface::_make_mesh_previews);

editor/editor_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class EditorPlugin;
4545
class EditorResourcePreview;
4646
class EditorSelection;
4747
class EditorSettings;
48+
class EditorToaster;
4849
class EditorUndoRedoManager;
4950
class FileSystemDock;
5051
class Mesh;
@@ -104,6 +105,7 @@ class EditorInterface : public Object {
104105
EditorResourcePreview *get_resource_previewer() const;
105106
EditorSelection *get_selection() const;
106107
Ref<EditorSettings> get_editor_settings() const;
108+
EditorToaster *get_editor_toaster() const;
107109
EditorUndoRedoManager *get_editor_undo_redo() const;
108110

109111
Vector<Ref<Texture2D>> make_mesh_previews(const Vector<Ref<Mesh>> &p_meshes, Vector<Transform3D> *p_transforms, int p_preview_size);

editor/gui/editor_toaster.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,14 @@ void EditorToaster::instant_close(Control *p_control) {
506506
p_control->set_modulate(Color(1, 1, 1, 0));
507507
}
508508

509+
void EditorToaster::_bind_methods() {
510+
ClassDB::bind_method(D_METHOD("push_toast", "message", "severity", "tooltip"), &EditorToaster::_popup_str, DEFVAL(EditorToaster::SEVERITY_INFO), DEFVAL(String()));
511+
512+
BIND_ENUM_CONSTANT(SEVERITY_INFO);
513+
BIND_ENUM_CONSTANT(SEVERITY_WARNING);
514+
BIND_ENUM_CONSTANT(SEVERITY_ERROR);
515+
}
516+
509517
EditorToaster *EditorToaster::get_singleton() {
510518
return singleton;
511519
}

editor/gui/editor_toaster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class EditorToaster : public HBoxContainer {
105105
void _toast_theme_changed(Control *p_control);
106106

107107
protected:
108+
static void _bind_methods();
108109
static EditorToaster *singleton;
109110

110111
void _notification(int p_what);

editor/register_editor_types.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "editor/filesystem_dock.h"
5353
#include "editor/gui/editor_file_dialog.h"
5454
#include "editor/gui/editor_spin_slider.h"
55+
#include "editor/gui/editor_toaster.h"
5556
#include "editor/import/3d/resource_importer_obj.h"
5657
#include "editor/import/3d/resource_importer_scene.h"
5758
#include "editor/import/editor_import_plugin.h"
@@ -146,6 +147,7 @@ void register_editor_types() {
146147
GDREGISTER_CLASS(EditorSelection);
147148
GDREGISTER_CLASS(EditorFileDialog);
148149
GDREGISTER_CLASS(EditorSettings);
150+
GDREGISTER_ABSTRACT_CLASS(EditorToaster);
149151
GDREGISTER_CLASS(EditorNode3DGizmo);
150152
GDREGISTER_CLASS(EditorNode3DGizmoPlugin);
151153
GDREGISTER_ABSTRACT_CLASS(EditorResourcePreview);

0 commit comments

Comments
 (0)