-
Notifications
You must be signed in to change notification settings - Fork 17
/
prefs3.js
129 lines (104 loc) · 5.09 KB
/
prefs3.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
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
var TimezoneExtensionPrefsWidget3 = new GObject.Class({
Name: 'TimezoneExtension.Prefs3.Widget',
GTypeName: 'TimezoneExtensionPrefsWidget3',
Extends: Gtk.Grid,
_init: function(params) {
this.parent(params);
this.orientation = Gtk.Orientation.VERTICAL;
this.margin = 12;
this._settings = Convenience.getSettings();
this.add(new Gtk.Label({ label: '<b>Location for the <i>people.json</i> file</b>',
use_markup: true, margin_bottom: 6,
hexpand: true, halign: Gtk.Align.START }));
let box = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL, spacing: 5});
box.add(this._createEntry());
box.add(this._createFileChooser());
this.add(box);
this.add(new Gtk.Label({ label: '<small>Remote files, e.g., starting with <i>http://</i> are also valid. <a href="https://github.com/jwendell/gnome-shell-extension-timezone/blob/master/editing-people.md">Need help with JSON?</a></small>',
use_markup: true, margin_bottom: 6,
hexpand: true, halign: Gtk.Align.START}));
this.add(this._createHighlightBox());
this.add(this._createPanelConfiguration());
this.add(this._createSaveButton());
this.show_all();
},
_createEntry: function() {
this._entry = new Gtk.Entry({hexpand: true,
text: this._settings.get_string("path-to-people-json"),
activates_default: true});
return this._entry;
},
_createHighlightBox: function() {
let box = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL,
margin_bottom: 20, margin_top: 20});
let box1 = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL, spacing: 5});
box.add(box1);
let label = new Gtk.Label({label: '<b>Highlight working hours</b>',
use_markup: true, hexpand: true,
halign: Gtk.Align.START});
box1.add(label);
let sb = new Gtk.Switch();
this._settings.bind('enable-working-hours', sb, 'active', Gio.SettingsBindFlags.DEFAULT);
box1.add(sb);
let box2 = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL,
spacing: 5});
box.add(box2);
sb.bind_property('active', box2, 'sensitive', GObject.BindingFlags.SYNC_CREATE);
box2.add(new Gtk.Label({label: 'From'}));
let from = Gtk.SpinButton.new_with_range (0, 23, 1);
box2.add(from);
this._settings.bind('working-hours-start', from, 'value', Gio.SettingsBindFlags.DEFAULT);
box2.add(new Gtk.Label({label: 'to'}));
let to = Gtk.SpinButton.new_with_range (0, 23, 1);
box2.add(to);
this._settings.bind('working-hours-end', to, 'value', Gio.SettingsBindFlags.DEFAULT);
return box;
},
_createFileChooser: function() {
this._chooser = new Gtk.FileChooserButton({local_only: false});
this._chooser.set_uri(this._settings.get_string("path-to-people-json"));
this._chooser.connect('file-set', Lang.bind(this, function() {
this._entry.text = this._chooser.get_uri();
}));
return this._chooser;
},
_createPanelConfiguration: function() {
let box = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL,
margin_bottom: 20, margin_top: 20});
let box1 = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL, spacing: 5});
box.add(box1);
let label = new Gtk.Label({label: '<b>Panel configuration</b>',
use_markup: true, hexpand: true,
halign: Gtk.Align.START});
box1.add(label);
let box2 = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL, spacing: 5});
box.add(box2);
box2.add(new Gtk.Label({label: 'Position in panel'}));
let combo = new Gtk.ComboBoxText({ active_id: this._settings.get_string('panel-position') });
combo.append('left', "Left");
combo.append('center', "Center");
combo.append('right', "Right");
this._settings.bind('panel-position', combo, 'active-id', Gio.SettingsBindFlags.DEFAULT);
box2.add(combo);
return box;
},
_createSaveButton: function() {
let b = new Gtk.Button({label: "Save",
halign: Gtk.Align.END,
hexpand: false,
can_default: true});
b.get_style_context().add_class('suggested-action');
b.connect("clicked", Lang.bind(this, function() {
this._settings.set_string("path-to-people-json", this._entry.text);
Gio.Application.get_default().quit();
}));
return b;
}
});