[gnome-builder/wip/gtk4-port: 936/1774] plugins/buildui: prototype select build target dialog




commit 3ec3bd3612ec8c4a5b506fcf1fd6b6a640d67636
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 9 19:39:03 2022 -0700

    plugins/buildui: prototype select build target dialog
    
    This isn't finished, but I prefer to get things in early and iterate. It
    is just a window that we'll show to allow the user to select the default
    build target.
    
    It probably needs some whizbangs to show while it extracts content in case
    that operation is slow (ie: requires building or configuring some stuff).
    
    Also, we might want to allow a free-form target to be specified if the
    backend supports it.

 src/plugins/buildui/gbp-buildui-targets-dialog.c  | 196 ++++++++++++++++++++++
 src/plugins/buildui/gbp-buildui-targets-dialog.h  |  35 ++++
 src/plugins/buildui/gbp-buildui-targets-dialog.ui |  33 ++++
 src/plugins/buildui/gbp-buildui-workspace-addin.c |  24 +++
 src/plugins/buildui/gtk/menus.ui                  |   7 +-
 src/plugins/buildui/meson.build                   |   1 +
 6 files changed, 293 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/buildui/gbp-buildui-targets-dialog.c 
b/src/plugins/buildui/gbp-buildui-targets-dialog.c
new file mode 100644
index 000000000..e8ffe215a
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-targets-dialog.c
@@ -0,0 +1,196 @@
+/*
+ * gbp-buildui-targets-dialog.c
+ *
+ * Copyright 2022 Christian Hergert <>
+ *
+ * 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-buildui-targets-dialog"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-gui.h>
+#include <libide-plugins.h>
+#include <libide-threading.h>
+
+#include "gbp-buildui-targets-dialog.h"
+
+struct _GbpBuilduiTargetsDialog
+{
+  AdwWindow               parent_instance;
+  GtkListBox             *list_box;
+  GListStore             *store;
+  IdeExtensionSetAdapter *set;
+};
+
+G_DEFINE_FINAL_TYPE (GbpBuilduiTargetsDialog, gbp_buildui_targets_dialog, ADW_TYPE_WINDOW)
+
+enum {
+  PROP_0,
+  PROP_CONTEXT,
+  N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+static GtkWidget *
+create_target_row (gpointer item,
+                   gpointer user_data)
+{
+  return g_object_new (ADW_TYPE_ACTION_ROW,
+                       "title", ide_build_target_get_display_name (item),
+                       NULL);
+}
+
+static void
+gbp_buildui_targets_dialog_get_targets_cb (GObject      *object,
+                                           GAsyncResult *result,
+                                           gpointer      user_data)
+{
+  IdeBuildTargetProvider *provider = (IdeBuildTargetProvider *)object;
+  g_autoptr(GbpBuilduiTargetsDialog) self = user_data;
+  g_autoptr(GPtrArray) targets = NULL;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_BUILD_TARGET_PROVIDER (provider));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (GBP_IS_BUILDUI_TARGETS_DIALOG (self));
+
+  targets = ide_build_target_provider_get_targets_finish (provider, result, &error);
+  IDE_PTR_ARRAY_SET_FREE_FUNC (targets, g_object_unref);
+
+  if (targets != NULL)
+    {
+      for (guint i = 0; i < targets->len; i++)
+        {
+          IdeBuildTarget *target = g_ptr_array_index (targets, i);
+
+          g_list_store_append (self->store, target);
+        }
+    }
+
+}
+
+static void
+gbp_buildui_targets_dialog_foreach_cb (IdeExtensionSetAdapter *set,
+                                       PeasPluginInfo         *plugin_info,
+                                       PeasExtension          *exten,
+                                       gpointer                user_data)
+{
+  IdeBuildTargetProvider *provider = (IdeBuildTargetProvider *)exten;
+  GbpBuilduiTargetsDialog *self = user_data;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (IDE_IS_EXTENSION_SET_ADAPTER (set));
+  g_assert (IDE_IS_BUILD_TARGET_PROVIDER (provider));
+  g_assert (GBP_IS_BUILDUI_TARGETS_DIALOG (self));
+
+  ide_build_target_provider_get_targets_async (provider,
+                                               NULL,
+                                               gbp_buildui_targets_dialog_get_targets_cb,
+                                               g_object_ref (self));
+}
+
+static void
+gbp_buildui_targets_dialog_set_context (GbpBuilduiTargetsDialog *self,
+                                        IdeContext              *context)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_BUILDUI_TARGETS_DIALOG (self));
+  g_assert (!context || IDE_IS_CONTEXT (context));
+  g_assert (self->set == NULL);
+
+  if (context == NULL)
+    IDE_EXIT;
+
+  self->set = ide_extension_set_adapter_new (IDE_OBJECT (context),
+                                             peas_engine_get_default (),
+                                             IDE_TYPE_BUILD_TARGET_PROVIDER,
+                                             NULL, NULL);
+
+
+  ide_extension_set_adapter_foreach (self->set,
+                                     gbp_buildui_targets_dialog_foreach_cb,
+                                     self);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_buildui_targets_dialog_dispose (GObject *object)
+{
+  GbpBuilduiTargetsDialog *self = (GbpBuilduiTargetsDialog *)object;
+
+  g_clear_object (&self->store);
+  ide_clear_and_destroy_object (&self->set);
+
+  G_OBJECT_CLASS (gbp_buildui_targets_dialog_parent_class)->dispose (object);
+}
+
+static void
+gbp_buildui_targets_dialog_set_property (GObject      *object,
+                                         guint         prop_id,
+                                         const GValue *value,
+                                         GParamSpec   *pspec)
+{
+  GbpBuilduiTargetsDialog *self = GBP_BUILDUI_TARGETS_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_CONTEXT:
+      gbp_buildui_targets_dialog_set_context (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_buildui_targets_dialog_class_init (GbpBuilduiTargetsDialogClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose = gbp_buildui_targets_dialog_dispose;
+  object_class->set_property = gbp_buildui_targets_dialog_set_property;
+
+  properties [PROP_CONTEXT] =
+    g_param_spec_object ("context",
+                         "Context",
+                         "The context for the build targets",
+                         IDE_TYPE_CONTEXT,
+                         (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/plugins/buildui/gbp-buildui-targets-dialog.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbpBuilduiTargetsDialog, list_box);
+}
+
+static void
+gbp_buildui_targets_dialog_init (GbpBuilduiTargetsDialog *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  self->store = g_list_store_new (IDE_TYPE_BUILD_TARGET);
+  gtk_list_box_bind_model (self->list_box, G_LIST_MODEL (self->store), create_target_row, NULL, NULL);
+}
diff --git a/src/plugins/buildui/gbp-buildui-targets-dialog.h 
b/src/plugins/buildui/gbp-buildui-targets-dialog.h
new file mode 100644
index 000000000..0c3efaae3
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-targets-dialog.h
@@ -0,0 +1,35 @@
+/* gbp-buildui-targets-dialog.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 <adwaita.h>
+
+#include <libide-foundry.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_BUILDUI_TARGETS_DIALOG (gbp_buildui_targets_dialog_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpBuilduiTargetsDialog, gbp_buildui_targets_dialog, GBP, BUILDUI_TARGETS_DIALOG, 
AdwWindow)
+
+GtkWidget *gbp_buildui_targets_dialog_new (IdeContext *context);
+
+G_END_DECLS
diff --git a/src/plugins/buildui/gbp-buildui-targets-dialog.ui 
b/src/plugins/buildui/gbp-buildui-targets-dialog.ui
new file mode 100644
index 000000000..c2d8b038b
--- /dev/null
+++ b/src/plugins/buildui/gbp-buildui-targets-dialog.ui
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GbpBuilduiTargetsDialog" parent="AdwWindow">
+    <property name="title" translatable="yes">Select Build Target</property>
+    <property name="default-width">700</property>
+    <property name="default-height">550</property>
+    <child type="content">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="AdwHeaderBar">
+          </object>
+        </child>
+        <child>
+          <object class="AdwPreferencesPage">
+            <child>
+              <object class="AdwPreferencesGroup">
+                <property name="title" translatable="yes">Build Targets</property>
+                <child>
+                  <object class="GtkListBox" id="list_box">
+                    <style>
+                      <class name="boxed-list"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/buildui/gbp-buildui-workspace-addin.c 
b/src/plugins/buildui/gbp-buildui-workspace-addin.c
index 317859e18..ae0add13a 100644
--- a/src/plugins/buildui/gbp-buildui-workspace-addin.c
+++ b/src/plugins/buildui/gbp-buildui-workspace-addin.c
@@ -30,9 +30,11 @@
 #if 0 /* TODO: port GbpBuilduiConfigSurface */
 #include "gbp-buildui-config-surface.h"
 #endif
+
 #include "gbp-buildui-log-pane.h"
 #include "gbp-buildui-omni-bar-section.h"
 #include "gbp-buildui-pane.h"
+#include "gbp-buildui-targets-dialog.h"
 #include "gbp-buildui-workspace-addin.h"
 
 struct _GbpBuilduiWorkspaceAddin
@@ -212,11 +214,33 @@ on_edit_config_cb (GSimpleAction *action,
 }
 #endif
 
+static void
+select_build_target_action (GSimpleAction *action,
+                            GVariant      *param,
+                            gpointer       user_data)
+{
+  GbpBuilduiWorkspaceAddin *self = user_data;
+  GbpBuilduiTargetsDialog *dialog;
+  IdeContext *context;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+
+  context = ide_workspace_get_context (self->workspace);
+  dialog = g_object_new (GBP_TYPE_BUILDUI_TARGETS_DIALOG,
+                         "context", context,
+                         "transient-for", self->workspace,
+                         "modal", TRUE,
+                         NULL);
+
+  gtk_window_present (GTK_WINDOW (dialog));
+}
+
 static const GActionEntry actions[] = {
 #if 0 /* TODO: port GbpBuilduiConfigSurface */
   { "edit-config", on_edit_config_cb, "s" },
 #endif
   { "show-build-log", on_view_output_cb },
+  { "select-build-target", select_build_target_action },
 };
 
 static void
diff --git a/src/plugins/buildui/gtk/menus.ui b/src/plugins/buildui/gtk/menus.ui
index e93868926..030e60f02 100644
--- a/src/plugins/buildui/gtk/menus.ui
+++ b/src/plugins/buildui/gtk/menus.ui
@@ -39,9 +39,10 @@
       </item>
     </section>
     <section id="build-menu-target">
-      <submenu id="build-menu-targets">
-        <attribute name="label" translatable="yes">Build Target</attribute>
-      </submenu>
+      <item>
+        <attribute name="label" translatable="yes">Select Build Target…</attribute>
+        <attribute name="action">win.select-build-target</attribute>
+      </item>
     </section>
     <section id="build-commands">
       <item>
diff --git a/src/plugins/buildui/meson.build b/src/plugins/buildui/meson.build
index f5a4c8720..059368039 100644
--- a/src/plugins/buildui/meson.build
+++ b/src/plugins/buildui/meson.build
@@ -9,6 +9,7 @@ plugins_sources += files([
   #'gbp-buildui-runtime-categories.c',
   #'gbp-buildui-runtime-row.c',
   'gbp-buildui-stage-row.c',
+  'gbp-buildui-targets-dialog.c',
   'gbp-buildui-tree-addin.c',
   'gbp-buildui-workspace-addin.c',
 ])


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