-
Notifications
You must be signed in to change notification settings - Fork 42
/
prefs.js
371 lines (304 loc) · 9.9 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
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
362
363
364
365
366
367
368
369
370
371
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const Extension = imports.misc.extensionUtils.getCurrentExtension();
const ExtensionUtils = imports.misc.extensionUtils;
const Gettext = imports.gettext.domain('shelltile');
const _ = Gettext.gettext;
function init(){
}
function getAccelerators(){
return [
"tile-left",
"tile-right",
"tile-up",
"tile-down"
]
}
function buildPrefsWidget(){
var gsettings;
if (ExtensionUtils){
ExtensionUtils.initTranslations();
gsettings = ExtensionUtils.getSettings();
} else {
Convenience.initTranslations();
gsettings = Convenience.getSettings();
}
settings = {
"enable-edge-tiling": {
type: "b",
label: _("Enable edge tiling")
},
"grouping-edge-tiling": {
type: "b",
label: _("Grouping edge tiling")
},
"keep-group-maximized": {
type: "b",
label: _("Keep the window group maximized")
},
"mouse-split-percent": {
type: "b",
label: _("Adjust the split percentage with the mouse while tiling")
},
"gap-between-windows": {
type: "i",
label: _("Size of the gaps between the windows"),
min: 0,
max: 50,
step: 1
},
"edge-zone-width": {
type: "i",
label: _("Size of active edge tiling zone"),
min: 1,
max: 50,
step: 1
},
"tile-modifier-key": {
type: "s",
label: _("Key to hold for tiling")
},
"enable-keybindings": {
type: "b",
label: _("Enable keybindings")
},
"tile-left": {
type: "as",
label: _("Tile to the left edge")
},
"tile-right": {
type: "as",
label: _("Tile to the right edge")
},
"tile-up": {
type: "as",
label: _("Tile to the top edge")
},
"tile-down": {
type: "as",
label: _("Tile to the bottom edge")
}
};
let frame = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
border_width: 10
});
let vbox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
margin: 20,
margin_top: 10
});
let hbox;
for (setting in settings){
hbox = buildHbox(gsettings, settings, setting);
if(hbox) vbox.add(hbox);
}
let keybindingWidget = createKeybindingWidget(gsettings);
vbox.add(keybindingWidget);
for (setting in settings){
let settingV = settings[setting];
if(settingV.type == "as"){
addKeybinding(keybindingWidget.model, gsettings, setting, settingV.label);
}
}
frame.add(vbox);
frame.show_all();
return frame;
}
function buildHbox(gsettings, settings, setting){
let hbox;
if (settings[setting].type == "i")
hbox = createIntSetting(gsettings, settings, setting);
if (settings[setting].type == "b")
hbox = createBoolSetting(gsettings, settings, setting);
if (settings[setting].type == "s")
hbox = createStringSetting(gsettings, settings, setting);
return hbox;
}
/** Adapted from https://developer.gnome.org/gnome-devel-demos/stable/combobox.js.html.en#combobox
* @author Eemil Lagerspetz
*/
function createStringSetting(gsettings, settings, setting){
let settingsV = settings[setting];
let settingsId = setting;
let hbox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
margin_top: 5
});
let setting_label = new Gtk.Label({
label: settingsV.label,
xalign: 0,
hexpand: true,
margin_right: 20
});
// This is to add the 'combo' filtering options
store = new Gtk.ListStore();
store.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING]);
store.set(store.append(), [0], ['Ctrl']);
store.set(store.append(), [0], ['Super']);
store.set(store.append(), [0], [_('Ctrl or Super')]);
combo = new Gtk.ComboBox({
model: store
});
renderer = new Gtk.CellRendererText();
combo.pack_start(renderer, false);
combo.add_attribute(renderer, "text", 0);
combo.set_active(0);
let previousValue = gsettings.get_string(settingsId);
if (previousValue === 'Super')
combo.set_active(1);
if (previousValue === 'Ctrl or Super')
combo.set_active(2);
combo.connect('changed', (widget) => {
let model, active, type, text, filter;
model = widget.get_model();
active = widget.get_active_iter()[1];
type = model.get_value(active, 0);
gsettings.set_string(settingsId, type);
});
// Create the combobox
/* this.tile_key_setting = new Gtk.ComboBoxText();
let options = ["Ctrl", "Super", "Ctrl or Super"];
for (let i = 0; i < options.length; i++ ) {
this.tile_key_setting.append_text(options[i]);
}
this.tile_key_setting.set_active(0);*/
if (settingsV.help){
setting_label.set_tooltip_text(settingsV.help)
this.tile_key_setting.set_tooltip_text(settingsV.help)
}
hbox.pack_start(setting_label, true, true, 0);
hbox.add(combo);
return hbox;
}
function createBoolSetting(gsettings, settings, setting){
let settingsV = settings[setting];
let settingsId = setting;
let hbox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
margin_top: 5
});
let setting_label = new Gtk.Label({
label: settingsV.label,
xalign: 0,
hexpand: true,
margin_right: 20
});
let setting_switch = new Gtk.Switch({
active: gsettings.get_boolean(settingsId)
});
setting_switch.connect('notify::active', function (button){
gsettings.set_boolean(settingsId, button.active);
});
if (settingsV.help){
setting_label.set_tooltip_text(settingsV.help)
setting_switch.set_tooltip_text(settingsV.help)
}
hbox.pack_start(setting_label, true, true, 0);
hbox.add(setting_switch);
return hbox;
}
function createIntSetting(gsettings, settings, setting){
let settingsV = settings[setting];
let settingsId = setting;
let hbox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
margin_top: 5
});
let setting_label = new Gtk.Label({
label: settingsV.label,
xalign: 0,
hexpand: true,
margin_right: 20
});
let adjustment = new Gtk.Adjustment({
lower: settingsV.min || 0,
upper: settingsV.max || 65535,
step_increment: settingsV.step || 1
});
let setting_int = new Gtk.SpinButton({
adjustment: adjustment,
snap_to_ticks: true
});
setting_int.set_value(gsettings.get_int(settingsId));
setting_int.connect('value-changed', function (entry){
gsettings.set_int(settingsId, entry.value);
});
if (settingsV.help){
setting_label.set_tooltip_text(settingsV.help)
setting_int.set_tooltip_text(settingsV.help)
}
hbox.pack_start(setting_label, true, true, 0);
hbox.add(setting_int);
return hbox;
}
const COLUMN_ID = 0;
const COLUMN_DESCRIPTION = 1;
const COLUMN_KEY = 2;
const COLUMN_MODS = 3;
function addKeybinding(model, gsettings, id, description){
// Get the current accelerator.
let accelerator = gsettings.get_strv(id)[0];
let key, mods;
if (accelerator == null)
[key, mods] = [0, 0];
else
[key, mods] = Gtk.accelerator_parse(gsettings.get_strv(id)[0]);
// Add a row for the keybinding.
let row = model.insert(100); // Erm...
model.set(row,
[COLUMN_ID, COLUMN_DESCRIPTION, COLUMN_KEY, COLUMN_MODS],
[id, description, key, mods]);
}
function createKeybindingWidget(gsettings){
let model = new Gtk.ListStore();
model.set_column_types(
[GObject.TYPE_STRING, // COLUMN_ID
GObject.TYPE_STRING, // COLUMN_DESCRIPTION
GObject.TYPE_INT, // COLUMN_KEY
GObject.TYPE_INT]); // COLUMN_MODS
let treeView = new Gtk.TreeView();
treeView.model = model;
treeView.headers_visible = false;
let column, renderer;
// Description column.
renderer = new Gtk.CellRendererText();
column = new Gtk.TreeViewColumn();
column.expand = true;
column.pack_start(renderer, true);
column.add_attribute(renderer, "text", COLUMN_DESCRIPTION);
treeView.append_column(column);
// Key binding column.
renderer = new Gtk.CellRendererAccel();
renderer.accel_mode = Gtk.CellRendererAccelMode.GTK;
renderer.editable = true;
renderer.connect("accel-edited",
function (renderer, path, key, mods, hwCode){
let [ok, iter] = model.get_iter_from_string(path);
if(!ok)
return;
// Update the UI.
model.set(iter, [COLUMN_KEY, COLUMN_MODS], [key, mods]);
// Update the stored setting.
let id = model.get_value(iter, COLUMN_ID);
let accelString = Gtk.accelerator_name(key, mods);
gsettings.set_strv(id, [accelString]);
});
renderer.connect("accel-cleared",
function (renderer, path){
let [ok, iter] = model.get_iter_from_string(path);
if(!ok)
return;
// Update the UI.
model.set(iter, [COLUMN_KEY, COLUMN_MODS], [0, 0]);
// Update the stored setting.
let id = model.get_value(iter, COLUMN_ID);
gsettings.set_strv(id, []);
});
column = new Gtk.TreeViewColumn();
column.pack_end(renderer, false);
column.add_attribute(renderer, "accel-key", COLUMN_KEY);
column.add_attribute(renderer, "accel-mods", COLUMN_MODS);
treeView.append_column(column);
return treeView;
}