messages.vala 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (c) 2012-2026 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. namespace Crown
  6. {
  7. public Gtk.Box message_widget(Gtk.Label h1, Gtk.Widget? p = null)
  8. {
  9. var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 12);
  10. box.valign = Gtk.Align.CENTER;
  11. box.pack_start(h1);
  12. if (p != null)
  13. box.pack_start(p);
  14. return box;
  15. }
  16. public Gtk.Box long_running_task(string markup)
  17. {
  18. var h1 = new Gtk.Label(null);
  19. h1.set_markup(markup);
  20. h1.valign = Gtk.Align.CENTER;
  21. var spinner = new Gtk.Spinner();
  22. spinner.active = true;
  23. return message_widget(h1, spinner);
  24. }
  25. public Gtk.Box compiling_data()
  26. {
  27. return long_running_task("<span font_weight=\"bold\">Compiling data...</span>");
  28. }
  29. public Gtk.Box connecting_to_data_compiler()
  30. {
  31. return long_running_task("<span font_weight=\"bold\">Connecting to Data Compiler...</span>");
  32. }
  33. public Gtk.Box restart_compiler(string markup)
  34. {
  35. Gtk.Label h1 = new Gtk.Label(null);
  36. h1.set_markup(markup);
  37. Gtk.Label p = new Gtk.Label(null);
  38. p.get_style_context().add_class("colorfast-link");
  39. p.set_markup("Fix errors and <a href=\"restart\">restart the compiler</a> to continue.");
  40. p.activate_link.connect(() => {
  41. GLib.Application.get_default().activate_action("restart-backend", null);
  42. return true;
  43. });
  44. return message_widget(h1, p);
  45. }
  46. public Gtk.Box compiler_failed_compilation()
  47. {
  48. return restart_compiler("<span font_weight=\"bold\">Data compilation failed.</span>");
  49. }
  50. public Gtk.Box compiler_crashed()
  51. {
  52. return restart_compiler("<span font_weight=\"bold\">Data Compiler disconnected unexpectedly.</span>");
  53. }
  54. public delegate void RestartVieport();
  55. public Gtk.Box editor_oops(RestartVieport restart_viewport)
  56. {
  57. var h1 = new Gtk.Label(null);
  58. h1.set_markup("<span font_weight=\"bold\">Something went wrong.</span>");
  59. var p = new Gtk.Label(null);
  60. p.get_style_context().add_class("colorfast-link");
  61. p.set_markup("Try to <a href=\"restart\">restart this view</a>.");
  62. p.activate_link.connect(() => {
  63. restart_viewport();
  64. return true;
  65. });
  66. return message_widget(h1, p);
  67. }
  68. public Gtk.Box editor_disconnected()
  69. {
  70. Gtk.Label h1 = new Gtk.Label(null);
  71. h1.set_markup("<span font_weight=\"bold\">Disconnected.</span>");
  72. return message_widget(h1);
  73. }
  74. public Gtk.Box stopping_backend()
  75. {
  76. return long_running_task("<span font_weight=\"bold\">Stopping Backend...</span>");
  77. }
  78. public Gtk.Dialog new_resource_changed_dialog(Gtk.Window? parent, string resource_name)
  79. {
  80. Gtk.MessageDialog md = new Gtk.MessageDialog(parent
  81. , Gtk.DialogFlags.MODAL
  82. , Gtk.MessageType.WARNING
  83. , Gtk.ButtonsType.NONE
  84. , "Save changes to '%s' before closing?".printf(resource_name)
  85. );
  86. Gtk.Widget btn;
  87. btn = md.add_button("Close _without Saving", Gtk.ResponseType.NO);
  88. btn.get_style_context().add_class("destructive-action");
  89. md.add_button("_Cancel", Gtk.ResponseType.CANCEL);
  90. md.add_button("_Save", Gtk.ResponseType.YES);
  91. md.set_default_response(Gtk.ResponseType.YES);
  92. return md;
  93. }
  94. } /* namespace Crown */