[gnome-builder/wip/gtk4-port] plugins/vcsui: start on updated clone page



commit 05db4c1eb8383a49e6f37500200d130357fa3c3c
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 30 11:05:37 2022 -0700

    plugins/vcsui: start on updated clone page

 src/plugins/vcsui/gbp-vcsui-clone-page.c  | 153 ++++++++++++++++++++++++++++++
 src/plugins/vcsui/gbp-vcsui-clone-page.h  |  33 +++++++
 src/plugins/vcsui/gbp-vcsui-clone-page.ui | 132 ++++++++++++++++++++++++++
 src/plugins/vcsui/meson.build             |   1 +
 src/plugins/vcsui/vcsui.gresource.xml     |   1 +
 5 files changed, 320 insertions(+)
---
diff --git a/src/plugins/vcsui/gbp-vcsui-clone-page.c b/src/plugins/vcsui/gbp-vcsui-clone-page.c
new file mode 100644
index 000000000..ba8c380ab
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-clone-page.c
@@ -0,0 +1,153 @@
+/* gbp-vcsui-clone-page.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-clone-page"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <adwaita.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;
+};
+
+G_DEFINE_FINAL_TYPE (GbpVcsuiClonePage, gbp_vcsui_clone_page, GTK_TYPE_WIDGET)
+
+static void
+location_row_changed_cb (GbpVcsuiClonePage *self,
+                         GtkEditable       *editable)
+{
+  g_autofree char *expanded = NULL;
+  g_autoptr(GFile) directory = NULL;
+  const char *text;
+
+  g_assert (GBP_IS_VCSUI_CLONE_PAGE (self));
+  g_assert (GTK_IS_EDITABLE (editable));
+
+  text = gtk_editable_get_text (editable);
+  expanded = ide_path_expand (text);
+  directory = g_file_new_for_path (expanded);
+
+  /* TODO: set value for clone input */
+}
+
+static void
+select_folder_response_cb (GbpVcsuiClonePage    *self,
+                           int                   response_id,
+                           GtkFileChooserNative *native)
+{
+  g_assert (GBP_IS_VCSUI_CLONE_PAGE (self));
+  g_assert (GTK_IS_FILE_CHOOSER_NATIVE (native));
+
+  if (response_id == GTK_RESPONSE_ACCEPT)
+    {
+      g_autoptr(GFile) file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
+      g_autofree char *path = ide_path_collapse (g_file_peek_path (file));
+
+      gtk_editable_set_text (GTK_EDITABLE (self->location_row), path);
+    }
+
+  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
+}
+
+static void
+select_folder_action (GtkWidget  *widget,
+                      const char *action_name,
+                      GVariant   *param)
+{
+  GbpVcsuiClonePage *self = (GbpVcsuiClonePage *)widget;
+  GtkFileChooserNative *native;
+  GtkRoot *root;
+
+  g_assert (GBP_IS_VCSUI_CLONE_PAGE (self));
+
+  root = gtk_widget_get_root (widget);
+  native = gtk_file_chooser_native_new (_("Select Location"),
+                                        GTK_WINDOW (root),
+                                        GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+                                        _("Select"),
+                                        _("Cancel"));
+  /* TODO: Apply folder from clone input */
+#if 0
+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (native),
+                                       ide_template_input_get_directory (self->input),
+                                       NULL);
+#endif
+  g_signal_connect_object (native,
+                           "response",
+                           G_CALLBACK (select_folder_response_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+  gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
+}
+
+static void
+gbp_vcsui_clone_page_dispose (GObject *object)
+{
+  GbpVcsuiClonePage *self = (GbpVcsuiClonePage *)object;
+
+  g_clear_pointer (&self->main, gtk_widget_unparent);
+
+  G_OBJECT_CLASS (gbp_vcsui_clone_page_parent_class)->dispose (object);
+}
+
+static void
+gbp_vcsui_clone_page_class_init (GbpVcsuiClonePageClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->dispose = gbp_vcsui_clone_page_dispose;
+
+  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, main);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, location_row);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, author_name_row);
+  gtk_widget_class_bind_template_child (widget_class, GbpVcsuiClonePage, author_email_row);
+
+  gtk_widget_class_bind_template_callback (widget_class, location_row_changed_cb);
+
+  gtk_widget_class_install_action (widget_class, "clone-page.select-folder", NULL, select_folder_action);
+}
+
+static void
+gbp_vcsui_clone_page_init (GbpVcsuiClonePage *self)
+{
+  g_autofree char *projects_dir = ide_path_collapse (ide_get_projects_dir ());
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  gtk_editable_set_text (GTK_EDITABLE (self->location_row), projects_dir);
+  gtk_editable_set_text (GTK_EDITABLE (self->author_name_row), g_get_real_name ());
+}
diff --git a/src/plugins/vcsui/gbp-vcsui-clone-page.h b/src/plugins/vcsui/gbp-vcsui-clone-page.h
new file mode 100644
index 000000000..574319c9c
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-clone-page.h
@@ -0,0 +1,33 @@
+/* gbp-vcsui-clone-page.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_CLONE_PAGE (gbp_vcsui_clone_page_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpVcsuiClonePage, gbp_vcsui_clone_page, GBP, VCSUI_CLONE_PAGE, GtkWidget)
+
+G_END_DECLS
diff --git a/src/plugins/vcsui/gbp-vcsui-clone-page.ui b/src/plugins/vcsui/gbp-vcsui-clone-page.ui
new file mode 100644
index 000000000..510fcc3ab
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-clone-page.ui
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="Adw" version="1.0"/>
+  <template class="GbpVcsuiClonePage" parent="GtkWidget">
+    <child>
+      <object class="AdwClamp" id="main">
+        <property name="orientation">horizontal</property>
+        <property name="maximum-size">550</property>
+        <child>
+          <object class="GtkBox">
+            <property name="margin-top">64</property>
+            <property name="margin-bottom">64</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">24</property>
+            <child>
+              <object class="AdwPreferencesGroup">
+                <child>
+                  <object class="AdwEntryRow" id="uri_row">
+                    <property name="title" translatable="yes">Repository URL</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="xalign">0</property>
+                    <property name="margin-top">12</property>
+                    <property name="wrap">true</property>
+                    <property name="label" translatable="yes">Enter the URL of the source code repository 
for the project you would like to clone.</property>
+                    <style>
+                      <class name="caption"/>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="AdwPreferencesGroup">
+                <child>
+                  <object class="AdwEntryRow" id="location_row">
+                    <property name="title" translatable="yes">Location</property>
+                    <signal name="changed" handler="location_row_changed_cb" swapped="true" 
object="GbpVcsuiClonePage"/>
+                    <child type="suffix">
+                      <object class="GtkButton">
+                        <property name="action-name">clone-page.select-folder</property>
+                        <property name="valign">center</property>
+                        <property name="icon-name">folder-symbolic</property>
+                        <style>
+                          <class name="flat"/>
+                        </style>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="label" translatable="yes">The repository will be cloned into a new 
subdirectory.</property>
+                    <property name="margin-top">12</property>
+                    <property name="wrap">true</property>
+                    <property name="xalign">0</property>
+                    <style>
+                      <class name="caption"/>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="AdwPreferencesGroup">
+                <property name="title" translatable="yes">Repository Details</property>
+                <child>
+                  <object class="AdwEntryRow" id="branch_row">
+                    <property name="title" translatable="yes">Branch</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="xalign">0</property>
+                    <property name="margin-top">12</property>
+                    <property name="wrap">true</property>
+                    <property name="label" translatable="yes">Specify a branch to clone if necessary. Unless 
specified, the default branch will be used.</property>
+                    <style>
+                      <class name="caption"/>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="AdwPreferencesGroup">
+                <child>
+                  <object class="AdwEntryRow" id="author_name_row">
+                    <property name="title" translatable="yes">Author</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="AdwEntryRow" id="author_email_row">
+                    <property name="title" translatable="yes">Email</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel">
+                    <property name="xalign">0</property>
+                    <property name="margin-top">12</property>
+                    <property name="wrap">true</property>
+                    <property name="label" translatable="yes">You may specify authorship information to 
override defaults.</property>
+                    <style>
+                      <class name="caption"/>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkButton">
+                <property name="action-name">clone-page.clone</property>
+                <property name="label" translatable="yes">Clone Repository</property>
+                <property name="margin-top">12</property>
+                <property name="halign">end</property>
+                <style>
+                  <class name="suggested-action"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/plugins/vcsui/meson.build b/src/plugins/vcsui/meson.build
index e40fde9cd..e39ce6139 100644
--- a/src/plugins/vcsui/meson.build
+++ b/src/plugins/vcsui/meson.build
@@ -1,5 +1,6 @@
 plugins_sources += files([
   'vcsui-plugin.c',
+  'gbp-vcsui-clone-page.c',
   'gbp-vcsui-clone-widget.c',
   'gbp-vcsui-editor-page-addin.c',
   'gbp-vcsui-switcher-popover.c',
diff --git a/src/plugins/vcsui/vcsui.gresource.xml b/src/plugins/vcsui/vcsui.gresource.xml
index 3c25e58b5..fe89a43ae 100644
--- a/src/plugins/vcsui/vcsui.gresource.xml
+++ b/src/plugins/vcsui/vcsui.gresource.xml
@@ -4,6 +4,7 @@
     <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-clone-page.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]