forked from ddVital/panel-wizard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
126 lines (108 loc) · 3.24 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const { GObject, St, Shell, Meta, GLib, Clutter } = imports.gi;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
let extension;
const DEFAULT_MENU_STRUCTURE = {
'File': [
{label: 'New Window', shortcut: '⌘N'},
{label: 'New Tab', shortcut: '⌘T'},
{label: 'Open...', shortcut: '⌘O'},
{label: 'Save', shortcut: '⌘S'},
{label: 'Save As...', shortcut: '⇧⌘S'},
{label: 'Close Window', shortcut: '⌘W'}
],
'Edit': [
{label: 'Undo', shortcut: '⌘Z'},
{label: 'Redo', shortcut: '⇧⌘Z'},
{label: 'Cut', shortcut: '⌘X'},
{label: 'Copy', shortcut: '⌘C'},
{label: 'Paste', shortcut: '⌘V'},
{label: 'Select All', shortcut: '⌘A'}
],
'View': [
{label: 'Show Sidebar', shortcut: '⌘1'},
{label: 'Enter Full Screen', shortcut: '⌃⌘F'},
{label: 'Zoom In', shortcut: '⌘+'},
{label: 'Zoom Out', shortcut: '⌘-'}
],
'Window': [
{label: 'Minimize', shortcut: '⌘M'},
{label: 'Zoom', shortcut: '⌃⌘Z'},
{label: 'Bring All to Front', shortcut: null}
],
'Help': [
{label: 'Welcome Guide', shortcut: null},
{label: 'Documentation', shortcut: null},
{label: 'Release Notes', shortcut: null}
]
};
const Extension = class Extension {
constructor(uuid) {
this._uuid = uuid;
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.topbar-menus');
log('Extension constructor called');
}
enable() {
log('Extension enable called');
this._panel = Main.panel;
this._createMenuButtons();
}
disable() {
log('Extension disable called');
if (this._menuButtons) {
this._menuButtons.forEach(button => {
if (button) button.destroy();
});
}
this._menuButtons = [];
}
_createMenuButtons() {
this._menuButtons = [];
const menuItems = ['File', 'Edit', 'View', 'Window', 'Help'];
menuItems.forEach(label => {
if (this._settings.get_boolean(`show-${label.toLowerCase()}`)) {
this._addMenuButton(label);
}
});
// Watch for settings changes
menuItems.forEach(label => {
this._settings.connect(`changed::show-${label.toLowerCase()}`, () => {
this.disable();
this._createMenuButtons();
});
});
}
_addMenuButton(label) {
let menuButton = new PanelMenu.Button(0.0, label);
let buttonText = new St.Label({
text: label,
y_align: Clutter.ActorAlign.CENTER,
style_class: 'panel-button-text'
});
menuButton.add_child(buttonText);
const menuItems = DEFAULT_MENU_STRUCTURE[label];
menuItems.forEach(item => {
if (item.shortcut) {
menuButton.menu.addAction(`${item.label} ${item.shortcut}`);
} else {
menuButton.menu.addAction(item.label);
}
});
Main.panel.addToStatusArea(`${label}-button`, menuButton, 0, 'left');
this._menuButtons.push(menuButton);
}
_getMenuStructure() {
try {
return JSON.parse(this._settings.get_string('menu-structure'));
} catch (e) {
return DEFAULT_MENU_STRUCTURE;
}
}
}
function init() {
extension = new Extension();
return extension;
}