[gnome-builder] inception: push the menu deeper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] inception: push the menu deeper
- Date: Wed, 2 Sep 2015 09:35:25 +0000 (UTC)
commit 9304df092c6d99c20090e6bc01553c41fc2d7735
Author: Christian Hergert <christian hergert me>
Date: Wed Sep 2 00:23:30 2015 -0700
inception: push the menu deeper
One more step towards getting mutable view menus that can be based on the
type of view (and/or addins).
data/ui/gb-view-stack.ui | 65 --------------------------
data/ui/gb-view.ui | 71 +++++++++++++++++++++++++++++
src/resources/gnome-builder.gresource.xml | 1 +
src/views/gb-view-stack-private.h | 2 -
src/views/gb-view-stack.c | 11 +++--
src/views/gb-view.c | 16 +++++++
src/views/gb-view.h | 1 +
7 files changed, 96 insertions(+), 71 deletions(-)
---
diff --git a/data/ui/gb-view-stack.ui b/data/ui/gb-view-stack.ui
index 6e11cf2..b5c12a2 100644
--- a/data/ui/gb-view-stack.ui
+++ b/data/ui/gb-view-stack.ui
@@ -190,69 +190,4 @@
</object>
</child>
</object>
- <menu id="stack_menu">
- <section id="gb-view-stack-splits">
- <attribute name="id">splits-section</attribute>
- <attribute name="display-hint">horizontal-buttons</attribute>
- <attribute name="label" translatable="yes">Split</attribute>
- <item>
- <attribute name="label" translatable="yes">Split Left</attribute>
- <attribute name="action">view-stack.split-left</attribute>
- <attribute name="verb-icon">builder-split-tab-left-symbolic</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Split Right</attribute>
- <attribute name="action">view-stack.split-right</attribute>
- <attribute name="verb-icon">builder-split-tab-right-symbolic</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Split Down</attribute>
- <attribute name="action">view-stack.split-down</attribute>
- <attribute name="verb-icon">builder-split-tab-symbolic</attribute>
- </item>
- </section>
- <section id="gb-view-stack-moves">
- <attribute name="id">move-section</attribute>
- <attribute name="display-hint">horizontal-buttons</attribute>
- <attribute name="label" translatable="yes">Move</attribute>
- <item>
- <attribute name="label" translatable="yes">Move Left</attribute>
- <attribute name="action">view-stack.move-left</attribute>
- <attribute name="verb-icon">builder-move-left-symbolic</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">Move Right</attribute>
- <attribute name="action">view-stack.move-right</attribute>
- <attribute name="verb-icon">builder-move-right-symbolic</attribute>
- </item>
- </section>
- <section id="gb-view-stack-preview">
- <item>
- <attribute name="label" translatable="yes">Pre_view</attribute>
- <attribute name="action">view.preview</attribute>
- </item>
- </section>
- <section id="gb-view-stack-save">
- <item>
- <attribute name="label" translatable="yes">_Save</attribute>
- <attribute name="action">view.save</attribute>
- </item>
- <item>
- <attribute name="label" translatable="yes">_Save As</attribute>
- <attribute name="action">view.save-as</attribute>
- </item>
- </section>
- <section id="gb-view-stack-print">
- <item>
- <attribute name="label" translatable="yes">Print</attribute>
- <attribute name="action">view.print</attribute>
- </item>
- </section>
- <section id="gb-view-stack-close">
- <item>
- <attribute name="label" translatable="yes">_Close</attribute>
- <attribute name="action">view-stack.close</attribute>
- </item>
- </section>
- </menu>
</interface>
diff --git a/data/ui/gb-view.ui b/data/ui/gb-view.ui
new file mode 100644
index 0000000..f5f1bf5
--- /dev/null
+++ b/data/ui/gb-view.ui
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.17 -->
+ <template class="GbView" parent="GtkBox">
+ </template>
+ <menu id="menu">
+ <section id="split-section">
+ <attribute name="id">splits-section</attribute>
+ <attribute name="display-hint">horizontal-buttons</attribute>
+ <attribute name="label" translatable="yes">Split</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Split Left</attribute>
+ <attribute name="action">view-stack.split-left</attribute>
+ <attribute name="verb-icon">builder-split-tab-left-symbolic</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Split Right</attribute>
+ <attribute name="action">view-stack.split-right</attribute>
+ <attribute name="verb-icon">builder-split-tab-right-symbolic</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Split Down</attribute>
+ <attribute name="action">view-stack.split-down</attribute>
+ <attribute name="verb-icon">builder-split-tab-symbolic</attribute>
+ </item>
+ </section>
+ <section id="move-section">
+ <attribute name="id">move-section</attribute>
+ <attribute name="display-hint">horizontal-buttons</attribute>
+ <attribute name="label" translatable="yes">Move</attribute>
+ <item>
+ <attribute name="label" translatable="yes">Move Left</attribute>
+ <attribute name="action">view-stack.move-left</attribute>
+ <attribute name="verb-icon">builder-move-left-symbolic</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Move Right</attribute>
+ <attribute name="action">view-stack.move-right</attribute>
+ <attribute name="verb-icon">builder-move-right-symbolic</attribute>
+ </item>
+ </section>
+ <section id="preview-section">
+ <item>
+ <attribute name="label" translatable="yes">Pre_view</attribute>
+ <attribute name="action">view.preview</attribute>
+ </item>
+ </section>
+ <section id="save-section">
+ <item>
+ <attribute name="label" translatable="yes">_Save</attribute>
+ <attribute name="action">view.save</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">_Save As</attribute>
+ <attribute name="action">view.save-as</attribute>
+ </item>
+ </section>
+ <section id="print-section">
+ <item>
+ <attribute name="label" translatable="yes">Print</attribute>
+ <attribute name="action">view.print</attribute>
+ </item>
+ </section>
+ <section id="close-section">
+ <item>
+ <attribute name="label" translatable="yes">_Close</attribute>
+ <attribute name="action">view-stack.close</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index d84ef05..028d89d 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -42,6 +42,7 @@
<file alias="ui/gb-search-display-group.ui">../../data/ui/gb-search-display-group.ui</file>
<file alias="ui/gb-search-display-row.ui">../../data/ui/gb-search-display-row.ui</file>
<file alias="ui/gb-shortcuts-window.ui">../../data/ui/gb-shortcuts-window.ui</file>
+ <file alias="ui/gb-view.ui">../../data/ui/gb-view.ui</file>
<file alias="ui/gb-view-stack.ui">../../data/ui/gb-view-stack.ui</file>
<file alias="ui/gb-workbench.ui">../../data/ui/gb-workbench.ui</file>
<file alias="ui/gb-workspace.ui">../../data/ui/gb-workspace.ui</file>
diff --git a/src/views/gb-view-stack-private.h b/src/views/gb-view-stack-private.h
index 72fd21c..6ca3d82 100644
--- a/src/views/gb-view-stack-private.h
+++ b/src/views/gb-view-stack-private.h
@@ -45,9 +45,7 @@ struct _GbViewStack
GtkButton *go_backward;
GtkButton *go_forward;
GtkLabel *modified_label;
- GtkPopover *popover;
GtkStack *stack;
- GMenuModel *stack_menu;
GtkLabel *title_label;
GtkListBox *views_button;
GtkListBox *views_listbox;
diff --git a/src/views/gb-view-stack.c b/src/views/gb-view-stack.c
index ffd0612..2efe61a 100644
--- a/src/views/gb-view-stack.c
+++ b/src/views/gb-view-stack.c
@@ -551,9 +551,7 @@ gb_view_stack_class_init (GbViewStackClass *klass)
GB_WIDGET_CLASS_BIND (klass, GbViewStack, go_backward);
GB_WIDGET_CLASS_BIND (klass, GbViewStack, go_forward);
GB_WIDGET_CLASS_BIND (klass, GbViewStack, modified_label);
- GB_WIDGET_CLASS_BIND (klass, GbViewStack, popover);
GB_WIDGET_CLASS_BIND (klass, GbViewStack, stack);
- GB_WIDGET_CLASS_BIND (klass, GbViewStack, stack_menu);
GB_WIDGET_CLASS_BIND (klass, GbViewStack, title_label);
GB_WIDGET_CLASS_BIND (klass, GbViewStack, views_button);
GB_WIDGET_CLASS_BIND (klass, GbViewStack, views_listbox);
@@ -565,8 +563,6 @@ gb_view_stack_init (GbViewStack *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
- gtk_popover_bind_model (self->popover, self->stack_menu, NULL);
-
g_signal_connect_object (self->stack,
"notify::visible-child",
G_CALLBACK (gb_view_stack__notify_visible_child),
@@ -643,11 +639,18 @@ gb_view_stack_set_active_view (GbViewStack *self,
GtkWidget *controls;
GBinding *binding;
GActionGroup *group;
+ GMenu *menu;
+ GtkPopover *popover;
ide_set_weak_pointer (&self->active_view, active_view);
if (active_view != gtk_stack_get_visible_child (self->stack))
gtk_stack_set_visible_child (self->stack, active_view);
+ menu = gb_view_get_menu (GB_VIEW (active_view));
+ popover = g_object_new (GTK_TYPE_POPOVER, NULL);
+ gtk_popover_bind_model (popover, G_MENU_MODEL (menu), NULL);
+ gtk_menu_button_set_popover (self->document_button, GTK_WIDGET (popover));
+
self->focus_history = g_list_remove (self->focus_history, active_view);
self->focus_history = g_list_prepend (self->focus_history, active_view);
diff --git a/src/views/gb-view.c b/src/views/gb-view.c
index a99b317..0a43ed1 100644
--- a/src/views/gb-view.c
+++ b/src/views/gb-view.c
@@ -23,6 +23,7 @@
typedef struct
{
GtkBox *controls;
+ GMenu *menu;
} GbViewPrivate;
static void buildable_iface_init (GtkBuildableIface *iface);
@@ -253,6 +254,9 @@ gb_view_class_init (GbViewClass *klass)
widget_class->destroy = gb_view_destroy;
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/gb-view.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, GbView, menu);
+
gParamSpecs [PROP_CAN_SPLIT] =
g_param_spec_boolean ("can-split",
"Can Split",
@@ -290,6 +294,8 @@ gb_view_init (GbView *self)
GbViewPrivate *priv = gb_view_get_instance_private (self);
GtkBox *controls;
+ gtk_widget_init_template (GTK_WIDGET (self));
+
controls = g_object_new (GTK_TYPE_BOX,
"orientation", GTK_ORIENTATION_HORIZONTAL,
"visible", TRUE,
@@ -318,3 +324,13 @@ buildable_iface_init (GtkBuildableIface *iface)
{
iface->get_internal_child = gb_view_get_internal_child;
}
+
+GMenu *
+gb_view_get_menu (GbView *self)
+{
+ GbViewPrivate *priv = gb_view_get_instance_private (self);
+
+ g_return_val_if_fail (GB_IS_VIEW (self), NULL);
+
+ return priv->menu;
+}
diff --git a/src/views/gb-view.h b/src/views/gb-view.h
index 9e3647d..13d8571 100644
--- a/src/views/gb-view.h
+++ b/src/views/gb-view.h
@@ -48,6 +48,7 @@ struct _GbViewClass
IdeSourceLocation *location);
};
+GMenu *gb_view_get_menu (GbView *self);
GbView *gb_view_create_split (GbView *self);
gboolean gb_view_get_can_preview (GbView *self);
gboolean gb_view_get_can_split (GbView *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]