[gnome-builder] plugins/shellcmd: add tweaks for shellcmd



commit 7ee893a4a9d74b9d5b5a3ff4188ae6b442769489
Author: Christian Hergert <chergert redhat com>
Date:   Fri Aug 19 16:27:56 2022 -0700

    plugins/shellcmd: add tweaks for shellcmd
    
    This is only for app-wide so far, but it gets things to the point that we
    can start looking to handle per-project settings now.

 src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.c | 198 +++++++++++++++++++++++
 src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.h |  31 ++++
 src/plugins/shellcmd/meson.build                 |   1 +
 src/plugins/shellcmd/shellcmd-plugin.c           |   4 +
 src/plugins/shellcmd/shellcmd.gresource.xml      |   1 +
 src/plugins/shellcmd/shellcmd.plugin             |   1 +
 src/plugins/shellcmd/tweaks.ui                   |  34 ++++
 7 files changed, 270 insertions(+)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.c 
b/src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.c
new file mode 100644
index 000000000..0f559a9aa
--- /dev/null
+++ b/src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.c
@@ -0,0 +1,198 @@
+/* gbp-shellcmd-tweaks-addin.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-shellcmd-tweaks-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-gui.h>
+
+#include "gbp-shellcmd-command-dialog.h"
+#include "gbp-shellcmd-command-model.h"
+#include "gbp-shellcmd-tweaks-addin.h"
+#include "gbp-shellcmd-run-command.h"
+
+struct _GbpShellcmdTweaksAddin
+{
+  IdeTweaksAddin parent_instance;
+};
+
+static void
+row_activated_cb (GbpShellcmdTweaksAddin *self,
+                  AdwActionRow           *row,
+                  GtkListBox             *list)
+{
+  g_autoptr(GbpShellcmdRunCommand) new_command = NULL;
+  GbpShellcmdCommandDialog *dialog;
+  GbpShellcmdRunCommand *command;
+  GtkRoot *root;
+
+  g_assert (GBP_IS_SHELLCMD_TWEAKS_ADDIN (self));
+  g_assert (ADW_IS_ACTION_ROW (row));
+  g_assert (GTK_IS_LIST_BOX (list));
+
+  command = g_object_get_data (G_OBJECT (row), "COMMAND");
+
+  if (command == NULL)
+    command = new_command = gbp_shellcmd_run_command_create (NULL);
+
+  dialog = gbp_shellcmd_command_dialog_new (command, !!new_command);
+  root = gtk_widget_get_root (GTK_WIDGET (row));
+
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (root));
+  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+  gtk_window_present (GTK_WINDOW (dialog));
+}
+
+static GtkWidget *
+create_creation_row_cb (GbpShellcmdTweaksAddin *self,
+                        IdeTweaksWidget        *widget,
+                        IdeTweaksWidget        *instance)
+{
+  AdwActionRow *row;
+  GtkListBox *list;
+  GtkLabel *caption;
+  GtkImage *image;
+  GtkBox *box;
+
+  g_assert (GBP_IS_SHELLCMD_TWEAKS_ADDIN (self));
+  g_assert (IDE_IS_TWEAKS_WIDGET (widget));
+  g_assert (IDE_IS_TWEAKS_WIDGET (instance));
+
+  box = g_object_new (GTK_TYPE_BOX,
+                      "orientation", GTK_ORIENTATION_VERTICAL,
+                      "spacing", 12,
+                      NULL);
+  list = g_object_new (GTK_TYPE_LIST_BOX,
+                       "css-classes", IDE_STRV_INIT ("boxed-list"),
+                       "selection-mode", GTK_SELECTION_NONE,
+                       NULL);
+  row = g_object_new (ADW_TYPE_ACTION_ROW,
+                      "activatable", TRUE,
+                      "title", _("Create Command"),
+                      "subtitle", _("Commands can be used to build, run, or modify your projects"),
+                      NULL);
+  image = g_object_new (GTK_TYPE_IMAGE,
+                        "icon-name", "go-next-symbolic",
+                        NULL);
+  adw_action_row_add_suffix (row, GTK_WIDGET (image));
+  gtk_list_box_append (list, GTK_WIDGET (row));
+  caption = g_object_new (GTK_TYPE_LABEL,
+                          "css-classes", IDE_STRV_INIT ("caption", "dim-label"),
+                          "label", _("These commands are shared across all projects."),
+                          "xalign", .0f,
+                          NULL);
+  gtk_box_append (box, GTK_WIDGET (list));
+  gtk_box_append (box, GTK_WIDGET (caption));
+
+  g_signal_connect_object (list,
+                           "row-activated",
+                           G_CALLBACK (row_activated_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  return GTK_WIDGET (box);
+}
+
+static GtkWidget *
+create_row_cb (gpointer item,
+               gpointer item_data)
+{
+  GbpShellcmdRunCommand *command = item;
+  AdwActionRow *row;
+  GtkLabel *accel;
+
+  g_assert (GBP_IS_SHELLCMD_RUN_COMMAND (command));
+
+  row = g_object_new (ADW_TYPE_ACTION_ROW,
+                      "activatable", TRUE,
+                      NULL);
+  g_object_bind_property (command, "display-name", row, "title",
+                          G_BINDING_SYNC_CREATE);
+  g_object_bind_property (command, "subtitle", row, "subtitle",
+                          G_BINDING_SYNC_CREATE);
+
+  accel = g_object_new (GTK_TYPE_LABEL,
+                        "margin-start", 6,
+                        "margin-end", 6,
+                        NULL);
+  g_object_bind_property (command, "accelerator-label", accel, "label",
+                          G_BINDING_SYNC_CREATE);
+  adw_action_row_add_suffix (row, GTK_WIDGET (accel));
+  adw_action_row_add_suffix (row,
+                             g_object_new (GTK_TYPE_IMAGE,
+                                           "icon-name", "go-next-symbolic",
+                                           NULL));
+  g_object_set_data_full (G_OBJECT (row),
+                          "COMMAND",
+                          g_object_ref (command),
+                          g_object_unref);
+
+  return GTK_WIDGET (row);
+}
+
+static GtkWidget *
+create_command_list_cb (GbpShellcmdTweaksAddin *self,
+                        IdeTweaksWidget        *widget,
+                        IdeTweaksWidget        *instance)
+{
+  g_autoptr(GbpShellcmdCommandModel) model = NULL;
+  GtkListBox *list;
+
+  g_assert (GBP_IS_SHELLCMD_TWEAKS_ADDIN (self));
+  g_assert (IDE_IS_TWEAKS_WIDGET (widget));
+  g_assert (IDE_IS_TWEAKS_WIDGET (instance));
+
+  model = gbp_shellcmd_command_model_new_for_app ();
+  list = g_object_new (GTK_TYPE_LIST_BOX,
+                       "css-classes", IDE_STRV_INIT ("boxed-list"),
+                       "selection-mode", GTK_SELECTION_NONE,
+                       NULL);
+  gtk_list_box_bind_model (list,
+                           G_LIST_MODEL (model),
+                           create_row_cb,
+                           NULL, NULL);
+  ide_gtk_widget_hide_when_empty (GTK_WIDGET (list), G_LIST_MODEL (model));
+  g_signal_connect_object (list,
+                           "row-activated",
+                           G_CALLBACK (row_activated_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  return GTK_WIDGET (list);
+}
+
+G_DEFINE_FINAL_TYPE (GbpShellcmdTweaksAddin, gbp_shellcmd_tweaks_addin, IDE_TYPE_TWEAKS_ADDIN)
+
+static void
+gbp_shellcmd_tweaks_addin_class_init (GbpShellcmdTweaksAddinClass *klass)
+{
+}
+
+static void
+gbp_shellcmd_tweaks_addin_init (GbpShellcmdTweaksAddin *self)
+{
+  ide_tweaks_addin_set_resource_paths (IDE_TWEAKS_ADDIN (self),
+                                       IDE_STRV_INIT ("/plugins/shellcmd/tweaks.ui"));
+  ide_tweaks_addin_bind_callback (IDE_TWEAKS_ADDIN (self), create_creation_row_cb);
+  ide_tweaks_addin_bind_callback (IDE_TWEAKS_ADDIN (self), create_command_list_cb);
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.h 
b/src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.h
new file mode 100644
index 000000000..889231e68
--- /dev/null
+++ b/src/plugins/shellcmd/gbp-shellcmd-tweaks-addin.h
@@ -0,0 +1,31 @@
+/* gbp-shellcmd-tweaks-addin.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-tweaks.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_SHELLCMD_TWEAKS_ADDIN (gbp_shellcmd_tweaks_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpShellcmdTweaksAddin, gbp_shellcmd_tweaks_addin, GBP, SHELLCMD_TWEAKS_ADDIN, 
IdeTweaksAddin)
+
+G_END_DECLS
diff --git a/src/plugins/shellcmd/meson.build b/src/plugins/shellcmd/meson.build
index 8c54dcd34..d8d591484 100644
--- a/src/plugins/shellcmd/meson.build
+++ b/src/plugins/shellcmd/meson.build
@@ -10,6 +10,7 @@ plugins_sources += files([
   'gbp-shellcmd-search-provider.c',
   'gbp-shellcmd-search-result.c',
   'gbp-shellcmd-shortcut-provider.c',
+  'gbp-shellcmd-tweaks-addin.c',
 ])
 
 plugin_shellcmd_enum_headers = [
diff --git a/src/plugins/shellcmd/shellcmd-plugin.c b/src/plugins/shellcmd/shellcmd-plugin.c
index 41c6c094c..f34d17b8c 100644
--- a/src/plugins/shellcmd/shellcmd-plugin.c
+++ b/src/plugins/shellcmd/shellcmd-plugin.c
@@ -30,6 +30,7 @@
 #include "gbp-shellcmd-run-command-provider.h"
 #include "gbp-shellcmd-search-provider.h"
 #include "gbp-shellcmd-shortcut-provider.h"
+#include "gbp-shellcmd-tweaks-addin.h"
 
 _IDE_EXTERN void
 _gbp_shellcmd_register_types (PeasObjectModule *module)
@@ -46,4 +47,7 @@ _gbp_shellcmd_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_SHORTCUT_PROVIDER,
                                               GBP_TYPE_SHELLCMD_SHORTCUT_PROVIDER);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_TWEAKS_ADDIN,
+                                              GBP_TYPE_SHELLCMD_TWEAKS_ADDIN);
 }
diff --git a/src/plugins/shellcmd/shellcmd.gresource.xml b/src/plugins/shellcmd/shellcmd.gresource.xml
index 9a01bc34d..b744e2a5a 100644
--- a/src/plugins/shellcmd/shellcmd.gresource.xml
+++ b/src/plugins/shellcmd/shellcmd.gresource.xml
@@ -3,5 +3,6 @@
   <gresource prefix="/plugins/shellcmd">
     <file>shellcmd.plugin</file>
     <file preprocess="xml-stripblanks">gbp-shellcmd-command-dialog.ui</file>
+    <file preprocess="xml-stripblanks">tweaks.ui</file>
   </gresource>
 </gresources>
diff --git a/src/plugins/shellcmd/shellcmd.plugin b/src/plugins/shellcmd/shellcmd.plugin
index 8aa4d21fb..543ce0423 100644
--- a/src/plugins/shellcmd/shellcmd.plugin
+++ b/src/plugins/shellcmd/shellcmd.plugin
@@ -2,6 +2,7 @@
 Authors=Christian Hergert <christian hergert me>
 Builtin=true
 Copyright=Copyright © 2019-2022 Christian Hergert
+Depends=buildui;
 Description=Use custom commands to run your project
 Embedded=_gbp_shellcmd_register_types
 Hidden=true
diff --git a/src/plugins/shellcmd/tweaks.ui b/src/plugins/shellcmd/tweaks.ui
new file mode 100644
index 000000000..06803a7d3
--- /dev/null
+++ b/src/plugins/shellcmd/tweaks.ui
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="IdeTweaks">
+    <child internal-child="foundry_section">
+      <object class="IdeTweaksSection">
+        <child>
+          <object class="IdeTweaksPage" id="commands_page">
+            <property name="title" translatable="yes">Commands</property>
+            <property name="icon-name">text-x-script-symbolic</property>
+            <child>
+              <object class="IdeTweaksGroup" id="command_create_group">
+                <property name="title" translatable="yes">Commands</property>
+                <child>
+                  <object class="IdeTweaksWidget" id="create_command_widget">
+                    <signal name="create-for-item" handler="create_creation_row_cb" swapped="true" 
object="GbpShellcmdTweaksAddin"/>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="IdeTweaksGroup" id="command_list_group">
+                <child>
+                  <object class="IdeTweaksWidget" id="command_list_widget">
+                    <signal name="create-for-item" handler="create_command_list_cb" swapped="true" 
object="GbpShellcmdTweaksAddin"/>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>


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