remoteMenu: Add support for submenu items

Wrap new GtkMenuTracker API that adds an easy way to bind to
tracker items, and use it to add back support for submenus.
This also adds support for a submenu feature that we didn't
have support for before, action namespaces.

https://bugzilla.gnome.org/show_bug.cgi?id=700257
This commit is contained in:
Jasper St. Pierre 2013-05-10 13:39:21 -04:00
parent 026f61f5aa
commit 8891a41793
3 changed files with 66 additions and 0 deletions

View File

@ -25,6 +25,9 @@ function _insertItem(menu, trackerItem, position) {
if (trackerItem.get_is_separator()) {
let mapper = new RemoteMenuSeparatorItemMapper(trackerItem);
item = mapper.menuItem;
} else if (trackerItem.get_has_submenu()) {
let mapper = new RemoteMenuSubmenuItemMapper(trackerItem);
item = mapper.menuItem;
} else {
let mapper = new RemoteMenuItemMapper(trackerItem);
item = mapper.menuItem;
@ -57,6 +60,34 @@ const RemoteMenuSeparatorItemMapper = new Lang.Class({
},
});
const RemoteMenuSubmenuItemMapper = new Lang.Class({
Name: 'RemoteMenuSubmenuItemMapper',
_init: function(trackerItem) {
this._trackerItem = trackerItem;
this.menuItem = new PopupMenu.PopupSubMenuMenuItem('');
this._trackerItem.connect('notify::label', Lang.bind(this, this._updateLabel));
this._updateLabel();
this._tracker = Shell.MenuTracker.new_for_item_submenu(this._trackerItem,
_insertItem.bind(null, this.menuItem.menu),
_removeItem.bind(null, this.menuItem.menu));
this.menuItem.connect('destroy', function() {
trackerItem.run_dispose();
});
},
destroy: function() {
this._tracker.destroy();
this.parent();
},
_updateLabel: function() {
this.menuItem.label.text = stripMnemonics(this._trackerItem.label);
},
});
const RemoteMenuItemMapper = new Lang.Class({
Name: 'RemoteMenuItemMapper',

View File

@ -106,6 +106,33 @@ shell_menu_tracker_new (GtkActionObservable *observable,
return tracker;
}
ShellMenuTracker *
shell_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
ShellMenuTrackerInsertFunc insert_func,
gpointer insert_user_data,
GDestroyNotify insert_notify,
ShellMenuTrackerRemoveFunc remove_func,
gpointer remove_user_data,
GDestroyNotify remove_notify)
{
ShellMenuTracker *tracker = g_slice_new0 (ShellMenuTracker);
tracker->ref_count = 1;
tracker->insert_func = insert_func;
tracker->insert_user_data = insert_user_data;
tracker->insert_notify = insert_notify;
tracker->remove_func = remove_func;
tracker->remove_user_data = remove_user_data;
tracker->remove_notify = remove_notify;
tracker->tracker = gtk_menu_tracker_new_for_item_submenu (item,
shell_menu_tracker_insert_func,
shell_menu_tracker_remove_func,
tracker);
return tracker;
}
ShellMenuTracker *
shell_menu_tracker_ref (ShellMenuTracker *tracker)
{

View File

@ -47,6 +47,14 @@ ShellMenuTracker * shell_menu_tracker_new (GtkActionObservable *observabl
ShellMenuTrackerRemoveFunc remove_func,
gpointer remove_user_data,
GDestroyNotify remove_notify);
ShellMenuTracker * shell_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
ShellMenuTrackerInsertFunc insert_func,
gpointer insert_user_data,
GDestroyNotify insert_notify,
ShellMenuTrackerRemoveFunc remove_func,
gpointer remove_user_data,
GDestroyNotify remove_notify);
ShellMenuTracker * shell_menu_tracker_ref (ShellMenuTracker *tracker);
void shell_menu_tracker_unref (ShellMenuTracker *tracker);
void shell_menu_tracker_destroy (ShellMenuTracker *tracker);