-
Notifications
You must be signed in to change notification settings - Fork 4
/
prefs.js
132 lines (121 loc) · 4.77 KB
/
prefs.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
127
128
129
130
/* prefs.js
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
'use strict';
import Gio from 'gi://Gio';
import Adw from 'gi://Adw';
import Gtk from 'gi://Gtk';
import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
export default class SimpleMessahePreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
window.settings = this.getSettings('org.gnome.shell.extensions.simple-message');
// const settings = ExtensionUtils.getSettings()
// Create a page
const page = new Adw.PreferencesPage();
window.add(page);
// Create a group of settings
const group = new Adw.PreferencesGroup();
page.add(group);
// Create a row for position settings
const positionRow = new Adw.ActionRow({
title: 'Top Panel Location',
subtitle: 'Group and Position',
});
group.add(positionRow);
// Create a group of toggle buttons to set the panel box
const left_button = new Gtk.ToggleButton({ label: 'Left', valign: Gtk.Align.CENTER });
const center_button = new Gtk.ToggleButton({ label: 'Center', valign: Gtk.Align.CENTER });
const right_button = new Gtk.ToggleButton({ label: 'Right', valign: Gtk.Align.CENTER });
center_button.set_group(left_button);// Add those buttons on the same line
right_button.set_group(left_button);
// Set the initial state of the toggle buttons and make them update
// the settings
const panelBoxes = [left_button, center_button, right_button];
const initialPanelBox = window.settings.get_int('panel-alignment');
function _initiatePanelButton(button, index, array) {
if ( initialPanelBox == index) { button.set_active(true) }
button.connect('toggled', () => {
window.settings.set_int('panel-alignment', index);
});
positionRow.add_suffix(button);
}
panelBoxes.forEach(_initiatePanelButton);
// Within a panel box, the position should be provided
// Create a spin button with the initial position value.
const initialPanelBoxPosition = window.settings.get_int('panel-position');
const positionButton = new Gtk.SpinButton({ valign: Gtk.Align.CENTER });
positionButton.set_adjustment(new Gtk.Adjustment({
lower: -100,
upper: 100,
value: initialPanelBoxPosition,
step_increment: 1,
page_increment: 1,
page_size: 0,
}));
// Let the spin button update the settings state.
positionButton.connect('value-changed', () => {
window.settings.set_int(
'panel-position', positionButton.get_adjustment().value);
});
// Add it to the GUI.
positionRow.add_suffix(positionButton);
// Create an option to access and edit the message
const messageRow = new Adw.ActionRow({
title: 'Write your message',
subtitle: 'Confirm with Enter'
});
group.add(messageRow);
// Create a text box where the user can enter the message
const messageText = new Gtk.EntryBuffer({
text: window.settings.get_string('message')
});
const messageField = new Gtk.Entry({
buffer: messageText,
hexpand: true,
valign:Gtk.Align.CENTER,
halign:Gtk.Align.CENTER
})
// Let the text box update the message
messageField.connect('activate', () => {
window.settings.set_string('message', messageText.text);
})
// Add the text box to the row
messageRow.add_suffix(messageField);
// Create an option to access and edit the command
const commandRow = new Adw.ActionRow({
title: 'Command to execute on click',
subtitle: 'Confirm with Enter'
});
group.add(commandRow);
// Create a text box where the user can enter the command
const commandText = new Gtk.EntryBuffer({
text: window.settings.get_string('command')
});
const commandField = new Gtk.Entry({
buffer: commandText,
hexpand: true,
valign:Gtk.Align.CENTER,
halign:Gtk.Align.CENTER
})
// Let the text box update the command
commandField.connect('activate', () => {
window.settings.set_string('command', commandText.text);
})
// Add the text box to the row
commandRow.add_suffix(commandField);
}
}