From 9ba4790b4d5e07ed61bcaf31aab4d8c248ac0310 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Mon, 21 Nov 2011 19:01:05 +0100 Subject: [PATCH] AppDisplay: clean up handling of right click popup menu Instead of connecting a global activate handler on the menu, have one on each menu item, individually doing the right thing. https://bugzilla.gnome.org/show_bug.cgi?id=669603 --- js/ui/appDisplay.js | 58 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 19ba949ee..47ff948ab 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -1457,8 +1457,6 @@ const AppIconMenu = new Lang.Class({ this._source = source; - this.connect('activate', Lang.bind(this, this._onActivate)); - this.actor.add_style_class_name('app-well-menu'); // Chain our visibility and lifecycle to that of the source @@ -1484,25 +1482,43 @@ const AppIconMenu = new Lang.Class({ let separatorShown = windows.length > 0 && windows[0].get_workspace() != activeWorkspace; for (let i = 0; i < windows.length; i++) { - if (!separatorShown && windows[i].get_workspace() != activeWorkspace) { + let window = windows[i]; + if (!separatorShown && window.get_workspace() != activeWorkspace) { this._appendSeparator(); separatorShown = true; } - let item = this._appendMenuItem(windows[i].title); - item._window = windows[i]; + let item = this._appendMenuItem(window.title); + item.connect('activate', Lang.bind(this, function() { + this.emit('activate-window', window); + })); } if (!this._source.app.is_window_backed()) { - if (windows.length > 0) - this._appendSeparator(); + this._appendSeparator(); + + this._newWindowMenuItem = this._appendMenuItem(_("New Window")); + this._newWindowMenuItem.connect('activate', Lang.bind(this, function() { + this._source.app.open_new_window(-1); + this.emit('activate-window', null); + })); + + this._appendSeparator(); let isFavorite = AppFavorites.getAppFavorites().isFavorite(this._source.app.get_id()); - this._newWindowMenuItem = this._appendMenuItem(_("New Window")); - this._appendSeparator(); - - this._toggleFavoriteMenuItem = this._appendMenuItem(isFavorite ? _("Remove from Favorites") - : _("Add to Favorites")); + if (isFavorite) { + let item = this._appendMenuItem(_("Remove from Favorites")); + item.connect('activate', Lang.bind(this, function() { + let favs = AppFavorites.getAppFavorites(); + favs.removeFavorite(this._source.app.get_id()); + })); + } else { + let item = this._appendMenuItem(_("Add to Favorites")); + item.connect('activate', Lang.bind(this, function() { + let favs = AppFavorites.getAppFavorites(); + favs.addFavorite(this._source.app.get_id()); + })); + } } }, @@ -1521,24 +1537,6 @@ const AppIconMenu = new Lang.Class({ popup: function(activatingButton) { this._redisplay(); this.open(); - }, - - _onActivate: function (actor, child) { - if (child._window) { - let metaWindow = child._window; - this.emit('activate-window', metaWindow); - } else if (child == this._newWindowMenuItem) { - this._source.app.open_new_window(-1); - this.emit('activate-window', null); - } else if (child == this._toggleFavoriteMenuItem) { - let favs = AppFavorites.getAppFavorites(); - let isFavorite = favs.isFavorite(this._source.app.get_id()); - if (isFavorite) - favs.removeFavorite(this._source.app.get_id()); - else - favs.addFavorite(this._source.app.get_id()); - } - this.close(); } }); Signals.addSignalMethods(AppIconMenu.prototype);