forked from daniellandau/switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
234 lines (201 loc) · 6.96 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
224
225
226
227
228
229
230
231
232
233
234
/*global imports, print */
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const ExtensionUtils = imports.misc.extensionUtils;
const Convenience = ExtensionUtils.getCurrentExtension().imports.convenience;
const Gettext = imports.gettext.domain('switcher');
const _ = Gettext.gettext;
let entry, settings;
function init() {
Convenience.initTranslations('switcher');
}
function buildPrefsWidget() {
let settings = Convenience.getSettings();
let vWidget = new Gtk.VBox({margin: 10});
addShortcut(vWidget, settings);
addImmediately(vWidget, settings);
addActivateByKey(vWidget, settings);
let behaviourWidget = new Gtk.HBox({spacing: 20, homogeneous: true});
let matchingWidget = new Gtk.VBox();
addMatching(matchingWidget, settings);
matchingWidget.show_all();
behaviourWidget.pack_start(matchingWidget, true, true, 0);
let orderingWidget = new Gtk.VBox();
addOrdering(orderingWidget, settings);
orderingWidget.show_all();
behaviourWidget.pack_start(orderingWidget, true, true, 0);
vWidget.add(behaviourWidget);
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);
vWidget.add(appearanceWidget);
addMaxWidth(vWidget, settings);
let workspaceWidget = new Gtk.HBox();
addWorkspace(workspaceWidget, settings);
vWidget.add(workspaceWidget);
vWidget.show_all();
return vWidget;
}
function addShortcut(widget, settings) {
widget.add(makeTitle(_("Hotkey to activate switcher")));
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('show-switcher')[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('show-switcher', [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 addImmediately(widget, settings) {
widget.add(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);
widget.add(box);
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);
widget.add(label);
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());
});
widget.add(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 addMaxWidth(widget, settings) {
widget.add(makeTitle(_("Max 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());
});
widget.add(input);
}
function addActivateByKey(widget, settings) {
widget.add(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());
});
widget.add(input);
}
function addWorkspace(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 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;
}