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
This commit is contained in:
Marina Zhurakhinskaya 2010-05-13 14:29:00 -04:00
parent ec6bc8f216
commit 4ce2620b68
3 changed files with 38 additions and 33 deletions

View File

@ -459,10 +459,12 @@ AppWellIcon.prototype = {
this._onActivate(event); this._onActivate(event);
} else if (button == 2) { } else if (button == 2) {
let newWorkspace = Main.overview.workspaces.addWorkspace(); let newWorkspace = Main.overview.workspaces.addWorkspace();
if (newWorkspace != null) {
newWorkspace.activate(global.get_current_time()); newWorkspace.activate(global.get_current_time());
this.emit('launching'); this.emit('launching');
this.app.open_new_window(); this.app.open_new_window();
Main.overview.hide(); Main.overview.hide();
}
} else if (button == 3) { } else if (button == 3) {
// Don't bind to the right click here; we want left click outside the // Don't bind to the right click here; we want left click outside the
// area to deactivate as well. // area to deactivate as well.

View File

@ -11,6 +11,8 @@ const Pango = imports.gi.Pango;
const Shell = imports.gi.Shell; const Shell = imports.gi.Shell;
const St = imports.gi.St; const St = imports.gi.St;
const Signals = imports.signals; const Signals = imports.signals;
const Gettext = imports.gettext.domain('gnome-shell');
const _ = Gettext.gettext;
const DND = imports.ui.dnd; const DND = imports.ui.dnd;
const Lightbox = imports.ui.lightbox; const Lightbox = imports.ui.lightbox;
@ -233,15 +235,31 @@ GenericWorkspacesView.prototype = {
}, },
addWorkspace: function() { 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"); throw new Error("Not implemented");
}, },
canRemoveWorkspace: function() { canRemoveWorkspace: function() {
throw new Error("Not implemented"); return this._getWorkspaceIndexToRemove() > 0;
}, },
removeWorkspace: function() { 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() { updateWorkspaces: function() {
@ -261,7 +279,9 @@ GenericWorkspacesView.prototype = {
}, },
_acceptNewWorkspaceDrop: function(source, dropActor, x, y, time) { _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); return this.acceptNewWorkspaceDrop(source, dropActor, x, y, time);
} }
}; };
@ -444,19 +464,8 @@ MosaicView.prototype = {
return null; return null;
}, },
addWorkspace: function() { _getWorkspaceIndexToRemove: function() {
return global.screen.append_new_workspace(false, global.get_current_time()); return this._workspaces.length - 1;
},
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());
} }
}; };
@ -1377,10 +1386,6 @@ SingleView.prototype = {
return actor; return actor;
}, },
canRemoveWorkspace: function() {
return global.screen.get_active_workspace_index() != 0;
},
_updatePanelVisibility: function() { _updatePanelVisibility: function() {
let showSwitches = (global.screen.n_workspaces > 1); let showSwitches = (global.screen.n_workspaces > 1);
if (this._scroll != null) { if (this._scroll != null) {
@ -1392,17 +1397,15 @@ SingleView.prototype = {
}, },
addWorkspace: function() { addWorkspace: function() {
let ws = global.screen.append_new_workspace(false, let ws = GenericWorkspacesView.prototype.addWorkspace.call(this);
global.get_current_time()); if (ws != null)
ws.activate(global.get_current_time()); ws.activate(global.get_current_time());
return ws; return ws;
}, },
removeWorkspace: function() { _getWorkspaceIndexToRemove: function() {
let removedIndex = global.screen.get_active_workspace_index(); return global.screen.get_active_workspace_index();
let metaWorkspace = this._workspaces[removedIndex].metaWorkspace;
global.screen.remove_workspace(metaWorkspace,
global.get_current_time());
} }
}; };
@ -1531,7 +1534,6 @@ WorkspacesControls.prototype = {
_setButtonSensitivity: function(button, sensitive) { _setButtonSensitivity: function(button, sensitive) {
if (button == null) if (button == null)
return; return;
button.reactive = sensitive;
button.opacity = sensitive ? 255 : 85; button.opacity = sensitive ? 255 : 85;
}, },

View File

@ -12,6 +12,7 @@ js/ui/placeDisplay.js
js/ui/runDialog.js js/ui/runDialog.js
js/ui/statusMenu.js js/ui/statusMenu.js
js/ui/windowAttentionHandler.js js/ui/windowAttentionHandler.js
js/ui/workspacesView.js
src/gdmuser/gdm-user.c src/gdmuser/gdm-user.c
src/shell-global.c src/shell-global.c
src/shell-uri-util.c src/shell-uri-util.c