~wasta-linux/wasta-core-wily/master

« back to all changes in this revision

Viewing changes to install-files/extensions/dash-to-dock@micxgx.gmail.com/prefs.js

  • Committer: Rik Shaw
  • Date: 2015-11-01 13:28:40 UTC
  • Revision ID: git-v1:59c62c9b2e4f4f1cf62db1f5dc1cf630feb99933
initial 15.10 commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: js2; indent-tabs-mode: nil; js2-basic-offset: 4 -*-
 
2
 
 
3
const Gio = imports.gi.Gio;
 
4
const GLib = imports.gi.GLib;
 
5
const GObject = imports.gi.GObject;
 
6
const Gtk = imports.gi.Gtk;
 
7
const Gdk = imports.gi.Gdk;
 
8
const Lang = imports.lang;
 
9
const Mainloop = imports.mainloop;
 
10
 
 
11
 
 
12
const Gettext = imports.gettext.domain('dashtodock');
 
13
const _ = Gettext.gettext;
 
14
const N_ = function(e) { return e };
 
15
 
 
16
const ExtensionUtils = imports.misc.extensionUtils;
 
17
const Me = ExtensionUtils.getCurrentExtension();
 
18
const Convenience = Me.imports.convenience;
 
19
 
 
20
const SCALE_UPDATE_TIMEOUT = 500;
 
21
const DEFAULT_ICONS_SIZES = [ 128, 96, 64, 48, 32, 24, 16 ];
 
22
 
 
23
const Settings = new Lang.Class({
 
24
    Name: 'DashToDockSettings',
 
25
 
 
26
 
 
27
    _init: function() {
 
28
 
 
29
        this._settings = Convenience.getSettings('org.gnome.shell.extensions.dash-to-dock');
 
30
 
 
31
        this._rtl = Gtk.Widget.get_default_direction()==Gtk.TextDirection.RTL;
 
32
 
 
33
        this._builder = new Gtk.Builder();
 
34
        this._builder.set_translation_domain(Me.metadata['gettext-domain']);
 
35
        this._builder.add_from_file(Me.path + '/Settings.ui');
 
36
 
 
37
        this.widget = this._builder.get_object('settings_notebook');
 
38
 
 
39
        // Timeout to delay the update of the settings
 
40
        this._dock_size_timeout = 0;
 
41
        this._icon_size_timeout = 0;
 
42
        this._opacity_timeout = 0;
 
43
 
 
44
        this._bindSettings();
 
45
 
 
46
        this._builder.connect_signals_full(Lang.bind(this, this._connector));
 
47
 
 
48
    },
 
49
 
 
50
    // Connect signals
 
51
    _connector: function(builder, object, signal, handler) {
 
52
        object.connect(signal, Lang.bind(this, this._SignalHandler[handler]));
 
53
    },
 
54
 
 
55
    _bindSettings: function() {
 
56
 
 
57
        /* Position and size panel */
 
58
 
 
59
        // Monitor options
 
60
 
 
61
        this._monitors = [];
 
62
        // Build options based on the number of monitors and the current settings.
 
63
        let n_monitors = Gdk.Screen.get_default().get_n_monitors();
 
64
        let primary_monitor = Gdk.Screen.get_default().get_primary_monitor();
 
65
 
 
66
        let monitor = this._settings.get_int('preferred-monitor');
 
67
 
 
68
        // Add primary monitor with index 0, because in GNOME Shell the primary monitor is always 0
 
69
        this._builder.get_object('dock_monitor_combo').append_text(_("Primary monitor"));
 
70
        this._monitors.push(0);
 
71
 
 
72
        // Add connected monitors
 
73
        let ctr = 0;
 
74
        for (let i = 0; i < n_monitors; i++) {
 
75
            if (i !== primary_monitor){
 
76
                ctr++;
 
77
                this._monitors.push(ctr);
 
78
                this._builder.get_object('dock_monitor_combo').append_text(_("Secondary monitor ") + ctr);
 
79
            }
 
80
        }
 
81
 
 
82
        // If one of the external monitor is set as preferred, show it even if not attached
 
83
        if ( monitor >= n_monitors && monitor !== primary_monitor) {
 
84
            this._monitors.push(monitor)
 
85
            this._builder.get_object('dock_monitor_combo').append_text(_("Secondary monitor ") + ++ctr);
 
86
        }
 
87
 
 
88
        this._builder.get_object('dock_monitor_combo').set_active(this._monitors.indexOf(monitor));
 
89
 
 
90
        // Position option
 
91
        let position = this._settings.get_enum('dock-position');
 
92
 
 
93
        switch (position) {
 
94
            case 0:
 
95
                this._builder.get_object('position_top_button').set_active(true);
 
96
                break;
 
97
            case 1:
 
98
                this._builder.get_object('position_right_button').set_active(true);
 
99
                break;
 
100
            case 2:
 
101
                this._builder.get_object('position_bottom_button').set_active(true);
 
102
                break;
 
103
            case 3:
 
104
                this._builder.get_object('position_left_button').set_active(true);
 
105
                break;
 
106
        }
 
107
 
 
108
        if (this._rtl) {
 
109
            /* Left is Right in rtl as a setting */
 
110
            this._builder.get_object('position_left_button').set_label(_("Right"));
 
111
            this._builder.get_object('position_right_button').set_label(_("Left"));
 
112
        }
 
113
 
 
114
        // Intelligent autohide options
 
115
        this._settings.bind('dock-fixed',
 
116
                            this._builder.get_object('intelligent_autohide_switch'),
 
117
                            'active',
 
118
                            Gio.SettingsBindFlags.INVERT_BOOLEAN);
 
119
        this._settings.bind('dock-fixed',
 
120
                            this._builder.get_object('intelligent_autohide_button'),
 
121
                            'sensitive',
 
122
                            Gio.SettingsBindFlags.INVERT_BOOLEAN);
 
123
        this._settings.bind('autohide',
 
124
                            this._builder.get_object('autohide_switch'),
 
125
                            'active',
 
126
                            Gio.SettingsBindFlags.DEFAULT);
 
127
        this._settings.bind('require-pressure-to-show',
 
128
                            this._builder.get_object('require_pressure_checkbutton'),
 
129
                            'active',
 
130
                            Gio.SettingsBindFlags.DEFAULT);
 
131
        this._settings.bind('intellihide',
 
132
                            this._builder.get_object('intellihide_switch'),
 
133
                            'active',
 
134
                            Gio.SettingsBindFlags.DEFAULT);
 
135
        this._settings.bind('intellihide-perapp',
 
136
                            this._builder.get_object('per_app_intellihide_checkbutton'),
 
137
                            'active',
 
138
                            Gio.SettingsBindFlags.DEFAULT);
 
139
        this._settings.bind('animation-time',
 
140
                            this._builder.get_object('animation_duration_spinbutton'),
 
141
                            'value',
 
142
                            Gio.SettingsBindFlags.DEFAULT);
 
143
        this._settings.bind('hide-delay',
 
144
                            this._builder.get_object('hide_timeout_spinbutton'),
 
145
                            'value',
 
146
                            Gio.SettingsBindFlags.DEFAULT);
 
147
        this._settings.bind('show-delay',
 
148
                            this._builder.get_object('show_timeout_spinbutton'),
 
149
                            'value',
 
150
                            Gio.SettingsBindFlags.DEFAULT);
 
151
        this._settings.bind('pressure-threshold',
 
152
                            this._builder.get_object('pressure_threshold_spinbutton'),
 
153
                            'value',
 
154
                            Gio.SettingsBindFlags.DEFAULT);
 
155
 
 
156
        //this._builder.get_object('animation_duration_spinbutton').set_value(this._settings.get_double('animation-time'));
 
157
 
 
158
        // Create dialog for intelligent autohide advanced settings
 
159
        this._builder.get_object('intelligent_autohide_button').connect('clicked', Lang.bind(this, function() {
 
160
 
 
161
            let dialog = new Gtk.Dialog({ title: _("Intelligent autohide customization"),
 
162
                                          transient_for: this.widget.get_toplevel(),
 
163
                                          use_header_bar: true,
 
164
                                          modal: true });
 
165
 
 
166
            // GTK+ leaves positive values for application-defined response ids.
 
167
            // Use +1 for the reset action 
 
168
            dialog.add_button(_("Reset to defaults"), 1);
 
169
 
 
170
            let box = this._builder.get_object('intelligent_autohide_advanced_settings_box');
 
171
            dialog.get_content_area().add(box);
 
172
 
 
173
            this._settings.bind('intellihide',
 
174
                            this._builder.get_object('per_app_intellihide_checkbutton'),
 
175
                            'sensitive',
 
176
                            Gio.SettingsBindFlags.GET);
 
177
 
 
178
            this._settings.bind('autohide',
 
179
                            this._builder.get_object('require_pressure_checkbutton'),
 
180
                            'sensitive',
 
181
                            Gio.SettingsBindFlags.GET);
 
182
 
 
183
            dialog.connect('response', Lang.bind(this, function(dialog, id) {
 
184
                if (id == 1) {
 
185
                    // restore default settings for the relevant keys
 
186
                    let keys = ['intellihide', 'autohide', 'intellihide-perapp', 'require-pressure-to-show',
 
187
                                'animation-time', 'show-delay', 'hide-delay'];
 
188
                    keys.forEach(function(val){
 
189
                        this._settings.set_value(val, this._settings.get_default_value(val));
 
190
                    }, this);
 
191
                } else {
 
192
                    // remove the settings box so it doesn't get destroyed;
 
193
                    dialog.get_content_area().remove(box);
 
194
                    dialog.destroy();
 
195
                }
 
196
                return;
 
197
            }));
 
198
 
 
199
            dialog.show_all();
 
200
 
 
201
        }));
 
202
 
 
203
        // size options
 
204
        this._builder.get_object('dock_size_scale').set_value(this._settings.get_double('height-fraction'));
 
205
        this._builder.get_object('dock_size_scale').add_mark(0.9, Gtk.PositionType.TOP, null);
 
206
        let icon_size_scale = this._builder.get_object('icon_size_scale');
 
207
        icon_size_scale.set_range(DEFAULT_ICONS_SIZES[DEFAULT_ICONS_SIZES.length -1], DEFAULT_ICONS_SIZES[0]);
 
208
        icon_size_scale.set_value(this._settings.get_int('dash-max-icon-size'));
 
209
        DEFAULT_ICONS_SIZES.forEach(function(val){
 
210
                icon_size_scale.add_mark(val, Gtk.PositionType.TOP, val.toString());
 
211
        });
 
212
 
 
213
        // Corrent for rtl languages
 
214
        if (this._rtl) {
 
215
            // Flip value position: this is not done automatically
 
216
            this._builder.get_object('dock_size_scale').set_value_pos(Gtk.PositionType.LEFT);
 
217
            icon_size_scale.set_value_pos(Gtk.PositionType.LEFT);
 
218
            /* I suppose due to a bug, having a more than one mark and one above a value of 100
 
219
             * makes the rendering of the marks wrong in rtl. This doesn't happen setting the scale as not flippable
 
220
             * and then manually inverting it
 
221
             */
 
222
            icon_size_scale.set_flippable(false);
 
223
            icon_size_scale.set_inverted(true);
 
224
        }
 
225
 
 
226
        this._settings.bind('icon-size-fixed', this._builder.get_object('icon_size_fixed_checkbutton'), 'active', Gio.SettingsBindFlags.DEFAULT);
 
227
        this._settings.bind('extend-height', this._builder.get_object('dock_size_extend_checkbutton'), 'active', Gio.SettingsBindFlags.DEFAULT);
 
228
        this._settings.bind('extend-height', this._builder.get_object('dock_size_scale'), 'sensitive', Gio.SettingsBindFlags.INVERT_BOOLEAN);
 
229
 
 
230
 
 
231
        /* Behavior panel */
 
232
 
 
233
        this._settings.bind('show-running',
 
234
                            this._builder.get_object('show_running_switch'),
 
235
                            'active',
 
236
                            Gio.SettingsBindFlags.DEFAULT);
 
237
        this._settings.bind('show-favorites',
 
238
                            this._builder.get_object('show_favorite_switch'),
 
239
                            'active',
 
240
                            Gio.SettingsBindFlags.DEFAULT);
 
241
        this._settings.bind('show-show-apps-button',
 
242
                            this._builder.get_object('show_applications_button_switch'),
 
243
                            'active',
 
244
                            Gio.SettingsBindFlags.DEFAULT);
 
245
        this._settings.bind('show-apps-at-top',
 
246
                            this._builder.get_object('application_button_first_button'),
 
247
                            'active',
 
248
                            Gio.SettingsBindFlags.DEFAULT);
 
249
        this._settings.bind('show-show-apps-button',
 
250
                            this._builder.get_object('application_button_first_button'),
 
251
                            'sensitive',
 
252
                            Gio.SettingsBindFlags.DEFAULT);
 
253
 
 
254
        this._builder.get_object('click_action_combo').set_active(this._settings.get_enum('click-action'));
 
255
        this._builder.get_object('click_action_combo').connect('changed', Lang.bind (this, function(widget) {
 
256
                this._settings.set_enum('click-action', widget.get_active());
 
257
        }));
 
258
 
 
259
        this._builder.get_object('shift_click_action_combo').set_active(this._settings.get_boolean('minimize-shift')?0:1);
 
260
 
 
261
        this._builder.get_object('shift_click_action_combo').connect('changed', Lang.bind (this, function(widget) {
 
262
                this._settings.set_boolean('minimize-shift', widget.get_active()==1);
 
263
        }));
 
264
 
 
265
        this._settings.bind('scroll-switch-workspace', this._builder.get_object('switch_workspace_switch'), 'active', Gio.SettingsBindFlags.DEFAULT);
 
266
 
 
267
        /* Appearance Panel */
 
268
 
 
269
        this._settings.bind('apply-custom-theme', this._builder.get_object('customize_theme'), 'sensitive', Gio.SettingsBindFlags.INVERT_BOOLEAN | Gio.SettingsBindFlags.GET);
 
270
        this._settings.bind('apply-custom-theme', this._builder.get_object('builtin_theme_switch'), 'active', Gio.SettingsBindFlags.DEFAULT);
 
271
        this._settings.bind('custom-theme-shrink', this._builder.get_object('shrink_dash_switch'), 'active', Gio.SettingsBindFlags.DEFAULT);
 
272
        this._settings.bind('custom-theme-running-dots', this._builder.get_object('running_dots_switch'), 'active', Gio.SettingsBindFlags.DEFAULT);
 
273
        this._settings.bind('opaque-background', this._builder.get_object('customize_opacity_switch'), 'active', Gio.SettingsBindFlags.DEFAULT);
 
274
        this._builder.get_object('custom_opacity_scale').set_value(this._settings.get_double('background-opacity'));
 
275
        this._settings.bind('opaque-background', this._builder.get_object('custom_opacity'), 'sensitive', Gio.SettingsBindFlags.DEFAULT);
 
276
 
 
277
        /* About Panel */
 
278
 
 
279
        this._builder.get_object('extension_version').set_label(Me.metadata.version.toString());
 
280
 
 
281
    },
 
282
 
 
283
 
 
284
    // Object containing all signals defined in the glade file
 
285
    _SignalHandler: {
 
286
 
 
287
            dock_display_combo_changed_cb: function (combo) {
 
288
                this._settings.set_int('preferred-monitor', this._monitors[combo.get_active()]);
 
289
            },
 
290
 
 
291
            position_top_button_toggled_cb: function (button){
 
292
                if (button.get_active()) 
 
293
                    this._settings.set_enum('dock-position', 0);
 
294
            },
 
295
 
 
296
            position_right_button_toggled_cb: function (button) {
 
297
                if (button.get_active()) 
 
298
                    this._settings.set_enum('dock-position', 1);
 
299
            },
 
300
 
 
301
            position_bottom_button_toggled_cb: function (button) {
 
302
                if (button.get_active()) 
 
303
                    this._settings.set_enum('dock-position', 2);
 
304
            },
 
305
 
 
306
            position_left_button_toggled_cb: function (button) {
 
307
                if (button.get_active()) 
 
308
                    this._settings.set_enum('dock-position', 3);
 
309
            },
 
310
 
 
311
            icon_size_combo_changed_cb: function(combo) {
 
312
                this._settings.set_int('dash-max-icon-size', this._allIconSizes[combo.get_active()]);
 
313
            },
 
314
 
 
315
            dock_size_scale_format_value_cb: function(scale, value) {
 
316
                return Math.round(value*100)+ ' %';
 
317
            },
 
318
 
 
319
            dock_size_scale_value_changed_cb: function(scale){
 
320
                // Avoid settings the size consinuosly
 
321
                if (this._dock_size_timeout >0)
 
322
                    Mainloop.source_remove(this._dock_size_timeout);
 
323
 
 
324
                this._dock_size_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function(){
 
325
                    this._settings.set_double('height-fraction', scale.get_value());
 
326
                    this._dock_size_timeout = 0;
 
327
                    return GLib.SOURCE_REMOVE;
 
328
                }));       
 
329
            },
 
330
 
 
331
            icon_size_scale_format_value_cb: function(scale, value) {
 
332
                return value+ ' px';
 
333
            },
 
334
 
 
335
            icon_size_scale_value_changed_cb: function(scale){
 
336
                // Avoid settings the size consinuosly
 
337
                if (this._icon_size_timeout >0)
 
338
                    Mainloop.source_remove(this._icon_size_timeout);
 
339
 
 
340
                this._icon_size_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function(){
 
341
                    this._settings.set_int('dash-max-icon-size', scale.get_value());
 
342
                    this._icon_size_timeout = 0;
 
343
                    return GLib.SOURCE_REMOVE;
 
344
                }));       
 
345
            },
 
346
 
 
347
            custom_opacity_scale_value_changed_cb: function(scale){
 
348
                // Avoid settings the opacity consinuosly as it's change is animated
 
349
                if (this._opacity_timeout >0)
 
350
                    Mainloop.source_remove(this._opacity_timeout);
 
351
 
 
352
                this._opacity_timeout = Mainloop.timeout_add(SCALE_UPDATE_TIMEOUT, Lang.bind(this, function(){
 
353
                    this._settings.set_double('background-opacity', scale.get_value());
 
354
                    this._opacity_timeout = 0;
 
355
                    return GLib.SOURCE_REMOVE;
 
356
                }));
 
357
            },
 
358
 
 
359
            custom_opacity_scale_format_value_cb: function(scale, value) {
 
360
                return Math.round(value*100) + ' %';
 
361
            }
 
362
    }
 
363
});
 
364
 
 
365
function init() {
 
366
    Convenience.initTranslations();
 
367
}
 
368
 
 
369
function buildPrefsWidget() {
 
370
    let settings = new Settings();
 
371
    let widget = settings.widget;
 
372
    widget.show_all();
 
373
    return widget;
 
374
}
 
375