forked from home-sweet-gnome/dash-to-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
409 lines (337 loc) · 17.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
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
/*
* This file is part of the Dash-To-Panel extension for Gnome 3
*
* 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/>.
*
*
* Credits:
* This file is based on code from the Dash to Dock extension by micheleg.
* Some code was also adapted from the upstream Gnome Shell source code.
*/
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Gdk = imports.gi.Gdk;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Gettext = imports.gettext.domain('dash-to-panel');
const _ = Gettext.gettext;
const N_ = function(e) { return e };
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const SCALE_UPDATE_TIMEOUT = 500;
const DEFAULT_PANEL_SIZES = [ 128, 96, 64, 48, 32, 24, 16 ];
const DEFAULT_FONT_SIZES = [ 96, 64, 48, 32, 24, 16, 0 ];
const DEFAULT_MARGIN_SIZES = [ 32, 24, 16, 12, 8, 4, 0 ];
const DEFAULT_PADDING_SIZES = [ 32, 24, 16, 12, 8, 4, 0, -1 ];
const Settings = new Lang.Class({
Name: 'DashToPanel.Settings',
_init: function() {
this._settings = Convenience.getSettings('org.gnome.shell.extensions.dash-to-panel');
this._rtl = (Gtk.Widget.get_default_direction() == Gtk.TextDirection.RTL);
this._builder = new Gtk.Builder();
this._builder.set_translation_domain(Me.metadata['gettext-domain']);
this._builder.add_from_file(Me.path + '/Settings.ui');
this.widget = this._builder.get_object('settings_notebook');
// Timeout to delay the update of the settings
this._panel_size_timeout = 0;
this._tray_size_timeout = 0;
this._leftbox_size_timeout = 0;
this._appicon_margin_timeout = 0;
this._tray_padding_timeout = 0;
this._statusicon_padding_timeout = 0;
this._leftbox_padding_timeout = 0;
this._bindSettings();
this._builder.connect_signals_full(Lang.bind(this, this._connector));
},
/**
* Connect signals
*/
_connector: function(builder, object, signal, handler) {
object.connect(signal, Lang.bind(this, this._SignalHandler[handler]));
},
_bindSettings: function() {
// Position and size panel
// Position option
let position = this._settings.get_string('panel-position');
switch (position) {
case 'BOTTOM':
this._builder.get_object('position_bottom_button').set_active(true);
break;
case 'TOP':
this._builder.get_object('position_top_button').set_active(true);
break;
}
this._builder.get_object('location_clock_combo').set_active_id(this._settings.get_string('location-clock'));
this._builder.get_object('location_clock_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_string('location-clock', widget.get_active_id());
}));
// size options
let panel_size_scale = this._builder.get_object('panel_size_scale');
panel_size_scale.set_range(DEFAULT_PANEL_SIZES[DEFAULT_PANEL_SIZES.length-1], DEFAULT_PANEL_SIZES[0]);
panel_size_scale.set_value(this._settings.get_int('panel-size'));
DEFAULT_PANEL_SIZES.slice(1, -1).forEach(function(val) {
panel_size_scale.add_mark(val, Gtk.PositionType.TOP, val.toString());
});
// Corrent for rtl languages
if (this._rtl) {
// Flip value position: this is not done automatically
panel_size_scale.set_value_pos(Gtk.PositionType.LEFT);
// I suppose due to a bug, having a more than one mark and one above a value of 100
// makes the rendering of the marks wrong in rtl. This doesn't happen setting the scale as not flippable
// and then manually inverting it
panel_size_scale.set_flippable(false);
panel_size_scale.set_inverted(true);
}
// Dots Position option
let dotPosition = this._settings.get_string('dot-position');
switch (dotPosition) {
case 'BOTTOM':
this._builder.get_object('dots_bottom_button').set_active(true);
break;
case 'TOP':
this._builder.get_object('dots_top_button').set_active(true);
break;
}
// Behavior panel
this._settings.bind('show-show-apps-button',
this._builder.get_object('show_applications_button_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('animate-show-apps',
this._builder.get_object('application_button_animation_button'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('show-show-apps-button',
this._builder.get_object('application_button_animation_button'),
'sensitive',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('show-activities-button',
this._builder.get_object('show_activities_button_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('isolate-workspaces',
this._builder.get_object('isolate_workspaces_switch'),
'active',
Gio.SettingsBindFlags.DEFAULT);
this._builder.get_object('click_action_combo').set_active_id(this._settings.get_string('click-action'));
this._builder.get_object('click_action_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_string('click-action', widget.get_active_id());
}));
this._builder.get_object('shift_click_action_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_string('shift-click-action', widget.get_active_id());
}));
this._builder.get_object('middle_click_action_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_string('middle-click-action', widget.get_active_id());
}));
this._builder.get_object('shift_middle_click_action_combo').connect('changed', Lang.bind (this, function(widget) {
this._settings.set_string('shift-middle-click-action', widget.get_active_id());
}));
// Create dialog for middle-click options
this._builder.get_object('middle_click_options_button').connect('clicked', Lang.bind(this, function() {
let dialog = new Gtk.Dialog({ title: _('Customize middle-click behavior'),
transient_for: this.widget.get_toplevel(),
use_header_bar: true,
modal: true });
// GTK+ leaves positive values for application-defined response ids.
// Use +1 for the reset action
dialog.add_button(_('Reset to defaults'), 1);
let box = this._builder.get_object('box_middle_click_options');
dialog.get_content_area().add(box);
this._builder.get_object('shift_click_action_combo').set_active_id(this._settings.get_string('shift-click-action'));
this._builder.get_object('middle_click_action_combo').set_active_id(this._settings.get_string('middle-click-action'));
this._builder.get_object('shift_middle_click_action_combo').set_active_id(this._settings.get_string('shift-middle-click-action'));
this._settings.bind('shift-click-action',
this._builder.get_object('shift_click_action_combo'),
'active-id',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('middle-click-action',
this._builder.get_object('middle_click_action_combo'),
'active-id',
Gio.SettingsBindFlags.DEFAULT);
this._settings.bind('shift-middle-click-action',
this._builder.get_object('shift_middle_click_action_combo'),
'active-id',
Gio.SettingsBindFlags.DEFAULT);
dialog.connect('response', Lang.bind(this, function(dialog, id) {
if (id == 1) {
// restore default settings for the relevant keys
let keys = ['shift-click-action', 'middle-click-action', 'shift-middle-click-action'];
keys.forEach(function(val) {
this._settings.set_value(val, this._settings.get_default_value(val));
}, this);
this._builder.get_object('shift_click_action_combo').set_active_id(this._settings.get_string('shift-click-action'));
this._builder.get_object('middle_click_action_combo').set_active_id(this._settings.get_string('middle-click-action'));
this._builder.get_object('shift_middle_click_action_combo').set_active_id(this._settings.get_string('shift-middle-click-action'));
} else {
// remove the settings box so it doesn't get destroyed;
dialog.get_content_area().remove(box);
dialog.destroy();
}
return;
}));
dialog.show_all();
}));
// Appearance panel
let sizeScales = [
{objectName: 'tray_size_scale', valueName: 'tray-size', range: DEFAULT_FONT_SIZES },
{objectName: 'leftbox_size_scale', valueName: 'leftbox-size', range: DEFAULT_FONT_SIZES },
{objectName: 'appicon_margin_scale', valueName: 'appicon-margin', range: DEFAULT_MARGIN_SIZES },
{objectName: 'tray_padding_scale', valueName: 'tray-padding', range: DEFAULT_PADDING_SIZES },
{objectName: 'leftbox_padding_scale', valueName: 'leftbox-padding', range: DEFAULT_PADDING_SIZES },
{objectName: 'statusicon_padding_scale', valueName: 'status-icon-padding', range: DEFAULT_PADDING_SIZES }
];
for(var idx in sizeScales) {
let size_scale = this._builder.get_object(sizeScales[idx].objectName);
let range = sizeScales[idx].range;
size_scale.set_range(range[range.length-1], range[0]);
size_scale.set_value(this._settings.get_int(sizeScales[idx].valueName));
range.slice(1, -1).forEach(function(val) {
size_scale.add_mark(val, Gtk.PositionType.TOP, val.toString());
});
// Corrent for rtl languages
if (this._rtl) {
// Flip value position: this is not done automatically
size_scale.set_value_pos(Gtk.PositionType.LEFT);
// I suppose due to a bug, having a more than one mark and one above a value of 100
// makes the rendering of the marks wrong in rtl. This doesn't happen setting the scale as not flippable
// and then manually inverting it
size_scale.set_flippable(false);
size_scale.set_inverted(true);
}
}
},
/**
* Object containing all signals defined in the glade file
*/
_SignalHandler: {
position_bottom_button_toggled_cb: function(button) {
if (button.get_active())
this._settings.set_string('panel-position', "BOTTOM");
},
position_top_button_toggled_cb: function(button) {
if (button.get_active())
this._settings.set_string('panel-position', "TOP");
},
dots_bottom_button_toggled_cb: function(button) {
if (button.get_active())
this._settings.set_string('dot-position', "BOTTOM");
},
dots_top_button_toggled_cb: function(button) {
if (button.get_active())
this._settings.set_string('dot-position', "TOP");
},
panel_size_scale_format_value_cb: function(scale, value) {
return value+ ' px';
},
panel_size_scale_value_changed_cb: function(scale) {
// Avoid settings the size consinuosly
if (this._panel_size_timeout > 0)
Mainloop.source_remove(this._panel_size_timeout);
this._panel_size_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function() {
this._settings.set_int('panel-size', scale.get_value());
this._panel_size_timeout = 0;
return GLib.SOURCE_REMOVE;
}));
},
tray_size_scale_format_value_cb: function(scale, value) {
return value+ ' px';
},
tray_size_scale_value_changed_cb: function(scale) {
// Avoid settings the size consinuosly
if (this._tray_size_timeout > 0)
Mainloop.source_remove(this._tray_size_timeout);
this._tray_size_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function() {
this._settings.set_int('tray-size', scale.get_value());
this._tray_size_timeout = 0;
return GLib.SOURCE_REMOVE;
}));
},
leftbox_size_scale_format_value_cb: function(scale, value) {
return value+ ' px';
},
leftbox_size_scale_value_changed_cb: function(scale) {
// Avoid settings the size consinuosly
if (this._leftbox_size_timeout > 0)
Mainloop.source_remove(this._leftbox_size_timeout);
this._leftbox_size_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function() {
this._settings.set_int('leftbox-size', scale.get_value());
this._leftbox_size_timeout = 0;
return GLib.SOURCE_REMOVE;
}));
},
appicon_margin_scale_format_value_cb: function(scale, value) {
return value+ ' px';
},
appicon_margin_scale_value_changed_cb: function(scale) {
// Avoid settings the size consinuosly
if (this._appicon_margin_timeout > 0)
Mainloop.source_remove(this._appicon_margin_timeout);
this._appicon_margin_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function() {
this._settings.set_int('appicon-margin', scale.get_value());
this._appicon_margin_timeout = 0;
return GLib.SOURCE_REMOVE;
}));
},
tray_padding_scale_format_value_cb: function(scale, value) {
return value+ ' px';
},
tray_padding_scale_value_changed_cb: function(scale) {
// Avoid settings the size consinuosly
if (this._tray_padding_timeout > 0)
Mainloop.source_remove(this._tray_padding_timeout);
this._tray_padding_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function() {
this._settings.set_int('tray-padding', scale.get_value());
this._tray_padding_timeout = 0;
return GLib.SOURCE_REMOVE;
}));
},
statusicon_padding_scale_format_value_cb: function(scale, value) {
return value+ ' px';
},
statusicon_padding_scale_value_changed_cb: function(scale) {
// Avoid settings the size consinuosly
if (this._statusicon_padding_timeout > 0)
Mainloop.source_remove(this._statusicon_padding_timeout);
this._statusicon_padding_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function() {
this._settings.set_int('status-icon-padding', scale.get_value());
this._statusicon_padding_timeout = 0;
return GLib.SOURCE_REMOVE;
}));
},
leftbox_padding_scale_format_value_cb: function(scale, value) {
return value+ ' px';
},
leftbox_padding_scale_value_changed_cb: function(scale) {
// Avoid settings the size consinuosly
if (this._leftbox_padding_timeout > 0)
Mainloop.source_remove(this._leftbox_padding_timeout);
this._leftbox_padding_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function() {
this._settings.set_int('leftbox-padding', scale.get_value());
this._leftbox_padding_timeout = 0;
return GLib.SOURCE_REMOVE;
}));
}
}
});
function init() {
Convenience.initTranslations();
}
function buildPrefsWidget() {
let settings = new Settings();
let widget = settings.widget;
widget.show_all();
return widget;
}