forked from daniellandau/switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefs.js
More file actions
361 lines (308 loc) · 10.8 KB
/
prefs.js
File metadata and controls
361 lines (308 loc) · 10.8 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*global imports, print */
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Gettext = imports.gettext.domain('switcher');
const _ = Gettext.gettext;
const getOnboardingMessages = Me.imports.onboardingmessages.messages;
let entry, settings;
function init() {
Convenience.initTranslations('switcher');
}
function buildPrefsWidget() {
let scrollableArea = new Gtk.ScrolledWindow();
let vWidget = new Gtk.VBox({margin: 10});
buildWidgets().forEach(w => vWidget.add(w));
scrollableArea.add(vWidget);
scrollableArea.set_size_request(800, -1);
scrollableArea.show_all();
return scrollableArea;
}
function buildWidgets() {
let settings = Convenience.getSettings();
let shortcutsWidget = new Gtk.HBox({spacing: 20, homogeneous: true});
let switcherWidget = new Gtk.VBox();
addShortcut(switcherWidget, settings, 'show-switcher', _("Hotkey to activate switcher"));
shortcutsWidget.pack_start(switcherWidget, true, true, 0);
let launcherWidget = new Gtk.VBox();
addShortcut(launcherWidget, settings, 'show-launcher', _("Hotkey to activate launcher"));
shortcutsWidget.pack_start(launcherWidget, true, true, 0);
let changeExplanation = new Gtk.Label({margin_top: 5});
changeExplanation.set_markup(_("Use Ctrl+Tab or Ctrl+Space to switch between switcher and launcher"));
changeExplanation.set_alignment(0, 0.5);
const immediatelyWidgets = buildImmediately(settings);
const activateByWidgets = buildActivateByKey( settings);
let behaviourWidget = new Gtk.HBox({spacing: 20, homogeneous: true});
let matchingWidget = new Gtk.VBox();
addMatching(matchingWidget, settings);
behaviourWidget.pack_start(matchingWidget, true, true, 0);
let orderingWidget = new Gtk.VBox();
addOrdering(orderingWidget, settings);
behaviourWidget.pack_start(orderingWidget, true, true, 0);
let appearanceWidget = new Gtk.HBox({spacing: 20, homogeneous: true});
let fontSizeWidget = new Gtk.VBox();
addFontSize(fontSizeWidget, settings);
appearanceWidget.add(fontSizeWidget);
let iconSizeWidget = new Gtk.VBox();
addIconSize(iconSizeWidget, settings);
appearanceWidget.add(iconSizeWidget);
const widthWidgets = buildWidth(settings);
let workspaceIndicatorWidget = new Gtk.HBox();
addWorkspaceIndicator(workspaceIndicatorWidget, settings);
let onlyOneWorkSpaceWidget = new Gtk.HBox();
addOnlyOneWorkspace(onlyOneWorkSpaceWidget, settings);
let fadeEffectWidget = new Gtk.HBox();
addFadeEffect(fadeEffectWidget, settings);
let activeDisplayWidget = new Gtk.HBox();
addActiveDisplay(activeDisplayWidget, settings);
const onboardingWidgets = buildOnboarding(settings);
return []
.concat(shortcutsWidget,
changeExplanation,
immediatelyWidgets,
activateByWidgets,
behaviourWidget,
appearanceWidget,
widthWidgets,
workspaceIndicatorWidget,
onlyOneWorkSpaceWidget,
fadeEffectWidget,
activeDisplayWidget,
onboardingWidgets
)
}
function addShortcut(widget, settings, shortcut, title) {
widget.add(makeTitle(title));
let model = new Gtk.ListStore();
model.set_column_types([GObject.TYPE_INT, GObject.TYPE_INT]);
const row = model.insert(0);
let [key, mods] = Gtk.accelerator_parse(settings.get_strv(shortcut)[0]);
model.set(row, [0, 1], [mods, key]);
let treeView = new Gtk.TreeView({model: model});
let accelerator = new Gtk.CellRendererAccel({
'editable': true,
'accel-mode': Gtk.CellRendererAccelMode.GTK
});
accelerator.connect('accel-edited', function(r, iter, key, mods) {
let value = Gtk.accelerator_name(key, mods);
let [succ, iterator] = model.get_iter_from_string(iter);
model.set(iterator, [0, 1], [mods, key]);
if (key != 0) {
settings.set_strv(shortcut, [value]);
}
});
let column = new Gtk.TreeViewColumn({title: _("Key")});
column.pack_start(accelerator, false);
column.add_attribute(accelerator, 'accel-mods', 0);
column.add_attribute(accelerator, 'accel-key', 1);
treeView.append_column(column);
widget.add(treeView);
}
function addMatching(widget, settings) {
widget.add(makeTitle(_("Pattern matching algorithm")));
let options = [_("Strict"), _("Fuzzy")];
let input = new Gtk.ComboBoxText();
options.forEach(o => input.append_text(o));
input.set_active(settings.get_uint('matching'));
input.connect('changed', function() {
settings.set_uint('matching', input.get_active());
});
widget.add(input);
}
function addOrdering(widget, settings) {
widget.add(makeTitle(_("Ordering criteria")));
let options = [_("Last focused"), _("Most relevant")];
let input = new Gtk.ComboBoxText();
options.forEach(o => input.append_text(o));
input.set_active(settings.get_uint('ordering'));
input.connect('changed', function() {
settings.set_uint('ordering', input.get_active());
});
widget.add(input);
}
function buildImmediately(settings) {
const title = makeTitle(_("Immediate activation"));
let input;
let box = new Gtk.HBox();
let label = new Gtk.Label();
label.set_markup(_("When there is just one result, activate immediately"));
label.set_alignment(0, 0.5);
box.add(label);
let _switch = new Gtk.Switch({
active: settings.get_boolean('activate-immediately'),
halign: Gtk.Align.END
});
_switch.connect('notify::active', function (o) {
settings.set_boolean('activate-immediately', o.active);
input.set_sensitive(o.active);
});
box.add(_switch);
label = new Gtk.Label();
label.set_markup(_("Activate immediately this many milliseconds after last keystroke"));
label.set_alignment(0, 0.5);
label.set_padding(0, 9);
input = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 5000,
step_increment: 100
})
});
input.set_value(settings.get_uint('activate-after-ms'));
input.connect('value-changed', function(button) {
settings.set_uint('activate-after-ms', button.get_value_as_int());
});
return [title, box, label, input];
}
function addIconSize(widget, settings) {
widget.add(makeTitle(_("Icon size (px)")));
let input = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 10,
upper: 64,
step_increment: 1
})
});
input.set_value(settings.get_uint('icon-size'));
input.connect('value-changed', function(button) {
settings.set_uint('icon-size', button.get_value_as_int());
});
widget.add(input);
}
function addFontSize(widget, settings) {
widget.add(makeTitle(_("Font size (px)")));
let input = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 10,
upper: 64,
step_increment: 1
})
});
input.set_value(settings.get_uint('font-size'));
input.connect('value-changed', function(button) {
settings.set_uint('font-size', button.get_value_as_int());
});
widget.add(input);
}
function buildWidth(settings) {
const title = makeTitle(_("Width (%)"));
let input = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 10,
upper: 100,
step_increment: 1
})
});
input.set_value(settings.get_uint('max-width-percentage'));
input.connect('value-changed', function(button) {
settings.set_uint('max-width-percentage', button.get_value_as_int());
});
return [title, input];
}
function buildActivateByKey(settings) {
const title = makeTitle(_("Activate by pressing a key matching the index in the list"));
let options = [_("Disable"), _("Function keys"), _("Number keys")];
let input = new Gtk.ComboBoxText();
options.forEach(o => input.append_text(o));
input.set_active(settings.get_uint('activate-by-key'));
input.connect('changed', function() {
settings.set_uint('activate-by-key', input.get_active());
});
return [title, input];
}
function addWorkspaceIndicator(widget, settings) {
widget.add(makeTitle(_("Show workspace indicators")));
let _switch = new Gtk.Switch({
active: settings.get_boolean('workspace-indicator'),
margin_top: 15,
halign: Gtk.Align.END
});
_switch.connect('notify::active', function (o) {
settings.set_boolean('workspace-indicator', o.active);
});
widget.add(_switch);
}
function addOnlyOneWorkspace(widget, settings) {
widget.add(makeTitle(_("Show only apps in the current workspace")));
let _switch = new Gtk.Switch({
active: settings.get_boolean('only-current-workspace'),
margin_top: 15,
halign: Gtk.Align.END
});
_switch.connect('notify::active', function (o) {
settings.set_boolean('only-current-workspace', o.active);
});
widget.add(_switch);
}
function addFadeEffect(widget, settings) {
widget.add(makeTitle(_("Fade Effect")));
let _switch = new Gtk.Switch({
active: settings.get_boolean('fade-enable'),
margin_top: 15,
halign: Gtk.Align.END
});
_switch.connect('notify::active', function (o) {
settings.set_boolean('fade-enable', o.active);
});
widget.add(_switch);
}
function addActiveDisplay(widget, settings) {
widget.add(makeTitle(_("Show Switcher on active display")));
let _switch = new Gtk.Switch({
active: settings.get_boolean('on-active-display'),
margin_top: 15,
halign: Gtk.Align.END
});
_switch.connect('notify::active', function (o) {
settings.set_boolean('on-active-display', o.active);
});
widget.add(_switch);
}
function buildOnboarding(settings) {
const title = makeTitle(_("Usage tips"));
let box = new Gtk.HBox();
let label = new Gtk.Label();
label.set_markup(_("Never show usage tips"));
label.set_alignment(0, 0.5);
box.add(label);
let _switch = new Gtk.Switch({
active: settings.get_boolean('never-show-onboarding'),
halign: Gtk.Align.END
});
_switch.connect('notify::active', function (o) {
settings.set_boolean('never-show-onboarding', o.active);
});
box.add(_switch);
const showMessages = new Gtk.Button({ label: _("Read all tips")});
showMessages.set_margin_top(10);
const popover = new Gtk.Popover(showMessages);
popover.set_relative_to(showMessages);
const vbox = new Gtk.VBox();
vbox.set_margin_start(5);
vbox.set_margin_end(5);
vbox.set_margin_bottom(5);
popover.add(vbox);
showMessages.connect('clicked', function () {
popover.show_all();
});
getOnboardingMessages(_)
.map((msg, i) => {
const label = new Gtk.Label();
label.set_markup((i + 1) + '. ' + msg);
label.set_alignment(0, 0.5);
label.set_line_wrap(true);
label.set_margin_top(5);
label.set_max_width_chars(72);
return label;
})
.forEach(l => vbox.add(l));
return [title, box, showMessages];
}
function makeTitle(markup) {
let title = new Gtk.Label({margin_top: 20, margin_bottom: 5});
title.set_markup('<b>'+markup+'</b>');
title.set_alignment(0, 0.5);
return title;
}