[gnome-builder/wip/gtk4-port] plugins/testui: bind model from test-manager to listview



commit 488efdcc3df0e529a1b0cffd31dfa0081f7095b1
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 29 15:41:35 2022 -0700

    plugins/testui: bind model from test-manager to listview
    
    We still need something to kick off the loading of the run commands to be
    filtered by the test-manager though.
    
    What we might want to do, is to have the IdeRunManager maintain that core
    model and have it update when building. At that point, it can always hand
    out the same model for results.

 src/plugins/testui/gbp-testui-panel.c           | 92 ++++++++++++++++++++++++-
 src/plugins/testui/gbp-testui-workspace-addin.c |  8 +++
 2 files changed, 99 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/testui/gbp-testui-panel.c b/src/plugins/testui/gbp-testui-panel.c
index 7bffb2178..c7826e5da 100644
--- a/src/plugins/testui/gbp-testui-panel.c
+++ b/src/plugins/testui/gbp-testui-panel.c
@@ -26,11 +26,24 @@
 
 struct _GbpTestuiPanel
 {
-  IdePane parent_instance;
+  IdePane          parent_instance;
+
+  GtkListView    *list_view;
+  GtkNoSelection *selection;
+
+  GListModel      *model;
 };
 
 G_DEFINE_FINAL_TYPE (GbpTestuiPanel, gbp_testui_panel, IDE_TYPE_PANE)
 
+enum {
+  PROP_0,
+  PROP_MODEL,
+  N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS];
+
 static void
 gbp_testui_panel_activate_cb (GbpTestuiPanel *self,
                               guint           position,
@@ -53,12 +66,89 @@ gbp_testui_panel_activate_cb (GbpTestuiPanel *self,
   IDE_EXIT;
 }
 
+static void
+gbp_testui_panel_set_model (GbpTestuiPanel *self,
+                            GListModel     *model)
+{
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_TESTUI_PANEL (self));
+  g_assert (!model || G_IS_LIST_MODEL (model));
+
+  if (g_set_object (&self->model, model))
+    {
+      gtk_no_selection_set_model (self->selection, model);
+      g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
+    }
+}
+
+static void
+gbp_testui_panel_dispose (GObject *object)
+{
+  GbpTestuiPanel *self = (GbpTestuiPanel *)object;
+
+  g_clear_object (&self->model);
+
+  G_OBJECT_CLASS (gbp_testui_panel_parent_class)->dispose (object);
+}
+
+static void
+gbp_testui_panel_get_property (GObject    *object,
+                               guint       prop_id,
+                               GValue     *value,
+                               GParamSpec *pspec)
+{
+  GbpTestuiPanel *self = GBP_TESTUI_PANEL (object);
+
+  switch (prop_id)
+    {
+    case PROP_MODEL:
+      g_value_set_object (value, self->model);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_testui_panel_set_property (GObject      *object,
+                               guint         prop_id,
+                               const GValue *value,
+                               GParamSpec   *pspec)
+{
+  GbpTestuiPanel *self = GBP_TESTUI_PANEL (object);
+
+  switch (prop_id)
+    {
+    case PROP_MODEL:
+      gbp_testui_panel_set_model (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
 static void
 gbp_testui_panel_class_init (GbpTestuiPanelClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
+  object_class->dispose = gbp_testui_panel_dispose;
+  object_class->get_property = gbp_testui_panel_get_property;
+  object_class->set_property = gbp_testui_panel_set_property;
+
+  properties [PROP_MODEL] =
+    g_param_spec_object ("model", NULL, NULL,
+                         G_TYPE_LIST_MODEL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
   gtk_widget_class_set_template_from_resource (widget_class, "/plugins/testui/gbp-testui-panel.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbpTestuiPanel, list_view);
+  gtk_widget_class_bind_template_child (widget_class, GbpTestuiPanel, selection);
   gtk_widget_class_bind_template_callback (widget_class, gbp_testui_panel_activate_cb);
 }
 
diff --git a/src/plugins/testui/gbp-testui-workspace-addin.c b/src/plugins/testui/gbp-testui-workspace-addin.c
index 2741d5ee2..d2308b553 100644
--- a/src/plugins/testui/gbp-testui-workspace-addin.c
+++ b/src/plugins/testui/gbp-testui-workspace-addin.c
@@ -41,6 +41,8 @@ gbp_testui_workspace_addin_load (IdeWorkspaceAddin *addin,
 {
   GbpTestuiWorkspaceAddin *self = (GbpTestuiWorkspaceAddin *)addin;
   g_autoptr(IdePanelPosition) position = NULL;
+  IdeTestManager *test_manager;
+  IdeContext *context;
 
   IDE_ENTRY;
 
@@ -50,7 +52,13 @@ gbp_testui_workspace_addin_load (IdeWorkspaceAddin *addin,
 
   self->workspace = workspace;
 
+  context = ide_workspace_get_context (workspace);
+  test_manager = ide_test_manager_from_context (context);
   self->panel = gbp_testui_panel_new ();
+  g_object_bind_property (test_manager, "model",
+                          self->panel, "model",
+                          G_BINDING_SYNC_CREATE);
+
   position = ide_panel_position_new ();
   ide_panel_position_set_edge (position, PANEL_DOCK_POSITION_END);
   ide_workspace_add_pane (workspace, IDE_PANE (self->panel), position);


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