[gnome-builder] libide/gui: add IdeWorkspace:id property
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/gui: add IdeWorkspace:id property
- Date: Fri, 16 Sep 2022 00:42:59 +0000 (UTC)
commit 34bdd797159af2f4a7659cbb4749dad84fe0fe2d
Author: Christian Hergert <chergert redhat com>
Date: Thu Sep 15 17:42:30 2022 -0700
libide/gui: add IdeWorkspace:id property
This is just easier than trying to abstract it into vfuncs.
src/libide/editor/ide-editor-workspace-private.h | 30 ---------
src/libide/editor/ide-editor-workspace.c | 25 +-------
src/libide/gui/ide-primary-workspace.c | 9 +--
src/libide/gui/ide-workspace-private.h | 82 ++++++++++++------------
src/libide/gui/ide-workspace.c | 76 ++++++++++++++++++----
src/libide/gui/ide-workspace.h | 4 +-
6 files changed, 113 insertions(+), 113 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-workspace.c b/src/libide/editor/ide-editor-workspace.c
index cf835c634..0a5063bad 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-private.h"
+#include "ide-editor-workspace.h"
#include "ide-workspace-private.h"
/**
@@ -48,9 +48,6 @@ 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)
@@ -254,12 +251,6 @@ 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_save_session (IdeWorkspace *workspace,
IdeSession *session)
@@ -284,8 +275,6 @@ 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);
}
@@ -308,7 +297,6 @@ 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;
workspace_class->save_session = ide_editor_workspace_save_session;
@@ -338,8 +326,6 @@ 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");
@@ -363,12 +349,3 @@ 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 81261246b..a4d1c42c8 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -265,12 +265,6 @@ 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_save_session (IdeWorkspace *workspace,
IdeSession *session)
@@ -318,7 +312,6 @@ 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;
workspace_class->save_session = ide_primary_workspace_save_session;
@@ -355,6 +348,8 @@ ide_primary_workspace_init (IdePrimaryWorkspace *self)
GMenu *build_menu;
GMenu *menu;
+ ide_workspace_set_id (IDE_WORKSPACE (self), "primary");
+
gtk_widget_init_template (GTK_WIDGET (self));
menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "new-document-menu");
diff --git a/src/libide/gui/ide-workspace-private.h b/src/libide/gui/ide-workspace-private.h
index a1a106fff..492b5ab1f 100644
--- a/src/libide/gui/ide-workspace-private.h
+++ b/src/libide/gui/ide-workspace-private.h
@@ -26,45 +26,47 @@
G_BEGIN_DECLS
-GList *_ide_workspace_get_mru_link (IdeWorkspace *self);
-void _ide_workspace_add_page_mru (IdeWorkspace *self,
- GList *mru_link);
-void _ide_workspace_remove_page_mru (IdeWorkspace *self,
- GList *mru_link);
-void _ide_workspace_move_front_page_mru (IdeWorkspace *workspace,
- GList *mru_link);
-void _ide_workspace_set_context (IdeWorkspace *workspace,
- IdeContext *context);
-gboolean _ide_workspace_can_search (IdeWorkspace *self);
-void _ide_workspace_begin_global_search (IdeWorkspace *self);
-void _ide_workspace_add_widget (IdeWorkspace *workspace,
- PanelWidget *widget,
- PanelPosition *position,
- PanelPaned *dock_start,
- PanelPaned *dock_end,
- PanelPaned *dock_bottom,
- IdeGrid *grid);
-PanelFrame *_ide_workspace_find_frame (IdeWorkspace *workspace,
- PanelPosition *position,
- PanelPaned *dock_start,
- PanelPaned *dock_end,
- PanelPaned *dock_bottom,
- IdeGrid *grid);
-void _ide_workspace_set_shortcut_model (IdeWorkspace *self,
- GListModel *shortcuts);
-void _ide_workspace_agree_to_close_async (IdeWorkspace *self,
- IdeGrid *grid,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gboolean _ide_workspace_agree_to_close_finish (IdeWorkspace *self,
- GAsyncResult *result,
- GError **error);
-void _ide_workspace_save_session_simple (IdeWorkspace *self,
- IdeSession *session,
- PanelDock *dock,
- IdeGrid *grid);
-void _ide_workspace_save_session (IdeWorkspace *self,
- IdeSession *session);
+GList *_ide_workspace_get_mru_link (IdeWorkspace *self);
+void _ide_workspace_add_page_mru (IdeWorkspace *self,
+ GList *mru_link);
+void _ide_workspace_remove_page_mru (IdeWorkspace *self,
+ GList *mru_link);
+void _ide_workspace_move_front_page_mru (IdeWorkspace *workspace,
+ GList *mru_link);
+void _ide_workspace_set_context (IdeWorkspace *workspace,
+ IdeContext *context);
+gboolean _ide_workspace_can_search (IdeWorkspace *self);
+void _ide_workspace_begin_global_search (IdeWorkspace *self);
+void _ide_workspace_add_widget (IdeWorkspace *workspace,
+ PanelWidget *widget,
+ PanelPosition *position,
+ PanelPaned *dock_start,
+ PanelPaned *dock_end,
+ PanelPaned *dock_bottom,
+ IdeGrid *grid);
+PanelFrame *_ide_workspace_find_frame (IdeWorkspace *workspace,
+ PanelPosition *position,
+ PanelPaned *dock_start,
+ PanelPaned *dock_end,
+ PanelPaned *dock_bottom,
+ IdeGrid *grid);
+void _ide_workspace_set_shortcut_model (IdeWorkspace *self,
+ GListModel *shortcuts);
+void _ide_workspace_agree_to_close_async (IdeWorkspace *self,
+ IdeGrid *grid,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean _ide_workspace_agree_to_close_finish (IdeWorkspace *self,
+ GAsyncResult *result,
+ GError **error);
+void _ide_workspace_save_session_simple (IdeWorkspace *self,
+ IdeSession *session,
+ PanelDock *dock,
+ IdeGrid *grid);
+void _ide_workspace_save_session (IdeWorkspace *self,
+ IdeSession *session);
+void _ide_workspace_set_ignore_size_setting (IdeWorkspace *self,
+ gboolean ignore_size_setting);
G_END_DECLS
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index a7ffd6155..dc8d37220 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -97,6 +97,10 @@ typedef struct
/* Inhibit desktop session logout */
guint inhibit_logout_count;
guint inhibit_logout_cookie;
+
+ /* The identifier for the workspace window */
+ char *id;
+
} IdeWorkspacePrivate;
typedef struct
@@ -108,6 +112,7 @@ typedef struct
enum {
PROP_0,
PROP_CONTEXT,
+ PROP_ID,
N_PROPS
};
@@ -519,17 +524,6 @@ 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,
@@ -635,6 +629,29 @@ ide_workspace_get_property (GObject *object,
g_value_set_object (value, ide_workspace_get_context (self));
break;
+ case PROP_ID:
+ g_value_set_string (value, ide_workspace_get_id (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_workspace_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeWorkspace *self = IDE_WORKSPACE (object);
+
+ switch (prop_id)
+ {
+ case PROP_ID:
+ ide_workspace_set_id (self, g_value_get_string (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -651,6 +668,7 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
object_class->dispose = ide_workspace_dispose;
object_class->finalize = ide_workspace_finalize;
object_class->get_property = ide_workspace_get_property;
+ object_class->set_property = ide_workspace_set_property;
widget_class->realize = ide_workspace_realize;
widget_class->size_allocate = ide_workspace_size_allocate;
@@ -680,6 +698,19 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
IDE_TYPE_CONTEXT,
(G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+ /**
+ * IdeWorkspace:id:
+ *
+ * The "id" property is a unique identifier for the workspace
+ * within the project.
+ */
+ properties [PROP_ID] =
+ g_param_spec_string ("id",
+ "Id",
+ "Identifier for the workspace window",
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_properties (object_class, N_PROPS, properties);
ide_action_mixin_init (&klass->action_mixin, object_class);
@@ -697,6 +728,7 @@ ide_workspace_init (IdeWorkspace *self)
gtk_widget_add_css_class (GTK_WIDGET (self), "devel");
#endif
+ priv->id = g_dbus_generate_guid ();
priv->mru_link.data = self;
/* Add org-gnome-Builder style CSS identifier */
@@ -1745,3 +1777,25 @@ _ide_workspace_save_session_simple (IdeWorkspace *self,
IDE_EXIT;
}
+
+void
+ide_workspace_set_id (IdeWorkspace *self,
+ const char *id)
+{
+ IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+
+ g_return_if_fail (IDE_IS_WORKSPACE (self));
+
+ if (ide_set_string (&priv->id, id))
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ID]);
+}
+
+const char *
+ide_workspace_get_id (IdeWorkspace *self)
+{
+ IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_WORKSPACE (self), NULL);
+
+ return priv->id;
+}
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 033136d61..547363c13 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -62,7 +62,6 @@ 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);
@@ -117,6 +116,9 @@ void ide_workspace_action_set_enabled (IdeWorkspace
IDE_AVAILABLE_IN_ALL
const char *ide_workspace_get_id (IdeWorkspace *self);
IDE_AVAILABLE_IN_ALL
+void ide_workspace_set_id (IdeWorkspace *self,
+ const char *id);
+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]