[gnome-builder/wip/gtk4-port] plugins/vcsui: (re)implement --clone URI



commit acdc48cbbe2822ec9ad2643066daf8ad75a2a498
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 1 00:04:16 2022 -0700

    plugins/vcsui: (re)implement --clone URI
    
    This is now living where it should, the vcsui plugin. --clone is allowed
    from something like "gnome-builder --clone example.com:example.git" and
    it will show a new greeter window w/ the clone page active, including the
    provided URI.

 src/plugins/vcsui/gbp-vcsui-application-addin.c | 117 ++++++++++++++++++++++++
 src/plugins/vcsui/gbp-vcsui-application-addin.h |  31 +++++++
 src/plugins/vcsui/meson.build                   |   1 +
 src/plugins/vcsui/vcsui-plugin.c                |   4 +
 src/plugins/vcsui/vcsui.plugin                  |   1 +
 5 files changed, 154 insertions(+)
---
diff --git a/src/plugins/vcsui/gbp-vcsui-application-addin.c b/src/plugins/vcsui/gbp-vcsui-application-addin.c
new file mode 100644
index 000000000..a874573b8
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-application-addin.c
@@ -0,0 +1,117 @@
+/* gbp-vcsui-application-addin.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-application-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-greeter.h>
+
+#include "gbp-vcsui-application-addin.h"
+#include "gbp-vcsui-clone-page.h"
+
+struct _GbpVcsuiApplicationAddin
+{
+  GObject parent_instance;
+};
+
+static void
+gbp_vcsui_application_addin_handle_command_line (IdeApplicationAddin     *addin,
+                                                 IdeApplication          *app,
+                                                 GApplicationCommandLine *cmdline)
+{
+  g_auto(GStrv) argv = NULL;
+  GVariantDict *dict;
+  const char *clone_uri = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_VCSUI_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (app));
+  g_assert (G_IS_APPLICATION_COMMAND_LINE (cmdline));
+
+  dict = g_application_command_line_get_options_dict (cmdline);
+  argv = ide_application_get_argv (app, cmdline);
+
+  /*
+   * If the --clone=URI option was provided, switch the greeter to the
+   * clone page and begin cloning.
+   */
+  if (dict != NULL && g_variant_dict_lookup (dict, "clone", "&s", &clone_uri))
+    {
+      IdeGreeterWorkspace *workspace;
+      IdeWorkbench *workbench;
+      GtkWidget *page;
+
+      workbench = ide_workbench_new ();
+      ide_application_add_workbench (app, workbench);
+
+      workspace = ide_greeter_workspace_new (app);
+      ide_workbench_add_workspace (workbench, IDE_WORKSPACE (workspace));
+
+      ide_greeter_workspace_set_page_name (workspace, "clone");
+      page = ide_greeter_workspace_get_page_named (workspace, "clone");
+
+      if (GBP_IS_VCSUI_CLONE_PAGE (page))
+        gbp_vcsui_clone_page_set_uri (GBP_VCSUI_CLONE_PAGE (page), clone_uri);
+
+      ide_workbench_focus_workspace (workbench, IDE_WORKSPACE (workspace));
+    }
+
+  IDE_EXIT;
+}
+
+static void
+gbp_vcsui_application_addin_add_option_entries (IdeApplicationAddin *addin,
+                                                IdeApplication      *app)
+{
+  g_assert (GBP_IS_VCSUI_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (app));
+
+  g_application_add_main_option (G_APPLICATION (app),
+                                 "clone",
+                                 0,
+                                 G_OPTION_FLAG_IN_MAIN,
+                                 G_OPTION_ARG_STRING,
+                                 _("Begin cloning project from URI"),
+                                 "URI");
+}
+
+static void
+application_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+  iface->add_option_entries = gbp_vcsui_application_addin_add_option_entries;
+  iface->handle_command_line = gbp_vcsui_application_addin_handle_command_line;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpVcsuiApplicationAddin, gbp_vcsui_application_addin, G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN, 
application_addin_iface_init))
+
+static void
+gbp_vcsui_application_addin_class_init (GbpVcsuiApplicationAddinClass *klass)
+{
+}
+
+static void
+gbp_vcsui_application_addin_init (GbpVcsuiApplicationAddin *self)
+{
+}
diff --git a/src/plugins/vcsui/gbp-vcsui-application-addin.h b/src/plugins/vcsui/gbp-vcsui-application-addin.h
new file mode 100644
index 000000000..e41f67cd8
--- /dev/null
+++ b/src/plugins/vcsui/gbp-vcsui-application-addin.h
@@ -0,0 +1,31 @@
+/* gbp-vcsui-application-addin.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 <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_VCSUI_APPLICATION_ADDIN (gbp_vcsui_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpVcsuiApplicationAddin, gbp_vcsui_application_addin, GBP, VCSUI_APPLICATION_ADDIN, 
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/vcsui/meson.build b/src/plugins/vcsui/meson.build
index e39ce6139..bd0aaa357 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-application-addin.c',
   'gbp-vcsui-clone-page.c',
   'gbp-vcsui-clone-widget.c',
   'gbp-vcsui-editor-page-addin.c',
diff --git a/src/plugins/vcsui/vcsui-plugin.c b/src/plugins/vcsui/vcsui-plugin.c
index 11a5207ea..5e5a46067 100644
--- a/src/plugins/vcsui/vcsui-plugin.c
+++ b/src/plugins/vcsui/vcsui-plugin.c
@@ -28,6 +28,7 @@
 #include <libide-gui.h>
 #include <libide-tree.h>
 
+#include "gbp-vcsui-application-addin.h"
 #include "gbp-vcsui-editor-page-addin.h"
 #include "gbp-vcsui-tree-addin.h"
 #include "gbp-vcsui-workbench-addin.h"
@@ -36,6 +37,9 @@
 _IDE_EXTERN void
 _gbp_vcsui_register_types (PeasObjectModule *module)
 {
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_APPLICATION_ADDIN,
+                                              GBP_TYPE_VCSUI_APPLICATION_ADDIN);
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_EDITOR_PAGE_ADDIN,
                                               GBP_TYPE_VCSUI_EDITOR_PAGE_ADDIN);
diff --git a/src/plugins/vcsui/vcsui.plugin b/src/plugins/vcsui/vcsui.plugin
index a76667263..9dc625106 100644
--- a/src/plugins/vcsui/vcsui.plugin
+++ b/src/plugins/vcsui/vcsui.plugin
@@ -8,4 +8,5 @@ Embedded=_gbp_vcsui_register_types
 Hidden=true
 Module=vcsui
 Name=VCS interface extensions
+X-At-Startup=true
 X-Workspace-Kind=primary;greeter;


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