[gnome-builder/wip/gtk4-port: 174/1774] libide/gui: figure out composition of header bars
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 174/1774] libide/gui: figure out composition of header bars
- Date: Mon, 11 Jul 2022 22:30:59 +0000 (UTC)
commit 2a1e60deed32994725662dd2b4344e1edaa2474d
Author: Christian Hergert <chergert redhat com>
Date: Tue Mar 29 16:44:03 2022 -0700
libide/gui: figure out composition of header bars
src/libide/gui/ide-header-bar.c | 34 +++++++++++------------
src/libide/gui/ide-header-bar.h | 19 ++++++-------
src/libide/gui/ide-header-bar.ui | 6 +----
src/libide/gui/ide-notifications-button.c | 3 ++-
src/libide/gui/ide-primary-workspace.c | 3 ++-
src/libide/gui/ide-primary-workspace.ui | 3 ---
src/libide/gui/ide-workspace.c | 45 ++++++++++++++++++++++++++++---
7 files changed, 70 insertions(+), 43 deletions(-)
---
diff --git a/src/libide/gui/ide-header-bar.c b/src/libide/gui/ide-header-bar.c
index 8aa79dbbc..9a283a20f 100644
--- a/src/libide/gui/ide-header-bar.c
+++ b/src/libide/gui/ide-header-bar.c
@@ -31,7 +31,7 @@ typedef struct
AdwHeaderBar *header_bar;
GtkMenuButton *menu_button;
- PanelOmniBar *omni_bar;
+ GtkCenterBox *center_box;
GtkBox *left;
GtkBox *left_of_center;
GtkBox *right;
@@ -50,6 +50,7 @@ G_DEFINE_TYPE_WITH_CODE (IdeHeaderBar, ide_header_bar, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (IdeHeaderBar)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init))
+static GtkBuildableIface *buildable_parent_iface;
static GParamSpec *properties [N_PROPS];
static void
@@ -123,11 +124,11 @@ ide_header_bar_class_init (IdeHeaderBarClass *klass)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/libide-gui/ui/ide-header-bar.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, center_box);
gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, header_bar);
gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, left);
gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, left_of_center);
gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, menu_button);
- gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, omni_bar);
gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, right);
gtk_widget_class_bind_template_child_private (widget_class, IdeHeaderBar, right_of_center);
}
@@ -206,14 +207,23 @@ ide_header_bar_add_child (GtkBuildable *buildable,
const gchar *type)
{
IdeHeaderBar *self = (IdeHeaderBar *)buildable;
+ IdeHeaderBarPrivate *priv = ide_header_bar_get_instance_private (self);
g_assert (IDE_IS_HEADER_BAR (self));
g_assert (GTK_IS_BUILDER (builder));
g_assert (G_IS_OBJECT (child));
+ if (ADW_IS_HEADER_BAR (child) && priv->header_bar == NULL)
+ {
+ buildable_parent_iface->add_child (buildable, builder, child, type);
+ return;
+ }
+
if (GTK_IS_WIDGET (child))
{
- if (ide_str_equal0 (type, "left"))
+ if (ide_str_equal0 (type, "title"))
+ gtk_center_box_set_center_widget (priv->center_box, GTK_WIDGET (child));
+ else if (ide_str_equal0 (type, "left"))
ide_header_bar_add (self, IDE_HEADER_BAR_POSITION_LEFT, 0, GTK_WIDGET (child));
else if (ide_str_equal0 (type, "right"))
ide_header_bar_add (self, IDE_HEADER_BAR_POSITION_RIGHT, 0, GTK_WIDGET (child));
@@ -236,6 +246,8 @@ failure:
static void
buildable_iface_init (GtkBuildableIface *iface)
{
+ buildable_parent_iface = g_type_interface_peek_parent (iface);
+
iface->add_child = ide_header_bar_add_child;
}
@@ -316,19 +328,3 @@ ide_header_bar_add (IdeHeaderBar *self,
gtk_box_insert_child_after (box, widget, sibling);
}
}
-
-/**
- * ide_header_bar_get_omni_bar:
- * @self: a #IdeHeaderBar
- *
- * Returns: (transfer none): a #PanelOmniBar
- */
-PanelOmniBar *
-ide_header_bar_get_omni_bar (IdeHeaderBar *self)
-{
- IdeHeaderBarPrivate *priv = ide_header_bar_get_instance_private (self);
-
- g_return_val_if_fail (IDE_IS_HEADER_BAR (self), NULL);
-
- return priv->omni_bar;
-}
diff --git a/src/libide/gui/ide-header-bar.h b/src/libide/gui/ide-header-bar.h
index 68bce3bf4..69be5e82d 100644
--- a/src/libide/gui/ide-header-bar.h
+++ b/src/libide/gui/ide-header-bar.h
@@ -25,7 +25,6 @@
#endif
#include <adwaita.h>
-#include <libpanel.h>
#include <libide-core.h>
G_BEGIN_DECLS
@@ -50,18 +49,16 @@ struct _IdeHeaderBarClass
};
IDE_AVAILABLE_IN_ALL
-GtkWidget *ide_header_bar_new (void);
+GtkWidget *ide_header_bar_new (void);
IDE_AVAILABLE_IN_ALL
-void ide_header_bar_add (IdeHeaderBar *self,
- IdeHeaderBarPosition position,
- int priority,
- GtkWidget *widget);
+void ide_header_bar_add (IdeHeaderBar *self,
+ IdeHeaderBarPosition position,
+ int priority,
+ GtkWidget *widget);
IDE_AVAILABLE_IN_ALL
-const char *ide_header_bar_get_menu_id (IdeHeaderBar *self);
+const char *ide_header_bar_get_menu_id (IdeHeaderBar *self);
IDE_AVAILABLE_IN_ALL
-void ide_header_bar_set_menu_id (IdeHeaderBar *self,
- const char *menu_id);
-IDE_AVAILABLE_IN_ALL
-PanelOmniBar *ide_header_bar_get_omni_bar (IdeHeaderBar *self);
+void ide_header_bar_set_menu_id (IdeHeaderBar *self,
+ const char *menu_id);
G_END_DECLS
diff --git a/src/libide/gui/ide-header-bar.ui b/src/libide/gui/ide-header-bar.ui
index 77c5d608c..636b4f8a9 100644
--- a/src/libide/gui/ide-header-bar.ui
+++ b/src/libide/gui/ide-header-bar.ui
@@ -11,15 +11,11 @@
</object>
</child>
<child type="title">
- <object class="GtkCenterBox">
+ <object class="GtkCenterBox" id="center_box">
<child type="start">
<object class="GtkBox" id="left_of_center">
</object>
</child>
- <child type="center">
- <object class="PanelOmniBar" id="omni_bar">
- </object>
- </child>
<child type="end">
<object class="GtkBox" id="right_of_center">
</object>
diff --git a/src/libide/gui/ide-notifications-button.c b/src/libide/gui/ide-notifications-button.c
index e937a7ef5..15f2a45d0 100644
--- a/src/libide/gui/ide-notifications-button.c
+++ b/src/libide/gui/ide-notifications-button.c
@@ -164,7 +164,7 @@ ide_notifications_button_context_set_cb (GtkWidget *widget,
ide_notifications_button_bind_model (self, G_LIST_MODEL (notifications));
g_object_bind_property (notifications, "progress",
- self->icon, "progress",
+ self->progress, "progress",
G_BINDING_SYNC_CREATE);
g_signal_connect_object (notifications,
"notify::has-progress",
@@ -226,6 +226,7 @@ ide_notifications_button_class_init (IdeNotificationsButtonClass *klass)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_bind_template_child (widget_class, IdeNotificationsButton, icon);
gtk_widget_class_bind_template_child (widget_class, IdeNotificationsButton, list_box);
+ gtk_widget_class_bind_template_child (widget_class, IdeNotificationsButton, menu_button);
gtk_widget_class_bind_template_child (widget_class, IdeNotificationsButton, popover);
gtk_widget_class_bind_template_child (widget_class, IdeNotificationsButton, progress);
gtk_widget_class_bind_template_child (widget_class, IdeNotificationsButton, revealer);
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index 38f77eef0..620fbc19b 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -94,8 +94,9 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, project_title);
gtk_widget_class_bind_template_child (widget_class, IdePrimaryWorkspace, run_button);
- g_type_ensure (IDE_TYPE_RUN_BUTTON);
g_type_ensure (IDE_TYPE_NOTIFICATIONS_BUTTON);
+ g_type_ensure (IDE_TYPE_OMNI_BAR);
+ g_type_ensure (IDE_TYPE_RUN_BUTTON);
}
static void
diff --git a/src/libide/gui/ide-primary-workspace.ui b/src/libide/gui/ide-primary-workspace.ui
index fdf9adf5d..7c9ba3c27 100644
--- a/src/libide/gui/ide-primary-workspace.ui
+++ b/src/libide/gui/ide-primary-workspace.ui
@@ -6,9 +6,6 @@
<property name="menu-id">ide-primary-workspace-menu</property>
<child type="title">
<object class="IdeOmniBar" id="omni_bar">
- <property name="halign">center</property>
- <property name="hexpand">false</property>
- <property name="hexpand-set">true</property>
<child type="placeholder">
<object class="GtkLabel" id="project_title">
<property name="ellipsize">end</property>
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index f2955237a..352b8ba25 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -62,6 +62,9 @@ typedef struct
/* Queued source to save window size/etc */
guint queued_window_save;
+
+ /* Vertical box for children */
+ GtkBox *box;
} IdeWorkspacePrivate;
typedef struct
@@ -76,7 +79,11 @@ enum {
N_PROPS
};
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (IdeWorkspace, ide_workspace, ADW_TYPE_APPLICATION_WINDOW)
+static void buildable_iface_init (GtkBuildableIface *iface);
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (IdeWorkspace, ide_workspace, ADW_TYPE_APPLICATION_WINDOW,
+ G_ADD_PRIVATE (IdeWorkspace)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init))
static GParamSpec *properties [N_PROPS];
static GSettings *settings;
@@ -418,13 +425,17 @@ ide_workspace_init (IdeWorkspace *self)
priv->mru_link.data = self;
- gtk_widget_init_template (GTK_WIDGET (self));
-
/* Add org-gnome-Builder style CSS identifier */
app_id = g_strdelimit (g_strdup (ide_get_application_id ()), ".", '-');
gtk_widget_add_css_class (GTK_WIDGET (self), app_id);
gtk_widget_add_css_class (GTK_WIDGET (self), "workspace");
+ /* Setup container for children widgetry */
+ priv->box = g_object_new (GTK_TYPE_BOX,
+ "orientation", GTK_ORIENTATION_VERTICAL,
+ NULL);
+ gtk_window_set_child (GTK_WINDOW (self), GTK_WIDGET (priv->box));
+
/* Initialize GActions for workspace */
_ide_workspace_init_actions (self);
}
@@ -649,3 +660,31 @@ ide_workspace_addin_find_by_module_name (IdeWorkspace *workspace,
return IDE_WORKSPACE_ADDIN (ret);
}
+
+static void
+ide_workspace_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *object,
+ const char *type)
+{
+ IdeWorkspace *self = (IdeWorkspace *)buildable;
+ IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+
+ g_assert (IDE_IS_WORKSPACE (self));
+ g_assert (GTK_IS_BUILDER (builder));
+ g_assert (G_IS_OBJECT (object));
+
+ if (GTK_IS_WIDGET (object))
+ {
+ if (g_strcmp0 (type, "titlebar") == 0)
+ gtk_box_prepend (priv->box, GTK_WIDGET (object));
+ else
+ gtk_box_append (priv->box, GTK_WIDGET (object));
+ }
+}
+
+static void
+buildable_iface_init (GtkBuildableIface *iface)
+{
+ iface->add_child = ide_workspace_add_child;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]