-
Notifications
You must be signed in to change notification settings - Fork 22
/
prefs.js
124 lines (98 loc) · 3.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Based on https://github.com/ubuntu/gnome-shell-extension-appindicator
"use strict";
const {
Gio,
Gtk,
GObject
} = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const WMCLASS_LIST = 'by-class';
const IGNORELIST_ENABLED = 'enable-ignorelist';
function init() {}
function buildPrefsWidget() {
let settings = ExtensionUtils.getSettings(
"org.gnome.shell.extensions.noannoyance"
);
let settingsBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 8,
margin_bottom: 60,
});
let enableIgnorelistBox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
});
let wmClassBox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL
});
let toggleLabel = new Gtk.Label({
label: "Enable Ignorelist",
halign: Gtk.Align.START,
hexpand: true,
visible: true,
});
let toggle = new Gtk.Switch({
active: settings.get_boolean(IGNORELIST_ENABLED),
halign: Gtk.Align.END,
visible: true,
});
enableIgnorelistBox.append(toggleLabel);
enableIgnorelistBox.append(toggle);
settings.bind(
IGNORELIST_ENABLED,
toggle,
"active",
Gio.SettingsBindFlags.DEFAULT
);
settingsBox.append(enableIgnorelistBox);
const customListStore = new Gtk.ListStore();
customListStore.set_column_types([GObject.TYPE_STRING]);
const customInitArray = settings.get_strv(WMCLASS_LIST);
for (let i = 0; i < customInitArray.length; i++) {
customListStore.set(customListStore.append(), [0], [customInitArray[i]]);
}
customListStore.append();
const customTreeView = new Gtk.TreeView({
model: customListStore,
hexpand: true,
vexpand: true,
});
const indicatorIdColumn = new Gtk.TreeViewColumn({
title: 'WM__CLASS List ("Alt + F2" > Run "lg" > Click "Windows")',
sizing: Gtk.TreeViewColumnSizing.AUTOSIZE,
});
const cellrenderer = new Gtk.CellRendererText({
editable: true
});
indicatorIdColumn.pack_start(cellrenderer, true);
indicatorIdColumn.add_attribute(cellrenderer, "text", 0);
customTreeView.insert_column(indicatorIdColumn, 0);
customTreeView.set_grid_lines(Gtk.TreeViewGridLines.BOTH);
wmClassBox.append(customTreeView);
settingsBox.append(wmClassBox);
cellrenderer.connect("edited", (w, path, text) => {
this.selection = customTreeView.get_selection();
const selection = this.selection.get_selected();
const iter = selection[2];
customListStore.set(iter, [0], [text]);
const storeLength = customListStore.iter_n_children(null);
const customIconArray = [];
for (let i = 0; i < storeLength; i++) {
const returnIter = customListStore.iter_nth_child(null, i);
const [success, iterList] = returnIter;
if (!success) break;
if (iterList) {
const id = customListStore.get_value(iterList, 0);
if (id) customIconArray.push(id);
} else {
break;
}
}
settings.set_strv(WMCLASS_LIST, customIconArray);
if (storeLength === 1 && text) customListStore.append();
if (storeLength > 1) {
if (!text && storeLength - 1 > path) customListStore.remove(iter);
if (text && storeLength - 1 <= path) customListStore.append();
}
});
return settingsBox;
}