Skip to content

Commit

Permalink
Expose toast notification methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydensipe committed Nov 12, 2024
1 parent ec6a1c0 commit 722d932
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/classes/EditorInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
[b]Note:[/b] When creating custom editor UI, prefer accessing theme items directly from your GUI nodes using the [code]get_theme_*[/code] methods.
</description>
</method>
<method name="get_editor_toaster" qualifiers="const">
<return type="EditorToaster" />
<description>
Returns the editor's [EditorToaster].
</description>
</method>
<method name="get_editor_undo_redo" qualifiers="const">
<return type="EditorUndoRedoManager" />
<description>
Expand Down
34 changes: 34 additions & 0 deletions doc/classes/EditorToaster.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorToaster" inherits="HBoxContainer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Manages toast notifications within the editor.
</brief_description>
<description>
This object manages the functionality and display of toast notifications within the editor, ensuring timely and informative alerts are presented to users.
[b]Note:[/b] This class shouldn't be instantiated directly. Instead, access the singleton using [method EditorInterface.get_editor_toaster].
</description>
<tutorials>
</tutorials>
<methods>
<method name="push_toast">
<return type="void" />
<param index="0" name="message" type="String" />
<param index="1" name="severity" type="int" enum="EditorToaster.Severity" default="0" />
<param index="2" name="tooltip" type="String" default="&quot;&quot;" />
<description>
Pushes a toast notification to the editor for display.
</description>
</method>
</methods>
<constants>
<constant name="SEVERITY_INFO" value="0" enum="Severity">
Toast will display with an INFO severity.
</constant>
<constant name="SEVERITY_WARNING" value="1" enum="Severity">
Toast will display with a WARNING severity and have a corresponding color.
</constant>
<constant name="SEVERITY_ERROR" value="2" enum="Severity">
Toast will display with an ERROR severity and have a corresponding color.
</constant>
</constants>
</class>
6 changes: 6 additions & 0 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "editor/gui/editor_quick_open_dialog.h"
#include "editor/gui/editor_run_bar.h"
#include "editor/gui/editor_scene_tabs.h"
#include "editor/gui/editor_toaster.h"
#include "editor/gui/scene_tree_editor.h"
#include "editor/inspector_dock.h"
#include "editor/plugins/node_3d_editor_plugin.h"
Expand Down Expand Up @@ -89,6 +90,10 @@ Ref<EditorSettings> EditorInterface::get_editor_settings() const {
return EditorSettings::get_singleton();
}

EditorToaster *EditorInterface::get_editor_toaster() const {
return EditorToaster::get_singleton();
}

EditorUndoRedoManager *EditorInterface::get_editor_undo_redo() const {
return EditorUndoRedoManager::get_singleton();
}
Expand Down Expand Up @@ -581,6 +586,7 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_resource_previewer"), &EditorInterface::get_resource_previewer);
ClassDB::bind_method(D_METHOD("get_selection"), &EditorInterface::get_selection);
ClassDB::bind_method(D_METHOD("get_editor_settings"), &EditorInterface::get_editor_settings);
ClassDB::bind_method(D_METHOD("get_editor_toaster"), &EditorInterface::get_editor_toaster);
ClassDB::bind_method(D_METHOD("get_editor_undo_redo"), &EditorInterface::get_editor_undo_redo);

ClassDB::bind_method(D_METHOD("make_mesh_previews", "meshes", "preview_size"), &EditorInterface::_make_mesh_previews);
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class EditorPlugin;
class EditorResourcePreview;
class EditorSelection;
class EditorSettings;
class EditorToaster;
class EditorUndoRedoManager;
class FileSystemDock;
class Mesh;
Expand Down Expand Up @@ -104,6 +105,7 @@ class EditorInterface : public Object {
EditorResourcePreview *get_resource_previewer() const;
EditorSelection *get_selection() const;
Ref<EditorSettings> get_editor_settings() const;
EditorToaster *get_editor_toaster() const;
EditorUndoRedoManager *get_editor_undo_redo() const;

Vector<Ref<Texture2D>> make_mesh_previews(const Vector<Ref<Mesh>> &p_meshes, Vector<Transform3D> *p_transforms, int p_preview_size);
Expand Down
8 changes: 8 additions & 0 deletions editor/gui/editor_toaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ void EditorToaster::instant_close(Control *p_control) {
p_control->set_modulate(Color(1, 1, 1, 0));
}

void EditorToaster::_bind_methods() {
ClassDB::bind_method(D_METHOD("push_toast", "message", "severity", "tooltip"), &EditorToaster::_popup_str, DEFVAL(EditorToaster::SEVERITY_INFO), DEFVAL(String()));

BIND_ENUM_CONSTANT(SEVERITY_INFO);
BIND_ENUM_CONSTANT(SEVERITY_WARNING);
BIND_ENUM_CONSTANT(SEVERITY_ERROR);
}

EditorToaster *EditorToaster::get_singleton() {
return singleton;
}
Expand Down
1 change: 1 addition & 0 deletions editor/gui/editor_toaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class EditorToaster : public HBoxContainer {
void _toast_theme_changed(Control *p_control);

protected:
static void _bind_methods();
static EditorToaster *singleton;

void _notification(int p_what);
Expand Down
2 changes: 2 additions & 0 deletions editor/register_editor_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "editor/filesystem_dock.h"
#include "editor/gui/editor_file_dialog.h"
#include "editor/gui/editor_spin_slider.h"
#include "editor/gui/editor_toaster.h"
#include "editor/import/3d/resource_importer_obj.h"
#include "editor/import/3d/resource_importer_scene.h"
#include "editor/import/editor_import_plugin.h"
Expand Down Expand Up @@ -146,6 +147,7 @@ void register_editor_types() {
GDREGISTER_CLASS(EditorSelection);
GDREGISTER_CLASS(EditorFileDialog);
GDREGISTER_CLASS(EditorSettings);
GDREGISTER_ABSTRACT_CLASS(EditorToaster);
GDREGISTER_CLASS(EditorNode3DGizmo);
GDREGISTER_CLASS(EditorNode3DGizmoPlugin);
GDREGISTER_ABSTRACT_CLASS(EditorResourcePreview);
Expand Down

0 comments on commit 722d932

Please sign in to comment.