[gnome-builder/wip/gtk4-port] plugins/editorui: implement open in new workspace



commit 414c95dca4d5e4e84d1389b66ceba153bb536201
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 6 22:16:30 2022 -0700

    plugins/editorui: implement open in new workspace

 .../editorui/gbp-editorui-workspace-addin.c        | 70 ++++++++++++++++++++++
 1 file changed, 70 insertions(+)
---
diff --git a/src/plugins/editorui/gbp-editorui-workspace-addin.c 
b/src/plugins/editorui/gbp-editorui-workspace-addin.c
index 1e7cd0e49..a46441355 100644
--- a/src/plugins/editorui/gbp-editorui-workspace-addin.c
+++ b/src/plugins/editorui/gbp-editorui-workspace-addin.c
@@ -24,8 +24,11 @@
 
 #include <glib/gi18n.h>
 
+#include <libide-gui.h>
 #include <libide-editor.h>
 
+#include "ide-workspace-private.h"
+
 #include "gbp-editorui-position-label.h"
 #include "gbp-editorui-workspace-addin.h"
 
@@ -133,11 +136,69 @@ cursor_moved_cb (GbpEditoruiWorkspaceAddin *self)
   self->queued_cursor_moved = g_idle_add (update_position_idle, self);
 }
 
+static void
+open_in_new_frame (GSimpleAction *action,
+                   GVariant      *param,
+                   gpointer       user_data)
+{
+  GbpEditoruiWorkspaceAddin *self = user_data;
+
+  IDE_ENTRY;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (GBP_IS_EDITORUI_WORKSPACE_ADDIN (self));
+
+  IDE_EXIT;
+}
+
+static void
+open_in_new_workspace (GSimpleAction *action,
+                       GVariant      *param,
+                       gpointer       user_data)
+{
+  GbpEditoruiWorkspaceAddin *self = user_data;
+  g_autoptr(IdePanelPosition) position = NULL;
+  IdeEditorWorkspace *workspace;
+  IdeContext *context;
+  IdePage *page;
+  IdePage *split;
+
+  IDE_ENTRY;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (GBP_IS_EDITORUI_WORKSPACE_ADDIN (self));
+
+  if (!(page = ide_workspace_get_most_recent_page (self->workspace)))
+    IDE_EXIT;
+
+  if (!(split = ide_page_create_split (page)))
+    IDE_EXIT;
+
+  context = ide_widget_get_context (GTK_WIDGET (page));
+
+  position = ide_panel_position_new ();
+  ide_panel_position_set_edge (position, PANEL_DOCK_POSITION_CENTER);
+
+  workspace = ide_editor_workspace_new (IDE_APPLICATION_DEFAULT);
+  _ide_workspace_set_context (IDE_WORKSPACE (workspace), context);
+  ide_workspace_add_page (IDE_WORKSPACE (workspace), IDE_PAGE (split), position);
+
+  gtk_window_present (GTK_WINDOW (workspace));
+
+  IDE_EXIT;
+}
+
+static const GActionEntry actions[] = {
+  { "open-in-new-frame", open_in_new_frame },
+  { "open-in-new-workspace", open_in_new_workspace },
+};
+
 static void
 gbp_editorui_workspace_addin_load (IdeWorkspaceAddin *addin,
                                    IdeWorkspace      *workspace)
 {
   GbpEditoruiWorkspaceAddin *self = (GbpEditoruiWorkspaceAddin *)addin;
+  g_autoptr(GSimpleActionGroup) group = NULL;
   GtkPopover *popover;
   GMenu *menu;
 
@@ -149,6 +210,15 @@ gbp_editorui_workspace_addin_load (IdeWorkspaceAddin *addin,
   self->workspace = workspace;
   self->statusbar = ide_workspace_get_statusbar (workspace);
 
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group),
+                                   actions,
+                                   G_N_ELEMENTS (actions),
+                                   self);
+  gtk_widget_insert_action_group (GTK_WIDGET (workspace),
+                                  "editorui",
+                                  G_ACTION_GROUP (group));
+
   self->buffer_signals = ide_signal_group_new (IDE_TYPE_BUFFER);
   ide_signal_group_connect_object (self->buffer_signals,
                                    "cursor-moved",


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