editor_toaster.cpp 21 KB

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