-
Notifications
You must be signed in to change notification settings - Fork 14
/
prefs.js
107 lines (77 loc) · 2.45 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
// Library imports
const GObject = imports.gi.GObject;
const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
// Extension imports
const Utils = imports.misc.extensionUtils.getCurrentExtension().imports.utils;
// Globals
const pretty_names = {
'key': 'start tilix in quake mode'
}
function init() {
}
function buildPrefsWidget() {
let model = new Gtk.ListStore();
model.set_column_types([
GObject.TYPE_STRING,
GObject.TYPE_STRING,
GObject.TYPE_INT,
GObject.TYPE_INT
]);
let settings = Utils.getSettings();
for (key in pretty_names) {
append_hotkey(model, settings, key, pretty_names[key]);
}
let treeview = new Gtk.TreeView({
'model': model
});
let col;
let cellrend;
cellrend = new Gtk.CellRendererText();
col = new Gtk.TreeViewColumn({
'title': 'Keybinding',
'expand': true
});
col.pack_start(cellrend, true);
col.add_attribute(cellrend, 'text', 1);
treeview.append_column(col);
cellrend = new Gtk.CellRendererAccel({
'editable': true,
'accel-mode': Gtk.CellRendererAccelMode.GTK
});
cellrend.connect('accel-edited', function(rend, iter, key, mods) {
let value = Gtk.accelerator_name(key, mods);
let success = false;
[success, iter] = model.get_iter_from_string(iter);
if (!success) {
throw new Error("Something be broken, yo.");
}
let name = model.get_value(iter, 0);
model.set(iter, [ 2, 3 ], [ mods, key ]);
settings.set_strv(name, [value]);
});
col = new Gtk.TreeViewColumn({
'title': 'Accel'
});
col.pack_end(cellrend, false);
col.add_attribute(cellrend, 'accel-mods', 2);
col.add_attribute(cellrend, 'accel-key', 3);
treeview.append_column(col);
let win = new Gtk.ScrolledWindow({
'vexpand': true
});
win.child = treeview;
return win;
}
function append_hotkey(model, settings, name, pretty_name) {
let [status, key, mods] = Gtk.accelerator_parse(settings.get_strv(name)[0]);
// Gtk_accelerator_parse returns different element count between GTK 3 (2)
// and GTK 4 (3). When using GTK 3, "shifting" the returned values will set
// the proper values to key and mods variables
if (typeof mods == 'undefined') {
mods = key;
key = status;
}
let row = model.insert(-1);
model.set(row, [0, 1, 2, 3], [name, pretty_name, mods, key ]);
}