[gnome-shell] messageTray: Add context menu



commit 9133f6d352c283387650a433feaff6e126ab6fa4
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Sun Feb 10 11:48:13 2013 +0100

    messageTray: Add context menu
    
    Add a context menu to the tray that allows cleaning up sources
    and open the notification settings panel.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691035

 js/ui/messageTray.js |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index b9eec17..dae841f 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -1448,6 +1448,49 @@ const SummaryItem = new Lang.Class({
 });
 Signals.addSignalMethods(SummaryItem.prototype);
 
+const MessageTrayContextMenu = new Lang.Class({
+    Name: 'MessageTrayContextMenu',
+    Extends: PopupMenu.PopupMenu,
+
+    _init: function(tray) {
+        this._dummy = new St.Bin({ opacity: 0 });
+        Main.uiGroup.add_actor(this._dummy);
+
+        this.parent(this._dummy, 0, St.Side.BOTTOM);
+
+        this.addAction(_("Clear"), function() {
+            let toDestroy = [];
+            let sources = tray.getSources();
+            for (let i = 0; i < sources.length; i++) {
+                // We exclude trayIcons, chat and resident sources
+                if (sources[i].trayIcon ||
+                    sources[i].isChat ||
+                    sources[i].resident)
+                    continue;
+                toDestroy.push(sources[i]);
+            }
+
+            for (let i = 0; i < toDestroy.length; i++) {
+                toDestroy[i].destroy();
+            }
+
+            toDestroy = null;
+            tray.close();
+        });
+
+        let separator = new PopupMenu.PopupSeparatorMenuItem();
+        this.addMenuItem(separator);
+
+        let settingsItem = this.addSettingsAction(_("Notification Settings"), 'gnome-notifications-panel.desktop');
+        settingsItem.connect('activate', function() { tray.close(); });
+    },
+
+    setPosition: function(x, y) {
+        this._dummy.set_position(x, y);
+    }
+
+});
+
 const MessageTray = new Lang.Class({
     Name: 'MessageTray',
 
@@ -1629,6 +1672,36 @@ const MessageTray = new Lang.Class({
                                           y_expand: true });
         this.actor.add_actor(this._noMessages);
         this._updateNoMessagesLabel();
+
+        this._contextMenu = new MessageTrayContextMenu(this);
+        this._grabHelper.addActor(this._contextMenu.actor);
+        this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
+            let button = event.get_button();
+            if (button == 3) {
+                let [stageX, stageY] = event.get_coords();
+                this._lock();
+                this._contextMenu.setPosition(Math.round(stageX), Math.round(stageY));
+                this._grabHelper.grab({ actor: this._contextMenu.actor,
+                                        grabFocus: true,
+                                        onUngrab: Lang.bind(this, function () {
+                                            this._unlock();
+                                            this._contextMenu.close();
+                                        })
+                });
+                this._contextMenu.open();
+            }
+            else {
+                this._grabHelper.ungrab({ actor: this._contextMenu.actor });
+            }
+        }));
+
+        this._contextMenu.actor.hide();
+        Main.layoutManager.addChrome(this._contextMenu.actor);
+
+    },
+
+    close: function() {
+        this._escapeTray();
     },
 
     _setupTrayDwellIfNeeded: function() {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]