[gnome-builder/wip/gtk4-port] plugins/vcsui: add a request object and use it



commit c4dde710633f80a3f9a7d370cf6213a0616f5c12
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 31 16:05:45 2022 -0700

    plugins/vcsui: add a request object and use it
    
    So that we can list branches and have some other settings bound to the
    underlying request object.

 src/plugins/vcsui/gbp-vcsui-clone-page.c  |  81 +++++++++++++++++++++---
 src/plugins/vcsui/gbp-vcsui-clone-page.ui | 100 ++++++++++++++++++++++++++++--
 2 files changed, 168 insertions(+), 13 deletions(-)
---
diff --git a/src/plugins/vcsui/gbp-vcsui-clone-page.c b/src/plugins/vcsui/gbp-vcsui-clone-page.c
index 3d5d38e93..580d7c1c4 100644
--- a/src/plugins/vcsui/gbp-vcsui-clone-page.c
+++ b/src/plugins/vcsui/gbp-vcsui-clone-page.c
@@ -27,20 +27,24 @@
 #include <adwaita.h>
 #include <vte/vte.h>
 
+#include <libide-gui.h>
 #include <libide-projects.h>
 
 #include "gbp-vcsui-clone-page.h"
 
 struct _GbpVcsuiClonePage
 {
-  GtkWidget    parent_instance;
-
-  GtkWidget   *main;
-  AdwEntryRow *location_row;
-  AdwEntryRow *author_name_row;
-  AdwEntryRow *author_email_row;
-  GtkStack    *stack;
-  VteTerminal *terminal;
+  GtkWidget           parent_instance;
+
+  AdwEntryRow        *author_email_row;
+  AdwEntryRow        *author_name_row;
+  GtkMenuButton      *branch_button;
+  AdwEntryRow        *location_row;
+  GtkWidget          *main;
+  GtkStack           *stack;
+  VteTerminal        *terminal;
+
+  IdeVcsCloneRequest *request;
 };
 
 G_DEFINE_FINAL_TYPE (GbpVcsuiClonePage, gbp_vcsui_clone_page, GTK_TYPE_WIDGET)
@@ -60,7 +64,7 @@ location_row_changed_cb (GbpVcsuiClonePage *self,
   expanded = ide_path_expand (text);
   directory = g_file_new_for_path (expanded);
 
-  /* TODO: set value for clone input */
+  ide_vcs_clone_request_set_directory (self->request, directory);
 }
 
 static void
@@ -137,11 +141,63 @@ clone_action (GtkWidget  *widget,
   IDE_EXIT;
 }
 
+static void
+branch_activated_cb (GbpVcsuiClonePage *self,
+                     guint              position,
+                     GtkListView       *list_view)
+{
+  g_autoptr(IdeVcsBranch) branch = NULL;
+  g_autofree char *branch_id = NULL;
+  GListModel *model;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_VCSUI_CLONE_PAGE (self));
+  g_assert (GTK_IS_LIST_VIEW (list_view));
+
+  model = G_LIST_MODEL (gtk_list_view_get_model (list_view));
+  branch = g_list_model_get_item (model, position);
+  branch_id = ide_vcs_branch_dup_id (branch);
+
+  ide_vcs_clone_request_set_branch_name (self->request, branch_id);
+
+  IDE_EXIT;
+}
+
+static void
+branch_popover_show_cb (GbpVcsuiClonePage *self,
+                        GtkPopover        *popover)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_VCSUI_CLONE_PAGE (self));
+  g_assert (GTK_IS_POPOVER (popover));
+
+  ide_vcs_clone_request_populate_branches (self->request);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_vcsui_clone_page_root (GtkWidget *widget)
+{
+  GbpVcsuiClonePage *self = (GbpVcsuiClonePage *)widget;
+  IdeContext *context;
+
+  g_assert (GBP_IS_VCSUI_CLONE_PAGE (self));
+
+  GTK_WIDGET_CLASS (gbp_vcsui_clone_page_parent_class)->root (widget);
+
+  if ((context = ide_widget_get_context (widget)))
+    ide_object_append (IDE_OBJECT (context), IDE_OBJECT (self->request));
+}
+
 static void
 gbp_vcsui_clone_page_dispose (GObject *object)
 {
   GbpVcsuiClonePage *self = (GbpVcsuiClonePage *)object;
 
+  ide_object_destroy (IDE_OBJECT (self->request));
   g_clear_pointer (&self->main, gtk_widget_unparent);
 
   G_OBJECT_CLASS (gbp_vcsui_clone_page_parent_class)->dispose (object);
@@ -155,22 +211,29 @@ gbp_vcsui_clone_page_class_init (GbpVcsuiClonePageClass *klass)
 
   object_class->dispose = gbp_vcsui_clone_page_dispose;
 
+  widget_class->root = gbp_vcsui_clone_page_root;
+
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
   gtk_widget_class_set_template_from_resource (widget_class, "/plugins/vcsui/gbp-vcsui-clone-page.ui");
 
   gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, author_email_row);
   gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, author_name_row);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, branch_button);
   gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, location_row);
   gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, main);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, request);
   gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, stack);
   gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, terminal);
 
   gtk_widget_class_bind_template_callback (widget_class, location_row_changed_cb);
+  gtk_widget_class_bind_template_callback (widget_class, branch_activated_cb);
+  gtk_widget_class_bind_template_callback (widget_class, branch_popover_show_cb);
 
   gtk_widget_class_install_action (widget_class, "clone-page.select-folder", NULL, select_folder_action);
   gtk_widget_class_install_action (widget_class, "clone-page.clone", NULL, clone_action);
 
   g_type_ensure (VTE_TYPE_TERMINAL);
+  g_type_ensure (IDE_TYPE_VCS_CLONE_REQUEST);
 }
 
 static void
diff --git a/src/plugins/vcsui/gbp-vcsui-clone-page.ui b/src/plugins/vcsui/gbp-vcsui-clone-page.ui
index 13b90fb14..09c0601b3 100644
--- a/src/plugins/vcsui/gbp-vcsui-clone-page.ui
+++ b/src/plugins/vcsui/gbp-vcsui-clone-page.ui
@@ -17,14 +17,96 @@
                 <child>
                   <object class="AdwEntryRow" id="uri_row">
                     <property name="title" translatable="yes">Repository URL</property>
+                    <property name="text" bind-source="request" bind-property="uri" 
bind-flags="sync-create|bidirectional"/>
                     <child type="suffix">
-                      <object class="GtkMenuButton">
-                        <property name="icon-name">builder-vcs-branch-symbolic</property>
-                        <property name="tooltip-text" translatable="yes">Choose an alternate 
branch</property>
-                        <property name="valign">center</property>
+                      <object class="GtkMenuButton" id="branch_button">
                         <style>
                           <class name="flat"/>
                         </style>
+                        <property name="icon-name">builder-vcs-branch-symbolic</property>
+                        <property name="tooltip-text" translatable="yes">Choose an alternate 
branch</property>
+                        <property name="valign">center</property>
+                        <property name="popover">
+                          <object class="GtkPopover">
+                            <signal name="show" handler="branch_popover_show_cb" swapped="true" 
object="GbpVcsuiClonePage"/>
+                            <child>
+                              <object class="GtkBox">
+                                <property name="orientation">vertical</property>
+                                <property name="spacing">12</property>
+                                <property name="margin-bottom">6</property>
+                                <property name="margin-end">6</property>
+                                <property name="margin-start">6</property>
+                                <property name="margin-top">6</property>
+                                <child>
+                                  <object class="GtkLabel">
+                                    <property name="label" translatable="yes">Branches</property>
+                                    <property name="xalign">0</property>
+                                    <style>
+                                      <class name="heading"/>
+                                    </style>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkFrame">
+                                    <child>
+                                      <object class="GtkScrolledWindow">
+                                        <property name="propagate-natural-height">true</property>
+                                        <property name="propagate-natural-width">true</property>
+                                        <property name="min-content-width">150</property>
+                                        <property name="min-content-height">200</property>
+                                        <child>
+                                          <object class="GtkListView">
+                                            <signal name="activate" handler="branch_activated_cb" 
swapped="true" object="GbpVcsuiClonePage"/>
+                                            <property name="model">
+                                              <object class="GtkSingleSelection">
+                                                <property name="model" bind-source="request" 
bind-property="branch-model" bind-flags="sync-create"/>
+                                              </object>
+                                            </property>
+                                            <property name="orientation">vertical</property>
+                                            <property name="single-click-activate">true</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>
+        <property name="margin-top">6</property>
+        <property name="margin-bottom">6</property>
+        <property name="margin-start">6</property>
+        <property name="margin-end">6</property>
+        <child>
+          <object class="GtkLabel">
+            <property name="xalign">0</property>
+            <property name="hexpand">true</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>
+                                        </child>
+                                      </object>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </property>
+                        <property name="sensitive" bind-source="request" bind-property="can-select-branch" 
bind-flags="sync-create"/>
                       </object>
                     </child>
                   </object>
@@ -90,11 +172,13 @@
                         <child>
                           <object class="AdwEntryRow" id="author_name_row">
                             <property name="title" translatable="yes">Name</property>
+                            <property name="text" bind-source="request" bind-property="author-name" 
bind-flags="sync-create|bidirectional"/>
                           </object>
                         </child>
                         <child>
                           <object class="AdwEntryRow" id="author_email_row">
                             <property name="title" translatable="yes">Email</property>
+                            <property name="text" bind-source="request" bind-property="author-email" 
bind-flags="sync-create|bidirectional"/>
                           </object>
                         </child>
                         <child>
@@ -161,4 +245,12 @@
       </object>
     </child>
   </template>
+  <object class="IdeVcsCloneRequest" id="request">
+    <!--
+      Currently only `git` clone is supported. Happy to support other
+      version-control systems if someone 1) writes the IdeVcs backend
+      and 2) sticks around to maintain it with me.
+    -->
+    <property name="module-name">git</property>
+  </object>
 </interface>


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