-
Notifications
You must be signed in to change notification settings - Fork 22
/
prefs.js
587 lines (524 loc) · 21.5 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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
/*
* Arc Menu: The new applications menu for Gnome 3.
*
* Copyright (C) 2017 LinxGem33, Alexander Rüedlinger
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Import Libraries
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Constants = Me.imports.constants;
const PW = Me.imports.prefsWidgets;
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
const _ = Gettext.gettext;
/*
* General Settings Page
*/
const GeneralSettingsPage = new Lang.Class({
Name: 'GeneralSettingsPage',
Extends: PW.NotebookPage,
_init: function(settings) {
this.parent(_('General'));
this.settings = settings;
}
});
/*
* Behaviour Settings Page
*/
const BehaviourSettingsPage = new Lang.Class({
Name: 'BehaviourSettingsPage',
Extends: PW.NotebookPage,
_init: function(settings) {
this.parent(_('Behaviour'));
this.settings = settings;
/*
* Hot Corner Box
*/
let disableHotCornerFrame = new PW.FrameBox();
let disableHotCornerRow = new PW.FrameBoxRow();
let disableHotCornerLabel = new Gtk.Label({
label: _("Disable activities hot corner"),
use_markup: true,
xalign: 0,
hexpand: true
});
let disableHotCornerSwitch = new Gtk.Switch({ halign: Gtk.Align.END });
disableHotCornerSwitch.set_active(this.settings.get_boolean('disable-activities-hotcorner'));
disableHotCornerSwitch.connect('notify::active', Lang.bind(this, function(check) {
this.settings.set_boolean('disable-activities-hotcorner', check.get_active());
}));
disableHotCornerRow.add(disableHotCornerLabel);
disableHotCornerRow.add(disableHotCornerSwitch);
disableHotCornerFrame.add(disableHotCornerRow);
/*
* Menu Hotkey and Keybinding Frame Box
*/
let menuKeybindingFrame = new PW.FrameBox();
// first row: hot key
let menuHotkeyRow = new PW.FrameBoxRow();
let menuHotkeyLabel = new Gtk.Label({
label: _("Set menu hotkey"),
use_markup: true,
xalign: 0,
hexpand: true
});
let menuHotkeyCombo = new Gtk.ComboBoxText({ halign:Gtk.Align.END });
menuHotkeyCombo.append_text(_("Undefined"));
menuHotkeyCombo.append_text(_("Left Super Key"));
menuHotkeyCombo.append_text(_("Right Super Key"));
menuHotkeyCombo.set_active(this.settings.get_enum('menu-hotkey'));
menuHotkeyCombo.connect('changed', Lang.bind (this, function(widget) {
this.settings.set_enum('menu-hotkey', widget.get_active());
}));
menuHotkeyRow.add(menuHotkeyLabel);
menuHotkeyRow.add(menuHotkeyCombo);
menuKeybindingFrame.add(menuHotkeyRow);
// second row: custom Keybinding
let menuKeybindingRow = new PW.FrameBoxRow();
let menuKeybindingLabel = new Gtk.Label({
label: _("Enable custom menu keybinding"),
use_markup: true,
xalign: 0,
hexpand: true
});
let menuKeybindingDescriptionRow = new PW.FrameBoxRow();
let menuKeybindingDescriptionLabel = new Gtk.Label({
label: _("Syntax: <Shift>, <Ctrl>, <Alt>, <Super>")
});
let menuKeybindingSwitch = new Gtk.Switch({ halign: Gtk.Align.END });
menuKeybindingSwitch.set_active(this.settings.get_boolean('enable-menu-keybinding'));
menuKeybindingSwitch.connect('notify::active', Lang.bind(this, function(check) {
this.settings.set_boolean('enable-menu-keybinding', check.get_active());
}));
let menuKeybindingEntry = new Gtk.Entry({ halign: Gtk.Align.END });
menuKeybindingEntry.set_width_chars(15);
menuKeybindingEntry.set_text(this.settings.get_string('menu-keybinding-text'));
menuKeybindingEntry.connect('changed', Lang.bind(this, function(entry) {
let _menuKeybinding = entry.get_text();
//TODO: catch possible user mistakes
this.settings.set_string('menu-keybinding-text', _menuKeybinding);
// Always deactivate the menu keybinding after it has been changed.
// By that we avoid pssible "UX" or sync bugs.
menuKeybindingSwitch.set_active(false);
}));
menuKeybindingRow.add(menuKeybindingLabel);
menuKeybindingRow.add(menuKeybindingEntry);
menuKeybindingRow.add(menuKeybindingSwitch);
menuKeybindingDescriptionRow.add(menuKeybindingDescriptionLabel);
menuKeybindingFrame.add(menuKeybindingRow);
menuKeybindingFrame.add(menuKeybindingDescriptionRow);
// add the frames
this.add(disableHotCornerFrame);
this.add(menuKeybindingFrame);
}
});
/*
* TODO: Appearance Settings Page
*/
const MenuButtonCustomizationWindow = new Lang.Class({
Name: 'MenuButtonCustomizationWindow',
Extends: PW.DialogWindow,
_init: function(settings, parent) {
this._settings = settings;
this.parent(_('Button appearance'), parent);
},
_createLayout: function(vbox) {
/*
* Text Appearance Frame
*/
let menuButtonTextFrame = new PW.FrameBox();
//first row
let menuButtonTextBoxRow = new PW.FrameBoxRow();
let menuButtonTextLabel = new Gtk.Label({
label: _('Text for the menu button'),
use_markup: true,
xalign: 0,
hexpand: true
});
let systemTextButton = new Gtk.RadioButton({
label: _('System text')
});
let customTextButton = new Gtk.RadioButton({
label: _('Custom text'),
group: systemTextButton
});
if(this._settings.get_enum('menu-button-text') === Constants.MENU_BUTTON_TEXT.System) {
systemTextButton.set_active(true);
} else {
customTextButton.set_active(true);
}
systemTextButton.connect('clicked', Lang.bind(this, function() {
this._settings.set_enum('menu-button-text', Constants.MENU_BUTTON_TEXT.System);
}));
customTextButton.connect('clicked', Lang.bind(this, function() {
this._settings.set_enum('menu-button-text', Constants.MENU_BUTTON_TEXT.Custom);
}));
menuButtonTextBoxRow.add(menuButtonTextLabel);
menuButtonTextBoxRow.add(systemTextButton);
menuButtonTextBoxRow.add(customTextButton);
menuButtonTextFrame.add(menuButtonTextBoxRow);
// second row
let menuButtonCustomTextBoxRow = new PW.FrameBoxRow();
let menuButtonCustomTextLabel = new Gtk.Label({
label: _('Set custom text for the menu button'),
use_markup: true,
xalign: 0,
hexpand: true
});
let menuButtonCustomTextEntry = new Gtk.Entry({ halign: Gtk.Align.END });
menuButtonCustomTextEntry.set_width_chars(15);
menuButtonCustomTextEntry.set_text(this._settings.get_string('custom-menu-button-text'));
menuButtonCustomTextEntry.connect('changed', Lang.bind(this, function(entry) {
let customMenuButtonText = entry.get_text();
this._settings.set_string('custom-menu-button-text', customMenuButtonText);
}));
menuButtonCustomTextBoxRow.add(menuButtonCustomTextLabel);
menuButtonCustomTextBoxRow.add(menuButtonCustomTextEntry);
menuButtonTextFrame.add(menuButtonCustomTextBoxRow);
// third row
let menuButtonArrowIconBoxRow = new PW.FrameBoxRow();
let menuButtonArrowIconLabel = new Gtk.Label({
label: _('Enable the arrow icon beside the button text'),
use_markup: true,
xalign: 0,
hexpand: true
});
let enableArrowIconSwitch = new Gtk.Switch({ halign: Gtk.Align.END });
enableArrowIconSwitch.set_active(this._settings.get_boolean('enable-menu-button-arrow'));
enableArrowIconSwitch.connect('notify::active', Lang.bind(this, function(check) {
this._settings.set_boolean('enable-menu-button-arrow', check.get_active());
}));
menuButtonArrowIconBoxRow.add(menuButtonArrowIconLabel);
menuButtonArrowIconBoxRow.add(enableArrowIconSwitch);
menuButtonTextFrame.add(menuButtonArrowIconBoxRow);
/*
* Icon Appearance Frame
*/
let menuButtonIconFrame = new PW.FrameBox();
// first row
let menuButtonIconBoxRow = new PW.FrameBoxRow();
let menuButtonIconBoxLabel = new Gtk.Label({
label: _('Select icon for the menu button'),
use_markup: true,
xalign: 0,
hexpand: true
});
// create file filter and file chooser button
let fileFilter = new Gtk.FileFilter();
fileFilter.add_pixbuf_formats();
let fileChooserButton = new Gtk.FileChooserButton({
action: Gtk.FileChooserAction.OPEN,
title: _('Please select an image icon'),
filter: fileFilter
});
let menuButtonIconCombo = new Gtk.ComboBoxText({ halign:Gtk.Align.END });
menuButtonIconCombo.append_text(_("Arc Menu Icon"));
menuButtonIconCombo.append_text(_("System Icon"));
menuButtonIconCombo.append_text(_("Custom Icon"));
menuButtonIconCombo.set_active(this._settings.get_enum('menu-button-icon'));
menuButtonIconCombo.connect('changed', Lang.bind(this, function(widget) {
this._settings.set_enum('menu-button-icon', widget.get_active());
}));
fileChooserButton.connect('file-set', Lang.bind(this, function(fileChooserButton) {
let iconFilepath = fileChooserButton.get_filename();
this._settings.set_string('custom-menu-button-icon', iconFilepath);
menuButtonIconCombo.set_active(Constants.MENU_BUTTON_ICON.Custom);
}));
fileChooserButton.set_current_folder(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES));
let iconFilepath = this._settings.get_string('custom-menu-button-icon');
if(iconFilepath) {
fileChooserButton.set_filename(iconFilepath);
}
menuButtonIconBoxRow.add(menuButtonIconBoxLabel);
menuButtonIconBoxRow.add(fileChooserButton);
menuButtonIconBoxRow.add(menuButtonIconCombo);
menuButtonIconFrame.add(menuButtonIconBoxRow);
// second row
let menuButtonIconScaleBoxRow = new PW.FrameBoxRow();
let iconSize = this._settings.get_double('custom-menu-button-icon-size');
let menuButtonIconScaleBoxLabel = new Gtk.Label({
label: _('Icon size') + '\n(' + _('default is') + ' ' + Constants.DEFAULT_ICON_SIZE + ')',
use_markup: true,
xalign: 0
});
let hscale = new Gtk.HScale({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 64,
step_increment: 1,
page_increment: 1,
page_size: 0
}),
digits: 0,
round_digits: 0,
hexpand: true,
value_pos: Gtk.PositionType.RIGHT
});
hscale.connect('format-value', function(scale, value) { return value.toString() + ' px'; });
Constants.ICON_SIZES.forEach(function(num) {
hscale.add_mark(num, Gtk.PositionType.BOTTOM, num.toString());
});
hscale.set_value(iconSize);
hscale.connect('value-changed', Lang.bind(this, function(){
this._settings.set_double('custom-menu-button-icon-size', hscale.get_value());
}));
menuButtonIconScaleBoxRow.add(menuButtonIconScaleBoxLabel);
menuButtonIconScaleBoxRow.add(hscale);
menuButtonIconFrame.add(menuButtonIconScaleBoxRow);
// add the frames to the vbox
vbox.add(menuButtonTextFrame);
vbox.add(menuButtonIconFrame);
}
});
const AppearanceSettingsPage = new Lang.Class({
Name: 'AppearanceSettingsPage',
Extends: PW.NotebookPage,
_init: function(settings) {
this.parent(_('Appearance'));
this.settings = settings;
/*
* Menu Button Appearance Frame Box
*/
let menuButtonAppearanceFrame = new PW.FrameBox();
let menuButtonAppearanceRow = new PW.FrameBoxRow();
let menuButtonAppearanceLabel = new Gtk.Label({
label: _("Customize menu button appearance"),
use_markup: true,
xalign: 0,
hexpand: true
});
let menuButtonAppearanceSettingsButton = new PW.IconButton({
circular: true,
icon_name: 'emblem-system-symbolic'
});
let menuButtonAppearanceCombo = new Gtk.ComboBoxText({ halign:Gtk.Align.END });
menuButtonAppearanceCombo.append_text(_("Icon"));
menuButtonAppearanceCombo.append_text(_("Text"));
menuButtonAppearanceCombo.append_text(_("Icon and Text"));
menuButtonAppearanceCombo.append_text(_("Text and Icon"));
menuButtonAppearanceCombo.set_active(this.settings.get_enum('menu-button-appearance'));
menuButtonAppearanceCombo.connect('changed', Lang.bind (this, function(widget) {
this.settings.set_enum('menu-button-appearance', widget.get_active());
}));
// Extra settings for the appearance of the menu button
menuButtonAppearanceSettingsButton.connect('clicked',
Lang.bind(this, function() {
let dialog = new MenuButtonCustomizationWindow(this.settings, this);
dialog.show_all();
}));
menuButtonAppearanceRow.add(menuButtonAppearanceLabel);
menuButtonAppearanceRow.add(menuButtonAppearanceSettingsButton);
menuButtonAppearanceRow.add(menuButtonAppearanceCombo);
menuButtonAppearanceFrame.add(menuButtonAppearanceRow);
this.add(menuButtonAppearanceFrame);
/*
* Menu Position Box
*/
let menuPositionFrame = new PW.FrameBox();
let menuPositionRow = new PW.FrameBoxRow();
let menuPositionBoxLabel = new Gtk.Label({
label: _("Menu position in panel"),
use_markup: true,
xalign: 0,
hexpand: true
});
let menuPositionLeftButton = new Gtk.RadioButton({
label: _('Left')
});
let menuPositionCenterButton = new Gtk.RadioButton({
label: _('Center'),
group: menuPositionLeftButton
});
let menuPositionRightButton = new Gtk.RadioButton({
label: _('Right'),
group: menuPositionLeftButton
});
// callback handlers for the radio buttons
menuPositionLeftButton.connect('clicked', Lang.bind(this, function() {
this.settings.set_enum('position-in-panel', Constants.MENU_POSITION.Left);
}));
menuPositionCenterButton.connect('clicked', Lang.bind(this, function() {
this.settings.set_enum('position-in-panel', Constants.MENU_POSITION.Center);
}));
menuPositionRightButton.connect('clicked', Lang.bind(this, function() {
this.settings.set_enum('position-in-panel', Constants.MENU_POSITION.Right);
}));
switch(this.settings.get_enum('position-in-panel')) {
case Constants.MENU_POSITION.Left:
menuPositionLeftButton.set_active(true);
break;
case Constants.MENU_POSITION.Center:
menuPositionCenterButton.set_active(true);
break;
case Constants.MENU_POSITION.Right:
menuPositionRightButton.set_active(true);
break;
}
menuPositionRow.add(menuPositionBoxLabel);
menuPositionRow.add(menuPositionLeftButton);
menuPositionRow.add(menuPositionCenterButton);
menuPositionRow.add(menuPositionRightButton);
menuPositionFrame.add(menuPositionRow);
// add the frames
this.add(menuPositionFrame);
}
});
/*
* Fine Tune Settings Page
*
const FineTuneSettingsPage = new Lang.Class({
Name: 'FineTuneSettingsPage',
Extends: PW.NotebookPage,
_init: function(settings) {
this.parent(_('Fine Tune'));
this.settings = settings;
/*
* Tooltips Box
*
let toolTipsFrame = new PW.FrameBox();
let toolTipsRow = new PW.FrameBoxRow();
let toolTipsLabel = new Gtk.Label({
label: _("Enable tooltips"),
use_markup: true,
xalign: 0,
hexpand: true
});
let toolTipsSwitch = new Gtk.Switch({ halign: Gtk.Align.END });
toolTipsSwitch.set_active(this.settings.get_boolean('enable-tooltips'));
toolTipsSwitch.connect('notify::active', Lang.bind(this, function(check) {
this.settings.set_boolean('enable-tooltips', check.get_active());
}));
toolTipsRow.add(toolTipsLabel);
toolTipsRow.add(toolTipsSwitch);
toolTipsFrame.add(toolTipsRow);
// add the frames
this.add(toolTipsFrame)
}
});
/*
* About Page
*/
const AboutPage = new Lang.Class({
Name: 'AboutPage',
Extends: PW.NotebookPage,
_init: function(settings) {
this.parent(_('About'));
this.settings = settings;
// Use meta information from metadata.json
let releaseVersion = Me.metadata.version || 'unknown';
let projectName = Me.metadata.name;
let projectDescription = Me.metadata.description;
let projectUrl = Me.metadata.url;
// Create GUI elements
// Create the image box
let logoPath = Me.path + Constants.ARC_MENU_LOGO.Path;
let [imageWidth, imageHeight] = Constants.ARC_MENU_LOGO.Size;
let pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(logoPath, imageWidth, imageHeight);
let arcMenuImage = new Gtk.Image({ pixbuf: pixbuf });
let arcMenuImageBox = new Gtk.VBox({
margin_top:5,
margin_bottom: 5,
expand: false
});
arcMenuImageBox.add(arcMenuImage);
// Create the info box
let arcMenuInfoBox = new Gtk.VBox({
margin_top:5,
margin_bottom: 5,
expand: false
});
let arcMenuLabel = new Gtk.Label({
label: '<b>' + _('Arc-Menu') + '</b>',
use_markup: true,
expand: false
});
let versionLabel = new Gtk.Label({
label: _('version: ') + releaseVersion,
expand: false
});
let projectDescriptionLabel = new Gtk.Label({
label: _(projectDescription),
expand: false
});
let projectLinkButton = new Gtk.LinkButton({
label: _('GitLab Page'),
uri: projectUrl,
expand: false
});
arcMenuInfoBox.add(arcMenuLabel);
arcMenuInfoBox.add(versionLabel);
arcMenuInfoBox.add(projectDescriptionLabel);
arcMenuInfoBox.add(projectLinkButton);
// Create the GNU software box
let gnuSofwareLabel = new Gtk.Label({
label: Constants.GNU_SOFTWARE,
use_markup: true,
justify: Gtk.Justification.CENTER,
expand: true
});
let gnuSofwareLabelBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL
});
gnuSofwareLabelBox.add(gnuSofwareLabel);
this.add(arcMenuImageBox);
this.add(arcMenuInfoBox);
this.add(gnuSofwareLabelBox);
}
});
/*
* Arc Menu Preferences Widget
*/
const ArcMenuPreferencesWidget= new GObject.Class({
Name: 'ArcMenu.ArcMenuPreferencesWidget',
GTypeName: 'ArcMenuPreferencesWidget',
Extends: Gtk.Box,
_init: function() {
this.parent({
orientation: Gtk.Orientation.VERTICAL,
spacing: 5,
border_width: 5
});
this.settings = Convenience.getSettings(Me.metadata['settings-schema']);
let notebook = new PW.Notebook();
// Spoiler alert: There will be a general settings page in vXX ;-)
//let generalSettingsPage = new GeneralSettingsPage(this.settings);
//notebook.append_page(generalSettingsPage, generalSettingsPage.title);
let behaviourSettingsPage = new BehaviourSettingsPage(this.settings);
notebook.append_page(behaviourSettingsPage);
let appearancePage = new AppearanceSettingsPage(this.settings);
notebook.append_page(appearancePage);
// let fineTunePage = new FineTuneSettingsPage(this.settings);
// notebook.append_page(fineTunePage);
let aboutPage = new AboutPage(this.settings);
notebook.append_page(aboutPage);
this.add(notebook);
}
});
// Initialize menu language translations
function init() {
Convenience.initTranslations(Me.metadata['gettext-domain']);
}
function buildPrefsWidget() {
let widget = new ArcMenuPreferencesWidget();
widget.show_all();
return widget;
}