[gnome-builder/wip/gtk4-port] plugins/shellcmd: start on preferences addin



commit 99bd21321a8c0d2edc4ea1eed4707864312e5dd3
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jun 10 15:09:06 2022 -0700

    plugins/shellcmd: start on preferences addin
    
    This will need to add editable lists for both app-wide and project-wide
    build and run commands.

 .../shellcmd/gbp-shellcmd-preferences-addin.c      | 127 +++++++++++++++++++++
 .../shellcmd/gbp-shellcmd-preferences-addin.h      |  31 +++++
 src/plugins/shellcmd/meson.build                   |   1 +
 src/plugins/shellcmd/shellcmd-plugin.c             |   5 +
 4 files changed, 164 insertions(+)
---
diff --git a/src/plugins/shellcmd/gbp-shellcmd-preferences-addin.c 
b/src/plugins/shellcmd/gbp-shellcmd-preferences-addin.c
new file mode 100644
index 000000000..0251bc9b6
--- /dev/null
+++ b/src/plugins/shellcmd/gbp-shellcmd-preferences-addin.c
@@ -0,0 +1,127 @@
+/* gbp-shellcmd-preferences-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-preferences-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-gui.h>
+
+#include "gbp-shellcmd-preferences-addin.h"
+
+struct _GbpShellcmdPreferencesAddin
+{
+  GObject               parent_instance;
+  IdePreferencesWindow *window;
+};
+
+static void
+handle_shellcmd_list (const char                   *page_name,
+                      const IdePreferenceItemEntry *entry,
+                      AdwPreferencesGroup          *group,
+                      gpointer                      user_data)
+{
+  IdePreferencesWindow *window = user_data;
+
+  IDE_ENTRY;
+
+  g_assert (ide_str_equal0 (page_name, "commands"));
+  g_assert (ADW_IS_PREFERENCES_GROUP (group));
+  g_assert (IDE_IS_PREFERENCES_WINDOW (window));
+
+  adw_preferences_group_set_header_suffix (group,
+                                           g_object_new (GTK_TYPE_BUTTON,
+                                                         "valign", GTK_ALIGN_CENTER,
+                                                         "icon-name", "list-add-symbolic",
+                                                         NULL));
+
+  adw_preferences_group_add (group, gtk_label_new ("empty"));
+
+  IDE_EXIT;
+}
+
+static const IdePreferenceGroupEntry groups[] = {
+  { "commands", "build", 0, N_("Build Commands") },
+  { "commands", "run", 0, N_("Run Commands") },
+};
+
+static const IdePreferenceItemEntry items[] = {
+  { "commands", "build", "list", 0, handle_shellcmd_list },
+  { "commands", "run", "list", 0, handle_shellcmd_list },
+};
+
+static void
+gbp_shellcmd_preferences_addin_load (IdePreferencesAddin  *addin,
+                                     IdePreferencesWindow *window,
+                                     IdeContext           *context)
+{
+  GbpShellcmdPreferencesAddin *self = (GbpShellcmdPreferencesAddin *)addin;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SHELLCMD_PREFERENCES_ADDIN (self));
+  g_assert (IDE_IS_PREFERENCES_WINDOW (window));
+
+  self->window = window;
+
+  ide_preferences_window_add_groups (window, groups, G_N_ELEMENTS (groups), GETTEXT_PACKAGE);
+  ide_preferences_window_add_items (window, items, G_N_ELEMENTS (items), window, NULL);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_shellcmd_preferences_addin_unload (IdePreferencesAddin  *addin,
+                                       IdePreferencesWindow *window,
+                                       IdeContext           *context)
+{
+  GbpShellcmdPreferencesAddin *self = (GbpShellcmdPreferencesAddin *)addin;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_SHELLCMD_PREFERENCES_ADDIN (self));
+  g_assert (IDE_IS_PREFERENCES_WINDOW (window));
+
+  self->window = NULL;
+
+  IDE_EXIT;
+}
+
+static void
+preferences_addin_iface_init (IdePreferencesAddinInterface *iface)
+{
+  iface->load = gbp_shellcmd_preferences_addin_load;
+  iface->unload = gbp_shellcmd_preferences_addin_unload;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpShellcmdPreferencesAddin, gbp_shellcmd_preferences_addin, G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN, 
preferences_addin_iface_init))
+
+static void
+gbp_shellcmd_preferences_addin_class_init (GbpShellcmdPreferencesAddinClass *klass)
+{
+}
+
+static void
+gbp_shellcmd_preferences_addin_init (GbpShellcmdPreferencesAddin *self)
+{
+}
diff --git a/src/plugins/shellcmd/gbp-shellcmd-preferences-addin.h 
b/src/plugins/shellcmd/gbp-shellcmd-preferences-addin.h
new file mode 100644
index 000000000..f9520182e
--- /dev/null
+++ b/src/plugins/shellcmd/gbp-shellcmd-preferences-addin.h
@@ -0,0 +1,31 @@
+/* gbp-shellcmd-preferences-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 <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_SHELLCMD_PREFERENCES_ADDIN (gbp_shellcmd_preferences_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpShellcmdPreferencesAddin, gbp_shellcmd_preferences_addin, GBP, 
SHELLCMD_PREFERENCES_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/shellcmd/meson.build b/src/plugins/shellcmd/meson.build
index 581953988..cecc199aa 100644
--- a/src/plugins/shellcmd/meson.build
+++ b/src/plugins/shellcmd/meson.build
@@ -2,6 +2,7 @@ if get_option('plugin_shellcmd')
 
 plugins_sources += files([
   'shellcmd-plugin.c',
+  'gbp-shellcmd-preferences-addin.c',
   'gbp-shellcmd-run-command.c',
   'gbp-shellcmd-run-command-provider.c',
 ])
diff --git a/src/plugins/shellcmd/shellcmd-plugin.c b/src/plugins/shellcmd/shellcmd-plugin.c
index 9ad48f036..b5a6daee8 100644
--- a/src/plugins/shellcmd/shellcmd-plugin.c
+++ b/src/plugins/shellcmd/shellcmd-plugin.c
@@ -23,12 +23,17 @@
 #include <libpeas/peas.h>
 
 #include <libide-foundry.h>
+#include <libide-gui.h>
 
+#include "gbp-shellcmd-preferences-addin.h"
 #include "gbp-shellcmd-run-command-provider.h"
 
 _IDE_EXTERN void
 _gbp_shellcmd_register_types (PeasObjectModule *module)
 {
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_PREFERENCES_ADDIN,
+                                              GBP_TYPE_SHELLCMD_PREFERENCES_ADDIN);
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_RUN_COMMAND_PROVIDER,
                                               GBP_TYPE_SHELLCMD_RUN_COMMAND_PROVIDER);


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