editor_toaster.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /**************************************************************************/
  2. /* editor_toaster.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_toaster.h"
  31. #include "editor/editor_scale.h"
  32. #include "editor/editor_settings.h"
  33. #include "editor/editor_string_names.h"
  34. #include "scene/gui/button.h"
  35. #include "scene/gui/label.h"
  36. #include "scene/gui/panel_container.h"
  37. #include "scene/resources/style_box_flat.h"
  38. EditorToaster *EditorToaster::singleton = nullptr;
  39. void EditorToaster::_notification(int p_what) {
  40. switch (p_what) {
  41. case NOTIFICATION_INTERNAL_PROCESS: {
  42. double delta = get_process_delta_time();
  43. // Check if one element is hovered, if so, don't elapse time.
  44. bool hovered = false;
  45. for (const KeyValue<Control *, Toast> &element : toasts) {
  46. if (Rect2(Vector2(), element.key->get_size()).has_point(element.key->get_local_mouse_position())) {
  47. hovered = true;
  48. break;
  49. }
  50. }
  51. // Elapses the time and remove toasts if needed.
  52. if (!hovered) {
  53. for (const KeyValue<Control *, Toast> &element : toasts) {
  54. if (!element.value.popped || element.value.duration <= 0) {
  55. continue;
  56. }
  57. toasts[element.key].remaining_time -= delta;
  58. if (toasts[element.key].remaining_time < 0) {
  59. close(element.key);
  60. }
  61. element.key->queue_redraw();
  62. }
  63. } else {
  64. // Reset the timers when hovered.
  65. for (const KeyValue<Control *, Toast> &element : toasts) {
  66. if (!element.value.popped || element.value.duration <= 0) {
  67. continue;
  68. }
  69. toasts[element.key].remaining_time = element.value.duration;
  70. element.key->queue_redraw();
  71. }
  72. }
  73. // Change alpha over time.
  74. bool needs_update = false;
  75. for (const KeyValue<Control *, Toast> &element : toasts) {
  76. Color modulate_fade = element.key->get_modulate();
  77. // Change alpha over time.
  78. if (element.value.popped && modulate_fade.a < 1.0) {
  79. modulate_fade.a += delta * 3;
  80. element.key->set_modulate(modulate_fade);
  81. } else if (!element.value.popped && modulate_fade.a > 0.0) {
  82. modulate_fade.a -= delta * 2;
  83. element.key->set_modulate(modulate_fade);
  84. }
  85. // Hide element if it is not visible anymore.
  86. if (modulate_fade.a <= 0.0 && element.key->is_visible()) {
  87. element.key->hide();
  88. needs_update = true;
  89. } else if (modulate_fade.a > 0.0 && !element.key->is_visible()) {
  90. element.key->show();
  91. needs_update = true;
  92. }
  93. }
  94. if (needs_update) {
  95. _update_vbox_position();
  96. _update_disable_notifications_button();
  97. main_button->queue_redraw();
  98. }
  99. } break;
  100. case NOTIFICATION_ENTER_TREE:
  101. case NOTIFICATION_THEME_CHANGED: {
  102. if (vbox_container->is_visible()) {
  103. main_button->set_icon(get_editor_theme_icon(SNAME("Notification")));
  104. } else {
  105. main_button->set_icon(get_editor_theme_icon(SNAME("NotificationDisabled")));
  106. }
  107. disable_notifications_button->set_icon(get_editor_theme_icon(SNAME("NotificationDisabled")));
  108. // Styleboxes background.
  109. info_panel_style_background->set_bg_color(get_theme_color(SNAME("base_color"), EditorStringName(Editor)));
  110. warning_panel_style_background->set_bg_color(get_theme_color(SNAME("base_color"), EditorStringName(Editor)));
  111. warning_panel_style_background->set_border_color(get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  112. error_panel_style_background->set_bg_color(get_theme_color(SNAME("base_color"), EditorStringName(Editor)));
  113. error_panel_style_background->set_border_color(get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  114. // Styleboxes progress.
  115. info_panel_style_progress->set_bg_color(get_theme_color(SNAME("base_color"), EditorStringName(Editor)).lightened(0.03));
  116. warning_panel_style_progress->set_bg_color(get_theme_color(SNAME("base_color"), EditorStringName(Editor)).lightened(0.03));
  117. warning_panel_style_progress->set_border_color(get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  118. error_panel_style_progress->set_bg_color(get_theme_color(SNAME("base_color"), EditorStringName(Editor)).lightened(0.03));
  119. error_panel_style_progress->set_border_color(get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  120. main_button->queue_redraw();
  121. disable_notifications_button->queue_redraw();
  122. } break;
  123. case NOTIFICATION_TRANSFORM_CHANGED: {
  124. _update_vbox_position();
  125. _update_disable_notifications_button();
  126. } break;
  127. }
  128. }
  129. void EditorToaster::_error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type) {
  130. // This may be called from a thread. Since we will deal with non-thread-safe elements,
  131. // we have to put it in the queue for safety.
  132. callable_mp_static(&EditorToaster::_error_handler_impl).bind(String::utf8(p_file), p_line, String::utf8(p_error), String::utf8(p_errorexp), p_editor_notify, p_type).call_deferred();
  133. }
  134. void EditorToaster::_error_handler_impl(const String &p_file, int p_line, const String &p_error, const String &p_errorexp, bool p_editor_notify, int p_type) {
  135. if (!EditorToaster::get_singleton() || !EditorToaster::get_singleton()->is_inside_tree()) {
  136. return;
  137. }
  138. #ifdef DEV_ENABLED
  139. bool in_dev = true;
  140. #else
  141. bool in_dev = false;
  142. #endif
  143. int show_all_setting = EDITOR_GET("interface/editor/show_internal_errors_in_toast_notifications");
  144. if (p_editor_notify || (show_all_setting == 0 && in_dev) || show_all_setting == 1) {
  145. String err_str = !p_errorexp.is_empty() ? p_errorexp : p_error;
  146. String tooltip_str = p_file + ":" + itos(p_line);
  147. if (!p_editor_notify) {
  148. if (p_type == ERR_HANDLER_WARNING) {
  149. err_str = "INTERNAL WARNING: " + err_str;
  150. } else {
  151. err_str = "INTERNAL ERROR: " + err_str;
  152. }
  153. }
  154. Severity severity = ((ErrorHandlerType)p_type == ERR_HANDLER_WARNING) ? SEVERITY_WARNING : SEVERITY_ERROR;
  155. EditorToaster::get_singleton()->popup_str(err_str, severity, tooltip_str);
  156. }
  157. }
  158. void EditorToaster::_update_vbox_position() {
  159. // This is kind of a workaround because it's hard to keep the VBox anchroed to the bottom.
  160. vbox_container->set_size(Vector2());
  161. vbox_container->set_position(get_global_position() - vbox_container->get_size() + Vector2(get_size().x, -5 * EDSCALE));
  162. }
  163. void EditorToaster::_update_disable_notifications_button() {
  164. bool any_visible = false;
  165. for (KeyValue<Control *, Toast> element : toasts) {
  166. if (element.key->is_visible()) {
  167. any_visible = true;
  168. break;
  169. }
  170. }
  171. if (!any_visible || !vbox_container->is_visible()) {
  172. disable_notifications_panel->hide();
  173. } else {
  174. disable_notifications_panel->show();
  175. disable_notifications_panel->set_position(get_global_position() + Vector2(5 * EDSCALE, -disable_notifications_panel->get_minimum_size().y) + Vector2(get_size().x, -5 * EDSCALE));
  176. }
  177. }
  178. void EditorToaster::_auto_hide_or_free_toasts() {
  179. // Hide or free old temporary items.
  180. int visible_temporary = 0;
  181. int temporary = 0;
  182. LocalVector<Control *> to_delete;
  183. for (int i = vbox_container->get_child_count() - 1; i >= 0; i--) {
  184. Control *control = Object::cast_to<Control>(vbox_container->get_child(i));
  185. if (toasts[control].duration <= 0) {
  186. continue; // Ignore non-temporary toasts.
  187. }
  188. temporary++;
  189. if (control->is_visible()) {
  190. visible_temporary++;
  191. }
  192. // Hide
  193. if (visible_temporary > max_temporary_count) {
  194. close(control);
  195. }
  196. // Free
  197. if (temporary > max_temporary_count * 2) {
  198. to_delete.push_back(control);
  199. }
  200. }
  201. // Delete the control right away (removed as child) as it might cause issues otherwise when iterative over the vbox_container children.
  202. for (Control *c : to_delete) {
  203. vbox_container->remove_child(c);
  204. c->queue_free();
  205. toasts.erase(c);
  206. }
  207. if (toasts.is_empty()) {
  208. main_button->set_tooltip_text(TTR("No notifications."));
  209. main_button->set_modulate(Color(0.5, 0.5, 0.5));
  210. main_button->set_disabled(true);
  211. } else {
  212. main_button->set_tooltip_text(TTR("Show notifications."));
  213. main_button->set_modulate(Color(1, 1, 1));
  214. main_button->set_disabled(false);
  215. }
  216. }
  217. void EditorToaster::_draw_button() {
  218. bool has_one = false;
  219. Severity highest_severity = SEVERITY_INFO;
  220. for (const KeyValue<Control *, Toast> &element : toasts) {
  221. if (!element.key->is_visible()) {
  222. continue;
  223. }
  224. has_one = true;
  225. if (element.value.severity > highest_severity) {
  226. highest_severity = element.value.severity;
  227. }
  228. }
  229. if (!has_one) {
  230. return;
  231. }
  232. Color color;
  233. real_t button_radius = main_button->get_size().x / 8;
  234. switch (highest_severity) {
  235. case SEVERITY_INFO:
  236. color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
  237. break;
  238. case SEVERITY_WARNING:
  239. color = get_theme_color(SNAME("warning_color"), EditorStringName(Editor));
  240. break;
  241. case SEVERITY_ERROR:
  242. color = get_theme_color(SNAME("error_color"), EditorStringName(Editor));
  243. break;
  244. default:
  245. break;
  246. }
  247. main_button->draw_circle(Vector2(button_radius * 2, button_radius * 2), button_radius, color);
  248. }
  249. void EditorToaster::_draw_progress(Control *panel) {
  250. if (toasts.has(panel) && toasts[panel].remaining_time > 0 && toasts[panel].duration > 0) {
  251. Size2 size = panel->get_size();
  252. size.x *= MIN(1, Math::remap(toasts[panel].remaining_time, 0, toasts[panel].duration, 0, 2));
  253. Ref<StyleBoxFlat> stylebox;
  254. switch (toasts[panel].severity) {
  255. case SEVERITY_INFO:
  256. stylebox = info_panel_style_progress;
  257. break;
  258. case SEVERITY_WARNING:
  259. stylebox = warning_panel_style_progress;
  260. break;
  261. case SEVERITY_ERROR:
  262. stylebox = error_panel_style_progress;
  263. break;
  264. default:
  265. break;
  266. }
  267. panel->draw_style_box(stylebox, Rect2(Vector2(), size));
  268. }
  269. }
  270. void EditorToaster::_set_notifications_enabled(bool p_enabled) {
  271. vbox_container->set_visible(p_enabled);
  272. if (p_enabled) {
  273. main_button->set_icon(get_editor_theme_icon(SNAME("Notification")));
  274. } else {
  275. main_button->set_icon(get_editor_theme_icon(SNAME("NotificationDisabled")));
  276. }
  277. _update_disable_notifications_button();
  278. }
  279. void EditorToaster::_repop_old() {
  280. // Repop olds, up to max_temporary_count
  281. bool needs_update = false;
  282. int visible_count = 0;
  283. for (int i = vbox_container->get_child_count() - 1; i >= 0; i--) {
  284. Control *control = Object::cast_to<Control>(vbox_container->get_child(i));
  285. if (!control->is_visible()) {
  286. control->show();
  287. toasts[control].remaining_time = toasts[control].duration;
  288. toasts[control].popped = true;
  289. needs_update = true;
  290. }
  291. visible_count++;
  292. if (visible_count >= max_temporary_count) {
  293. break;
  294. }
  295. }
  296. if (needs_update) {
  297. _update_vbox_position();
  298. _update_disable_notifications_button();
  299. main_button->queue_redraw();
  300. }
  301. }
  302. Control *EditorToaster::popup(Control *p_control, Severity p_severity, double p_time, String p_tooltip) {
  303. // Create the panel according to the severity.
  304. PanelContainer *panel = memnew(PanelContainer);
  305. panel->set_tooltip_text(p_tooltip);
  306. switch (p_severity) {
  307. case SEVERITY_INFO:
  308. panel->add_theme_style_override("panel", info_panel_style_background);
  309. break;
  310. case SEVERITY_WARNING:
  311. panel->add_theme_style_override("panel", warning_panel_style_background);
  312. break;
  313. case SEVERITY_ERROR:
  314. panel->add_theme_style_override("panel", error_panel_style_background);
  315. break;
  316. default:
  317. break;
  318. }
  319. panel->set_modulate(Color(1, 1, 1, 0));
  320. panel->connect("draw", callable_mp(this, &EditorToaster::_draw_progress).bind(panel));
  321. // Horizontal container.
  322. HBoxContainer *hbox_container = memnew(HBoxContainer);
  323. hbox_container->set_h_size_flags(SIZE_EXPAND_FILL);
  324. panel->add_child(hbox_container);
  325. // Content control.
  326. p_control->set_h_size_flags(SIZE_EXPAND_FILL);
  327. hbox_container->add_child(p_control);
  328. // Close button.
  329. if (p_time > 0.0) {
  330. Button *close_button = memnew(Button);
  331. close_button->set_flat(true);
  332. close_button->set_icon(get_editor_theme_icon(SNAME("Close")));
  333. close_button->connect("pressed", callable_mp(this, &EditorToaster::close).bind(panel));
  334. close_button->connect("theme_changed", callable_mp(this, &EditorToaster::_close_button_theme_changed).bind(close_button));
  335. hbox_container->add_child(close_button);
  336. }
  337. toasts[panel].severity = p_severity;
  338. if (p_time > 0.0) {
  339. toasts[panel].duration = p_time;
  340. toasts[panel].remaining_time = p_time;
  341. } else {
  342. toasts[panel].duration = -1.0;
  343. }
  344. toasts[panel].popped = true;
  345. vbox_container->add_child(panel);
  346. _auto_hide_or_free_toasts();
  347. _update_vbox_position();
  348. _update_disable_notifications_button();
  349. main_button->queue_redraw();
  350. return panel;
  351. }
  352. void EditorToaster::popup_str(String p_message, Severity p_severity, String p_tooltip) {
  353. if (is_processing_error) {
  354. return;
  355. }
  356. // Since "_popup_str" adds nodes to the tree, and since the "add_child" method is not
  357. // thread-safe, it's better to defer the call to the next cycle to be thread-safe.
  358. is_processing_error = true;
  359. call_deferred(SNAME("_popup_str"), p_message, p_severity, p_tooltip);
  360. is_processing_error = false;
  361. }
  362. void EditorToaster::_popup_str(String p_message, Severity p_severity, String p_tooltip) {
  363. is_processing_error = true;
  364. // Check if we already have a popup with the given message.
  365. Control *control = nullptr;
  366. for (KeyValue<Control *, Toast> element : toasts) {
  367. if (element.value.message == p_message && element.value.severity == p_severity && element.value.tooltip == p_tooltip) {
  368. control = element.key;
  369. break;
  370. }
  371. }
  372. // Create a new message if needed.
  373. if (control == nullptr) {
  374. HBoxContainer *hb = memnew(HBoxContainer);
  375. hb->add_theme_constant_override("separation", 0);
  376. Label *label = memnew(Label);
  377. hb->add_child(label);
  378. Label *count_label = memnew(Label);
  379. hb->add_child(count_label);
  380. control = popup(hb, p_severity, default_message_duration, p_tooltip);
  381. toasts[control].message = p_message;
  382. toasts[control].tooltip = p_tooltip;
  383. toasts[control].count = 1;
  384. toasts[control].message_label = label;
  385. toasts[control].message_count_label = count_label;
  386. } else {
  387. if (toasts[control].popped) {
  388. toasts[control].count += 1;
  389. } else {
  390. toasts[control].count = 1;
  391. }
  392. toasts[control].remaining_time = toasts[control].duration;
  393. toasts[control].popped = true;
  394. control->show();
  395. vbox_container->move_child(control, vbox_container->get_child_count());
  396. _auto_hide_or_free_toasts();
  397. _update_vbox_position();
  398. _update_disable_notifications_button();
  399. main_button->queue_redraw();
  400. }
  401. // Retrieve the label back, then update the text.
  402. Label *message_label = toasts[control].message_label;
  403. ERR_FAIL_NULL(message_label);
  404. message_label->set_text(p_message);
  405. message_label->set_text_overrun_behavior(TextServer::OVERRUN_NO_TRIMMING);
  406. message_label->set_custom_minimum_size(Size2());
  407. Size2i size = message_label->get_combined_minimum_size();
  408. int limit_width = get_viewport_rect().size.x / 2; // Limit label size to half the viewport size.
  409. if (size.x > limit_width) {
  410. message_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS);
  411. message_label->set_custom_minimum_size(Size2(limit_width, 0));
  412. }
  413. // Retrieve the count label back, then update the text.
  414. Label *message_count_label = toasts[control].message_count_label;
  415. if (toasts[control].count == 1) {
  416. message_count_label->hide();
  417. } else {
  418. message_count_label->set_text(vformat("(%d)", toasts[control].count));
  419. message_count_label->show();
  420. }
  421. vbox_container->reset_size();
  422. is_processing_error = false;
  423. }
  424. void EditorToaster::close(Control *p_control) {
  425. ERR_FAIL_COND(!toasts.has(p_control));
  426. toasts[p_control].remaining_time = -1.0;
  427. toasts[p_control].popped = false;
  428. }
  429. void EditorToaster::_close_button_theme_changed(Control *p_close_button) {
  430. Button *close_button = Object::cast_to<Button>(p_close_button);
  431. if (close_button) {
  432. close_button->set_icon(get_editor_theme_icon(SNAME("Close")));
  433. }
  434. }
  435. EditorToaster *EditorToaster::get_singleton() {
  436. return singleton;
  437. }
  438. void EditorToaster::_bind_methods() {
  439. // Binding method to make it defer-able.
  440. ClassDB::bind_method(D_METHOD("_popup_str", "message", "severity", "tooltip"), &EditorToaster::_popup_str);
  441. }
  442. EditorToaster::EditorToaster() {
  443. set_notify_transform(true);
  444. set_process_internal(true);
  445. // VBox.
  446. vbox_container = memnew(VBoxContainer);
  447. vbox_container->set_as_top_level(true);
  448. vbox_container->connect("resized", callable_mp(this, &EditorToaster::_update_vbox_position));
  449. add_child(vbox_container);
  450. // Theming (background).
  451. info_panel_style_background.instantiate();
  452. info_panel_style_background->set_corner_radius_all(stylebox_radius * EDSCALE);
  453. warning_panel_style_background.instantiate();
  454. warning_panel_style_background->set_border_width(SIDE_LEFT, stylebox_radius * EDSCALE);
  455. warning_panel_style_background->set_corner_radius_all(stylebox_radius * EDSCALE);
  456. error_panel_style_background.instantiate();
  457. error_panel_style_background->set_border_width(SIDE_LEFT, stylebox_radius * EDSCALE);
  458. error_panel_style_background->set_corner_radius_all(stylebox_radius * EDSCALE);
  459. Ref<StyleBoxFlat> boxes[] = { info_panel_style_background, warning_panel_style_background, error_panel_style_background };
  460. for (int i = 0; i < 3; i++) {
  461. boxes[i]->set_content_margin_individual(int(stylebox_radius * 2.5), 3, int(stylebox_radius * 2.5), 3);
  462. }
  463. // Theming (progress).
  464. info_panel_style_progress.instantiate();
  465. info_panel_style_progress->set_corner_radius_all(stylebox_radius * EDSCALE);
  466. warning_panel_style_progress.instantiate();
  467. warning_panel_style_progress->set_border_width(SIDE_LEFT, stylebox_radius * EDSCALE);
  468. warning_panel_style_progress->set_corner_radius_all(stylebox_radius * EDSCALE);
  469. error_panel_style_progress.instantiate();
  470. error_panel_style_progress->set_border_width(SIDE_LEFT, stylebox_radius * EDSCALE);
  471. error_panel_style_progress->set_corner_radius_all(stylebox_radius * EDSCALE);
  472. // Main button.
  473. main_button = memnew(Button);
  474. main_button->set_tooltip_text(TTR("No notifications."));
  475. main_button->set_modulate(Color(0.5, 0.5, 0.5));
  476. main_button->set_disabled(true);
  477. main_button->set_flat(true);
  478. main_button->connect("pressed", callable_mp(this, &EditorToaster::_set_notifications_enabled).bind(true));
  479. main_button->connect("pressed", callable_mp(this, &EditorToaster::_repop_old));
  480. main_button->connect("draw", callable_mp(this, &EditorToaster::_draw_button));
  481. add_child(main_button);
  482. // Disable notification button.
  483. disable_notifications_panel = memnew(PanelContainer);
  484. disable_notifications_panel->set_as_top_level(true);
  485. disable_notifications_panel->add_theme_style_override("panel", info_panel_style_background);
  486. add_child(disable_notifications_panel);
  487. disable_notifications_button = memnew(Button);
  488. disable_notifications_button->set_tooltip_text(TTR("Silence the notifications."));
  489. disable_notifications_button->set_flat(true);
  490. disable_notifications_button->connect("pressed", callable_mp(this, &EditorToaster::_set_notifications_enabled).bind(false));
  491. disable_notifications_panel->add_child(disable_notifications_button);
  492. // Other
  493. singleton = this;
  494. eh.errfunc = _error_handler;
  495. add_error_handler(&eh);
  496. };
  497. EditorToaster::~EditorToaster() {
  498. singleton = nullptr;
  499. remove_error_handler(&eh);
  500. }