-
Notifications
You must be signed in to change notification settings - Fork 6
/
prefs.js
executable file
·174 lines (131 loc) · 5.26 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
/*
* Portions originate from the gnome-shell source code, Copyright (c)
* its respectives authors.
* This project is released under the GNU GPL License.
* See COPYING for details.
*/
#!/usr/bin/cjs
const Gdk = imports.gi.Gdk;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const Lang = imports.lang;
let file_info = getCurrentFile();
const LIB_PATH = file_info[1];
imports.searchPath.unshift(LIB_PATH);
const Convenience = 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({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], ["Just Label", 0]);
appearanceOptions.set(appearanceOptions.append(), [0, 1], ["Icon and duration", 1]);
appearanceOptions.set(appearanceOptions.append(), [0, 1], ["Just 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 cinnamon after updating prefs (alt+f2 > r)",
margin_top: 70}));
},
_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;
}
const AppletPrefsWindow = new Lang.Class ({
Name: 'Hamster Applet Preferences',
_init: function () {
this.application = new Gtk.Application ();
this.application.connect('activate', Lang.bind(this, this._onActivate));
this.application.connect('startup', Lang.bind(this, this._onStartup));
},
_onActivate: function () {
this._window.present ();
},
_onStartup: function () {
this._buildUI ();
},
_buildUI: function () {
this._window = new Gtk.ApplicationWindow ({
application: this.application,
title: "Hamster Applet Preferences",
default_height: 200,
default_width: 400,
window_position: Gtk.WindowPosition.CENTER });
this._widget = new HamsterSettingsWidget();
this._window.add (this._widget);
this._window.show_all();
},
});
function getCurrentFile() {
let stack = (new Error()).stack;
// Assuming we're importing this directly from an extension (and we shouldn't
// ever not be), its UUID should be directly in the path here.
let stackLine = stack.split('\n')[1];
if (!stackLine)
throw new Error('Could not find current file');
// The stack line is like:
// init([object Object])@/home/user/data/gnome-shell/extensions/[email protected]/prefs.js:8
//
// In the case that we're importing from
// module scope, the first field is blank:
// @/home/user/data/gnome-shell/extensions/[email protected]/prefs.js:8
let match = new RegExp('@(.+):\\d+').exec(stackLine);
if (!match)
throw new Error('Could not find current file');
let path = match[1];
let file = Gio.File.new_for_path(path);
return [file.get_path(), file.get_parent().get_path(), file.get_basename()];
}
// Run the application
let app = new AppletPrefsWindow();
app.application.run (ARGV);