[gnome-shell] [appDisplay] Unify Inactive/RunningWellItem, split into AppIcon, AppWellIcon



commit f5f92b2e7993a023ea0f868ff510109a5a26ed98
Author: Colin Walters <walters verbum org>
Date:   Tue Dec 8 12:51:05 2009 -0500

    [appDisplay] Unify Inactive/RunningWellItem, split into AppIcon, AppWellIcon
    
    The distinction between the inactive and running was silly; just
    have one class which can handle both running states.  However for
    a future search patch, we do want a separation between an icon which
    just has icon + name + glow, and a well icon which does the menu
    integration.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=603523

 js/ui/appDisplay.js |  220 ++++++++++++++++++++++++---------------------------
 js/ui/overview.js   |    2 +-
 2 files changed, 104 insertions(+), 118 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 6a88e8c..651ab3a 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -221,19 +221,20 @@ AppDisplay.prototype = {
 Signals.addSignalMethods(AppDisplay.prototype);
 
 
-function BaseWellItem(app, isFavorite) {
-    this._init(app, isFavorite);
+function AppIcon(app) {
+    this._init(app);
 }
 
-BaseWellItem.prototype = {
-    _init : function(app, isFavorite) {
+AppIcon.prototype = {
+    _init : function(app) {
         this.app = app;
 
         this._glowExtendVertical = 0;
         this._glowShrinkHorizontal = 0;
 
-        this.actor = new St.Clickable({ style_class: 'app-well-app',
-                                         reactive: true });
+        this.actor = new St.Bin({ style_class: 'app-icon',
+                                  x_fill: true,
+                                  y_fill: true });
         this.actor._delegate = this;
         this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
         this._workId = Main.initializeDeferredWork(this.actor, Lang.bind(this, this._rerenderGlow));
@@ -241,10 +242,6 @@ BaseWellItem.prototype = {
         let box = new St.BoxLayout({ vertical: true });
         this.actor.set_child(box);
 
-        this.actor.connect('clicked', Lang.bind(this, this._onClicked));
-
-        this._menu = null;
-
         this.icon = this.app.create_icon_texture(APPICON_SIZE);
 
         box.add(this.icon, { expand: true, x_fill: false, y_fill: false });
@@ -265,13 +262,6 @@ BaseWellItem.prototype = {
         this._appWindowChangedId = this.app.connect('windows-changed', Lang.bind(this, this._queueRerenderGlow));
 
         box.add(nameBox);
-
-        this._draggable = DND.makeDraggable(this.actor, true);
-        this._dragStartX = null;
-        this._dragStartY = null;
-
-        this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress));
-        this.actor.connect('notify::hover', Lang.bind(this, this._onHoverChange));
     },
 
     _nameBoxGetPreferredWidth: function (nameBox, forHeight, alloc) {
@@ -322,6 +312,19 @@ BaseWellItem.prototype = {
         Main.queueDeferredWork(this._workId);
     },
 
+    _onStyleChanged: function() {
+        let themeNode = this._glowBox.get_theme_node();
+
+        let success, len;
+        [success, len] = themeNode.get_length('-shell-glow-extend-vertical', false);
+        if (success)
+            this._glowExtendVertical = len;
+        [success, len] = themeNode.get_length('-shell-glow-shrink-horizontal', false);
+        if (success)
+            this._glowShrinkHorizontal = len;
+        this.actor.queue_relayout();
+    },
+
     _rerenderGlow: function() {
         this._glowBox.destroy_children();
         let glowPath = GLib.filename_to_uri(global.imagedir + 'app-well-glow.png', '');
@@ -332,6 +335,34 @@ BaseWellItem.prototype = {
             glow.keep_aspect_ratio = false;
             this._glowBox.add(glow);
         }
+    }
+}
+
+function AppWellIcon(app) {
+    this._init(app);
+}
+
+AppWellIcon.prototype = {
+    _init : function(app) {
+        this.app = app;
+        this.actor = new St.Clickable({ style_class: 'app-well-app',
+                                         reactive: true,
+                                         x_fill: true,
+                                         y_fill: true });
+        this.actor._delegate = this;
+
+        this._icon = new AppIcon(app);
+        this.actor.set_child(this._icon.actor);
+
+        this.actor.connect('clicked', Lang.bind(this, this._onClicked));
+        this._menu = null;
+
+        this._draggable = DND.makeDraggable(this.actor, true);
+        this._dragStartX = null;
+        this._dragStartY = null;
+
+        this.actor.connect('button-press-event', Lang.bind(this, this._onButtonPress));
+        this.actor.connect('notify::hover', Lang.bind(this, this._onHoverChange));
     },
 
     _onButtonPress: function(actor, event) {
@@ -366,19 +397,6 @@ BaseWellItem.prototype = {
         return false;
     },
 
-    _onStyleChanged: function() {
-        let themeNode = this._glowBox.get_theme_node();
-
-        let success, len;
-        [success, len] = themeNode.get_length('-shell-glow-extend-vertical', false);
-        if (success)
-            this._glowExtendVertical = len;
-        [success, len] = themeNode.get_length('-shell-glow-shrink-horizontal', false);
-        if (success)
-            this._glowShrinkHorizontal = len;
-        this.actor.queue_relayout();
-    },
-
     popupMenu: function(activatingButton) {
         if (!this._menu) {
             this._menu = new AppIconMenu(this);
@@ -402,13 +420,60 @@ BaseWellItem.prototype = {
         return false;
     },
 
-    // Default implementations; AppDisplay.RunningWellItem overrides these
-    highlightWindow: function(window) {
-        this.emit('highlight-window', window);
+    activateMostRecentWindow: function () {
+        let mostRecentWindow = this.app.get_windows()[0];
+        Main.overview.activateWindow(mostRecentWindow, Main.currentTime());
+    },
+
+    highlightWindow: function(metaWindow) {
+        if (!this._getRunning())
+            return;
+        Main.overview.getWorkspacesForWindow(metaWindow).setHighlightWindow(metaWindow);
+    },
+
+    activateWindow: function(metaWindow) {
+        if (metaWindow) {
+            this._didActivateWindow = true;
+            Main.overview.activateWindow(metaWindow, Main.currentTime());
+        } else
+            Main.overview.hide();
     },
 
-    activateWindow: function(window) {
-        this.emit('activate-window', window);
+    _onMenuPoppedUp: function() {
+        if (this._getRunning()) {
+            Main.overview.getWorkspacesForWindow(null).setApplicationWindowSelection(this.app.get_id());
+            this._setWindowSelection = true;
+        }
+    },
+
+    _onMenuPoppedDown: function() {
+        if (this._didActivateWindow)
+            return;
+        if (!this._setWindowSelection)
+            return;
+
+        Main.overview.getWorkspacesForWindow(null).setApplicationWindowSelection(null);
+        this._setWindowSelection = false;
+    },
+
+    _getRunning: function() {
+        return this.app.get_windows().length > 0;
+    },
+
+    _onActivate: function (event) {
+        let running = this._getRunning();
+
+        if (!running) {
+            this.app.launch();
+        } else {
+            let modifiers = Shell.get_event_state(event);
+
+            if (modifiers & Clutter.ModifierType.CONTROL_MASK) {
+                this.app.launch();
+            } else {
+                this.activateMostRecentWindow();
+            }
+        }
     },
 
     shellWorkspaceLaunch : function() {
@@ -433,7 +498,7 @@ BaseWellItem.prototype = {
         return this.actor;
     }
 }
-Signals.addSignalMethods(BaseWellItem.prototype);
+Signals.addSignalMethods(AppWellIcon.prototype);
 
 function AppIconMenu(source) {
     this._init(source);
@@ -733,80 +798,6 @@ AppIconMenu.prototype = {
 };
 Signals.addSignalMethods(AppIconMenu.prototype);
 
-function RunningWellItem(app, isFavorite) {
-    this._init(app, isFavorite);
-}
-
-RunningWellItem.prototype = {
-    __proto__: BaseWellItem.prototype,
-
-    _init: function(app, isFavorite) {
-        BaseWellItem.prototype._init.call(this, app, isFavorite);
-    },
-
-    _onActivate: function (event) {
-        let modifiers = Shell.get_event_state(event);
-
-        if (modifiers & Clutter.ModifierType.CONTROL_MASK) {
-            this.app.launch();
-        } else {
-            this.activateMostRecentWindow();
-        }
-    },
-
-    activateMostRecentWindow: function () {
-        let mostRecentWindow = this.app.get_windows()[0];
-        Main.overview.activateWindow(mostRecentWindow, global.get_current_time());
-    },
-
-    highlightWindow: function(metaWindow) {
-        Main.overview.getWorkspacesForWindow(metaWindow).setHighlightWindow(metaWindow);
-    },
-
-    activateWindow: function(metaWindow) {
-        if (metaWindow) {
-            this._didActivateWindow = true;
-            Main.overview.activateWindow(metaWindow, global.get_current_time());
-        } else
-            Main.overview.hide();
-    },
-
-    _onMenuPoppedUp: function() {
-        Main.overview.getWorkspacesForWindow(null).setApplicationWindowSelection(this.app.get_id());
-    },
-
-    _onMenuPoppedDown: function() {
-        if (this._didActivateWindow)
-            return;
-
-        Main.overview.getWorkspacesForWindow(null).setApplicationWindowSelection(null);
-    }
-};
-
-function InactiveWellItem(app, isFavorite) {
-    this._init(app, isFavorite);
-}
-
-InactiveWellItem.prototype = {
-    __proto__: BaseWellItem.prototype,
-
-    _init : function(app, isFavorite) {
-        BaseWellItem.prototype._init.call(this, app, isFavorite);
-    },
-
-    _onActivate: function(event) {
-        this.app.launch();
-        Main.overview.hide();
-        return true;
-    },
-
-    _onMenuPoppedUp: function() {
-    },
-
-    _onMenuPoppedDown: function() {
-    }
-};
-
 function WellGrid() {
     this._init();
 }
@@ -986,12 +977,7 @@ AppWell.prototype = {
         let nFavorites = 0;
         for (let id in favorites) {
             let app = favorites[id];
-            let display;
-            if (app.get_windows().length > 0) {
-                display = new RunningWellItem(app, true);
-            } else {
-                display = new InactiveWellItem(app, true);
-            }
+            let display = new AppWellIcon(app);
             this._grid.addItem(display.actor);
             nFavorites++;
         }
@@ -1000,7 +986,7 @@ AppWell.prototype = {
             let app = running[i];
             if (app.get_id() in favorites)
                 continue;
-            let display = new RunningWellItem(app, false);
+            let display = new AppWellIcon(app);
             this._grid.addItem(display.actor);
         }
 
diff --git a/js/ui/overview.js b/js/ui/overview.js
index 1b13a5d..74859a7 100644
--- a/js/ui/overview.js
+++ b/js/ui/overview.js
@@ -248,7 +248,7 @@ Overview.prototype = {
     // This allows the user to place the item on any workspace.
     handleDragOver : function(source, actor, x, y, time) {
         if (source instanceof GenericDisplay.GenericDisplayItem
-            || source instanceof AppDisplay.BaseWellItem) {
+            || source instanceof AppDisplay.AppIcon) {
             if (this._activeDisplayPane != null)
                 this._activeDisplayPane.close();
             return true;



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