Improve panel buttons
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: 2020, 2021 Romain Vigier <contact AT romainvigier.fr>
|
// SPDX-FileCopyrightText: 2020-2022 Romain Vigier <contact AT romainvigier.fr>
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
|
const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
|
||||||
@@ -8,7 +8,7 @@ const Signals = imports.signals;
|
|||||||
const { main } = imports.ui;
|
const { main } = imports.ui;
|
||||||
|
|
||||||
const { Button: PanelMenuButton } = imports.ui.panelMenu;
|
const { Button: PanelMenuButton } = imports.ui.panelMenu;
|
||||||
const { PopupBaseMenuItem } = imports.ui.popupMenu;
|
const { PopupMenuItem, PopupSubMenuMenuItem } = imports.ui.popupMenu;
|
||||||
|
|
||||||
const Me = extensionUtils.getCurrentExtension();
|
const Me = extensionUtils.getCurrentExtension();
|
||||||
const _ = extensionUtils.gettext;
|
const _ = extensionUtils.gettext;
|
||||||
@@ -54,7 +54,7 @@ var TimerOndemand = class {
|
|||||||
|
|
||||||
|
|
||||||
get time() {
|
get time() {
|
||||||
return this._timeSettings.get_string('ondemand-time');
|
return this._timeSettings.get_string('ondemand-time') === 'day' ? Time.DAY : Time.NIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -166,9 +166,7 @@ var TimerOndemand = class {
|
|||||||
|
|
||||||
_addButtonToPanel() {
|
_addButtonToPanel() {
|
||||||
console.debug('Adding On-demand Timer button to the panel...');
|
console.debug('Adding On-demand Timer button to the panel...');
|
||||||
this._button = new NtsPanelMenuButton();
|
this._button = new NtsPanelMenuButton({ toggleCallback: this._toggleTime.bind(this) });
|
||||||
this._button.connect('button-press-event', () => this._toggleTime());
|
|
||||||
this._button.connect('touch-event', () => this._toggleTime());
|
|
||||||
main.panel.addToStatusArea('NightThemeSwitcherButton', this._button);
|
main.panel.addToStatusArea('NightThemeSwitcherButton', this._button);
|
||||||
console.debug('Added On-demand Timer button to the panel.');
|
console.debug('Added On-demand Timer button to the panel.');
|
||||||
}
|
}
|
||||||
@@ -177,10 +175,7 @@ var TimerOndemand = class {
|
|||||||
console.debug('Adding On-demand Timer button to the menu...');
|
console.debug('Adding On-demand Timer button to the menu...');
|
||||||
const aggregateMenu = main.panel.statusArea.aggregateMenu;
|
const aggregateMenu = main.panel.statusArea.aggregateMenu;
|
||||||
const position = utils.findShellAggregateMenuItemPosition(aggregateMenu._system.menu) - 1;
|
const position = utils.findShellAggregateMenuItemPosition(aggregateMenu._system.menu) - 1;
|
||||||
this._button = new NtsPopupMenuItem();
|
this._button = new NtsPopupSubMenuMenuItem({ toggleCallback: this._toggleTime.bind(this) });
|
||||||
this._button.connect('activate', () => {
|
|
||||||
this._toggleTime();
|
|
||||||
});
|
|
||||||
aggregateMenu.menu.addMenuItem(this._button, position);
|
aggregateMenu.menu.addMenuItem(this._button, position);
|
||||||
console.debug('Added On-demand Timer button to the menu.');
|
console.debug('Added On-demand Timer button to the menu.');
|
||||||
}
|
}
|
||||||
@@ -194,41 +189,43 @@ Signals.addSignalMethods(TimerOndemand.prototype);
|
|||||||
|
|
||||||
var NtsPanelMenuButton = GObject.registerClass(
|
var NtsPanelMenuButton = GObject.registerClass(
|
||||||
class NtsPanelMenuButton extends PanelMenuButton {
|
class NtsPanelMenuButton extends PanelMenuButton {
|
||||||
constructor() {
|
constructor({ toggleCallback }) {
|
||||||
super(0.0);
|
super(0.0);
|
||||||
this.icon = new St.Icon({
|
this.icon = new St.Icon({
|
||||||
style_class: 'system-status-icon',
|
style_class: 'system-status-icon',
|
||||||
});
|
});
|
||||||
this.add_child(this.icon);
|
this.add_child(this.icon);
|
||||||
|
this.connect('button-press-event', () => toggleCallback());
|
||||||
|
this.connect('touch-event', () => toggleCallback());
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
this.icon.icon_name = _getIconNameForTime(e.timer.time);
|
this.icon.icon_name = _getIconNameForTime(e.timer.time);
|
||||||
this.icon.fallback_gicon = _getGiconForTime(e.timer.time);
|
this.icon.fallback_gicon = _getGiconForTime(e.timer.time);
|
||||||
this.accessible_name = _getLabelForTime(e.timer.time);
|
this.accessible_name = e.timer.time === Time.DAY ? _('Turn Night Mode On') : _('Turn Night Mode Off');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var NtsPopupMenuItem = GObject.registerClass(
|
var NtsPopupSubMenuMenuItem = GObject.registerClass(
|
||||||
class NtsPopupMenuItem extends PopupBaseMenuItem {
|
class NtsPopupSubMenuMenuItem extends PopupSubMenuMenuItem {
|
||||||
constructor(params) {
|
constructor({ toggleCallback }) {
|
||||||
super(params);
|
super('', true);
|
||||||
this.icon = new St.Icon({
|
this._toggleItem = new PopupMenuItem('');
|
||||||
style_class: 'popup-menu-icon',
|
this._toggleItem.connect('activate', () => toggleCallback());
|
||||||
x_align: Clutter.ActorAlign.END,
|
this.menu.addMenuItem(this._toggleItem);
|
||||||
});
|
this._prefsItem = new PopupMenuItem(_('Extension Settings'));
|
||||||
this.add_child(this.icon);
|
this._prefsItem.connect('activate', () => main.extensionManager.openExtensionPrefs(Me.uuid, '', []));
|
||||||
this.label = new St.Label();
|
this.menu.addMenuItem(this._prefsItem);
|
||||||
this.add_child(this.label);
|
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
this.icon.icon_name = _getIconNameForTime(e.timer.time);
|
this.icon.icon_name = _getIconNameForTime(e.timer.time);
|
||||||
this.icon.fallback_gicon = _getGiconForTime(e.timer.time);
|
this.icon.fallback_gicon = _getGiconForTime(e.timer.time);
|
||||||
this.label.text = _getLabelForTime(e.timer.time);
|
this.label.text = e.timer.time === Time.DAY ? _('Night Mode Off') : _('Night Mode On');
|
||||||
|
this._toggleItem.label.text = e.timer.time === Time.DAY ? _('Turn On') : _('Turn Off');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -240,7 +237,3 @@ var _getIconNameForTime = time => {
|
|||||||
var _getGiconForTime = time => {
|
var _getGiconForTime = time => {
|
||||||
return Gio.icon_new_for_string(GLib.build_filenamev([Me.path, 'icons', 'hicolor', 'scalable', 'status', `${this._getIconNameForTime(time)}.svg`]));
|
return Gio.icon_new_for_string(GLib.build_filenamev([Me.path, 'icons', 'hicolor', 'scalable', 'status', `${this._getIconNameForTime(time)}.svg`]));
|
||||||
};
|
};
|
||||||
|
|
||||||
var _getLabelForTime = time => {
|
|
||||||
return time === Time.DAY ? _('Switch to night theme') : _('Switch to day theme');
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Night Theme Switcher\n"
|
"Project-Id-Version: Night Theme Switcher\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2022-02-18 01:57+0100\n"
|
"POT-Creation-Date: 2022-02-18 14:04+0100\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@@ -17,12 +17,32 @@ msgstr ""
|
|||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
#: src/modules/TimerOndemand.js:245
|
#: src/modules/TimerOndemand.js:206
|
||||||
msgid "Switch to night theme"
|
msgid "Turn Night Mode On"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/modules/TimerOndemand.js:245
|
#: src/modules/TimerOndemand.js:206
|
||||||
msgid "Switch to day theme"
|
msgid "Turn Night Mode Off"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/modules/TimerOndemand.js:218
|
||||||
|
msgid "Extension Preferences"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/modules/TimerOndemand.js:227
|
||||||
|
msgid "Night Mode Off"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/modules/TimerOndemand.js:227
|
||||||
|
msgid "Night Mode On"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/modules/TimerOndemand.js:228
|
||||||
|
msgid "Turn On"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/modules/TimerOndemand.js:228
|
||||||
|
msgid "Turn Off"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/preferences/SchedulePage.js:42 src/preferences/ui/SchedulePage.ui:47
|
#: src/preferences/SchedulePage.js:42 src/preferences/ui/SchedulePage.ui:47
|
||||||
|
|||||||
Reference in New Issue
Block a user