|
| 1 | +/* extension.js |
| 2 | + * |
| 3 | + * This program is free software: you can redistribute it and/or modify |
| 4 | + * it under the terms of the GNU General Public License as published by |
| 5 | + * the Free Software Foundation, either version 2 of the License, or |
| 6 | + * (at your option) any later version. |
| 7 | + * |
| 8 | + * This program is distributed in the hope that it will be useful, |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | + * GNU General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU General Public License |
| 14 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: GPL-2.0-or-later |
| 17 | + */ |
| 18 | + |
| 19 | +// Inspired by the macOS app 'One Thing' |
| 20 | +// Extension uses elements from 'Just Another Search Bar' (https://extensions.gnome.org/extension/5522/just-another-search-bar/) |
| 21 | + |
| 22 | +import GObject from 'gi://GObject'; |
| 23 | +import St from 'gi://St'; |
| 24 | +import Clutter from 'gi://Clutter'; |
| 25 | + |
| 26 | +import { Extension, gettext as _ } from 'resource:///org/gnome/shell/extensions/extension.js'; |
| 27 | +import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js'; |
| 28 | +import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js'; |
| 29 | + |
| 30 | +import * as Main from 'resource:///org/gnome/shell/ui/main.js'; |
| 31 | + |
| 32 | +const Indicator = GObject.registerClass( |
| 33 | + class Indicator extends PanelMenu.Button { |
| 34 | + _init(settings) { |
| 35 | + super._init(0.0, _('Panel Note')); |
| 36 | + |
| 37 | + /* ------------------------------- Panel Note ------------------------------- */ |
| 38 | + let noteInPanel = new St.Label({ |
| 39 | + text: settings.get_string('note'), |
| 40 | + y_expand: true, |
| 41 | + y_align: Clutter.ActorAlign.CENTER, |
| 42 | + }); |
| 43 | + this.add_child(noteInPanel); |
| 44 | + |
| 45 | + |
| 46 | + /* ----------------------------- Note Entry Box ----------------------------- */ |
| 47 | + this.entry = new St.Entry({ |
| 48 | + text: settings.get_string('note'), |
| 49 | + can_focus: true, |
| 50 | + track_hover: true |
| 51 | + }); |
| 52 | + |
| 53 | + this.entry.set_primary_icon(new St.Icon({ |
| 54 | + icon_name: 'document-edit-symbolic', |
| 55 | + style_class: 'popup-menu-icon', |
| 56 | + })); |
| 57 | + |
| 58 | + this.entry.clutter_text.connect('text-changed', () => { |
| 59 | + let text = this.entry.get_text(); |
| 60 | + if (text == "") |
| 61 | + text = "No Note"; |
| 62 | + settings.set_string('note', text); |
| 63 | + noteInPanel.text = text; |
| 64 | + }); |
| 65 | + |
| 66 | + let popupEdit = new PopupMenu.PopupMenuSection(); |
| 67 | + popupEdit.actor.add_actor(this.entry); |
| 68 | + |
| 69 | + this.menu.addMenuItem(popupEdit); |
| 70 | + this.menu.actor.add_style_class_name('note-entry'); |
| 71 | + } |
| 72 | + }); |
| 73 | + |
| 74 | +export default class IndicatorExampleExtension extends Extension { |
| 75 | + enable() { |
| 76 | + this._settings = this.getSettings(); |
| 77 | + this._indicator = new Indicator(this._settings); |
| 78 | + Main.panel.addToStatusArea(this.uuid, this._indicator); |
| 79 | + } |
| 80 | + |
| 81 | + disable() { |
| 82 | + this._indicator.entry.disconnect(); |
| 83 | + this._indicator.destroy(); |
| 84 | + this._indicator = null; |
| 85 | + this._settings = null; |
| 86 | + } |
| 87 | +} |
0 commit comments