[gnome-builder] plugins/terminal: use action group more fluently



commit c2dd24c96640e8dcdcad91863ce0453856514a29
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 29 16:18:23 2022 -0700

    plugins/terminal: use action group more fluently
    
    We already have an action group, so we can use it via the auto-inserted
    workspace.terminal. action prefix.

 .../terminal/gbp-terminal-workspace-addin.c        | 28 +++++++++++++---------
 src/plugins/terminal/gtk/keybindings.json          |  7 +++---
 src/plugins/terminal/gtk/menus.ui                  |  6 ++---
 3 files changed, 24 insertions(+), 17 deletions(-)
---
diff --git a/src/plugins/terminal/gbp-terminal-workspace-addin.c 
b/src/plugins/terminal/gbp-terminal-workspace-addin.c
index 6d335f8fd..b0e51c716 100644
--- a/src/plugins/terminal/gbp-terminal-workspace-addin.c
+++ b/src/plugins/terminal/gbp-terminal-workspace-addin.c
@@ -52,10 +52,10 @@ static void terminal_in_runtime_action    (GbpTerminalWorkspaceAddin *self,
                                            GVariant                  *param);
 
 IDE_DEFINE_ACTION_GROUP (GbpTerminalWorkspaceAddin, gbp_terminal_workspace_addin, {
-  { "terminal-on-host", terminal_on_host_action, "s" },
-  { "terminal-as-subprocess", terminal_as_subprocess_action, "s" },
-  { "terminal-in-pipeline", terminal_in_pipeline_action, "s" },
-  { "terminal-in-runtime", terminal_in_runtime_action, "s" },
+  { "new-in-host", terminal_on_host_action, "s" },
+  { "new-in-subprocess", terminal_as_subprocess_action, "s" },
+  { "new-in-pipeline", terminal_in_pipeline_action, "s" },
+  { "new-in-runtime", terminal_in_runtime_action, "s" },
 })
 
 static void
@@ -238,6 +238,7 @@ gbp_terminal_workspace_addin_load (IdeWorkspaceAddin *addin,
 {
   GbpTerminalWorkspaceAddin *self = (GbpTerminalWorkspaceAddin *)addin;
   g_autoptr(IdePanelPosition) position = NULL;
+  IdeContext *context;
   IdePage *page;
   IdePane *pane;
 
@@ -247,9 +248,16 @@ gbp_terminal_workspace_addin_load (IdeWorkspaceAddin *addin,
 
   self->workspace = workspace;
 
-  gtk_widget_insert_action_group (GTK_WIDGET (workspace),
-                                  "terminal",
-                                  G_ACTION_GROUP (self));
+  context = ide_workspace_get_context (workspace);
+
+  /* Only allow activating runtime/pipeline terminals if we have a project
+   * (and therefore a build pipeline we can use).
+   */
+  if (ide_context_has_project (context))
+    {
+      gbp_terminal_workspace_addin_set_action_enabled (self, "terminal-in-pipeline", TRUE);
+      gbp_terminal_workspace_addin_set_action_enabled (self, "terminal-in-runtime", TRUE);
+    }
 
   /* Always add the terminal panel to primary/editor workspaces */
   position = ide_panel_position_new ();
@@ -268,8 +276,6 @@ gbp_terminal_workspace_addin_load (IdeWorkspaceAddin *addin,
   /* Setup panel for application output */
   if (IDE_IS_PRIMARY_WORKSPACE (workspace))
     {
-      IdeWorkbench *workbench = ide_workspace_get_workbench (workspace);
-      IdeContext *context = ide_workbench_get_context (workbench);
       IdeRunManager *run_manager = ide_run_manager_from_context (context);
       VtePty *pty = ide_pty_new_sync (NULL);
 
@@ -328,8 +334,6 @@ gbp_terminal_workspace_addin_unload (IdeWorkspaceAddin *addin,
   self->app_page = NULL;
   g_clear_pointer ((PanelWidget **)&self->app_pane, panel_widget_close);
 
-  gtk_widget_insert_action_group (GTK_WIDGET (workspace), "terminal", NULL);
-
   self->workspace = NULL;
 }
 
@@ -352,4 +356,6 @@ gbp_terminal_workspace_addin_class_init (GbpTerminalWorkspaceAddinClass *klass)
 static void
 gbp_terminal_workspace_addin_init (GbpTerminalWorkspaceAddin *self)
 {
+  gbp_terminal_workspace_addin_set_action_enabled (self, "terminal-in-pipeline", FALSE);
+  gbp_terminal_workspace_addin_set_action_enabled (self, "terminal-in-runtime", FALSE);
 }
diff --git a/src/plugins/terminal/gtk/keybindings.json b/src/plugins/terminal/gtk/keybindings.json
index bde7d2148..893a3de02 100644
--- a/src/plugins/terminal/gtk/keybindings.json
+++ b/src/plugins/terminal/gtk/keybindings.json
@@ -1,7 +1,8 @@
 /* New Terminal Actions */
-{ "trigger" : "<Control><Shift>t", "action" : "terminal.terminal-on-host", "args" : "''", "when" : 
"canEdit()", "phase" : "capture" },
-{ "trigger" : "<Control><Alt><Shift>t", "action" : "terminal.terminal-in-pipeline", "args" : "''", "when" : 
"canEdit()", "phase" : "capture" },
-{ "trigger" : "<Control><Alt>t", "action" : "terminal.terminal-in-runtime", "args" : "''", "when" : 
"canEdit()", "phase" : "capture" },
+{ "trigger" : "<Control><Shift>t", "action" : "workspace.terminal.new-in-host", "args" : "''", "when" : 
"canEdit()", "phase" : "capture" },
+{ "trigger" : "<Control><Alt><Shift>t", "action" : "workspace.terminal.new-in-pipeline", "args" : "''", 
"when" : "canEdit()", "phase" : "capture" },
+{ "trigger" : "<Control><Alt>t", "action" : "workspace.terminal.new-in-runtime", "args" : "''", "when" : 
"canEdit()", "phase" : "capture" },
+{ "trigger" : "<Control>Scroll_Lock", "action" : "workspace.terminal.new-in-subprocess", "args" : "''", 
"when" : "canEdit()", "phase" : "capture" },
 
 /* IdeTerminal */
 { "trigger" : "<Control><Shift>c", "action" : "clipboard.copy", "when" : "inTerminal()", "phase" : "capture" 
},
diff --git a/src/plugins/terminal/gtk/menus.ui b/src/plugins/terminal/gtk/menus.ui
index 80312207d..67c02ba6e 100644
--- a/src/plugins/terminal/gtk/menus.ui
+++ b/src/plugins/terminal/gtk/menus.ui
@@ -4,7 +4,7 @@
     <section id="new-terminal-section">
       <item>
         <attribute name="label" translatable="yes">New _Terminal</attribute>
-        <attribute name="action">terminal.terminal-on-host</attribute>
+        <attribute name="action">workspace.terminal.new-in-host</attribute>
         <attribute name="target" type="s">''</attribute>
         <attribute name="accel">&lt;ctrl&gt;&lt;shift&gt;t</attribute>
         <attribute name="verb-icon">builder-terminal-symbolic</attribute>
@@ -12,7 +12,7 @@
       </item>
       <item>
         <attribute name="label" translatable="yes">New _Build Terminal</attribute>
-        <attribute name="action">terminal.terminal-in-pipeline</attribute>
+        <attribute name="action">workspace.terminal.new-in-pipeline</attribute>
         <attribute name="target" type="s">''</attribute>
         <attribute name="accel">&lt;ctrl&gt;&lt;shift&gt;&lt;alt&gt;t</attribute>
         <attribute name="verb-icon">builder-terminal-symbolic</attribute>
@@ -20,7 +20,7 @@
       </item>
       <item>
         <attribute name="label" translatable="yes">New _Runtime Terminal</attribute>
-        <attribute name="action">terminal.terminal-in-runtime</attribute>
+        <attribute name="action">workspace.terminal.new-in-runtime</attribute>
         <attribute name="target" type="s">''</attribute>
         <attribute name="accel">&lt;ctrl&gt;&lt;alt&gt;t</attribute>
         <attribute name="verb-icon">builder-terminal-symbolic</attribute>


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