GtkMenuTracker: add hidden-when='macos-menubar'

Provide a mechanism for hiding the "Quit", "About" and "Preferences"
menu items from the normal places in a traditional menubar layout (in
the File and Edit menus) when the menu is being rendered in the Mac OS
menubar.

These items can already be found in the application menu.

With this feature, applications can now define a single menu to use in
all 'traditional' scenarios.

Use this new attribute in Bloatpad.

https://bugzilla.gnome.org/show_bug.cgi?id=741610
This commit is contained in:
Ryan Lortie 2014-12-16 12:14:23 -05:00 committed by Matthias Clasen
parent 4bc3f02d51
commit 6b26664c41
8 changed files with 31 additions and 9 deletions

View File

@ -11,12 +11,14 @@
<section>
<item>
<attribute name='label' translatable='yes'>_About Bloatpad</attribute>
<attribute name='hidden-when'>macos-menubar</attribute>
<attribute name='action'>app.about</attribute>
</item>
</section>
<section>
<item>
<attribute name='label' translatable='yes'>_Quit</attribute>
<attribute name='hidden-when'>macos-menubar</attribute>
<attribute name='action'>app.quit</attribute>
</item>
</section>

View File

@ -379,6 +379,7 @@ menu_item_removed (gint position,
model,
NO,
YES,
YES,
NULL,
menu_item_inserted,
menu_item_removed,
@ -397,6 +398,7 @@ menu_item_removed (gint position,
tracker = gtk_menu_tracker_new_for_item_link (trackerItem,
G_MENU_LINK_SUBMENU,
YES,
YES,
menu_item_inserted,
menu_item_removed,
self);

View File

@ -380,7 +380,7 @@ gtk_menu_section_box_new_toplevel (GtkStack *stack,
gtk_stack_add_named (stack, GTK_WIDGET (box), "main");
box->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (_gtk_widget_get_action_muxer (GTK_WIDGET (box), TRUE)),
model, TRUE, FALSE, action_namespace,
model, TRUE, FALSE, FALSE, action_namespace,
gtk_menu_section_box_insert_func,
gtk_menu_section_box_remove_func, box);
@ -420,7 +420,7 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
GTK_WIDGET (box), gtk_menu_tracker_item_get_label (item));
gtk_widget_show (GTK_WIDGET (box));
box->tracker = gtk_menu_tracker_new_for_item_link (item, G_MENU_LINK_SUBMENU, FALSE,
box->tracker = gtk_menu_tracker_new_for_item_link (item, G_MENU_LINK_SUBMENU, FALSE, FALSE,
gtk_menu_section_box_insert_func,
gtk_menu_section_box_remove_func,
box);
@ -486,7 +486,7 @@ gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
gtk_widget_show (box->separator);
}
box->tracker = gtk_menu_tracker_new_for_item_link (item, G_MENU_LINK_SECTION, FALSE,
box->tracker = gtk_menu_tracker_new_for_item_link (item, G_MENU_LINK_SECTION, FALSE, FALSE,
gtk_menu_section_box_insert_func,
gtk_menu_section_box_remove_func,
box);

View File

@ -2087,7 +2087,7 @@ gtk_menu_shell_tracker_insert_func (GtkMenuTrackerItem *item,
* lazy...
*/
submenu->priv->tracker = gtk_menu_tracker_new_for_item_link (item,
G_MENU_LINK_SUBMENU, TRUE,
G_MENU_LINK_SUBMENU, TRUE, FALSE,
gtk_menu_shell_tracker_insert_func,
gtk_menu_shell_tracker_remove_func,
submenu);
@ -2202,8 +2202,8 @@ gtk_menu_shell_bind_model (GtkMenuShell *menu_shell,
gtk_container_remove (GTK_CONTAINER (menu_shell), menu_shell->priv->children->data);
if (model)
menu_shell->priv->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (muxer),
model, with_separators, TRUE, action_namespace,
menu_shell->priv->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (muxer), model,
with_separators, TRUE, FALSE, action_namespace,
gtk_menu_shell_tracker_insert_func,
gtk_menu_shell_tracker_remove_func,
menu_shell);

View File

@ -60,7 +60,8 @@ typedef struct _GtkMenuTrackerSection GtkMenuTrackerSection;
struct _GtkMenuTracker
{
GtkActionObservable *observable;
gboolean merge_sections;
guint merge_sections : 1;
guint mac_os_mode : 1;
GtkMenuTrackerInsertFunc insert_func;
GtkMenuTrackerRemoveFunc remove_func;
gpointer user_data;
@ -200,7 +201,7 @@ gtk_menu_tracker_section_sync_separators (GtkMenuTrackerSection *section,
/* Add a separator */
GtkMenuTrackerItem *item;
item = _gtk_menu_tracker_item_new (tracker->observable, parent_model, parent_index, NULL, TRUE);
item = _gtk_menu_tracker_item_new (tracker->observable, parent_model, parent_index, FALSE, NULL, TRUE);
(* tracker->insert_func) (item, offset, tracker->user_data);
g_object_unref (item);
@ -345,6 +346,7 @@ gtk_menu_tracker_add_items (GtkMenuTracker *tracker,
GtkMenuTrackerItem *item;
item = _gtk_menu_tracker_item_new (tracker->observable, model, position + n_items,
tracker->mac_os_mode,
section->action_namespace, submenu != NULL);
/* In the case that the item may disappear we handle that by
@ -498,6 +500,7 @@ gtk_menu_tracker_section_new (GtkMenuTracker *tracker,
* @merge_sections: if sections should have their items merged in the
* usual way or reported only as separators (which can be queried to
* manually handle the items)
* @mac_os_mode: if this is on behalf of the Mac OS menubar
* @action_namespace: the passed-in action namespace
* @insert_func: insert callback
* @remove_func: remove callback
@ -549,6 +552,7 @@ gtk_menu_tracker_new (GtkActionObservable *observable,
GMenuModel *model,
gboolean with_separators,
gboolean merge_sections,
gboolean mac_os_mode,
const gchar *action_namespace,
GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func,
@ -558,6 +562,7 @@ gtk_menu_tracker_new (GtkActionObservable *observable,
tracker = g_slice_new (GtkMenuTracker);
tracker->merge_sections = merge_sections;
tracker->mac_os_mode = mac_os_mode;
tracker->observable = g_object_ref (observable);
tracker->insert_func = insert_func;
tracker->remove_func = remove_func;
@ -573,6 +578,7 @@ GtkMenuTracker *
gtk_menu_tracker_new_for_item_link (GtkMenuTrackerItem *item,
const gchar *link_name,
gboolean merge_sections,
gboolean mac_os_mode,
GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data)
@ -585,7 +591,8 @@ gtk_menu_tracker_new_for_item_link (GtkMenuTrackerItem *item,
namespace = _gtk_menu_tracker_item_get_link_namespace (item);
tracker = gtk_menu_tracker_new (_gtk_menu_tracker_item_get_observable (item), submenu,
TRUE, merge_sections, namespace, insert_func, remove_func, user_data);
TRUE, merge_sections, mac_os_mode,
namespace, insert_func, remove_func, user_data);
g_object_unref (submenu);
g_free (namespace);

View File

@ -36,6 +36,7 @@ GtkMenuTracker * gtk_menu_tracker_new (GtkActi
GMenuModel *model,
gboolean with_separators,
gboolean merge_sections,
gboolean mac_os_mode,
const gchar *action_namespace,
GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func,
@ -44,6 +45,7 @@ GtkMenuTracker * gtk_menu_tracker_new (GtkActi
GtkMenuTracker * gtk_menu_tracker_new_for_item_link (GtkMenuTrackerItem *item,
const gchar *link_name,
gboolean merge_sections,
gboolean mac_os_mode,
GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data);

View File

@ -103,6 +103,7 @@ struct _GtkMenuTrackerItem
#define HIDDEN_NEVER 0
#define HIDDEN_WHEN_MISSING 1
#define HIDDEN_WHEN_DISABLED 2
#define HIDDEN_WHEN_ALWAYS 3
enum {
PROP_0,
@ -271,6 +272,10 @@ gtk_menu_tracker_item_update_visibility (GtkMenuTrackerItem *self)
visible = self->sensitive;
break;
case HIDDEN_WHEN_ALWAYS:
visible = FALSE;
break;
default:
g_assert_not_reached ();
}
@ -479,6 +484,7 @@ GtkMenuTrackerItem *
_gtk_menu_tracker_item_new (GtkActionObservable *observable,
GMenuModel *model,
gint item_index,
gboolean mac_os_mode,
const gchar *action_namespace,
gboolean is_separator)
{
@ -501,6 +507,8 @@ _gtk_menu_tracker_item_new (GtkActionObservable *observable,
self->hidden_when = HIDDEN_WHEN_DISABLED;
else if (g_str_equal (hidden_when, "action-missing"))
self->hidden_when = HIDDEN_WHEN_MISSING;
else if (mac_os_mode && g_str_equal (hidden_when, "macos-menubar"))
self->hidden_when = HIDDEN_WHEN_ALWAYS;
/* Ignore other values -- this code may be running in context of a
* desktop shell or the like and should not spew criticals due to

View File

@ -45,6 +45,7 @@ GType gtk_menu_tracker_item_role_get_type (void) G
GtkMenuTrackerItem * _gtk_menu_tracker_item_new (GtkActionObservable *observable,
GMenuModel *model,
gint item_index,
gboolean mac_os_mode,
const gchar *action_namespace,
gboolean is_separator);