[gnome-builder/wip/gtk4-port] plugins/vcsui: show list of branches and tags



commit fc4dc26d04de9108ace6d6c9e5d1f024ae9a0748
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 13 16:04:04 2022 -0700

    plugins/vcsui: show list of branches and tags
    
    There is still more work to do here, in that we'd like to be able to
    activate the row to switch to the branch/tag and/or check it out into
    a new worktree.
    
    Additionally, we'd want some commit stuff here too. But all in good time.

 src/plugins/vcsui/gbp-vcsui-switcher-popover.c  | 102 ++++++++++++++++
 src/plugins/vcsui/gbp-vcsui-switcher-popover.ui | 153 +++++++++++++++++++-----
 2 files changed, 226 insertions(+), 29 deletions(-)
---
diff --git a/src/plugins/vcsui/gbp-vcsui-switcher-popover.c b/src/plugins/vcsui/gbp-vcsui-switcher-popover.c
index 4d7fcde4e..2e798f1fe 100644
--- a/src/plugins/vcsui/gbp-vcsui-switcher-popover.c
+++ b/src/plugins/vcsui/gbp-vcsui-switcher-popover.c
@@ -27,7 +27,13 @@
 struct _GbpVcsuiSwitcherPopover
 {
   GtkPopover parent_instance;
+
   IdeVcs *vcs;
+
+  GtkListView *branches_view;
+  GListStore  *branches_model;
+  GtkListView *tags_view;
+  GListStore  *tags_model;
 };
 
 enum {
@@ -40,6 +46,70 @@ G_DEFINE_FINAL_TYPE (GbpVcsuiSwitcherPopover, gbp_vcsui_switcher_popover, GTK_TY
 
 static GParamSpec *properties [N_PROPS];
 
+static void
+gbp_vcsui_switcher_popover_list_branches_cb (GObject      *object,
+                                             GAsyncResult *result,
+                                             gpointer      user_data)
+{
+  IdeVcs *vcs = (IdeVcs *)object;
+  g_autoptr(GbpVcsuiSwitcherPopover) self = user_data;
+  g_autoptr(GListStore) store = NULL;
+  g_autoptr(GPtrArray) ar = NULL;
+  g_autoptr(GError) error = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_VCS (vcs));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (GBP_IS_VCSUI_SWITCHER_POPOVER (self));
+
+  if (!(ar = ide_vcs_list_branches_finish (vcs, result, &error)))
+    {
+      g_warning ("Failed to list branches: %s\n", error->message);
+      IDE_EXIT;
+    }
+
+  g_ptr_array_set_free_func (ar, g_object_unref);
+  g_list_store_remove_all (self->branches_model);
+
+  for (guint i = 0; i < ar->len; i++)
+    g_list_store_append (self->branches_model, g_ptr_array_index (ar, i));
+
+  IDE_EXIT;
+}
+
+static void
+gbp_vcsui_switcher_popover_list_tags_cb (GObject      *object,
+                                         GAsyncResult *result,
+                                         gpointer      user_data)
+{
+  IdeVcs *vcs = (IdeVcs *)object;
+  g_autoptr(GbpVcsuiSwitcherPopover) self = user_data;
+  g_autoptr(GListStore) store = NULL;
+  g_autoptr(GPtrArray) ar = NULL;
+  g_autoptr(GError) error = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_VCS (vcs));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (GBP_IS_VCSUI_SWITCHER_POPOVER (self));
+
+  if (!(ar = ide_vcs_list_tags_finish (vcs, result, &error)))
+    {
+      g_warning ("Failed to list tags: %s\n", error->message);
+      IDE_EXIT;
+    }
+
+  g_ptr_array_set_free_func (ar, g_object_unref);
+  g_list_store_remove_all (self->tags_model);
+
+  for (guint i = 0; i < ar->len; i++)
+    g_list_store_append (self->tags_model, g_ptr_array_index (ar, i));
+
+  IDE_EXIT;
+}
+
 static void
 gbp_vcsui_switcher_popover_dispose (GObject *object)
 {
@@ -50,6 +120,32 @@ gbp_vcsui_switcher_popover_dispose (GObject *object)
   G_OBJECT_CLASS (gbp_vcsui_switcher_popover_parent_class)->dispose (object);
 }
 
+static void
+gbp_vcsui_switcher_popover_show (GtkWidget *widget)
+{
+  GbpVcsuiSwitcherPopover *self = (GbpVcsuiSwitcherPopover *)widget;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_VCSUI_SWITCHER_POPOVER (self));
+
+  if (self->vcs != NULL)
+    {
+      ide_vcs_list_branches_async (self->vcs,
+                                   NULL,
+                                   gbp_vcsui_switcher_popover_list_branches_cb,
+                                   g_object_ref (self));
+      ide_vcs_list_tags_async (self->vcs,
+                               NULL,
+                               gbp_vcsui_switcher_popover_list_tags_cb,
+                               g_object_ref (self));
+    }
+
+  GTK_WIDGET_CLASS (gbp_vcsui_switcher_popover_parent_class)->show (widget);
+
+  IDE_EXIT;
+}
+
 static void
 gbp_vcsui_switcher_popover_get_property (GObject    *object,
                                          guint       prop_id,
@@ -98,6 +194,8 @@ gbp_vcsui_switcher_popover_class_init (GbpVcsuiSwitcherPopoverClass *klass)
   object_class->get_property = gbp_vcsui_switcher_popover_get_property;
   object_class->set_property = gbp_vcsui_switcher_popover_set_property;
 
+  widget_class->show = gbp_vcsui_switcher_popover_show;
+
   properties [PROP_VCS] =
     g_param_spec_object ("vcs",
                          "Vcs",
@@ -108,6 +206,10 @@ gbp_vcsui_switcher_popover_class_init (GbpVcsuiSwitcherPopoverClass *klass)
   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");
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiSwitcherPopover, branches_view);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiSwitcherPopover, branches_model);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiSwitcherPopover, tags_view);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiSwitcherPopover, tags_model);
 }
 
 static void
diff --git a/src/plugins/vcsui/gbp-vcsui-switcher-popover.ui b/src/plugins/vcsui/gbp-vcsui-switcher-popover.ui
index ddf6b8577..1ebddfdef 100644
--- a/src/plugins/vcsui/gbp-vcsui-switcher-popover.ui
+++ b/src/plugins/vcsui/gbp-vcsui-switcher-popover.ui
@@ -1,51 +1,140 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <template class="GbpVcsuiSwitcherPopover" parent="GtkPopover">
+    <style>
+      <class name="menu"/>
+    </style>
     <child>
       <object class="GtkBox">
         <property name="orientation">vertical</property>
-        <property name="spacing">6</property>
         <child>
           <object class="GtkStackSwitcher">
             <property name="stack">stack</property>
+            <property name="margin-top">6</property>
+            <property name="margin-start">6</property>
+            <property name="margin-end">6</property>
+            <property name="margin-bottom">6</property>
           </object>
         </child>
         <child>
-          <object class="GtkFrame">
+          <object class="GtkStack" id="stack">
+            <property name="vhomogeneous">false</property>
+            <property name="interpolate-size">true</property>
+            <property name="transition-type">crossfade</property>
             <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 class="GtkStackPage">
+                <property name="name">branches</property>
+                <property name="title" translatable="yes">_Branches</property>
+                <property name="use-underline">true</property>
+                <property name="child">
+                  <object class="GtkScrolledWindow">
+                    <property name="propagate-natural-height">true</property>
+                    <property name="propagate-natural-width">true</property>
+                    <property name="min-content-height">100</property>
+                    <property name="max-content-height">600</property>
+                    <property name="min-content-width">300</property>
+                    <property name="max-content-width">300</property>
+                    <child>
+                      <object class="GtkListView" id="branches_view">
+                        <!--signal name="activate" handler="activate_branch_cb" swapped="true" 
object="GbpVcsuiSwitcherPopover"/-->
+                        <property name="orientation">vertical</property>
+                        <property name="single-click-activate">true</property>
+                        <property name="model">
+                          <object class="GtkNoSelection">
+                            <property name="model">branches_model</property>
                           </object>
-                        </child>
+                        </property>
+                        <property name="factory">
+                          <object class="GtkBuilderListItemFactory">
+                            <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkBox">
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="halign">start</property>
+            <property name="hexpand">true</property>
+            <property name="ellipsize">start</property>
+            <binding name="label">
+              <lookup name="name" type="IdeVcsBranch">
+                <lookup name="item">GtkListItem</lookup>
+              </lookup>
+            </binding>
+          </object>
+        </child>
+      </object>
+    </property>
+  </template>
+</interface>
+]]>
+                            </property>
+                          </object>
+                        </property>
                       </object>
-                    </property>
+                    </child>
                   </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">
+                </property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkStackPage">
+                <property name="name">tags</property>
+                <property name="title" translatable="yes">_Tags</property>
+                <property name="use-underline">true</property>
+                <property name="child">
+                  <object class="GtkScrolledWindow">
+                    <property name="propagate-natural-height">true</property>
+                    <property name="propagate-natural-width">true</property>
+                    <property name="min-content-height">100</property>
+                    <property name="max-content-height">600</property>
+                    <property name="min-content-width">300</property>
+                    <property name="max-content-width">300</property>
+                    <child>
+                      <object class="GtkListView" id="tags_view">
+                        <!--signal name="activate" handler="activate_tag_cb" swapped="true" 
object="GbpVcsuiSwitcherPopover"/-->
+                        <property name="orientation">vertical</property>
+                        <property name="single-click-activate">true</property>
+                        <property name="model">
+                          <object class="GtkNoSelection">
+                            <property name="model">tags_model</property>
+                          </object>
+                        </property>
+                        <property name="factory">
+                          <object class="GtkBuilderListItemFactory">
+                            <property name="bytes"><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="GtkListItem">
+    <property name="child">
+      <object class="GtkBox">
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="halign">start</property>
+            <property name="hexpand">true</property>
+            <property name="ellipsize">start</property>
+            <binding name="label">
+              <lookup name="name" type="IdeVcsTag">
+                <lookup name="item">GtkListItem</lookup>
+              </lookup>
+            </binding>
+          </object>
+        </child>
+      </object>
+    </property>
+  </template>
+</interface>
+]]>
+                            </property>
                           </object>
-                        </child>
+                        </property>
                       </object>
-                    </property>
+                    </child>
                   </object>
-                </child>
+                </property>
               </object>
             </child>
           </object>
@@ -53,4 +142,10 @@
       </object>
     </child>
   </template>
+  <object class="GListStore" id="branches_model">
+    <property name="item-type">IdeVcsBranch</property>
+  </object>
+  <object class="GListStore" id="tags_model">
+    <property name="item-type">IdeVcsTag</property>
+  </object>
 </interface>


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