Skip to content

Commit

Permalink
add toggle widget helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Nov 26, 2018
1 parent 6ef057d commit f5b90fa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 50 deletions.
8 changes: 8 additions & 0 deletions [email protected]/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ function isMaximized(win, matchState) {
case 'tiled': return primaryScreen && tileMaximized;
}
}

function toggleWidget(widget, hide) {
if (hide && widget.visible)
widget.hide();

if (!hide && !widget.visible)
widget.show();
}
16 changes: 7 additions & 9 deletions [email protected]/modules/activitiesButton.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const Lang = imports.lang;
const Shell = imports.gi.Shell;
const Main = imports.ui.main;
const Unite = imports.misc.extensionUtils.getCurrentExtension();
const Base = Unite.imports.module.BaseModule;
const Lang = imports.lang;
const Shell = imports.gi.Shell;
const Main = imports.ui.main;
const Unite = imports.misc.extensionUtils.getCurrentExtension();
const Base = Unite.imports.module.BaseModule;
const toggleWidget = Unite.imports.helpers.toggleWidget;

var ActivitiesButton = new Lang.Class({
Name: 'Unite.ActivitiesButton',
Expand Down Expand Up @@ -39,9 +40,6 @@ var ActivitiesButton = new Lang.Class({
if (!hidden && this._settings.get('show-desktop-name'))
hidden = !appMenu && !overview;

if (hidden)
this._container.hide();
else
this._container.show();
toggleWidget(this._container, hidden);
}
});
32 changes: 9 additions & 23 deletions [email protected]/modules/desktopName.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const Lang = imports.lang;
const St = imports.gi.St;
const Shell = imports.gi.Shell;
const Main = imports.ui.main;
const Unite = imports.misc.extensionUtils.getCurrentExtension();
const Base = Unite.imports.module.BaseModule;
const Lang = imports.lang;
const St = imports.gi.St;
const Shell = imports.gi.Shell;
const Main = imports.ui.main;
const Unite = imports.misc.extensionUtils.getCurrentExtension();
const Base = Unite.imports.module.BaseModule;
const toggleWidget = Unite.imports.helpers.toggleWidget;

var DesktopName = new Lang.Class({
Name: 'Unite.DesktopName',
Expand Down Expand Up @@ -53,16 +54,6 @@ var DesktopName = new Lang.Class({
return windows;
},

_toggleAppMenu(hide) {
let container = this.appMenu.container;

if (hide && container.visible)
container.hide();

if (!hide && !container.visible)
container.show();
},

_setLabelText() {
let text = this._settings.get('desktop-name-text');
this._labelText.set_text(text);
Expand All @@ -76,13 +67,8 @@ var DesktopName = new Lang.Class({
if (visible)
visible = visible && !this._visibleWindows();

if (visible) {
this._toggleAppMenu(true);
this._labelBox.show();
} else {
this._labelBox.hide();
this._toggleAppMenu(false);
}
toggleWidget(this._labelBox, !visible);
toggleWidget(this.appMenu.container, visible);
},

_createLabel() {
Expand Down
27 changes: 13 additions & 14 deletions [email protected]/modules/topIcons.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const Lang = imports.lang;
const System = imports.system;
const Clutter = imports.gi.Clutter;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const Unite = imports.misc.extensionUtils.getCurrentExtension();
const Base = Unite.imports.module.BaseModule;
const scaleSize = Unite.imports.helpers.scaleSize;
const Lang = imports.lang;
const System = imports.system;
const Clutter = imports.gi.Clutter;
const Shell = imports.gi.Shell;
const St = imports.gi.St;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const Unite = imports.misc.extensionUtils.getCurrentExtension();
const Base = Unite.imports.module.BaseModule;
const scaleSize = Unite.imports.helpers.scaleSize;
const toggleWidget = Unite.imports.helpers.toggleWidget;

var TopIcons = new Lang.Class({
Name: 'Unite.TopIcons',
Expand Down Expand Up @@ -103,10 +104,8 @@ var TopIcons = new Lang.Class({
},

_toggleContainer() {
if (this._iconsBoxLayout.get_n_children() == 0)
this._iconsContainer.actor.hide();
else
this._iconsContainer.actor.show();
let hidden = this._iconsBoxLayout.get_n_children() == 0;
toggleWidget(this._iconsContainer.actor, hidden);
},

_transformIcon(icon) {
Expand Down
6 changes: 2 additions & 4 deletions [email protected]/modules/windowButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const isWindow = Unite.imports.helpers.isWindow;
const isMaximized = Unite.imports.helpers.isMaximized;
const loadStyles = Unite.imports.helpers.loadStyles;
const unloadStyles = Unite.imports.helpers.unloadStyles;
const toggleWidget = Unite.imports.helpers.toggleWidget;

var WindowButtons = new Lang.Class({
Name: 'Unite.WindowButtons',
Expand Down Expand Up @@ -167,9 +168,6 @@ var WindowButtons = new Lang.Class({
visible = running && !overview;
}

if (visible)
this._buttonsActor.show();
else
this._buttonsActor.hide();
toggleWidget(this._buttonsActor, !visible);
}
});

0 comments on commit f5b90fa

Please sign in to comment.