[gnome-builder] libide/gui: add id for workspaces
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/gui: add id for workspaces
- Date: Thu, 15 Sep 2022 08:12:49 +0000 (UTC)
commit 6d1f04c6d7188f6a633b949a66fc1fbf737c105d
Author: Christian Hergert <chergert redhat com>
Date: Wed Sep 14 21:24:25 2022 -0700
libide/gui: add id for workspaces
The goal here is to save id's across sessions so that we can pair pages
into the right workspace, including secondary workspaces.
src/libide/editor/ide-editor-workspace-private.h | 30 ++++++++++++++++++++++++
src/libide/editor/ide-editor-workspace.c | 25 +++++++++++++++++++-
src/libide/gui/ide-primary-workspace.c | 7 ++++++
src/libide/gui/ide-workspace.c | 11 +++++++++
src/libide/gui/ide-workspace.h | 3 +++
5 files changed, 75 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/editor/ide-editor-workspace-private.h
b/src/libide/editor/ide-editor-workspace-private.h
new file mode 100644
index 000000000..8b6ab1a07
--- /dev/null
+++ b/src/libide/editor/ide-editor-workspace-private.h
@@ -0,0 +1,30 @@
+/* ide-editor-workspace-private.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 "ide-editor-workspace.h"
+
+G_BEGIN_DECLS
+
+void ide_editor_workspace_set_id (IdeEditorWorkspace *self,
+ const char *id);
+
+G_END_DECLS
diff --git a/src/libide/editor/ide-editor-workspace.c b/src/libide/editor/ide-editor-workspace.c
index 3f0175859..4f3aa2f57 100644
--- a/src/libide/editor/ide-editor-workspace.c
+++ b/src/libide/editor/ide-editor-workspace.c
@@ -22,7 +22,7 @@
#include "config.h"
-#include "ide-editor-workspace.h"
+#include "ide-editor-workspace-private.h"
#include "ide-workspace-private.h"
/**
@@ -48,6 +48,9 @@ struct _IdeEditorWorkspace
PanelPaned *edge_end;
PanelPaned *edge_bottom;
IdeGrid *grid;
+
+ /* Identifier for cross-session use */
+ char *id;
};
G_DEFINE_FINAL_TYPE (IdeEditorWorkspace, ide_editor_workspace, IDE_TYPE_WORKSPACE)
@@ -251,6 +254,12 @@ ide_editor_workspace_agree_to_close_finish (IdeWorkspace *workspace,
return _ide_workspace_agree_to_close_finish (workspace, result, error);
}
+static const char *
+ide_editor_workspace_get_id (IdeWorkspace *workspace)
+{
+ return IDE_EDITOR_WORKSPACE (workspace)->id;
+}
+
static void
ide_editor_workspace_dispose (GObject *object)
{
@@ -263,6 +272,8 @@ ide_editor_workspace_dispose (GObject *object)
panel_dock_remove (self->dock, GTK_WIDGET (self->grid));
self->grid = NULL;
+ g_clear_pointer (&self->id, g_free);
+
G_OBJECT_CLASS (ide_editor_workspace_parent_class)->dispose (object);
}
@@ -285,6 +296,7 @@ ide_editor_workspace_class_init (IdeEditorWorkspaceClass *klass)
workspace_class->foreach_page = ide_editor_workspace_foreach_page;
workspace_class->get_frame_at_position = ide_editor_workspace_get_frame_at_position;
workspace_class->get_header_bar = ide_editor_workspace_get_header_bar;
+ workspace_class->get_id = ide_editor_workspace_get_id;
workspace_class->get_most_recent_frame = ide_editor_workspace_get_most_recent_frame;
ide_workspace_class_set_kind (workspace_class, "editor");
@@ -313,6 +325,8 @@ ide_editor_workspace_init (IdeEditorWorkspace *self)
{
GMenu *menu;
+ self->id = g_dbus_generate_guid ();
+
gtk_widget_init_template (GTK_WIDGET (self));
menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "new-document-menu");
@@ -336,3 +350,12 @@ ide_editor_workspace_new (IdeApplication *application)
"application", application,
NULL);
}
+
+void
+ide_editor_workspace_set_id (IdeEditorWorkspace *self,
+ const char *id)
+{
+ g_return_if_fail (IDE_IS_EDITOR_WORKSPACE (self));
+
+ ide_set_string (&self->id, id);
+}
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index ae0b9662a..0bb9531fc 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -265,6 +265,12 @@ ide_primary_workspace_agree_to_close_finish (IdeWorkspace *workspace,
return _ide_workspace_agree_to_close_finish (workspace, result, error);
}
+static const char *
+ide_primary_workspace_get_id (IdeWorkspace *workspace)
+{
+ return "primary";
+}
+
static void
ide_primary_workspace_dispose (GObject *object)
{
@@ -300,6 +306,7 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
workspace_class->foreach_page = ide_primary_workspace_foreach_page;
workspace_class->get_frame_at_position = ide_primary_workspace_get_frame_at_position;
workspace_class->get_header_bar = ide_primary_workspace_get_header_bar;
+ workspace_class->get_id = ide_primary_workspace_get_id;
workspace_class->get_most_recent_frame = ide_primary_workspace_get_most_recent_frame;
workspace_class->remove_overlay = ide_primary_workspace_remove_overlay;
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index de8ac1c49..837250e94 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -519,6 +519,17 @@ ide_workspace_real_get_header_bar (IdeWorkspace *workspace)
return NULL;
}
+const char *
+ide_workspace_get_id (IdeWorkspace *self)
+{
+ g_return_val_if_fail (IDE_IS_WORKSPACE (self), NULL);
+
+ if (IDE_WORKSPACE_GET_CLASS (self)->get_id)
+ return IDE_WORKSPACE_GET_CLASS (self)->get_id (self);
+
+ return G_OBJECT_TYPE_NAME (self);
+}
+
static void
ide_workspace_action_close (gpointer instance,
const char *action_name,
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 1f8c6a78d..724fd9071 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -61,6 +61,7 @@ struct _IdeWorkspaceClass
void (*foreach_page) (IdeWorkspace *self,
IdePageCallback callback,
gpointer user_data);
+ const char *(*get_id) (IdeWorkspace *self);
IdeHeaderBar *(*get_header_bar) (IdeWorkspace *self);
IdePage *(*get_most_recent_page) (IdeWorkspace *self);
IdeFrame *(*get_most_recent_frame) (IdeWorkspace *self);
@@ -111,6 +112,8 @@ void ide_workspace_action_set_enabled (IdeWorkspace
const char *action_name,
gboolean enabled);
IDE_AVAILABLE_IN_ALL
+const char *ide_workspace_get_id (IdeWorkspace *self);
+IDE_AVAILABLE_IN_ALL
IdeHeaderBar *ide_workspace_get_header_bar (IdeWorkspace *self);
IDE_AVAILABLE_IN_ALL
IdeContext *ide_workspace_get_context (IdeWorkspace *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]