[gnome-builder/wip/gtk4-port: 586/1774] libide/gui: add preference toggle for using tabbar
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 586/1774] libide/gui: add preference toggle for using tabbar
- Date: Mon, 11 Jul 2022 22:31:17 +0000 (UTC)
commit 142ee15d05652b4a91207c6a70ed158929d6abac
Author: Christian Hergert <chergert redhat com>
Date: Sun Apr 17 20:38:36 2022 -0700
libide/gui: add preference toggle for using tabbar
.../gsettings/org.gnome.builder.editor.gschema.xml | 5 +
src/libide/gui/ide-frame.c | 136 +++++++++++++++++++--
src/libide/gui/ide-frame.h | 9 +-
src/libide/gui/ide-grid.c | 10 +-
src/libide/gui/ide-preferences-builtin.c | 6 +
5 files changed, 145 insertions(+), 21 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.editor.gschema.xml
b/data/gsettings/org.gnome.builder.editor.gschema.xml
index f3e0f605a..d9d091eea 100644
--- a/data/gsettings/org.gnome.builder.editor.gschema.xml
+++ b/data/gsettings/org.gnome.builder.editor.gschema.xml
@@ -139,5 +139,10 @@
<summary>Minimum characters for matching selection.</summary>
<description>Specify the minimum number of characters for selection matching.</description>
</key>
+ <key name="use-tabbar" type="b">
+ <default>false</default>
+ <summary>Use Tabs</summary>
+ <description>Use the tabbar within the page grid.</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/libide/gui/ide-frame.c b/src/libide/gui/ide-frame.c
index b54c6a5db..fdd49ef9e 100644
--- a/src/libide/gui/ide-frame.c
+++ b/src/libide/gui/ide-frame.c
@@ -49,10 +49,20 @@ struct _IdeFrame
{
PanelFrame parent_instance;
PeasExtensionSet *addins;
+ guint use_tabbar : 1;
};
G_DEFINE_TYPE (IdeFrame, ide_frame, PANEL_TYPE_FRAME)
+enum {
+ PROP_0,
+ PROP_USE_TABBAR,
+ N_PROPS
+};
+
+static GSettings *editor_settings;
+static GParamSpec *properties[N_PROPS];
+
static void
ide_frame_notify_addin_of_page (PeasExtensionSet *set,
PeasPluginInfo *plugin_info,
@@ -138,31 +148,50 @@ ide_frame_addin_removed (PeasExtensionSet *set,
}
static void
-ide_frame_constructed (GObject *object)
+ide_frame_reload_addins (IdeFrame *self)
{
- IdeFrame *self = (IdeFrame *)object;
+ IDE_ENTRY;
g_assert (IDE_IS_FRAME (self));
- G_OBJECT_CLASS (ide_frame_parent_class)->constructed (object);
-
+ g_clear_object (&self->addins);
self->addins = peas_extension_set_new (peas_engine_get_default (),
IDE_TYPE_FRAME_ADDIN,
NULL);
-
g_signal_connect (self->addins,
"extension-added",
G_CALLBACK (ide_frame_addin_added),
self);
-
g_signal_connect (self->addins,
"extension-removed",
G_CALLBACK (ide_frame_addin_removed),
self);
+ peas_extension_set_foreach (self->addins, ide_frame_addin_added, self);
+
+ IDE_EXIT;
+}
+
+static void
+ide_frame_constructed (GObject *object)
+{
+ IdeFrame *self = (IdeFrame *)object;
+ PanelFrameHeader *header;
+
+ g_assert (IDE_IS_FRAME (self));
+
+ G_OBJECT_CLASS (ide_frame_parent_class)->constructed (object);
+
+ self->use_tabbar = g_settings_get_boolean (editor_settings, "use-tabbar");
+ if (self->use_tabbar)
+ header = PANEL_FRAME_HEADER (panel_frame_tab_bar_new ());
+ else
+ header = PANEL_FRAME_HEADER (panel_frame_header_bar_new ());
+ panel_frame_set_header (PANEL_FRAME (self), header);
+ g_settings_bind (editor_settings, "use-tabbar",
+ self, "use-tabbar",
+ G_SETTINGS_BIND_GET);
- peas_extension_set_foreach (self->addins,
- ide_frame_addin_added,
- self);
+ ide_frame_reload_addins (self);
}
static void
@@ -177,14 +206,63 @@ ide_frame_dispose (GObject *object)
G_OBJECT_CLASS (ide_frame_parent_class)->dispose (object);
}
+static void
+ide_frame_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeFrame *self = IDE_FRAME (object);
+
+ switch (prop_id)
+ {
+ case PROP_USE_TABBAR:
+ g_value_set_boolean (value, ide_frame_get_use_tabbar (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_frame_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeFrame *self = IDE_FRAME (object);
+
+ switch (prop_id)
+ {
+ case PROP_USE_TABBAR:
+ ide_frame_set_use_tabbar (self, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
static void
ide_frame_class_init (IdeFrameClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->dispose = ide_frame_dispose;
object_class->constructed = ide_frame_constructed;
+ object_class->dispose = ide_frame_dispose;
+ object_class->get_property = ide_frame_get_property;
+ object_class->set_property = ide_frame_set_property;
+
+ properties [PROP_USE_TABBAR] =
+ g_param_spec_boolean ("use-tabbar",
+ "Use Tabbar",
+ "If tabs should be used",
+ FALSE,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/libide-gui/ui/ide-frame.ui");
}
@@ -192,6 +270,9 @@ ide_frame_class_init (IdeFrameClass *klass)
static void
ide_frame_init (IdeFrame *self)
{
+ if (editor_settings == NULL)
+ editor_settings = g_settings_new ("org.gnome.builder.editor");
+
gtk_widget_init_template (GTK_WIDGET (self));
g_signal_connect (self,
@@ -291,3 +372,38 @@ ide_frame_get_position (IdeFrame *self)
return ret;
}
+
+gboolean
+ide_frame_get_use_tabbar (IdeFrame *self)
+{
+ g_return_val_if_fail (IDE_IS_FRAME (self), FALSE);
+
+ return self->use_tabbar;
+}
+
+void
+ide_frame_set_use_tabbar (IdeFrame *self,
+ gboolean use_tabbar)
+{
+ g_return_if_fail (IDE_IS_FRAME (self));
+
+ use_tabbar = !!use_tabbar;
+
+ if (use_tabbar != self->use_tabbar)
+ {
+ PanelFrameHeader *header;
+
+ self->use_tabbar = use_tabbar;
+
+ if (self->use_tabbar)
+ header = PANEL_FRAME_HEADER (panel_frame_tab_bar_new ());
+ else
+ header = PANEL_FRAME_HEADER (panel_frame_header_bar_new ());
+
+ panel_frame_set_header (PANEL_FRAME (self), header);
+
+ ide_frame_reload_addins (self);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_USE_TABBAR]);
+ }
+}
diff --git a/src/libide/gui/ide-frame.h b/src/libide/gui/ide-frame.h
index ea2721779..de758fcad 100644
--- a/src/libide/gui/ide-frame.h
+++ b/src/libide/gui/ide-frame.h
@@ -37,8 +37,13 @@ IDE_AVAILABLE_IN_ALL
G_DECLARE_FINAL_TYPE (IdeFrame, ide_frame, IDE, FRAME, PanelFrame)
IDE_AVAILABLE_IN_ALL
-GtkWidget *ide_frame_new (void);
+GtkWidget *ide_frame_new (void);
IDE_AVAILABLE_IN_ALL
-IdePanelPosition *ide_frame_get_position (IdeFrame *self);
+IdePanelPosition *ide_frame_get_position (IdeFrame *self);
+IDE_AVAILABLE_IN_ALL
+gboolean ide_frame_get_use_tabbar (IdeFrame *self);
+IDE_AVAILABLE_IN_ALL
+void ide_frame_set_use_tabbar (IdeFrame *self,
+ gboolean use_tabbar);
G_END_DECLS
diff --git a/src/libide/gui/ide-grid.c b/src/libide/gui/ide-grid.c
index 51cb638f5..990dc1613 100644
--- a/src/libide/gui/ide-grid.c
+++ b/src/libide/gui/ide-grid.c
@@ -43,17 +43,9 @@ G_DEFINE_TYPE (IdeGrid, ide_grid, PANEL_TYPE_GRID)
static PanelFrame *
ide_grid_real_create_frame (PanelGrid *grid)
{
- PanelFrame *frame;
- PanelFrameHeader *header;
-
g_assert (PANEL_IS_GRID (grid));
- frame = PANEL_FRAME (ide_frame_new ());
- header = PANEL_FRAME_HEADER (panel_frame_header_bar_new ());
-
- panel_frame_set_header (frame, header);
-
- return frame;
+ return PANEL_FRAME (ide_frame_new ());
}
static void
diff --git a/src/libide/gui/ide-preferences-builtin.c b/src/libide/gui/ide-preferences-builtin.c
index cfd361e8b..aaa217066 100644
--- a/src/libide/gui/ide-preferences-builtin.c
+++ b/src/libide/gui/ide-preferences-builtin.c
@@ -666,6 +666,7 @@ static const IdePreferencePageEntry pages[] = {
static const IdePreferenceGroupEntry groups[] = {
{ "appearance", "style", 0, N_("Appearance") },
+ { "appearance", "interface", 1000, N_("Interface") },
{ "editing", "formatting", 100, N_("Formatting") },
@@ -703,6 +704,11 @@ static const IdePreferenceGroupEntry groups[] = {
static const IdePreferenceItemEntry items[] = {
{ "appearance", "style", "style-variant", 0, handle_style_variant },
+ { "appearance", "interface", "use-tabbar", 0, ide_preferences_window_toggle,
+ N_("Use Tabs"),
+ N_("Switch pages using a tab bar"),
+ "org.gnome.builder.editor", NULL, "use-tabbar" },
+
{ "projects", "workspace", "restore", 0, ide_preferences_window_toggle,
N_("Restore Previous Session"),
N_("Open previously opened files when loading a project"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]