forked from projecthamster/hamster-shell-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
142 lines (102 loc) · 4.59 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
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const Lang = imports.lang;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const HamsterSettingsWidget = new GObject.Class({
Name: 'ProjectHamster.Prefs.HamsterSettingsWidget',
GTypeName: 'HamsterSettingsWidget',
Extends: Gtk.VBox,
_init : function(params) {
this.parent(params);
this.margin = 10;
this._settings = Convenience.getSettings();
let vbox, label;
label = new Gtk.Label();
label.set_markup("<b>Positioning</b>");
label.set_alignment(0, 0.5);
this.add(label);
vbox = new Gtk.VBox({margin: 10});
this.add(vbox);
let placementOptions = new Gtk.ListStore();
placementOptions.set_column_types([GObject.TYPE_STRING, GObject.TYPE_INT]);
placementOptions.set(placementOptions.append(), [0, 1], ["Default", 0]);
placementOptions.set(placementOptions.append(), [0, 1], ["Replace calendar", 1]);
placementOptions.set(placementOptions.append(), [0, 1], ["Replace activities", 2]);
let placementCombo = new Gtk.ComboBox({model: placementOptions});
let renderer = new Gtk.CellRendererText();
placementCombo.pack_start(renderer, true);
placementCombo.add_attribute(renderer, 'text', 0);
placementCombo.connect('changed', Lang.bind(this, this._onPlacementChange));
placementCombo.set_active(this._settings.get_int("panel-placement"));
vbox.add(placementCombo);
label = new Gtk.Label({margin_top: 20});
label.set_markup("<b>Appearance in panel</b>");
label.set_alignment(0, 0.5);
this.add(label);
vbox = new Gtk.VBox({margin: 10});
this.add(vbox);
let appearanceOptions = new Gtk.ListStore();
appearanceOptions.set_column_types([GObject.TYPE_STRING, GObject.TYPE_INT]);
appearanceOptions.set(appearanceOptions.append(), [0, 1], ["Label", 0]);
appearanceOptions.set(appearanceOptions.append(), [0, 1], ["Icon", 1]);
appearanceOptions.set(appearanceOptions.append(), [0, 1], ["Label and icon", 2]);
let appearanceCombo = new Gtk.ComboBox({model: appearanceOptions});
let renderer = new Gtk.CellRendererText();
appearanceCombo.pack_start(renderer, true);
appearanceCombo.add_attribute(renderer, 'text', 0);
appearanceCombo.connect('changed', Lang.bind(this, this._onAppearanceChange));
appearanceCombo.set_active(this._settings.get_int("panel-appearance"));
vbox.add(appearanceCombo);
label = new Gtk.Label({margin_top: 20});
label.set_markup("<b>Global hotkey</b>");
label.set_alignment(0, 0.5);
this.add(label);
vbox = new Gtk.VBox({margin: 10});
this.add(vbox);
let entry = new Gtk.Entry({margin_bottom: 10,
margin_top: 5,
text: this._settings.get_strv("show-hamster-dropdown")[0]});
vbox.add(entry);
entry.connect('changed', Lang.bind(this, this._onHotkeyChange));
vbox.add(new Gtk.Label({label: "Reload gnome shell after updating prefs (alt+f2 > r)",
margin_top: 70}));
},
_onPlacementChange: function(widget) {
let [success, iter] = widget.get_active_iter();
if (!success)
return;
let newPlacement = widget.get_model().get_value(iter, 1);
if (this._settings.get_int("panel-placement") == newPlacement)
return;
this._settings.set_int("panel-placement", newPlacement);
},
_onAppearanceChange: function(widget) {
let [success, iter] = widget.get_active_iter();
if (!success)
return;
let newAppearance = widget.get_model().get_value(iter, 1);
if (this._settings.get_int("panel-appearance") == newAppearance)
return;
this._settings.set_int("panel-appearance", newAppearance);
},
_onHotkeyChange: function(widget, bananas) {
//global.log(widget, bananas);
let hotkey = widget.get_text();
let [key, mods] = Gtk.accelerator_parse(hotkey);
if (key != 0) {
let parsedName = Gtk.accelerator_name(key, mods);
this._settings.set_strv("show-hamster-dropdown", [parsedName]);
}
}
});
function init() {
}
function buildPrefsWidget() {
let widget = new HamsterSettingsWidget();
widget.show_all();
return widget;
}