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