[gnome-builder/wip/gtk4-port: 597/736] plugins/vcsui: stub out branch switcher popover




commit b7cec57b504bb967a3dbaca56d747ec9e5d87355
Author: Christian Hergert <chergert redhat com>
Date:   Sat Apr 16 22:56:47 2022 -0700

    plugins/vcsui: stub out branch switcher popover

 src/plugins/vcsui/gbp-vcsui-switcher-popover.c  | 144 ++++++++++++++++++++++++
 src/plugins/vcsui/gbp-vcsui-switcher-popover.h  |  38 +++++++
 src/plugins/vcsui/gbp-vcsui-switcher-popover.ui |  56 +++++++++
 src/plugins/vcsui/gbp-vcsui-workspace-addin.c   |  11 +-
 src/plugins/vcsui/meson.build                   |   1 +
 src/plugins/vcsui/vcsui.gresource.xml           |   1 +
 6 files changed, 250 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/vcsui/gbp-vcsui-switcher-popover.c b/src/plugins/vcsui/gbp-vcsui-switcher-popover.c
new file mode 100644
index 000000000..4d7fcde4e
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-switcher-popover.c
@@ -0,0 +1,144 @@
+/* gbp-vcsui-switcher-popover.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-vcsui-switcher-popover"
+
+#include "config.h"
+
+#include "gbp-vcsui-switcher-popover.h"
+
+struct _GbpVcsuiSwitcherPopover
+{
+  GtkPopover parent_instance;
+  IdeVcs *vcs;
+};
+
+enum {
+  PROP_0,
+  PROP_VCS,
+  N_PROPS
+};
+
+G_DEFINE_FINAL_TYPE (GbpVcsuiSwitcherPopover, gbp_vcsui_switcher_popover, GTK_TYPE_POPOVER)
+
+static GParamSpec *properties [N_PROPS];
+
+static void
+gbp_vcsui_switcher_popover_dispose (GObject *object)
+{
+  GbpVcsuiSwitcherPopover *self = (GbpVcsuiSwitcherPopover *)object;
+
+  g_clear_object (&self->vcs);
+
+  G_OBJECT_CLASS (gbp_vcsui_switcher_popover_parent_class)->dispose (object);
+}
+
+static void
+gbp_vcsui_switcher_popover_get_property (GObject    *object,
+                                         guint       prop_id,
+                                         GValue     *value,
+                                         GParamSpec *pspec)
+{
+  GbpVcsuiSwitcherPopover *self = GBP_VCSUI_SWITCHER_POPOVER (object);
+
+  switch (prop_id)
+    {
+    case PROP_VCS:
+      g_value_set_object (value, self->vcs);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_vcsui_switcher_popover_set_property (GObject      *object,
+                                         guint         prop_id,
+                                         const GValue *value,
+                                         GParamSpec   *pspec)
+{
+  GbpVcsuiSwitcherPopover *self = GBP_VCSUI_SWITCHER_POPOVER (object);
+
+  switch (prop_id)
+    {
+    case PROP_VCS:
+      gbp_vcsui_switcher_popover_set_vcs (self, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gbp_vcsui_switcher_popover_class_init (GbpVcsuiSwitcherPopoverClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = gbp_vcsui_switcher_popover_dispose;
+  object_class->get_property = gbp_vcsui_switcher_popover_get_property;
+  object_class->set_property = gbp_vcsui_switcher_popover_set_property;
+
+  properties [PROP_VCS] =
+    g_param_spec_object ("vcs",
+                         "Vcs",
+                         "The version control system",
+                         IDE_TYPE_VCS,
+                         (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, N_PROPS, properties);
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/plugins/vcsui/gbp-vcsui-switcher-popover.ui");
+}
+
+static void
+gbp_vcsui_switcher_popover_init (GbpVcsuiSwitcherPopover *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+IdeVcs *
+gbp_vcsui_switcher_popover_get_vcs (GbpVcsuiSwitcherPopover *self)
+{
+  g_return_val_if_fail (GBP_IS_VCSUI_SWITCHER_POPOVER (self), NULL);
+
+  return self->vcs;
+}
+
+void
+gbp_vcsui_switcher_popover_set_vcs (GbpVcsuiSwitcherPopover *self,
+                                    IdeVcs                  *vcs)
+{
+  g_return_if_fail (GBP_IS_VCSUI_SWITCHER_POPOVER (self));
+  g_return_if_fail (!vcs || IDE_IS_VCS (vcs));
+
+  if (g_set_object (&self->vcs, vcs))
+    {
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_VCS]);
+    }
+}
+
+GtkWidget *
+gbp_vcsui_switcher_popover_new (void)
+{
+  return g_object_new (GBP_TYPE_VCSUI_SWITCHER_POPOVER, NULL);
+}
diff --git a/src/plugins/vcsui/gbp-vcsui-switcher-popover.h b/src/plugins/vcsui/gbp-vcsui-switcher-popover.h
new file mode 100644
index 000000000..3948133b5
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-switcher-popover.h
@@ -0,0 +1,38 @@
+/* gbp-vcsui-switcher-popover.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 <gtk/gtk.h>
+
+#include <libide-vcs.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_VCSUI_SWITCHER_POPOVER (gbp_vcsui_switcher_popover_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpVcsuiSwitcherPopover, gbp_vcsui_switcher_popover, GBP, VCSUI_SWITCHER_POPOVER, 
GtkPopover)
+
+GtkWidget *gbp_vcsui_switcher_popover_new     (void);
+IdeVcs    *gbp_vcsui_switcher_popover_get_vcs (GbpVcsuiSwitcherPopover *self);
+void       gbp_vcsui_switcher_popover_set_vcs (GbpVcsuiSwitcherPopover *self,
+                                               IdeVcs                  *vcs);
+
+G_END_DECLS
diff --git a/src/plugins/vcsui/gbp-vcsui-switcher-popover.ui b/src/plugins/vcsui/gbp-vcsui-switcher-popover.ui
new file mode 100644
index 000000000..ddf6b8577
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-switcher-popover.ui
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GbpVcsuiSwitcherPopover" parent="GtkPopover">
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkStackSwitcher">
+            <property name="stack">stack</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkFrame">
+            <child>
+              <object class="GtkStack" id="stack">
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="name">branches</property>
+                    <property name="title" translatable="yes">Branches</property>
+                    <property name="child">
+                      <object class="GtkScrolledWindow">
+                        <property name="min-content-width">250</property>
+                        <property name="min-content-height">350</property>
+                        <child>
+                          <object class="GtkListBox">
+                          </object>
+                        </child>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkStackPage">
+                    <property name="name">tags</property>
+                    <property name="title" translatable="yes">Tags</property>
+                    <property name="child">
+                      <object class="GtkScrolledWindow">
+                        <property name="min-content-width">250</property>
+                        <property name="min-content-height">350</property>
+                        <child>
+                          <object class="GtkListBox">
+                          </object>
+                        </child>
+                      </object>
+                    </property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/vcsui/gbp-vcsui-workspace-addin.c b/src/plugins/vcsui/gbp-vcsui-workspace-addin.c
index 02856834a..0037588ea 100644
--- a/src/plugins/vcsui/gbp-vcsui-workspace-addin.c
+++ b/src/plugins/vcsui/gbp-vcsui-workspace-addin.c
@@ -28,6 +28,7 @@
 #include <libide-greeter.h>
 
 #include "gbp-vcsui-clone-widget.h"
+#include "gbp-vcsui-switcher-popover.h"
 #include "gbp-vcsui-workspace-addin.h"
 
 struct _GbpVcsuiWorkspaceAddin
@@ -71,9 +72,11 @@ gbp_vcsui_workspace_addin_load (IdeWorkspaceAddin *addin,
     {
       PanelStatusbar *statusbar;
       IdeWorkbench *workbench;
+      GtkWidget *popover;
       GtkImage *image;
       GtkBox *box;
 
+      workbench = ide_workspace_get_workbench (workspace);
       statusbar = ide_workspace_get_statusbar (workspace);
 
       box = g_object_new (GTK_TYPE_BOX,
@@ -90,13 +93,18 @@ gbp_vcsui_workspace_addin_load (IdeWorkspaceAddin *addin,
       gtk_box_append (box, GTK_WIDGET (image));
       gtk_box_append (box, GTK_WIDGET (self->branch_label));
 
+      popover = gbp_vcsui_switcher_popover_new ();
+      g_object_bind_property (workbench, "vcs",
+                              popover, "vcs",
+                              G_BINDING_SYNC_CREATE);
+
       self->branch_button = g_object_new (GTK_TYPE_MENU_BUTTON,
                                           "child", box,
                                           "direction", GTK_ARROW_UP,
+                                          "popover", popover,
                                           NULL);
       panel_statusbar_add_prefix (statusbar, GTK_WIDGET (self->branch_button));
 
-      workbench = ide_workspace_get_workbench (workspace);
       self->vcs_bindings = ide_binding_group_new ();
       ide_binding_group_bind (self->vcs_bindings, "branch-name",
                               self->branch_label, "label",
@@ -146,6 +154,7 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (GbpVcsuiWorkspaceAddin, gbp_vcsui_workspace_addin
 static void
 gbp_vcsui_workspace_addin_class_init (GbpVcsuiWorkspaceAddinClass *klass)
 {
+  g_type_ensure (GBP_TYPE_VCSUI_SWITCHER_POPOVER);
 }
 
 static void
diff --git a/src/plugins/vcsui/meson.build b/src/plugins/vcsui/meson.build
index ddf9b8854..e40fde9cd 100644
--- a/src/plugins/vcsui/meson.build
+++ b/src/plugins/vcsui/meson.build
@@ -2,6 +2,7 @@ plugins_sources += files([
   'vcsui-plugin.c',
   'gbp-vcsui-clone-widget.c',
   'gbp-vcsui-editor-page-addin.c',
+  'gbp-vcsui-switcher-popover.c',
   'gbp-vcsui-tree-addin.c',
   'gbp-vcsui-workbench-addin.c',
   'gbp-vcsui-workspace-addin.c',
diff --git a/src/plugins/vcsui/vcsui.gresource.xml b/src/plugins/vcsui/vcsui.gresource.xml
index c02f0a5c5..3c25e58b5 100644
--- a/src/plugins/vcsui/vcsui.gresource.xml
+++ b/src/plugins/vcsui/vcsui.gresource.xml
@@ -4,5 +4,6 @@
     <file>vcsui.plugin</file>
     <file preprocess="xml-stripblanks">gtk/menus.ui</file>
     <file preprocess="xml-stripblanks">gbp-vcsui-clone-widget.ui</file>
+    <file preprocess="xml-stripblanks">gbp-vcsui-switcher-popover.ui</file>
   </gresource>
 </gresources>


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