Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Uses a button rather than a menu, breaks translations
Browse files Browse the repository at this point in the history
The translations are currently broken because I removed the original string and replaced it with two tooltips
  • Loading branch information
Mystro256 committed May 17, 2012
1 parent c2851a7 commit 776de59
Showing 1 changed file with 66 additions and 35 deletions.
101 changes: 66 additions & 35 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,93 @@ let DisabledIcon = 'preferences-desktop-screensaver-symbolic';
let EnabledIcon = 'system-run-symbolic';
////An alternative icon could be 'action-unavailable-symbolic'

function init(extensionMeta) {
imports.gettext.bindtextdomain("gnome-shell-extension-inhibitapplet",
extensionMeta.path + "/locale");
}
const TOOLTIPON = _("Suspend Inhibited");
const TOOLTIPOFF = _("Suspend Enabled");
const ROLE = 'inhibitbutton';

function InhibitMenu() {
function InhibitButton() {
this._init.apply(this, arguments);
}

function enable() {
indicationmenu = new InhibitMenu();
Main.panel.addToStatusArea('inhibit-menu', indicationmenu);
}
InhibitButton.prototype = {
__proto__: PanelMenu.ButtonBox.prototype,

__proto__: PanelMenu.ButtonBox.prototype,

InhibitMenu.prototype = {
__proto__: PanelMenu.SystemStatusButton.prototype,
_init: function(metadata, params)
{
PanelMenu.ButtonBox.prototype._init.call(this, {
reactive: true,
can_focus: true,
track_hover: true
});

_init: function() {
PanelMenu.SystemStatusButton.prototype._init.call(this, DisabledIcon);
this.temp = new St.Icon({
icon_name: DisabledIcon,
icon_type: St.IconType.SYMBOLIC,
style_class: 'system-status-icon'
});

this.actor.add_actor(this.temp);

this.actor.add_style_class_name('panel-status-button');
this.actor.has_tooltip = true;
this.actor.tooltip_text = TOOLTIPOFF;

///Power Setting
InhibitMenu._powerSettings = new Gio.Settings({ schema: POWER_SCHEMA });
var powerManagementFlag = InhibitMenu._powerSettings.get_boolean(POWER_KEY);
this._powerSettings = new Gio.Settings({ schema: POWER_SCHEMA });
var powerManagementFlag = this._powerSettings.get_boolean(POWER_KEY);
///ScreenSaver Setting
InhibitMenu._screenSettings = new Gio.Settings({ schema: SCREEN_SCHEMA });
this._screenSettings = new Gio.Settings({ schema: SCREEN_SCHEMA });
//Make sure the screensaver enable is synchronized
InhibitMenu._screenSettings.set_boolean(SCREEN_KEY, powerManagementFlag);

//Add the Inhibit Option
this._inhibitswitch = new PopupMenu.PopupSwitchMenuItem(_("Inhibit Suspend"), !powerManagementFlag);
this.menu.addMenuItem(this._inhibitswitch);

this._screenSettings.set_boolean(SCREEN_KEY, powerManagementFlag);
//Change Icon if necessary
if(!powerManagementFlag) {
this.setIcon(EnabledIcon);
this.actor.tooltip_text = TOOLTIPON;
this.temp.icon_name = EnabledIcon;
}

this._inhibitswitch.connect('toggled', Lang.bind(this, function() {
var powerManagementFlag = InhibitMenu._powerSettings.get_boolean(POWER_KEY);
InhibitMenu._powerSettings.set_boolean(POWER_KEY, !powerManagementFlag);
InhibitMenu._screenSettings.set_boolean(SCREEN_KEY, !powerManagementFlag);
this.actor.connect('button-press-event', Lang.bind(this, function () {
var powerManagementFlag = this._powerSettings.get_boolean(POWER_KEY);
this._powerSettings.set_boolean(POWER_KEY, !powerManagementFlag);
this._screenSettings.set_boolean(SCREEN_KEY, !powerManagementFlag);
if(powerManagementFlag) {
this.setIcon(EnabledIcon);
this.actor.tooltip_text = TOOLTIPON;
this.temp.icon_name = EnabledIcon;
} else {
this.setIcon(DisabledIcon);
this.actor.tooltip_text = TOOLTIPOFF;
this.temp.icon_name = DisabledIcon;
}
}));
Main.panel._insertStatusItem(this.actor, 0);
Main.panel._statusArea[ROLE] = this;
},

destroy: function() {
if (indicationmenu._powerSettings) {
indicationmenu._powerSettings.set_boolean(POWER_KEY, true);
}
if (indicationmenu._screenSettings) {
indicationmenu._screenSettings.set_boolean(SCREEN_KEY, true);
}

Main.panel._statusArea[ROLE] = null;

this.actor._delegate = null;
this.actor.destroy();
this.actor.emit('destroy');
}
};

function init(extensionMeta) {
imports.gettext.bindtextdomain("gnome-shell-extension-inhibitapplet",
extensionMeta.path + "/locale");
}

function enable() {
indicationmenu = new InhibitButton();
}

function disable() {
indicationmenu.destroy();
if (InhibitMenu._powerSettings) {
InhibitMenu._powerSettings.set_boolean(POWER_KEY, true);
}
if (InhibitMenu._screenSettings) {
InhibitMenu._screenSettings.set_boolean(SCREEN_KEY, true);
}
}

0 comments on commit 776de59

Please sign in to comment.