Refactor show()/hide() sequences

We seem to have a lot of code that does something along the lines of:

    if (condition)
        actor.show();
    else
        actor.hide();

ClutterActor already has such a thing for exactly this purpose: the 'visible'
property. Use it instead of the mess above.

https://bugzilla.gnome.org/show_bug.cgi?id=672272
This commit is contained in:
Jasper St. Pierre 2012-03-16 18:53:14 -04:00
parent e333263fd6
commit 723a1c843a
7 changed files with 19 additions and 74 deletions

View File

@ -60,10 +60,8 @@ const PowerMenuButton = new Lang.Class({
}, },
_updateVisibility: function() { _updateVisibility: function() {
if (!this._haveSuspend && !this._haveShutdown && !this._haveRestart) let shouldBeVisible = (this._haveSuspend || this._haveShutdown || this._haveRestart);
this.actor.hide(); this.actor.visible = shouldBeVisible;
else
this.actor.show();
}, },
_updateHaveShutdown: function() { _updateHaveShutdown: function() {
@ -76,11 +74,7 @@ const PowerMenuButton = new Lang.Class({
else else
this._haveShutdown = false; this._haveShutdown = false;
if (this._haveShutdown) this._powerOffItem.actor.visible = this._haveShutdown;
this._powerOffItem.actor.show();
else
this._powerOffItem.actor.hide();
this._updateVisibility(); this._updateVisibility();
})); }));
} else { } else {
@ -91,12 +85,7 @@ const PowerMenuButton = new Lang.Class({
else else
this._haveShutdown = false; this._haveShutdown = false;
if (this._haveShutdown) { this._powerOffItem.actor.visible = this._haveShutdown;
this._powerOffItem.actor.show();
} else {
this._powerOffItem.actor.hide();
}
this._updateVisibility(); this._updateVisibility();
})); }));
} }
@ -112,11 +101,7 @@ const PowerMenuButton = new Lang.Class({
else else
this._haveRestart = false; this._haveRestart = false;
if (this._haveRestart) this._restartItem.actor.visible = this._haveRestart;
this._restartItem.actor.show();
else
this._restartItem.actor.hide();
this._updateVisibility(); this._updateVisibility();
})); }));
} else { } else {
@ -127,12 +112,7 @@ const PowerMenuButton = new Lang.Class({
else else
this._haveRestart = false; this._haveRestart = false;
if (this._haveRestart) { this._restartItem.actor.visible = this._haveRestart;
this._restartItem.actor.show();
} else {
this._restartItem.actor.hide();
}
this._updateVisibility(); this._updateVisibility();
})); }));
} }
@ -140,12 +120,7 @@ const PowerMenuButton = new Lang.Class({
_updateHaveSuspend: function() { _updateHaveSuspend: function() {
this._haveSuspend = this._upClient.get_can_suspend(); this._haveSuspend = this._upClient.get_can_suspend();
this._suspendItem.actor.visible = this._haveSuspend;
if (this._haveSuspend)
this._suspendItem.actor.show();
else
this._suspendItem.actor.hide();
this._updateVisibility(); this._updateVisibility();
}, },

View File

@ -1228,10 +1228,7 @@ const Crosshairs = new Lang.Class({
crosshairsActor = new Clutter.Clone({ source: this._actor }); crosshairsActor = new Clutter.Clone({ source: this._actor });
this._clones.push(crosshairsActor); this._clones.push(crosshairsActor);
} }
if (this._actor.visible) crosshairsActor.visible = this._actor.visible;
crosshairsActor.show();
else
crosshairsActor.hide();
container.add_actor(crosshairsActor); container.add_actor(crosshairsActor);
container.raise_child(magnifiedMouse, crosshairsActor); container.raise_child(magnifiedMouse, crosshairsActor);

View File

@ -106,10 +106,7 @@ const Indicator = new Lang.Class({
/* TRANSLATORS: this means that bluetooth was disabled by hardware rfkill */ /* TRANSLATORS: this means that bluetooth was disabled by hardware rfkill */
this._killswitch.setStatus(_("hardware disabled")); this._killswitch.setStatus(_("hardware disabled"));
if (has_adapter) this.actor.visible = has_adapter;
this.actor.show();
else
this.actor.hide();
if (on) { if (on) {
this._discoverable.actor.show(); this._discoverable.actor.show();

View File

@ -707,10 +707,7 @@ const NMDeviceWired = new Lang.Class({
// the device // the device
// we can do it here because addConnection and removeConnection // we can do it here because addConnection and removeConnection
// both call _createSection at some point // both call _createSection at some point
if (this._connections.length <= 1) this.section.actor.visible = this._connections.length <= 1;
this.section.actor.hide();
else
this.section.actor.show();
}, },
_createAutomaticConnection: function() { _createAutomaticConnection: function() {
@ -1038,13 +1035,8 @@ const NMDeviceWireless = new Lang.Class({
}, },
setEnabled: function(enabled) { setEnabled: function(enabled) {
if (enabled) { this.statusItem.actor.visible = enabled;
this.statusItem.actor.show(); this.section.actor.visible = enabled;
this.section.actor.show();
} else {
this.statusItem.actor.hide();
this.section.actor.hide();
}
}, },
activate: function() { activate: function() {

View File

@ -149,13 +149,9 @@ const Indicator = new Lang.Class({
} }
} }
} }
if (showInput) {
this._inputTitle.actor.show(); this._inputTitle.actor.visible = showInput;
this._inputSlider.actor.show(); this._inputSlider.actor.visible = showInput;
} else {
this._inputTitle.actor.hide();
this._inputSlider.actor.hide();
}
}, },
_volumeToIcon: function(volume) { _volumeToIcon: function(volume) {

View File

@ -554,18 +554,12 @@ const UserMenuButton = new Lang.Class({
_updateLogout: function() { _updateLogout: function() {
let allowLogout = !this._lockdownSettings.get_boolean(DISABLE_LOG_OUT_KEY); let allowLogout = !this._lockdownSettings.get_boolean(DISABLE_LOG_OUT_KEY);
if (allowLogout) this._logoutItem.actor.visible = allowLogout;
this._logoutItem.actor.show();
else
this._logoutItem.actor.hide();
}, },
_updateLockScreen: function() { _updateLockScreen: function() {
let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY); let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
if (allowLockScreen) this._logoutItem.actor.visible = allowLockScreen;
this._lockScreenItem.actor.show();
else
this._lockScreenItem.actor.hide();
}, },
_updateHaveShutdown: function() { _updateHaveShutdown: function() {
@ -584,10 +578,7 @@ const UserMenuButton = new Lang.Class({
if (!this._suspendOrPowerOffItem) if (!this._suspendOrPowerOffItem)
return; return;
if (!this._haveShutdown && !this._haveSuspend) this._suspendOrPowerOffItem.actor.visible = this._haveShutdown || this._haveSuspend;
this._suspendOrPowerOffItem.actor.hide();
else
this._suspendOrPowerOffItem.actor.show();
// If we can't suspend show Power Off... instead // If we can't suspend show Power Off... instead
// and disable the alt key // and disable the alt key

View File

@ -844,10 +844,7 @@ const WorkspacesDisplay = new Lang.Class({
if (!primaryView) if (!primaryView)
return; return;
primaryView.actor.opacity = opacity; primaryView.actor.opacity = opacity;
if (opacity == 0) primaryView.actor.visible = opacity != 0;
primaryView.actor.hide();
else
primaryView.actor.show();
})); }));
})); }));
}, },