-
Notifications
You must be signed in to change notification settings - Fork 2
/
prefs.js
157 lines (141 loc) · 4.67 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
const Gettext = imports.gettext;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const SETTINGS_SCALING_MODE_KEY = 'scaling-mode';
const SETTINGS_EXTEND_DIRECTION_KEY = 'extend-direction';
const SETTINGS_MESSAGE_FADE_OUT_TIME_KEY = 'message-fade-out-time';
const SETTINGS_USE_BELOW_SETTINGS = 'use-below-settings';
let _;
let settings;
function init() {
let extension = imports.misc.extensionUtils.getCurrentExtension();
let convenience = extension.imports.convenience;
convenience.initTranslations();
_ = Gettext.domain(extension.metadata['gettext-domain']).gettext;
settings = convenience.getSettings();
}
const Box = new Lang.Class({
Name: 'Box',
Extends: Gtk.Box,
_init: function (grid) {
this.parent({
orientation: Gtk.Orientation.HORIZONTAL,
border_width: 18
});
this.set_center_widget(grid);
this.show_all();
}
});
const Grid = new Lang.Class({
Name: 'Grid',
Extends: Gtk.Grid,
_init: function (controls) {
this.parent({
column_spacing: 12,
row_spacing: 18
});
let maxWidth = 0;
for (let i in controls) {
let width = controls[i].length;
if (maxWidth < width) {
maxWidth = width;
}
}
for (let i in controls) {
if (controls[i].length != 1) {
for (let j in controls[i]) {
this.attach(controls[i][j], j, i, 1, 1);
}
} else {
this.attach(controls[i][0], 0, i, maxWidth, 1);
}
}
}
});
const Label = new Lang.Class({
Name: 'Label',
Extends: Gtk.Label,
_init: function (label) {
this.parent({
label: label
});
this.set_alignment(1.0, 0.5);
}
});
const CheckBox = new Lang.Class({
Name: 'CheckBox',
Extends: Gtk.CheckButton,
_init: function (settings, settings_key, toggled_hook) {
let state = settings.get_boolean(settings_key);
this.parent({
active: state
});
toggled_hook(state);
this.connect('toggled', function (checkBox) {
let state = checkBox.get_active();
settings.set_boolean(settings_key, state);
toggled_hook(state);
});
}
});
const Select = new Lang.Class({
Name: 'Select',
Extends: Gtk.ComboBoxText,
_init: function (texts, settings, settingsKey) {
this.parent();
for (let i in texts) {
this.append_text(texts[i]);
}
this.set_active(settings.get_enum(settingsKey));
this.connect('changed', function (select) {
settings.set_enum(settingsKey, select.get_active());
});
}
});
const NumberEdit = new Lang.Class({
Name: 'NumberEdit',
Extends: Gtk.SpinButton,
_init: function (settings, settings_key) {
this.parent({
adjustment: new Gtk.Adjustment({
value: settings.get_int(settings_key),
lower: 0,
upper: 8,
'step-increment': 1
})
});
this.connect('value-changed', function (numberEdit) {
settings.set_int(settings_key, numberEdit.get_value());
});
}
});
function buildPrefsWidget() {
let labelUseBelowSettings = new Label(_('Use below settings'));
let labelScalingMode = new Label(_('Scaling mode') + ':');
let labelExtendDirection = new Label(_('Display extend direction') + ':');
let labelMessageFadeOutTime = new Label(_('Messages fade out time') + ' (s):');
let scalingModes = [_('default'), _('native'), _('scaled'), _('centered'), _('aspect-scaled')];
let scalingMode = new Select(scalingModes, settings, SETTINGS_SCALING_MODE_KEY);
let extendDirections = [_('left'), _('right'), _('top'), _('bottom')];
let extendDirection = new Select(extendDirections, settings, SETTINGS_EXTEND_DIRECTION_KEY);
let useBelowSettings = new CheckBox(settings, SETTINGS_USE_BELOW_SETTINGS, function (state) {
let belowSettings = [
labelScalingMode, scalingMode,
labelExtendDirection, extendDirection
];
for (let i in belowSettings) {
belowSettings[i].set_sensitive(state);
}
});
let messageFadeOutTime = new NumberEdit(settings, SETTINGS_MESSAGE_FADE_OUT_TIME_KEY);
let controls = [
[labelMessageFadeOutTime, messageFadeOutTime],
[labelUseBelowSettings, useBelowSettings],
[new Gtk.HSeparator()],
[labelScalingMode, scalingMode],
[labelExtendDirection, extendDirection]
];
let grid = new Grid(controls);
let box = new Box(grid);
return box;
}