-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs.js
327 lines (286 loc) · 12.3 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
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Extension = imports.misc.extensionUtils.getCurrentExtension();
const Utils = Extension.imports.utils;
const prettyPrint = Utils.prettyPrint;
const Gettext = imports.gettext;
const _ = Gettext.domain('clipboard-indicator').gettext;
const Fields = {
INTERVAL : 'refresh-interval',
HISTORY_SIZE : 'history-size',
PREVIEW_SIZE : 'preview-size',
CACHE_FILE_SIZE : 'cache-size',
CACHE_ONLY_FAVORITE : 'cache-only-favorites',
DELETE : 'enable-deletion',
NOTIFY_ON_COPY : 'notify-on-copy',
MOVE_ITEM_FIRST : 'move-item-first',
ENABLE_KEYBINDING : 'enable-keybindings',
TOPBAR_PREVIEW_SIZE: 'topbar-preview-size',
TOPBAR_DISPLAY_MODE_ID : 'display-mode'
};
const SCHEMA_NAME = 'org.gnome.shell.extensions.clipboard-indicator';
const getSchema = function () {
let schemaDir = Extension.dir.get_child('schemas').get_path();
let schemaSource = Gio.SettingsSchemaSource.new_from_directory(schemaDir, Gio.SettingsSchemaSource.get_default(), false);
let schema = schemaSource.lookup(SCHEMA_NAME, false);
return new Gio.Settings({ settings_schema: schema });
};
const SettingsSchema = getSchema();
function init() {
let localeDir = Extension.dir.get_child('locale');
if (localeDir.query_exists(null))
Gettext.bindtextdomain('clipboard-indicator', localeDir.get_path());
}
const App = new Lang.Class({
Name: 'ClipboardIndicator.App',
_init: function() {
this.main = new Gtk.Grid({
margin: 10,
row_spacing: 12,
column_spacing: 18,
column_homogeneous: false,
row_homogeneous: false
});
this.field_interval = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 500,
upper: 5000,
step_increment: 100
})
});
this.field_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 50,
step_increment: 1
})
});
this.field_preview_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 10,
upper: 100,
step_increment: 1
})
});
this.field_cache_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 512,
upper: Math.pow(2, 14),
step_increment: 1
})
});
this.field_topbar_preview_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 100,
step_increment: 1
})
});
this.field_display_mode = new Gtk.ComboBox({
model: this._create_display_mode_options()});
let rendererText = new Gtk.CellRendererText();
this.field_display_mode.pack_start (rendererText, false);
this.field_display_mode.add_attribute (rendererText, "text", 0);
this.field_cache_disable = new Gtk.Switch();
this.field_notification_toggle = new Gtk.Switch();
this.field_move_item_first = new Gtk.Switch();
this.field_keybinding = createKeybindingWidget(SettingsSchema);
addKeybinding(this.field_keybinding.model, SettingsSchema, "toggle-menu",
_("Toggle the menu"));
addKeybinding(this.field_keybinding.model, SettingsSchema, "clear-history",
_("Clear history"));
addKeybinding(this.field_keybinding.model, SettingsSchema, "prev-entry",
_("Previous entry"));
addKeybinding(this.field_keybinding.model, SettingsSchema, "next-entry",
_("Next entry"));
var that = this;
this.field_keybinding_activation = new Gtk.Switch();
this.field_keybinding_activation.connect("notify::active", function(widget){
that.field_keybinding.set_sensitive(widget.active);
});
//this.field_deletion = new Gtk.Switch({
//active: true
//});
let sizeLabel = new Gtk.Label({
label: _("History Size"),
hexpand: true,
halign: Gtk.Align.START
});
let intervalLabel = new Gtk.Label({
label: _("Refresh Interval (ms)"),
hexpand: true,
halign: Gtk.Align.START
});
let previewLabel = new Gtk.Label({
label: _("Preview Size (characters)"),
hexpand: true,
halign: Gtk.Align.START
});
let cacheSizeLabel = new Gtk.Label({
label: _("Max cache file size (kb)"),
hexpand: true,
halign: Gtk.Align.START
});
let cacheDisableLabel = new Gtk.Label({
label: _("Cache only favorites"),
hexpand: true,
halign: Gtk.Align.START
});
let notificationLabel = new Gtk.Label({
label: _("Show notification on copy"),
hexpand: true,
halign: Gtk.Align.START
});
let moveFirstLabel = new Gtk.Label({
label: _("Move item to the top after selection"),
hexpand: true,
halign: Gtk.Align.START
});
let keybindingLabel = new Gtk.Label({
label: _("Keyboard shortcuts"),
hexpand: true,
halign: Gtk.Align.START
});
let topbarPreviewLabel = new Gtk.Label({
label: _("Number of characters in top bar"),
hexpand: true,
halign: Gtk.Align.START
});
let displayModeLabel = new Gtk.Label({
label: _("What to show in top bar"),
hexpand: true,
halign: Gtk.Align.START
});
//let deleteLabel = new Gtk.Label({
//label: _("Enable Deletion"),
//hexpand: true,
//halign: Gtk.Align.START
//});
this.main.attach(sizeLabel , 2, 1, 2 ,1);
this.main.attach(previewLabel , 2, 2, 2 ,1);
this.main.attach(intervalLabel , 2, 3, 2 ,1);
this.main.attach(cacheSizeLabel , 2, 4, 2 ,1);
this.main.attach(cacheDisableLabel , 2, 5, 2 ,1);
//this.main.attach(deleteLabel , 2, 4, 2 ,1);
this.main.attach(notificationLabel , 2, 6, 2 ,1);
this.main.attach(moveFirstLabel , 2, 7, 2 ,1);
this.main.attach(displayModeLabel , 2, 8, 2, 1);
this.main.attach(topbarPreviewLabel , 2, 9, 2 ,1);
this.main.attach(keybindingLabel , 2, 10, 2 ,1);
this.main.attach(this.field_size , 4, 1, 2, 1);
this.main.attach(this.field_preview_size , 4, 2, 2, 1);
this.main.attach(this.field_interval , 4, 3, 2, 1);
this.main.attach(this.field_cache_size , 4, 4, 2, 1);
this.main.attach(this.field_cache_disable , 4, 5, 2, 1);
//this.main.attach(this.field_deletion , 4, 4, 2, 1);
this.main.attach(this.field_notification_toggle , 4, 6, 2, 1);
this.main.attach(this.field_move_item_first , 4, 7, 2, 1);
this.main.attach(this.field_display_mode , 4, 8, 2, 1);
this.main.attach(this.field_topbar_preview_size , 4, 9, 2, 1);
this.main.attach(this.field_keybinding_activation , 4, 10, 2, 1);
this.main.attach(this.field_keybinding , 2, 11, 4, 2);
SettingsSchema.bind(Fields.INTERVAL, this.field_interval, 'value', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.HISTORY_SIZE, this.field_size, 'value', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.PREVIEW_SIZE, this.field_preview_size, 'value', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.CACHE_FILE_SIZE, this.field_cache_size, 'value', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.CACHE_ONLY_FAVORITE, this.field_cache_disable, 'active', Gio.SettingsBindFlags.DEFAULT);
//SettingsSchema.bind(Fields.DELETE, this.field_deletion, 'active', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.NOTIFY_ON_COPY, this.field_notification_toggle, 'active', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.MOVE_ITEM_FIRST, this.field_move_item_first, 'active', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.TOPBAR_DISPLAY_MODE_ID, this.field_display_mode, 'active', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.TOPBAR_PREVIEW_SIZE, this.field_topbar_preview_size, 'value', Gio.SettingsBindFlags.DEFAULT);
SettingsSchema.bind(Fields.ENABLE_KEYBINDING, this.field_keybinding_activation, 'active', Gio.SettingsBindFlags.DEFAULT);
this.main.show_all();
},
_create_display_mode_options : function(){
let options = [{ name: _("Icon") },
{ name: _("Clipboard Content"),},
{ name: _("Both")}];
let liststore = new Gtk.ListStore();
liststore.set_column_types([GObject.TYPE_STRING])
for (let i = 0; i < options.length; i++ ) {
let option = options[i];
let iter = liststore.append();
liststore.set (iter, [0], [option.name]);
}
return liststore;
}
});
function buildPrefsWidget(){
let widget = new App();
return widget.main;
}
//binding widgets
//////////////////////////////////
const COLUMN_ID = 0;
const COLUMN_DESCRIPTION = 1;
const COLUMN_KEY = 2;
const COLUMN_MODS = 3;
function addKeybinding(model, settings, id, description) {
// Get the current accelerator.
let accelerator = settings.get_strv(id)[0];
let key, mods;
if (accelerator == null)
[key, mods] = [0, 0];
else
[key, mods] = Gtk.accelerator_parse(settings.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(SettingsSchema) {
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);
SettingsSchema.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);
SettingsSchema.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;
}