[gnome-shell/wip/gtkmenutrackeritem: 30/32] remoteMenu: Add support for submenu items
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/gtkmenutrackeritem: 30/32] remoteMenu: Add support for submenu items
- Date: Mon, 13 May 2013 20:07:41 +0000 (UTC)
commit 607e35dd864bfe35ebce9fcb0a271c34e2c098d9
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri May 10 13:39:21 2013 -0400
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.
js/ui/remoteMenu.js | 27 +++++++++++++++++++++++++++
src/shell-menu-tracker.c | 27 +++++++++++++++++++++++++++
src/shell-menu-tracker.h | 8 ++++++++
3 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/remoteMenu.js b/js/ui/remoteMenu.js
index fe09342..33e3c94 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;
@@ -53,6 +56,30 @@ 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));
+ },
+
+ 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 ac1c8b2..a208870 100644
--- a/src/shell-menu-tracker.c
+++ b/src/shell-menu-tracker.c
@@ -107,6 +107,33 @@ shell_menu_tracker_new (GtkActionObservable *observable,
}
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)
{
tracker->ref_count++;
diff --git a/src/shell-menu-tracker.h b/src/shell-menu-tracker.h
index df1482a..ea53930 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]