Update visibility of controls on view change.

https://bugzilla.gnome.org/show_bug.cgi?id=610191
This commit is contained in:
Maxim Ermilov 2010-04-16 17:38:21 +04:00
parent 5012d64580
commit 54168fcd31

View File

@ -1378,6 +1378,9 @@ WorkspacesControls.prototype = {
this._nWorkspacesNotifyId = this._nWorkspacesNotifyId =
global.screen.connect('notify::n-workspaces', global.screen.connect('notify::n-workspaces',
Lang.bind(this, this._workspacesChanged)); Lang.bind(this, this._workspacesChanged));
this._switchWorkspaceNotifyId =
global.window_manager.connect('switch-workspace',
Lang.bind(this, this.updateControlsSensitivity));
this._workspacesChanged(); this._workspacesChanged();
}, },
@ -1385,6 +1388,8 @@ WorkspacesControls.prototype = {
updateControls: function(view) { updateControls: function(view) {
this._currentView = view; this._currentView = view;
this.updateControlsSensitivity();
let newControls = this._currentView.createControllerBar(); let newControls = this._currentView.createControllerBar();
if (newControls) { if (newControls) {
this._viewControls.child = newControls; this._viewControls.child = newControls;
@ -1425,19 +1430,15 @@ WorkspacesControls.prototype = {
this._gconf.set_string(WORKSPACES_VIEW_KEY, view); this._gconf.set_string(WORKSPACES_VIEW_KEY, view);
}, },
setCanRemove: function(canRemove) {
this._setButtonSensitivity(this._removeButton, canRemove);
},
setCanAdd: function(canAdd) {
this._setButtonSensitivity(this._addButton, canAdd);
},
_onDestroy: function() { _onDestroy: function() {
if (this._nWorkspacesNotifyId > 0) { if (this._nWorkspacesNotifyId > 0) {
global.screen.disconnect(this._nWorkspacesNotifyId); global.screen.disconnect(this._nWorkspacesNotifyId);
this._nWorkspacesNotifyId = 0; this._nWorkspacesNotifyId = 0;
} }
if (this._switchWorkspaceNotifyId > 0) {
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
this._switchWorkspaceNotifyId = 0;
}
}, },
_setButtonSensitivity: function(button, sensitive) { _setButtonSensitivity: function(button, sensitive) {
@ -1447,11 +1448,19 @@ WorkspacesControls.prototype = {
button.opacity = sensitive ? 255 : 85; button.opacity = sensitive ? 255 : 85;
}, },
updateControlsSensitivity: function() {
if (this._currentView) {
this._setButtonSensitivity(this._removeButton, this._currentView.canRemoveWorkspace());
this._setButtonSensitivity(this._addButton, this._currentView.canAddWorkspace());
}
},
_workspacesChanged: function() { _workspacesChanged: function() {
if (global.screen.n_workspaces == 1) if (global.screen.n_workspaces == 1)
this._toggleViewButton.hide(); this._toggleViewButton.hide();
else else
this._toggleViewButton.show(); this._toggleViewButton.show();
this.updateControlsSensitivity();
} }
}; };
Signals.addSignalMethods(WorkspacesControls.prototype); Signals.addSignalMethods(WorkspacesControls.prototype);
@ -1485,10 +1494,6 @@ WorkspacesManager.prototype = {
this._nWorkspacesNotifyId = this._nWorkspacesNotifyId =
global.screen.connect('notify::n-workspaces', global.screen.connect('notify::n-workspaces',
Lang.bind(this, this._workspacesChanged)); Lang.bind(this, this._workspacesChanged));
this._switchWorkspaceNotifyId =
global.window_manager.connect('switch-workspace',
Lang.bind(this, this._updateControlsSensitivity));
}, },
_updateView: function() { _updateView: function() {
@ -1566,21 +1571,11 @@ WorkspacesManager.prototype = {
this.workspacesView.updateWorkspaces(oldNumWorkspaces, this.workspacesView.updateWorkspaces(oldNumWorkspaces,
newNumWorkspaces, newNumWorkspaces,
lostWorkspaces); lostWorkspaces);
this.controlsBar.setCanAdd(this.workspacesView.canAddWorkspace());
this.controlsBar.setCanRemove(this.workspacesView.canRemoveWorkspace());
},
_updateControlsSensitivity: function() {
this.controlsBar.setCanAdd(this.workspacesView.canAddWorkspace());
this.controlsBar.setCanRemove(this.workspacesView.canRemoveWorkspace());
}, },
_onDestroy: function() { _onDestroy: function() {
if (this._nWorkspacesNotifyId > 0) if (this._nWorkspacesNotifyId > 0)
global.screen.disconnect(this._nWorkspacesNotifyId); global.screen.disconnect(this._nWorkspacesNotifyId);
if (this._switchWorkspaceNotifyId > 0)
global.window_manager.disconnect(this._switchWorkspaceNotifyId);
if (this._viewChangedId > 0) if (this._viewChangedId > 0)
Shell.GConf.get_default().disconnect(this._viewChangedId); Shell.GConf.get_default().disconnect(this._viewChangedId);
for (let w = 0; w < this._workspaces.length; w++) { for (let w = 0; w < this._workspaces.length; w++) {