[gnome-builder] libide/gui: add secondary workspace action for workbench



commit 49d4fbcf935fc9a72421a0c874f79e2b85df2404
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jul 29 12:09:17 2022 -0700

    libide/gui: add secondary workspace action for workbench
    
    This adds context.workbench.workspace.new and some plumbing for it to be
    called through other measures too. I'd like to remove the layer violation
    here at some point, but for now it's good-enough given the libide-editor
    is also internal library/plugin.

 src/libide/gui/ide-workbench-private.h |  5 ++--
 src/libide/gui/ide-workbench.c         | 45 ++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/src/libide/gui/ide-workbench-private.h b/src/libide/gui/ide-workbench-private.h
index 68bc88638..f01e9fad8 100644
--- a/src/libide/gui/ide-workbench-private.h
+++ b/src/libide/gui/ide-workbench-private.h
@@ -25,7 +25,8 @@
 
 G_BEGIN_DECLS
 
-gboolean _ide_workbench_is_last_workspace (IdeWorkbench *self,
-                                           IdeWorkspace *workspace);
+gboolean      _ide_workbench_is_last_workspace (IdeWorkbench *self,
+                                                IdeWorkspace *workspace);
+IdeWorkspace *_ide_workbench_create_secondary  (IdeWorkbench *self);
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-workbench.c b/src/libide/gui/ide-workbench.c
index 6f6c1451c..1503a2c5d 100644
--- a/src/libide/gui/ide-workbench.c
+++ b/src/libide/gui/ide-workbench.c
@@ -115,6 +115,9 @@ enum {
   N_PROPS
 };
 
+static void ide_workbench_action_add_workspace (gpointer      instance,
+                                                const char   *action_name,
+                                                GVariant     *param);
 static void ide_workbench_action_close         (gpointer      instance,
                                                 const char   *action_name,
                                                 GVariant     *param);
@@ -517,6 +520,7 @@ ide_workbench_class_init (IdeWorkbenchClass *klass)
 
   ide_action_mixin_init (&action_mixin, object_class);
 
+  ide_action_mixin_install_action (&action_mixin, "workspace.new", NULL, ide_workbench_action_add_workspace);
   ide_action_mixin_install_action (&action_mixin, "close", NULL, ide_workbench_action_close);
   ide_action_mixin_install_action (&action_mixin, "open", NULL, ide_workbench_action_open);
   ide_action_mixin_install_action (&action_mixin, "open-uri", "s", ide_workbench_action_open_uri);
@@ -1363,6 +1367,24 @@ ide_workbench_action_close (gpointer    instance,
                                 NULL);
 }
 
+static void
+ide_workbench_action_add_workspace (gpointer    instance,
+                                    const char *action_name,
+                                    GVariant   *param)
+{
+  IdeWorkbench *self = instance;
+  IdeWorkspace *workspace;
+
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_WORKBENCH (self));
+
+  workspace = _ide_workbench_create_secondary (self);
+  gtk_window_present (GTK_WINDOW (workspace));
+
+  IDE_EXIT;
+}
+
 static void
 ide_workbench_action_reload_all (gpointer    instance,
                                  const char *action_name,
@@ -2718,3 +2740,26 @@ ide_workbench_action_configure (gpointer    instance,
   if (page != NULL)
     ide_preferences_window_set_page (IDE_PREFERENCES_WINDOW (window), page);
 }
+
+IdeWorkspace *
+_ide_workbench_create_secondary (IdeWorkbench *self)
+{
+  IdeWorkspace *workspace;
+  GType secondary_type;
+
+  g_return_val_if_fail (IDE_IS_WORKBENCH (self), NULL);
+
+  /* TODO: allow secondary workspace type to be set so we don't
+   *       have this layering violation.
+   */
+
+  secondary_type = g_type_from_name ("IdeEditorWorkspace");
+  g_return_val_if_fail (secondary_type != G_TYPE_INVALID, NULL);
+
+  workspace = g_object_new (secondary_type,
+                            "application", IDE_APPLICATION_DEFAULT,
+                            NULL);
+  ide_workbench_add_workspace (self, IDE_WORKSPACE (workspace));
+
+  return workspace;
+}


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