[gnome-builder] plugins/buildui: move run command selection to preferences



commit 4cf03b51cf9442cb8d93104c284936633430485f
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 19 21:33:29 2022 -0700

    plugins/buildui: move run command selection to preferences
    
    This really belongs in project settings rather than a custom dialog that
    is completely separate from project settings.
    
    It would be nice to use AdwComboRow, but we need search for this to be
    useful for projects like GTK. Especially since the DropDown looks bad
    even with "flat" on the row.
    
    We still probably want to add a switch row so that we can allow the default
    selection via providers to work.

 src/libide/gui/ide-preferences-builtin.c           |   5 +-
 src/plugins/buildui/buildui.gresource.xml          |   2 +-
 .../buildui/gbp-buildui-preferences-addin.c        | 125 ++++++++
 src/plugins/buildui/gbp-buildui-run-command-row.ui |  76 +++++
 src/plugins/buildui/gbp-buildui-runnables-dialog.c | 315 ---------------------
 src/plugins/buildui/gbp-buildui-runnables-dialog.h |  35 ---
 .../buildui/gbp-buildui-runnables-dialog.ui        | 101 -------
 src/plugins/buildui/gbp-buildui-workspace-addin.c  |  23 --
 src/plugins/buildui/gtk/menus.ui                   |   3 +-
 src/plugins/buildui/meson.build                    |   1 -
 10 files changed, 207 insertions(+), 479 deletions(-)
---
diff --git a/src/libide/gui/ide-preferences-builtin.c b/src/libide/gui/ide-preferences-builtin.c
index d96950158..490a3178f 100644
--- a/src/libide/gui/ide-preferences-builtin.c
+++ b/src/libide/gui/ide-preferences-builtin.c
@@ -715,8 +715,9 @@ static const IdePreferenceGroupEntry groups[] = {
 };
 
 static const IdePreferenceGroupEntry project_groups[] = {
-  { "application", "install",  0, N_("Starting & Stopping") },
-  { "application", "stop",    10 },
+  { "application", "running",  0, N_("Running") },
+  { "application", "install", 10, N_("Starting & Stopping") },
+  { "application", "stop",    20 },
 };
 
 static const IdePreferenceItemEntry items[] = {
diff --git a/src/plugins/buildui/buildui.gresource.xml b/src/plugins/buildui/buildui.gresource.xml
index 8eb6d16ee..565085148 100644
--- a/src/plugins/buildui/buildui.gresource.xml
+++ b/src/plugins/buildui/buildui.gresource.xml
@@ -6,7 +6,7 @@
     <file preprocess="xml-stripblanks">gbp-buildui-log-pane.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-omni-bar-section.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-pane.ui</file>
-    <file preprocess="xml-stripblanks">gbp-buildui-runnables-dialog.ui</file>
+    <file preprocess="xml-stripblanks">gbp-buildui-run-command-row.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-stage-row.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-status-indicator.ui</file>
     <file preprocess="xml-stripblanks">gbp-buildui-status-popover.ui</file>
diff --git a/src/plugins/buildui/gbp-buildui-preferences-addin.c 
b/src/plugins/buildui/gbp-buildui-preferences-addin.c
index 153a5170d..ccefc52e0 100644
--- a/src/plugins/buildui/gbp-buildui-preferences-addin.c
+++ b/src/plugins/buildui/gbp-buildui-preferences-addin.c
@@ -25,8 +25,11 @@
 
 #include <glib/gi18n.h>
 
+#include <libide-foundry.h>
 #include <libide-sourceview.h>
 
+#include "ide-run-manager-private.h"
+
 #include "gbp-buildui-preferences-addin.h"
 #include "gbp-buildui-runtime-categories.h"
 #include "gbp-buildui-runtime-row.h"
@@ -108,6 +111,122 @@ static const IdePreferenceItemEntry overview_items[] = {
   { "overview", "project", "vcsuri", 0, overview_func, N_("Version Control") },
 };
 
+static void
+notify_run_command_cb (GtkDropDown   *drop_down,
+                       GParamSpec    *pspec,
+                       IdeRunManager *run_manager)
+{
+  IdeRunCommand *run_command = NULL;
+  const char *id = NULL;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GTK_IS_DROP_DOWN (drop_down));
+  g_assert (IDE_IS_RUN_MANAGER (run_manager));
+
+  if ((run_command = gtk_drop_down_get_selected_item (drop_down)))
+    id = ide_run_command_get_id (run_command);
+
+  _ide_run_manager_set_default_id (run_manager, id);
+}
+
+static void
+list_run_commands_cb (GObject      *object,
+                      GAsyncResult *result,
+                      gpointer      user_data)
+{
+  IdeRunManager *run_manager = (IdeRunManager *)object;
+  g_autoptr(GtkDropDown) drop_down = user_data;
+  g_autoptr(GListModel) model = NULL;
+  g_autoptr(GError) error = NULL;
+  int command_index = -1;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_RUN_MANAGER (run_manager));
+  g_assert (GTK_IS_DROP_DOWN (drop_down));
+
+  if (!(model = ide_run_manager_list_commands_finish (run_manager, result, &error)))
+    {
+      g_warning ("%s", error->message);
+    }
+  else
+    {
+      const char *id = _ide_run_manager_get_default_id (run_manager);
+      guint n_items = g_list_model_get_n_items (model);
+
+      for (guint i = 0; i < n_items; i++)
+        {
+          g_autoptr(IdeRunCommand) command = g_list_model_get_item (model, i);
+          const char *command_id = ide_run_command_get_id (command);
+
+          if (g_strcmp0 (command_id, id) == 0)
+            {
+              command_index = i;
+              break;
+            }
+        }
+    }
+
+  gtk_drop_down_set_model (drop_down, model);
+
+  if (command_index > -1)
+    gtk_drop_down_set_selected (drop_down, command_index);
+
+  g_signal_connect_object (drop_down,
+                           "notify::selected-item",
+                           G_CALLBACK (notify_run_command_cb),
+                           run_manager,
+                           0);
+}
+
+static void
+run_command_func (const char                   *page_name,
+                  const IdePreferenceItemEntry *entry,
+                  AdwPreferencesGroup          *group,
+                  gpointer                      user_data)
+{
+  g_autoptr(GtkListItemFactory) list_factory = NULL;
+  g_autoptr(GtkExpression) expression = NULL;
+  IdeContext *context = user_data;
+  IdeRunManager *run_manager;
+  AdwActionRow *row;
+  GtkDropDown *drop_down;
+
+  g_assert (IDE_IS_CONTEXT (context));
+  g_assert (ADW_IS_PREFERENCES_GROUP (group));
+
+  run_manager = ide_run_manager_from_context (context);
+
+  list_factory = g_object_new (GTK_TYPE_BUILDER_LIST_ITEM_FACTORY,
+                               "resource", "/plugins/buildui/gbp-buildui-run-command-row.ui",
+                               NULL);
+  expression = gtk_property_expression_new (IDE_TYPE_RUN_COMMAND, NULL, "display-name");
+  drop_down = g_object_new (GTK_TYPE_DROP_DOWN,
+                            "enable-search", TRUE,
+                            "expression", expression,
+                            "list-factory", list_factory,
+                            "css-classes", IDE_STRV_INIT ("flat"),
+                            "valign", GTK_ALIGN_CENTER,
+                            NULL);
+
+  ide_run_manager_list_commands_async (run_manager,
+                                       NULL,
+                                       list_run_commands_cb,
+                                       g_object_ref (drop_down));
+
+  row = g_object_new (ADW_TYPE_ACTION_ROW,
+                      "title", _("Run Command"),
+                      "subtitle", _("The run command is used to run your project"),
+                      "activatable-widget", drop_down,
+                      NULL);
+  adw_action_row_add_suffix (row, GTK_WIDGET (drop_down));
+
+  adw_preferences_group_add (group, GTK_WIDGET (row));
+}
+
+static const IdePreferenceItemEntry app_items[] = {
+  { "application", "running", "run-command", 0, run_command_func },
+};
+
 static gboolean
 treat_null_as_empty (GBinding     *binding,
                      const GValue *from_value,
@@ -492,6 +611,12 @@ gbp_buildui_preferences_addin_load (IdePreferencesAddin  *addin,
                                     g_object_ref (context),
                                     g_object_unref);
 
+  ide_preferences_window_add_items (window,
+                                    app_items,
+                                    G_N_ELEMENTS (app_items),
+                                    g_object_ref (context),
+                                    g_object_unref);
+
   config_manager = ide_config_manager_from_context (context);
   n_configs = g_list_model_get_n_items (G_LIST_MODEL (config_manager));
   pages = g_new0 (IdePreferencePageEntry, n_configs);
diff --git a/src/plugins/buildui/gbp-buildui-run-command-row.ui 
b/src/plugins/buildui/gbp-buildui-run-command-row.ui
new file mode 100644
index 000000000..3af0537c4
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-run-command-row.ui
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkBox">
+        <property name="orientation">horizontal</property>
+        <child>
+          <object class="GtkBox">
+            <property name="orientation">vertical</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="hexpand">true</property>
+                <property name="xalign">0</property>
+                <property name="max-width-chars">40</property>
+                <property name="width-chars">40</property>
+                <property name="ellipsize">middle</property>
+                <binding name="tooltip-text">
+                  <lookup name="shell-command" type="IdeRunCommand">
+                    <lookup name="item">GtkListItem</lookup>
+                  </lookup>
+                </binding>
+                <binding name="label">
+                  <lookup name="display-name" type="IdeRunCommand">
+                    <lookup name="item">GtkListItem</lookup>
+                  </lookup>
+                </binding>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="hexpand">true</property>
+                <property name="xalign">0</property>
+                <property name="max-width-chars">40</property>
+                <property name="width-chars">40</property>
+                <property name="ellipsize">start</property>
+                <style>
+                  <class name="caption"/>
+                  <class name="dim-label"/>
+                </style>
+                <binding name="tooltip-text">
+                  <lookup name="shell-command" type="IdeRunCommand">
+                    <lookup name="item">GtkListItem</lookup>
+                  </lookup>
+                </binding>
+                <binding name="label">
+                  <lookup name="shell-command" type="IdeRunCommand">
+                    <lookup name="item">GtkListItem</lookup>
+                  </lookup>
+                </binding>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="css-name">button</property>
+            <style>
+              <class name="pill"/>
+              <class name="small"/>
+            </style>
+            <binding name="visible">
+              <lookup name="has-category" type="IdeRunCommand">
+                <lookup name="item">GtkListItem</lookup>
+              </lookup>
+            </binding>
+            <binding name="label">
+              <lookup name="category" type="IdeRunCommand">
+                <lookup name="item">GtkListItem</lookup>
+              </lookup>
+            </binding>
+          </object>
+        </child>
+      </object>
+    </property>
+  </template>
+</interface>
diff --git a/src/plugins/buildui/gbp-buildui-workspace-addin.c 
b/src/plugins/buildui/gbp-buildui-workspace-addin.c
index bf9c8d7fe..3aea73dac 100644
--- a/src/plugins/buildui/gbp-buildui-workspace-addin.c
+++ b/src/plugins/buildui/gbp-buildui-workspace-addin.c
@@ -30,7 +30,6 @@
 #include "gbp-buildui-log-pane.h"
 #include "gbp-buildui-omni-bar-section.h"
 #include "gbp-buildui-pane.h"
-#include "gbp-buildui-runnables-dialog.h"
 #include "gbp-buildui-status-indicator.h"
 #include "gbp-buildui-status-popover.h"
 #include "gbp-buildui-targets-dialog.h"
@@ -204,27 +203,6 @@ select_build_target_action (GSimpleAction *action,
   gtk_window_present (GTK_WINDOW (dialog));
 }
 
-static void
-select_run_command_action (GSimpleAction *action,
-                           GVariant      *param,
-                           gpointer       user_data)
-{
-  GbpBuilduiWorkspaceAddin *self = user_data;
-  GbpBuilduiRunnablesDialog *dialog;
-  IdeContext *context;
-
-  g_assert (G_IS_SIMPLE_ACTION (action));
-
-  context = ide_workspace_get_context (self->workspace);
-  dialog = g_object_new (GBP_TYPE_BUILDUI_RUNNABLES_DIALOG,
-                         "context", context,
-                         "transient-for", self->workspace,
-                         "modal", TRUE,
-                         NULL);
-
-  gtk_window_present (GTK_WINDOW (dialog));
-}
-
 static void
 show_status_popover (GSimpleAction *action,
                      GVariant      *param,
@@ -250,7 +228,6 @@ show_status_popover (GSimpleAction *action,
 static const GActionEntry actions[] = {
   { "show-build-log", on_view_output_cb },
   { "select-build-target", select_build_target_action },
-  { "select-run-command", select_run_command_action },
   { "show-build-status-popover", show_status_popover, "s" },
 };
 
diff --git a/src/plugins/buildui/gtk/menus.ui b/src/plugins/buildui/gtk/menus.ui
index 2191d57d4..ca215f316 100644
--- a/src/plugins/buildui/gtk/menus.ui
+++ b/src/plugins/buildui/gtk/menus.ui
@@ -121,7 +121,8 @@
     <section id="run-command-section">
       <item>
         <attribute name="label" translatable="yes">Select Run Command…</attribute>
-        <attribute name="action">win.select-run-command</attribute>
+        <attribute name="action">workbench.configure-page</attribute>
+        <attribute name="target" type="s">'application'</attribute>
       </item>
     </section>
     <section id="run-menu-observation-section">
diff --git a/src/plugins/buildui/meson.build b/src/plugins/buildui/meson.build
index 0020afbaf..0cb5fed4b 100644
--- a/src/plugins/buildui/meson.build
+++ b/src/plugins/buildui/meson.build
@@ -6,7 +6,6 @@ plugins_sources += files([
   'gbp-buildui-omni-bar-section.c',
   'gbp-buildui-pane.c',
   'gbp-buildui-preferences-addin.c',
-  'gbp-buildui-runnables-dialog.c',
   'gbp-buildui-runtime-categories.c',
   'gbp-buildui-runtime-row.c',
   'gbp-buildui-stage-row.c',


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