forked from SUPERCILEX/gnome-clipboard-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs.js
446 lines (407 loc) · 12.1 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
'use strict';
const { GObject, Gtk, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Gettext = imports.gettext;
const _ = Gettext.domain(Me.uuid).gettext;
var Fields = {
HISTORY_SIZE: 'history-size',
WINDOW_WIDTH_PERCENTAGE: 'window-width-percentage',
CACHE_FILE_SIZE: 'cache-size',
CACHE_ONLY_FAVORITES: 'cache-only-favorites',
NOTIFY_ON_COPY: 'notify-on-copy',
CONFIRM_ON_CLEAR: 'confirm-clear',
MOVE_ITEM_FIRST: 'move-item-first',
ENABLE_KEYBINDING: 'enable-keybindings',
TOPBAR_PREVIEW_SIZE: 'topbar-preview-size',
TOPBAR_DISPLAY_MODE_ID: 'display-mode',
DISABLE_DOWN_ARROW: 'disable-down-arrow',
STRIP_TEXT: 'strip-text',
PRIVATE_MODE: 'private-mode',
PASTE_ON_SELECTION: 'paste-on-selection',
PROCESS_PRIMARY_SELECTION: 'process-primary-selection',
};
const SCHEMA_NAME = 'org.gnome.shell.extensions.clipboard-history';
var Settings = ExtensionUtils.getSettings(SCHEMA_NAME);
function init() {
ExtensionUtils.initTranslations(Me.uuid);
}
class Prefs extends GObject.Object {
_init() {
this.main = new Gtk.Grid({
margin_top: 10,
margin_bottom: 10,
margin_start: 10,
margin_end: 10,
row_spacing: 12,
column_spacing: 18,
column_homogeneous: false,
row_homogeneous: false,
});
this.field_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 100_000,
step_increment: 100,
}),
});
this.window_width_percentage = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 5,
}),
});
this.field_cache_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 1024,
step_increment: 5,
}),
});
this.field_topbar_preview_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 100,
step_increment: 10,
}),
});
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_disable_down_arrow = new Gtk.Switch();
this.field_cache_disable = new Gtk.Switch();
this.field_notification_toggle = new Gtk.Switch();
this.field_confirm_clear_toggle = new Gtk.Switch();
this.field_strip_text = new Gtk.Switch();
this.field_paste_on_selection = new Gtk.Switch();
this.field_process_primary_selection = new Gtk.Switch();
this.field_move_item_first = new Gtk.Switch();
this.field_keybinding = createKeybindingWidget(Settings);
addKeybinding(
this.field_keybinding.model,
Settings,
'toggle-menu',
_('Toggle the menu'),
);
addKeybinding(
this.field_keybinding.model,
Settings,
'clear-history',
_('Clear history'),
);
addKeybinding(
this.field_keybinding.model,
Settings,
'prev-entry',
_('Previous entry'),
);
addKeybinding(
this.field_keybinding.model,
Settings,
'next-entry',
_('Next entry'),
);
addKeybinding(
this.field_keybinding.model,
Settings,
'toggle-private-mode',
_('Toggle private mode'),
);
this.field_keybinding_activation = new Gtk.Switch();
this.field_keybinding_activation.connect('notify::active', (widget) => {
this.field_keybinding.set_sensitive(widget.active);
});
let sizeLabel = new Gtk.Label({
label: _('Max number of items'),
hexpand: true,
halign: Gtk.Align.START,
});
let windowWidthPercentageLabel = new Gtk.Label({
label: _('Window width (%)'),
hexpand: true,
halign: Gtk.Align.START,
});
let cacheSizeLabel = new Gtk.Label({
label: _('Max clipboard history size (MiB)'),
hexpand: true,
halign: Gtk.Align.START,
});
let cacheDisableLabel = new Gtk.Label({
label: _('Only save favorites to disk'),
hexpand: true,
halign: Gtk.Align.START,
});
let notificationLabel = new Gtk.Label({
label: _('Show notification on copy'),
hexpand: true,
halign: Gtk.Align.START,
});
let confirmClearLabel = new Gtk.Label({
label: _('Ask for confirmation before clearing history'),
hexpand: true,
halign: Gtk.Align.START,
});
let moveFirstLabel = new Gtk.Label({
label: _('Move previously copied items to the top'),
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 status bar'),
hexpand: true,
halign: Gtk.Align.START,
});
let displayModeLabel = new Gtk.Label({
label: _('What to show in status bar'),
hexpand: true,
halign: Gtk.Align.START,
});
let disableDownArrowLabel = new Gtk.Label({
label: _('Remove down arrow in status bar'),
hexpand: true,
halign: Gtk.Align.START,
});
let stripTextLabel = new Gtk.Label({
label: _('Remove whitespace around text'),
hexpand: true,
halign: Gtk.Align.START,
});
let pasteOnSelectionLabel = new Gtk.Label({
label: _('Paste on selection'),
hexpand: true,
halign: Gtk.Align.START,
});
let processPrimarySelection = new Gtk.Label({
label: _('Process primary selection'),
hexpand: true,
halign: Gtk.Align.START,
});
const addRow = ((main) => {
let row = 0;
return (label, input) => {
let inputWidget = input;
if (input instanceof Gtk.Switch) {
inputWidget = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
});
inputWidget.append(input);
}
if (label) {
main.attach(label, 0, row, 1, 1);
main.attach(inputWidget, 1, row, 1, 1);
} else {
main.attach(inputWidget, 0, row, 2, 1);
}
row++;
};
})(this.main);
addRow(windowWidthPercentageLabel, this.window_width_percentage);
addRow(sizeLabel, this.field_size);
addRow(cacheSizeLabel, this.field_cache_size);
addRow(cacheDisableLabel, this.field_cache_disable);
addRow(moveFirstLabel, this.field_move_item_first);
addRow(stripTextLabel, this.field_strip_text);
addRow(pasteOnSelectionLabel, this.field_paste_on_selection);
addRow(processPrimarySelection, this.field_process_primary_selection);
addRow(displayModeLabel, this.field_display_mode);
addRow(disableDownArrowLabel, this.field_disable_down_arrow);
addRow(topbarPreviewLabel, this.field_topbar_preview_size);
addRow(notificationLabel, this.field_notification_toggle);
addRow(confirmClearLabel, this.field_confirm_clear_toggle);
addRow(keybindingLabel, this.field_keybinding_activation);
addRow(null, this.field_keybinding);
Settings.bind(
Fields.HISTORY_SIZE,
this.field_size,
'value',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.WINDOW_WIDTH_PERCENTAGE,
this.window_width_percentage,
'value',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.CACHE_FILE_SIZE,
this.field_cache_size,
'value',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.CACHE_ONLY_FAVORITES,
this.field_cache_disable,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.NOTIFY_ON_COPY,
this.field_notification_toggle,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.CONFIRM_ON_CLEAR,
this.field_confirm_clear_toggle,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.MOVE_ITEM_FIRST,
this.field_move_item_first,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.TOPBAR_DISPLAY_MODE_ID,
this.field_display_mode,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.DISABLE_DOWN_ARROW,
this.field_disable_down_arrow,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.TOPBAR_PREVIEW_SIZE,
this.field_topbar_preview_size,
'value',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.STRIP_TEXT,
this.field_strip_text,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.PASTE_ON_SELECTION,
this.field_paste_on_selection,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.PROCESS_PRIMARY_SELECTION,
this.field_process_primary_selection,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
Settings.bind(
Fields.ENABLE_KEYBINDING,
this.field_keybinding_activation,
'active',
Gio.SettingsBindFlags.DEFAULT,
);
}
_create_display_mode_options() {
let options = [
{ name: _('Icon') },
{ name: _('Clipboard contents') },
{ name: _('Both') },
{ name: _('Neither') },
];
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;
}
}
const PrefsObj = new GObject.registerClass(Prefs);
function buildPrefsWidget() {
let widget = new PrefsObj();
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(Settings) {
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);
Settings.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);
Settings.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;
}