-
Notifications
You must be signed in to change notification settings - Fork 1
/
prefs.js
223 lines (198 loc) · 6.73 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
'use strict';
const { Adw, Gdk, GObject, Gtk } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Extension = ExtensionUtils.getCurrentExtension();
const { Preferences } = Extension.imports.lib.preferences;
const { _ } = Extension.imports.lib.utils;
const ShortcutWindow = GObject.registerClass(
class ShortcutWindow extends Adw.Window {
static [GObject.signals] = {
'shortcut': {
param_types: [GObject.TYPE_STRING],
},
};
constructor(parent) {
super({
content: new Adw.StatusPage({
description: _(`Press Backspace to clear shortcut or Esc to cancel`),
title: _(`Enter a new shortcut`),
}),
modal: true,
resizable: false,
transient_for: parent,
width_request: 450,
});
const keyController = new Gtk.EventControllerKey();
keyController.connect(`key-pressed`, (...[, keyval, keycode, state]) => {
switch (keyval) {
case Gdk.KEY_Escape: {
this.close();
return Gdk.EVENT_STOP;
}
case Gdk.KEY_BackSpace: {
this.emit(`shortcut`, ``);
return Gdk.EVENT_STOP;
}
default: {
const mask = state & Gtk.accelerator_get_default_mod_mask();
if (mask && Gtk.accelerator_valid(keyval, mask)) {
const shortcut = Gtk.accelerator_name_with_keycode(null, keyval, keycode, mask);
if (shortcut.length > 0) {
this.emit(`shortcut`, shortcut);
return Gdk.EVENT_STOP;
}
}
break;
}
}
return Gdk.EVENT_PROPAGATE;
});
this.add_controller(keyController);
}
});
const ShortcutRow = GObject.registerClass(
class ShortcutRow extends Adw.ActionRow {
constructor(title, preferences, property) {
super({
title: title,
});
this._preferences = preferences;
this._property = property;
this.activatable_widget = new Gtk.ShortcutLabel({
disabled_text: _(`Disabled`, `Keyboard shortcut is disabled`),
valign: Gtk.Align.CENTER,
});
this._preferences.bind_property(
this._property,
this.activatable_widget,
`accelerator`,
GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE
);
this.add_suffix(this.activatable_widget);
}
vfunc_activate() {
const window = new ShortcutWindow(this.get_root());
window.connect(`shortcut`, (...[, shortcut]) => {
this._preferences.set_property(this._property, shortcut);
window.close();
});
window.connect(`close-request`, () => {
window.destroy();
});
window.present();
}
});
var init = () => {
ExtensionUtils.initTranslations(Extension.uuid);
};
var fillPreferencesWindow = (window) => {
window._preferences = new Preferences();
window.connect(`close-request`, () => {
window._preferences.destroy();
});
const historySizeSpinBox = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 500,
step_increment: 1,
}),
valign: Gtk.Align.CENTER,
});
window._preferences.bind_property(
`historySize`,
historySizeSpinBox,
`value`,
GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE
);
const historySizeRow = new Adw.ActionRow({
activatable_widget: historySizeSpinBox,
title: _(`History size`),
});
historySizeRow.add_suffix(historySizeSpinBox);
const boundaryWhitespaceSwitch = new Gtk.Switch({
valign: Gtk.Align.CENTER,
});
window._preferences.bind_property(
`showBoundaryWhitespace`,
boundaryWhitespaceSwitch,
`active`,
GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE
);
const boundaryWhitespaceRow = new Adw.ActionRow({
activatable_widget: boundaryWhitespaceSwitch,
title: _(`Show leading and trailing whitespace`),
});
boundaryWhitespaceRow.add_suffix(boundaryWhitespaceSwitch);
const generalGroup = new Adw.PreferencesGroup({
title: _(`General`, `General options`),
});
generalGroup.add(historySizeRow);
generalGroup.add(boundaryWhitespaceRow);
const webSearchUrlEntry = new Gtk.Entry({
placeholder_text: _(`URL with %s in place of query`),
valign: Gtk.Align.CENTER,
});
webSearchUrlEntry.set_size_request(300, -1);
window._preferences.bind_property(
`webSearchUrl`,
webSearchUrlEntry,
`text`,
GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE
);
const webSearchUrlRow = new Adw.ActionRow({
activatable_widget: webSearchUrlEntry,
title: _(`Search URL`),
});
webSearchUrlRow.add_suffix(webSearchUrlEntry);
const webSearchGroup = new Adw.PreferencesGroup({
title: _(`Web Search`),
});
webSearchGroup.add(webSearchUrlRow);
const expiryDaysSpinBox = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 365,
step_increment: 1,
}),
valign: Gtk.Align.CENTER,
});
window._preferences.bind_property(
`expiryDays`,
expiryDaysSpinBox,
`value`,
GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE
);
const expiryDaysRow = new Adw.ActionRow({
activatable_widget: expiryDaysSpinBox,
title: _(`Days to keep`, `The number of days to keep the shared text`),
});
expiryDaysRow.add_suffix(expiryDaysSpinBox);
const sharingOnlineGroup = new Adw.PreferencesGroup({
title: _(`Sharing Online`),
});
sharingOnlineGroup.add(expiryDaysRow);
const keybindingGroup = new Adw.PreferencesGroup({
title: _(`Keyboard Shortcuts`),
});
keybindingGroup.add(new ShortcutRow(
_(`Toggle menu`),
window._preferences,
`toggleMenuShortcut`
));
keybindingGroup.add(new ShortcutRow(
_(`Toggle private mode`),
window._preferences,
`togglePrivateModeShortcut`
));
keybindingGroup.add(new ShortcutRow(
_(`Clear history`),
window._preferences,
`clearHistoryShortcut`
));
const page = new Adw.PreferencesPage();
page.add(generalGroup);
page.add(webSearchGroup);
page.add(sharingOnlineGroup);
page.add(keybindingGroup);
window.add(page);
};