From 8891a417937a70c3a7da71a7f2113052efd5199e Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Fri, 10 May 2013 13:39:21 -0400 Subject: [PATCH] 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 --- js/ui/remoteMenu.js | 31 +++++++++++++++++++++++++++++++ src/shell-menu-tracker.c | 27 +++++++++++++++++++++++++++ src/shell-menu-tracker.h | 8 ++++++++ 3 files changed, 66 insertions(+) diff --git a/js/ui/remoteMenu.js b/js/ui/remoteMenu.js index 7d6d7e0af..09ae06659 100644 --- a/js/ui/remoteMenu.js +++ b/js/ui/remoteMenu.js @@ -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', diff --git a/src/shell-menu-tracker.c b/src/shell-menu-tracker.c index ac1c8b23c..a20887004 100644 --- a/src/shell-menu-tracker.c +++ b/src/shell-menu-tracker.c @@ -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) { diff --git a/src/shell-menu-tracker.h b/src/shell-menu-tracker.h index df1482a42..ea5393031 100644 --- a/src/shell-menu-tracker.h +++ b/src/shell-menu-tracker.h @@ -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);