[gnome-builder/wip/gtk4-port: 1537/1774] plugins/shellcmd: add locality to run command object




commit 417ef9753e99ee4e122ad63e80ff4ce8b1cb3937
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 15 18:03:49 2022 -0700

    plugins/shellcmd: add locality to run command object
    
    This still needs a GSetting and the ability to create the right launcher.

 src/plugins/shellcmd/gbp-shellcmd-command-dialog.c | 18 ++++++++
 .../shellcmd/gbp-shellcmd-command-dialog.ui        | 14 +++---
 src/plugins/shellcmd/gbp-shellcmd-run-command.c    | 52 +++++++++++++++++++---
 src/plugins/shellcmd/gbp-shellcmd-run-command.h    | 18 ++++++++
 src/plugins/shellcmd/meson.build                   | 10 ++++-
 5 files changed, 99 insertions(+), 13 deletions(-)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c 
b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
index 41a6ae66d..8b61a20eb 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
@@ -27,6 +27,7 @@
 #include <libide-gtk.h>
 
 #include "gbp-shellcmd-command-dialog.h"
+#include "gbp-shellcmd-enums.h"
 
 struct _GbpShellcmdCommandDialog
 {
@@ -37,6 +38,7 @@ struct _GbpShellcmdCommandDialog
   AdwEntryRow           *argv;
   AdwEntryRow           *location;
   AdwEntryRow           *name;
+  AdwComboRow           *locality;
   GtkStringList         *envvars;
   GtkListBox            *envvars_list_box;
   GtkLabel              *shortcut_label;
@@ -249,6 +251,7 @@ gbp_shellcmd_command_dialog_set_command (GbpShellcmdCommandDialog *self,
                                          GbpShellcmdRunCommand    *command)
 {
   g_autofree char *argvstr = NULL;
+  GbpShellcmdLocality locality;
   const char * const *argv;
   const char * const *env;
   const char *accel;
@@ -268,6 +271,7 @@ gbp_shellcmd_command_dialog_set_command (GbpShellcmdCommandDialog *self,
   env = ide_run_command_get_env (IDE_RUN_COMMAND (command));
   cwd = ide_run_command_get_cwd (IDE_RUN_COMMAND (command));
   accel = gbp_shellcmd_run_command_get_accelerator (command);
+  locality = gbp_shellcmd_run_command_get_locality (command);
 
   argvstr = normalize_argv (argv);
 
@@ -276,6 +280,9 @@ gbp_shellcmd_command_dialog_set_command (GbpShellcmdCommandDialog *self,
   gtk_editable_set_text (GTK_EDITABLE (self->name), name);
   set_accel (self, accel);
 
+  /* locality value equates to position in list model for simplicity */
+  adw_combo_row_set_selected (self->locality, locality);
+
   if (env != NULL)
     {
       for (guint i = 0; env[i]; i++)
@@ -385,9 +392,13 @@ command_save_action (GtkWidget  *widget,
                      GVariant   *param)
 {
   GbpShellcmdCommandDialog *self = (GbpShellcmdCommandDialog *)widget;
+  g_autoptr(GEnumClass) enum_class = NULL;
   g_auto(GStrv) argv = NULL;
   g_auto(GStrv) env = NULL;
   const char *argvstr;
+  IdeEnumObject *item;
+  const char *nick;
+  GEnumValue *value;
   int argc;
 
   IDE_ENTRY;
@@ -410,6 +421,12 @@ command_save_action (GtkWidget  *widget,
   ide_run_command_set_env (IDE_RUN_COMMAND (self->command),
                            (const char * const *)env);
 
+  item = adw_combo_row_get_selected_item (self->locality);
+  nick = ide_enum_object_get_nick (item);
+  enum_class = g_type_class_ref (GBP_TYPE_SHELLCMD_LOCALITY);
+  value = g_enum_get_value_by_nick (enum_class, nick);
+  gbp_shellcmd_run_command_set_locality (self->command, value->value);
+
   g_object_thaw_notify (G_OBJECT (self->command));
 
  gtk_window_destroy (GTK_WINDOW (self));
@@ -569,6 +586,7 @@ gbp_shellcmd_command_dialog_class_init (GbpShellcmdCommandDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandDialog, delete_button);
   gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandDialog, envvars);
   gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandDialog, envvars_list_box);
+  gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandDialog, locality);
   gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandDialog, location);
   gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandDialog, name);
   gtk_widget_class_bind_template_child (widget_class, GbpShellcmdCommandDialog, save);
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui 
b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui
index 132eae1f3..e7cfb7bb8 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.ui
@@ -240,6 +240,13 @@
   <object class="GtkStringList" id="envvars">
   </object>
   <object class="GListStore" id="localities">
+    <child>
+      <object class="IdeEnumObject">
+        <property name="nick">internal</property>
+        <property name="title" translatable="yes">Subprocess</property>
+        <property name="description" translatable="yes">Runs the command as a subprocess of 
Builder.</property>
+      </object>
+    </child>
     <child>
       <object class="IdeEnumObject">
         <property name="nick">host</property>
@@ -261,12 +268,5 @@
         <property name="description" translatable="yes">Runs the command as if it were the target 
application.</property>
       </object>
     </child>
-    <child>
-      <object class="IdeEnumObject">
-        <property name="nick">internal</property>
-        <property name="title" translatable="yes">Subprocess</property>
-        <property name="description" translatable="yes">Runs the command as a subprocess of 
Builder.</property>
-      </object>
-    </child>
   </object>
 </interface>
diff --git a/src/plugins/shellcmd/gbp-shellcmd-run-command.c b/src/plugins/shellcmd/gbp-shellcmd-run-command.c
index 465a77808..99d8be969 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-run-command.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-run-command.c
@@ -22,21 +22,26 @@
 
 #include "config.h"
 
+#include "gbp-shellcmd-enums.h"
 #include "gbp-shellcmd-run-command.h"
 
 struct _GbpShellcmdRunCommand
 {
-  IdeRunCommand  parent_instance;
-  char          *settings_path;
-  GSettings     *settings;
-  char          *id;
-  char          *accelerator;
+  IdeRunCommand        parent_instance;
+
+  char                *settings_path;
+  GSettings           *settings;
+  char                *id;
+  char                *accelerator;
+
+  GbpShellcmdLocality  locality;
 };
 
 enum {
   PROP_0,
   PROP_ACCELERATOR,
   PROP_ACCELERATOR_LABEL,
+  PROP_LOCALITY,
   PROP_SETTINGS_PATH,
   PROP_SUBTITLE,
   N_PROPS
@@ -158,6 +163,10 @@ gbp_shellcmd_run_command_get_property (GObject    *object,
       g_value_take_string (value, get_accelerator_label (self));
       break;
 
+    case PROP_LOCALITY:
+      g_value_set_enum (value, gbp_shellcmd_run_command_get_locality (self));
+      break;
+
     case PROP_SETTINGS_PATH:
       g_value_set_string (value, self->settings_path);
       break;
@@ -185,6 +194,10 @@ gbp_shellcmd_run_command_set_property (GObject      *object,
       gbp_shellcmd_run_command_set_accelerator (self, g_value_get_string (value));
       break;
 
+    case PROP_LOCALITY:
+      gbp_shellcmd_run_command_set_locality (self, g_value_get_enum (value));
+      break;
+
     case PROP_SETTINGS_PATH:
       self->settings_path = g_value_dup_string (value);
       break;
@@ -212,6 +225,12 @@ gbp_shellcmd_run_command_class_init (GbpShellcmdRunCommandClass *klass)
     g_param_spec_string ("accelerator-label", NULL, NULL, NULL,
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_LOCALITY] =
+    g_param_spec_enum ("locality", NULL, NULL,
+                       GBP_TYPE_SHELLCMD_LOCALITY,
+                       GBP_SHELLCMD_LOCALITY_PIPELINE,
+                       (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_SETTINGS_PATH] =
     g_param_spec_string ("settings-path", NULL, NULL, NULL,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
@@ -226,6 +245,8 @@ gbp_shellcmd_run_command_class_init (GbpShellcmdRunCommandClass *klass)
 static void
 gbp_shellcmd_run_command_init (GbpShellcmdRunCommand *self)
 {
+  self->locality = GBP_SHELLCMD_LOCALITY_PIPELINE;
+
   g_signal_connect (self, "notify::accelerator", G_CALLBACK (accelerator_label_changed_cb), NULL);
   g_signal_connect (self, "notify::cwd", G_CALLBACK (subtitle_changed_cb), NULL);
   g_signal_connect (self, "notify::argv", G_CALLBACK (subtitle_changed_cb), NULL);
@@ -425,3 +446,24 @@ gbp_shellcmd_run_command_create_launcher (GbpShellcmdRunCommand *self,
 
   return ide_terminal_launcher_new_for_launcher (launcher);
 }
+
+GbpShellcmdLocality
+gbp_shellcmd_run_command_get_locality (GbpShellcmdRunCommand *self)
+{
+  g_return_val_if_fail (GBP_IS_SHELLCMD_RUN_COMMAND (self), 0);
+
+  return self->locality;
+}
+
+void
+gbp_shellcmd_run_command_set_locality (GbpShellcmdRunCommand *self,
+                                       GbpShellcmdLocality    locality)
+{
+  g_return_if_fail (GBP_IS_SHELLCMD_RUN_COMMAND (self));
+
+  if (locality != self->locality)
+    {
+      self->locality = locality;
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOCALITY]);
+    }
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-run-command.h b/src/plugins/shellcmd/gbp-shellcmd-run-command.h
index 8abca3b3a..c25ac2e55 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-run-command.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-run-command.h
@@ -25,6 +25,21 @@
 
 G_BEGIN_DECLS
 
+/**
+ * GbpShellcmdLocality:
+ * %GBP_SHELLCMD_LOCALITY_SUBPROCESS: run as a subprocess of builder
+ * %GBP_SHELLCMD_LOCALITY_HOST: run on the host system, possibly bypassing container
+ * %GBP_SHELLCMD_LOCALITY_PIPELINE: run from build pipeline
+ * %GBP_SHELLCMD_LOCALITY_RUNNER: run from an application IdeRunner
+ */
+typedef enum
+{
+  GBP_SHELLCMD_LOCALITY_SUBPROCESS = 0,
+  GBP_SHELLCMD_LOCALITY_HOST,
+  GBP_SHELLCMD_LOCALITY_PIPELINE,
+  GBP_SHELLCMD_LOCALITY_RUNNER,
+} GbpShellcmdLocality;
+
 #define GBP_TYPE_SHELLCMD_RUN_COMMAND (gbp_shellcmd_run_command_get_type())
 
 G_DECLARE_FINAL_TYPE (GbpShellcmdRunCommand, gbp_shellcmd_run_command, GBP, SHELLCMD_RUN_COMMAND, 
IdeRunCommand)
@@ -35,6 +50,9 @@ void                   gbp_shellcmd_run_command_delete          (GbpShellcmdRunC
 const char            *gbp_shellcmd_run_command_get_accelerator (GbpShellcmdRunCommand *self);
 void                   gbp_shellcmd_run_command_set_accelerator (GbpShellcmdRunCommand *self,
                                                                  const char            *accelerator);
+GbpShellcmdLocality    gbp_shellcmd_run_command_get_locality    (GbpShellcmdRunCommand *self);
+void                   gbp_shellcmd_run_command_set_locality    (GbpShellcmdRunCommand *self,
+                                                                 GbpShellcmdLocality    locality);
 IdeTerminalLauncher   *gbp_shellcmd_run_command_create_launcher (GbpShellcmdRunCommand *self,
                                                                  IdeContext            *context);
 
diff --git a/src/plugins/shellcmd/meson.build b/src/plugins/shellcmd/meson.build
index 7cd294749..23251b1a6 100644
--- a/src/plugins/shellcmd/meson.build
+++ b/src/plugins/shellcmd/meson.build
@@ -11,9 +11,16 @@ plugins_sources += files([
 ])
 
 plugin_shellcmd_enum_headers = [
-  'gbp-shellcmd-command.h',
+  'gbp-shellcmd-run-command.h',
 ]
 
+plugin_shellcmd_enums = gnome.mkenums_simple('gbp-shellcmd-enums',
+     body_prefix: '#include "config.h"',
+   header_prefix: '#include <libide-core.h>',
+         sources: plugin_shellcmd_enum_headers,
+  install_header: false,
+)
+
 plugin_shellcmd_resources = gnome.compile_resources(
   'shellcmd-resources',
   'shellcmd.gresource.xml',
@@ -21,6 +28,7 @@ plugin_shellcmd_resources = gnome.compile_resources(
 )
 
 plugins_sources += plugin_shellcmd_resources
+plugins_sources += plugin_shellcmd_enums
 plugins_include_directories += [include_directories('.')]
 
 install_data(['org.gnome.builder.shellcmd.gschema.xml'], install_dir: schema_dir)


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