[gnome-shell] Don't add a new workspace when the maximum workspaces limit is reached



commit 4ce2620b68d380d2d3c38df333ed6a2b5a44a855
Author: Marina Zhurakhinskaya <marinaz redhat com>
Date:   Thu May 13 14:29:00 2010 -0400

    Don't add a new workspace when the maximum workspaces limit is reached
    
    It was previously possible to add a workspace above the maximum workspaces
    limit by dragging an item to the "add workspace" button or using the middle
    mouse button click.
    
    Provide the user with feedback in the info bar when it is not possible to create
    a new workspace or remove the current workspace.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=591645

 js/ui/appDisplay.js     |   10 ++++---
 js/ui/workspacesView.js |   60 ++++++++++++++++++++++++----------------------
 po/POTFILES.in          |    1 +
 3 files changed, 38 insertions(+), 33 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 29aeaa8..acc12fc 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -459,10 +459,12 @@ AppWellIcon.prototype = {
             this._onActivate(event);
         } else if (button == 2) {
             let newWorkspace = Main.overview.workspaces.addWorkspace();
-            newWorkspace.activate(global.get_current_time());
-            this.emit('launching');
-            this.app.open_new_window();
-            Main.overview.hide();
+            if (newWorkspace != null) {
+                newWorkspace.activate(global.get_current_time());
+                this.emit('launching');
+                this.app.open_new_window();
+                Main.overview.hide();
+            }
         } else if (button == 3) {
             // Don't bind to the right click here; we want left click outside the
             // area to deactivate as well.
diff --git a/js/ui/workspacesView.js b/js/ui/workspacesView.js
index 8624cee..7ba13b9 100644
--- a/js/ui/workspacesView.js
+++ b/js/ui/workspacesView.js
@@ -11,6 +11,8 @@ const Pango = imports.gi.Pango;
 const Shell = imports.gi.Shell;
 const St = imports.gi.St;
 const Signals = imports.signals;
+const Gettext = imports.gettext.domain('gnome-shell');
+const _ = Gettext.gettext;
 
 const DND = imports.ui.dnd;
 const Lightbox = imports.ui.lightbox;
@@ -233,15 +235,31 @@ GenericWorkspacesView.prototype = {
     },
 
     addWorkspace: function() {
+        if (!this.canAddWorkspace()) {
+            Main.overview.infoBar.setMessage(_("Can't add a new workspace because maximum workspaces limit has been reached."));
+            return null;
+        }
+
+        return global.screen.append_new_workspace(false, global.get_current_time());
+    },
+
+    _getWorkspaceIndexToRemove: function() {
         throw new Error("Not implemented");
     },
 
     canRemoveWorkspace: function() {
-        throw new Error("Not implemented");
+        return this._getWorkspaceIndexToRemove() > 0;
     },
 
     removeWorkspace: function() {
-        throw new Error("Not implemented");
+        if (!this.canRemoveWorkspace()) {
+            Main.overview.infoBar.setMessage(_("Can't remove the first workspace."));
+            return;
+        }
+        let index = this._getWorkspaceIndexToRemove();
+        let metaWorkspace = this._workspaces[index].metaWorkspace;
+        global.screen.remove_workspace(metaWorkspace,
+                                       global.get_current_time());
     },
 
     updateWorkspaces: function() {
@@ -261,7 +279,9 @@ GenericWorkspacesView.prototype = {
     },
 
     _acceptNewWorkspaceDrop: function(source, dropActor, x, y, time) {
-        this.addWorkspace();
+        let ws = this.addWorkspace();
+        if (ws == null)
+            return false;
         return this.acceptNewWorkspaceDrop(source, dropActor, x, y, time);
     }
 };
@@ -444,19 +464,8 @@ MosaicView.prototype = {
         return null;
     },
 
-    addWorkspace: function() {
-        return global.screen.append_new_workspace(false, global.get_current_time());
-    },
-
-    canRemoveWorkspace: function() {
-        return global.screen.n_workspaces > 1;
-    },
-
-    removeWorkspace: function() {
-        let removedIndex = this._workspaces.length - 1;
-        let metaWorkspace = this._workspaces[removedIndex].metaWorkspace;
-        global.screen.remove_workspace(metaWorkspace,
-                                       global.get_current_time());
+    _getWorkspaceIndexToRemove: function() {
+        return this._workspaces.length - 1;
     }
 };
 
@@ -1377,10 +1386,6 @@ SingleView.prototype = {
         return actor;
     },
 
-    canRemoveWorkspace: function() {
-        return global.screen.get_active_workspace_index() != 0;
-    },
-
     _updatePanelVisibility: function() {
         let showSwitches = (global.screen.n_workspaces > 1);
         if (this._scroll != null) {
@@ -1392,17 +1397,15 @@ SingleView.prototype = {
     },
 
     addWorkspace: function() {
-        let ws = global.screen.append_new_workspace(false,
-                                                    global.get_current_time());
-        ws.activate(global.get_current_time());
+        let ws = GenericWorkspacesView.prototype.addWorkspace.call(this);
+        if (ws != null)
+            ws.activate(global.get_current_time());
+
         return ws;
     },
 
-    removeWorkspace: function() {
-        let removedIndex = global.screen.get_active_workspace_index();
-        let metaWorkspace = this._workspaces[removedIndex].metaWorkspace;
-        global.screen.remove_workspace(metaWorkspace,
-                                       global.get_current_time());
+    _getWorkspaceIndexToRemove: function() {
+        return global.screen.get_active_workspace_index();
     }
 };
 
@@ -1531,7 +1534,6 @@ WorkspacesControls.prototype = {
     _setButtonSensitivity: function(button, sensitive) {
         if (button == null)
             return;
-        button.reactive = sensitive;
         button.opacity = sensitive ? 255 : 85;
     },
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f770ea1..22936bc 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ js/ui/placeDisplay.js
 js/ui/runDialog.js
 js/ui/statusMenu.js
 js/ui/windowAttentionHandler.js
+js/ui/workspacesView.js
 src/gdmuser/gdm-user.c
 src/shell-global.c
 src/shell-uri-util.c



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