[gnome-builder/wip/gtk4-port: 977/1774] plugins/debuggerui: menu actions to break on warning/critical




commit 4c8fd0a569feb79d2f7b5b0712381a4203d6712a
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 11 11:12:44 2022 -0700

    plugins/debuggerui: menu actions to break on warning/critical
    
    This allows setting the G_DEBUG=fatal-warnings or G_DEBUG=fatal-criticals
    environment variables with check menu items in the run menu. A new
    "Debugger" sections section is added to contain this.
    
    Even though we show these as checks, it's mostly to just not have to add
    a third "Don't break on log" menu item as we can't really toggle them
    individually.
    
    This also makes the IdeDebugManager a GActionGroup like we do for other
    manager objects with two new GAction for the breakpoint settings.

 src/libide/debugger/ide-debug-manager.c | 57 ++++++++++++++++++++++++++++++++-
 src/libide/gui/ide-workbench.c          |  1 +
 src/plugins/debuggerui/gtk/menus.ui     | 19 +++++++++++
 3 files changed, 76 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/debugger/ide-debug-manager.c b/src/libide/debugger/ide-debug-manager.c
index 2d4a9d359..b9d4fe6cd 100644
--- a/src/libide/debugger/ide-debug-manager.c
+++ b/src/libide/debugger/ide-debug-manager.c
@@ -50,6 +50,8 @@ struct _IdeDebugManager
   GPtrArray      *supported_languages;
 
   guint           active : 1;
+  guint           stop_at_criticals : 1;
+  guint           stop_at_warnings : 1;
 };
 
 typedef struct
@@ -74,10 +76,23 @@ enum {
   N_SIGNALS
 };
 
+static void ide_debug_manager_actions_stop_at_criticals (IdeDebugManager *self,
+                                                         GVariant        *param);
+static void ide_debug_manager_actions_stop_at_warnings  (IdeDebugManager *self,
+                                                         GVariant        *param);
+
+
 static GParamSpec *properties [N_PROPS];
 static guint signals [N_SIGNALS];
 
-G_DEFINE_FINAL_TYPE (IdeDebugManager, ide_debug_manager, IDE_TYPE_OBJECT)
+IDE_DEFINE_ACTION_GROUP (IdeDebugManager, ide_debug_manager, {
+  { "stop-at-criticals", ide_debug_manager_actions_stop_at_criticals, NULL, "false" },
+  { "stop-at-warnings", ide_debug_manager_actions_stop_at_warnings, NULL, "false" },
+})
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (IdeDebugManager, ide_debug_manager, IDE_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP,
+                                                      ide_debug_manager_init_action_group))
 
 static gint
 compare_language_id (gconstpointer a,
@@ -1004,7 +1019,15 @@ ide_debug_manager_start (IdeDebugManager  *self,
     }
 
   environment = ide_runner_get_environment (runner);
+
+  /* TODO: Make this toggle-able */
   ide_environment_setenv (environment, "G_MESSAGES_DEBUG", "all");
+
+  if (self->stop_at_criticals)
+    ide_environment_setenv (environment, "G_DEBUG", "fatal-criticals");
+  else if (self->stop_at_warnings)
+    ide_environment_setenv (environment, "G_DEBUG", "fatal-warnings");
+
   ide_debugger_prepare (debugger, runner);
 
   g_signal_connect_object (runner,
@@ -1235,3 +1258,35 @@ ide_debug_manager_from_context (IdeContext *context)
 
   return ret;
 }
+
+static void
+ide_debug_manager_actions_stop_at_criticals (IdeDebugManager *self,
+                                             GVariant        *param)
+{
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_DEBUG_MANAGER (self));
+
+  self->stop_at_criticals = !self->stop_at_criticals;
+  ide_debug_manager_set_action_state (self,
+                                      "stop-at-criticals",
+                                      g_variant_new_boolean (self->stop_at_criticals));
+
+  IDE_EXIT;
+}
+
+static void
+ide_debug_manager_actions_stop_at_warnings (IdeDebugManager *self,
+                                            GVariant        *param)
+{
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_DEBUG_MANAGER (self));
+
+  self->stop_at_warnings = !self->stop_at_warnings;
+  ide_debug_manager_set_action_state (self,
+                                      "stop-at-warnings",
+                                      g_variant_new_boolean (self->stop_at_warnings));
+
+  IDE_EXIT;
+}
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 09c551548..9a1780fa3 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -724,6 +724,7 @@ insert_action_groups_foreach_cb (IdeWorkspace *workspace,
   } groups[] = {
     { "config-manager", IDE_TYPE_CONFIG_MANAGER },
     { "build-manager", IDE_TYPE_BUILD_MANAGER },
+    { "debug-manager", IDE_TYPE_DEBUG_MANAGER },
     { "device-manager", IDE_TYPE_DEVICE_MANAGER },
     { "run-manager", IDE_TYPE_RUN_MANAGER },
     { "test-manager", IDE_TYPE_TEST_MANAGER },
diff --git a/src/plugins/debuggerui/gtk/menus.ui b/src/plugins/debuggerui/gtk/menus.ui
index 15e303347..774e5aec3 100644
--- a/src/plugins/debuggerui/gtk/menus.ui
+++ b/src/plugins/debuggerui/gtk/menus.ui
@@ -13,6 +13,25 @@
       </item>
     </section>
   </menu>
+  <menu id="run-menu-settings-section">
+    <submenu id="run-menu-debug-submenu">
+      <attribute name="after">run-menu-a11y</attribute>
+      <attribute name="label" translatable="yes">Debugger</attribute>
+      <section id="run-menu-debug-breakpoints-section">
+        <attribute name="label" translatable="yes">Breakpoints</attribute>
+        <item>
+          <attribute name="label" translatable="yes">Stop at Warnings</attribute>
+          <attribute name="action">debug-manager.stop-at-warnings</attribute>
+          <attribute name="role">check</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">Stop at Criticals</attribute>
+          <attribute name="action">debug-manager.stop-at-criticals</attribute>
+          <attribute name="role">check</attribute>
+        </item>
+      </section>
+    </submenu>
+  </menu>
   <menu id="project-tree-menu">
     <section id="project-tree-menu-foundry-section">
       <submenu id="project-tree-run-with-submenu">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]