[gnome-builder/wip/gtk4-port] libide/foundry: lower accelerator property into shellcmd



commit 7f2814c71c5e1162e19c63debf1351626a184f2e
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 14 13:09:22 2022 -0700

    libide/foundry: lower accelerator property into shellcmd
    
    This isn't needed for all run commands, just for those provided by the
    GbpShellcmdRunCommand and various providers.

 src/libide/foundry/ide-run-command.c               | 42 ----------------------
 src/libide/foundry/ide-run-command.h               |  5 ---
 src/plugins/shellcmd/gbp-shellcmd-command-dialog.c |  4 +--
 src/plugins/shellcmd/gbp-shellcmd-run-command.c    | 41 +++++++++++++++++++--
 src/plugins/shellcmd/gbp-shellcmd-run-command.h    |  9 +++--
 5 files changed, 46 insertions(+), 55 deletions(-)
---
diff --git a/src/libide/foundry/ide-run-command.c b/src/libide/foundry/ide-run-command.c
index 8b2870514..f06934d07 100644
--- a/src/libide/foundry/ide-run-command.c
+++ b/src/libide/foundry/ide-run-command.c
@@ -27,7 +27,6 @@
 
 typedef struct
 {
-  char *accelerator;
   char *id;
   char *cwd;
   char *display_name;
@@ -39,7 +38,6 @@ typedef struct
 
 enum {
   PROP_0,
-  PROP_ACCELERATOR,
   PROP_ARGV,
   PROP_CWD,
   PROP_DISPLAY_NAME,
@@ -86,7 +84,6 @@ ide_run_command_finalize (GObject *object)
   IdeRunCommand *self = (IdeRunCommand *)object;
   IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
 
-  g_clear_pointer (&priv->accelerator, g_free);
   g_clear_pointer (&priv->id, g_free);
   g_clear_pointer (&priv->cwd, g_free);
   g_clear_pointer (&priv->display_name, g_free);
@@ -106,10 +103,6 @@ ide_run_command_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_ACCELERATOR:
-      g_value_set_string (value, ide_run_command_get_accelerator (self));
-      break;
-
     case PROP_CWD:
       g_value_set_string (value, ide_run_command_get_cwd (self));
       break;
@@ -153,10 +146,6 @@ ide_run_command_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_ACCELERATOR:
-      ide_run_command_set_accelerator (self, g_value_get_string (value));
-      break;
-
     case PROP_CWD:
       ide_run_command_set_cwd (self, g_value_get_string (value));
       break;
@@ -201,11 +190,6 @@ ide_run_command_class_init (IdeRunCommandClass *klass)
 
   klass->get_arguments = ide_run_command_real_get_arguments;
 
-  properties [PROP_ACCELERATOR] =
-    g_param_spec_string ("accelerator", NULL, NULL,
-                         NULL,
-                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
-
   properties [PROP_ARGV] =
     g_param_spec_boxed ("argv", NULL, NULL,
                         G_TYPE_STRV,
@@ -282,32 +266,6 @@ ide_run_command_set_id (IdeRunCommand *self,
     }
 }
 
-const char *
-ide_run_command_get_accelerator (IdeRunCommand *self)
-{
-  IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
-
-  g_return_val_if_fail (IDE_IS_RUN_COMMAND (self), NULL);
-
-  return priv->accelerator;
-}
-
-void
-ide_run_command_set_accelerator (IdeRunCommand *self,
-                                 const char    *accelerator)
-{
-  IdeRunCommandPrivate *priv = ide_run_command_get_instance_private (self);
-
-  g_return_if_fail (IDE_IS_RUN_COMMAND (self));
-
-  if (g_strcmp0 (priv->accelerator, accelerator) != 0)
-    {
-      g_free (priv->accelerator);
-      priv->accelerator = g_strdup (accelerator);
-      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ACCELERATOR]);
-    }
-}
-
 const char *
 ide_run_command_get_cwd (IdeRunCommand *self)
 {
diff --git a/src/libide/foundry/ide-run-command.h b/src/libide/foundry/ide-run-command.h
index 60b6e1d12..c97edbb63 100644
--- a/src/libide/foundry/ide-run-command.h
+++ b/src/libide/foundry/ide-run-command.h
@@ -64,11 +64,6 @@ IDE_AVAILABLE_IN_ALL
 void                ide_run_command_set_cwd          (IdeRunCommand      *self,
                                                       const char         *cwd);
 IDE_AVAILABLE_IN_ALL
-const char         *ide_run_command_get_accelerator  (IdeRunCommand      *self);
-IDE_AVAILABLE_IN_ALL
-void                ide_run_command_set_accelerator  (IdeRunCommand      *self,
-                                                      const char         *accelerator);
-IDE_AVAILABLE_IN_ALL
 const char         *ide_run_command_get_display_name (IdeRunCommand      *self);
 IDE_AVAILABLE_IN_ALL
 void                ide_run_command_set_display_name (IdeRunCommand      *self,
diff --git a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c 
b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
index 379ff2ab9..ed6a3f234 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-command-dialog.c
@@ -267,7 +267,7 @@ gbp_shellcmd_command_dialog_set_command (GbpShellcmdCommandDialog *self,
   argv = ide_run_command_get_argv (IDE_RUN_COMMAND (command));
   env = ide_run_command_get_env (IDE_RUN_COMMAND (command));
   cwd = ide_run_command_get_cwd (IDE_RUN_COMMAND (command));
-  accel = ide_run_command_get_accelerator (IDE_RUN_COMMAND (command));
+  accel = gbp_shellcmd_run_command_get_accelerator (command);
 
   argvstr = normalize_argv (argv);
 
@@ -403,7 +403,7 @@ command_save_action (GtkWidget  *widget,
                                     gtk_editable_get_text (GTK_EDITABLE (self->name)));
   ide_run_command_set_cwd (IDE_RUN_COMMAND (self->command),
                            gtk_editable_get_text (GTK_EDITABLE (self->location)));
-  ide_run_command_set_accelerator (IDE_RUN_COMMAND (self->command), self->accel);
+  gbp_shellcmd_run_command_set_accelerator (self->command, self->accel);
 
   env = string_list_to_strv (self->envvars);
   ide_run_command_set_env (IDE_RUN_COMMAND (self->command),
diff --git a/src/plugins/shellcmd/gbp-shellcmd-run-command.c b/src/plugins/shellcmd/gbp-shellcmd-run-command.c
index a1d2d5ab1..ca685829e 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-run-command.c
+++ b/src/plugins/shellcmd/gbp-shellcmd-run-command.c
@@ -30,10 +30,12 @@ struct _GbpShellcmdRunCommand
   char          *settings_path;
   GSettings     *settings;
   char          *id;
+  char          *accelerator;
 };
 
 enum {
   PROP_0,
+  PROP_ACCELERATOR,
   PROP_ACCELERATOR_LABEL,
   PROP_SETTINGS_PATH,
   PROP_SUBTITLE,
@@ -113,14 +115,13 @@ accelerator_label_changed_cb (GbpShellcmdRunCommand *self)
 static char *
 get_accelerator_label (GbpShellcmdRunCommand *self)
 {
-  const char *accelerator = ide_run_command_get_accelerator (IDE_RUN_COMMAND (self));
   GdkModifierType state;
   guint keyval;
 
-  if (ide_str_empty0 (accelerator))
+  if (ide_str_empty0 (self->accelerator))
     return NULL;
 
-  if (gtk_accelerator_parse (accelerator, &keyval, &state))
+  if (gtk_accelerator_parse (self->accelerator, &keyval, &state))
     return gtk_accelerator_get_label (keyval, state);
 
   return NULL;
@@ -131,6 +132,7 @@ gbp_shellcmd_run_command_dispose (GObject *object)
 {
   GbpShellcmdRunCommand *self = (GbpShellcmdRunCommand *)object;
 
+  g_clear_pointer (&self->accelerator, g_free);
   g_clear_pointer (&self->id, g_free);
   g_clear_pointer (&self->settings_path, g_free);
   g_clear_object (&self->settings);
@@ -148,6 +150,10 @@ gbp_shellcmd_run_command_get_property (GObject    *object,
 
   switch (prop_id)
     {
+    case PROP_ACCELERATOR:
+      g_value_set_string (value, gbp_shellcmd_run_command_get_accelerator (self));
+      break;
+
     case PROP_ACCELERATOR_LABEL:
       g_value_take_string (value, get_accelerator_label (self));
       break;
@@ -175,6 +181,10 @@ gbp_shellcmd_run_command_set_property (GObject      *object,
 
   switch (prop_id)
     {
+    case PROP_ACCELERATOR:
+      gbp_shellcmd_run_command_set_accelerator (self, g_value_get_string (value));
+      break;
+
     case PROP_SETTINGS_PATH:
       self->settings_path = g_value_dup_string (value);
       break;
@@ -194,6 +204,10 @@ gbp_shellcmd_run_command_class_init (GbpShellcmdRunCommandClass *klass)
   object_class->get_property = gbp_shellcmd_run_command_get_property;
   object_class->set_property = gbp_shellcmd_run_command_set_property;
 
+  properties [PROP_ACCELERATOR] =
+    g_param_spec_string ("accelerator", NULL, NULL, NULL,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_ACCELERATOR_LABEL] =
     g_param_spec_string ("accelerator-label", NULL, NULL, NULL,
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
@@ -265,3 +279,24 @@ gbp_shellcmd_run_command_delete (GbpShellcmdRunCommand *self)
   for (guint i = 0; keys[i]; i++)
     g_settings_reset (self->settings, keys[i]);
 }
+
+const char *
+gbp_shellcmd_run_command_get_accelerator (GbpShellcmdRunCommand *self)
+{
+  g_return_val_if_fail (GBP_IS_SHELLCMD_RUN_COMMAND (self), NULL);
+
+  return self->accelerator;
+}
+
+void
+gbp_shellcmd_run_command_set_accelerator (GbpShellcmdRunCommand *self,
+                                          const char            *accelerator)
+{
+  g_return_if_fail (GBP_IS_SHELLCMD_RUN_COMMAND (self));
+
+  if (ide_set_string (&self->accelerator, accelerator))
+    {
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACCELERATOR]);
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACCELERATOR_LABEL]);
+    }
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-run-command.h b/src/plugins/shellcmd/gbp-shellcmd-run-command.h
index 61b8e53e2..30aeb79df 100644
--- a/src/plugins/shellcmd/gbp-shellcmd-run-command.h
+++ b/src/plugins/shellcmd/gbp-shellcmd-run-command.h
@@ -28,8 +28,11 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GbpShellcmdRunCommand, gbp_shellcmd_run_command, GBP, SHELLCMD_RUN_COMMAND, 
IdeRunCommand)
 
-GbpShellcmdRunCommand *gbp_shellcmd_run_command_new    (const char            *settings_path);
-GbpShellcmdRunCommand *gbp_shellcmd_run_command_create (IdeContext            *context);
-void                   gbp_shellcmd_run_command_delete (GbpShellcmdRunCommand *self);
+GbpShellcmdRunCommand *gbp_shellcmd_run_command_new             (const char            *settings_path);
+GbpShellcmdRunCommand *gbp_shellcmd_run_command_create          (IdeContext            *context);
+void                   gbp_shellcmd_run_command_delete          (GbpShellcmdRunCommand *self);
+const char            *gbp_shellcmd_run_command_get_accelerator (GbpShellcmdRunCommand *self);
+void                   gbp_shellcmd_run_command_set_accelerator (GbpShellcmdRunCommand *self,
+                                                                 const char            *accelerator);
 
 G_END_DECLS


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