-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathprefs.js
197 lines (146 loc) · 6.22 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
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Mainloop = imports.mainloop;
const Gettext = imports.gettext.domain('emoji-selector');
const _ = Gettext.gettext;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
//------------------------------------------------------------------------------
function init() {
ExtensionUtils.initTranslations();
}
let SETTINGS = ExtensionUtils.getSettings();
//------------------------------------------------------------------------------
const EmojiSelectorSettingsWidget = new GObject.Class({
Name: 'EmojiSelector.Prefs.Widget',
GTypeName: 'EmojiSelectorPrefsWidget',
_init (params) {
let builder = new Gtk.Builder();
builder.add_from_file(Me.path+'/prefs.ui');
this.prefs_stack = builder.get_object('prefs_stack');
this.switcher = new Gtk.StackSwitcher({
halign: Gtk.Align.CENTER,
visible: true,
stack: this.prefs_stack
});
this._loadPrefsPage(builder);
this._loadAboutPage(builder);
},
//--------------------------------------------------------------------------
_loadPrefsPage(builder) {
let RELOAD_TEXT = _("Modifications will be effective after reloading the extension.");
let positionCombobox = builder.get_object('position_combobox');
positionCombobox.append('top', _("From top to bottom"));
positionCombobox.append('bottom', _("From bottom to top"));
positionCombobox.active_id = SETTINGS.get_string('position');
positionCombobox.set_tooltip_text(
_("Displaying the interface from the bottom is better if you use " +
"a bottom panel instead of the default top bar.")
+ '\n' + RELOAD_TEXT
);
positionCombobox.connect("changed", (widget) => {
SETTINGS.set_string('position', widget.get_active_id());
});
SETTINGS.connect('changed::position', () => {
positionCombobox.set_active_id(SETTINGS.get_string('position'));
});
//----------------------------------------------------------------------
let emojiSize = builder.get_object('size_spinbtn');
emojiSize.set_value(SETTINGS.get_int('emojisize'));
emojiSize.connect('value-changed', w => {
var value = w.get_value_as_int();
SETTINGS.set_int('emojisize', value);
});
SETTINGS.connect('changed::emojisize', () => {
emojiSize.set_value(SETTINGS.get_int('emojisize'));
});
//----------------------------------------------------------------------
let nbColsSpinBtn = builder.get_object('nbcols_spinbtn');
nbColsSpinBtn.set_value(SETTINGS.get_int('nbcols'));
nbColsSpinBtn.connect('value-changed', w => {
var value = w.get_value_as_int();
SETTINGS.set_int('nbcols', value);
});
SETTINGS.connect('changed::nbcols', () => {
nbColsSpinBtn.set_value(SETTINGS.get_int('nbcols'));
});
//----------------------------------------------------------------------
let default_kbs_label = _("The default value is %s");
default_kbs_label = default_kbs_label.replace('%s', "<Super>e");
builder.get_object('default-kbs-help-1').set_label(default_kbs_label);
builder.get_object('default-kbs-help-2').set_label(RELOAD_TEXT);
let keybindingEntry = builder.get_object('keybinding_entry');
keybindingEntry.set_sensitive(SETTINGS.get_boolean('use-keybinding'));
if (SETTINGS.get_strv('emoji-keybinding') != '') {
keybindingEntry.text = SETTINGS.get_strv('emoji-keybinding')[0];
}
SETTINGS.connect('changed::emoji-keybinding', () => {
keybindingEntry.set_text(SETTINGS.get_strv('emoji-keybinding')[0]);
});
let keybindingButton = builder.get_object('keybinding_button');
keybindingButton.set_sensitive(SETTINGS.get_boolean('use-keybinding'));
keybindingButton.connect('clicked', widget => {
SETTINGS.set_strv('emoji-keybinding', [keybindingEntry.text]);
});
//----------------------------------------------------------------------
let keybindingSwitch = builder.get_object('keybinding_switch');
keybindingSwitch.set_state(SETTINGS.get_boolean('use-keybinding'));
keybindingSwitch.connect('notify::active', widget => {
if (widget.active) {
SETTINGS.set_boolean('use-keybinding', true);
keybindingEntry.sensitive = true;
keybindingButton.sensitive = true;
alwaysShowSwitch.sensitive = true;
} else {
SETTINGS.set_boolean('use-keybinding', false);
keybindingEntry.sensitive = false;
keybindingButton.sensitive = false;
SETTINGS.set_boolean('always-show', true);
alwaysShowSwitch.set_state(true);
alwaysShowSwitch.sensitive = false;
}
});
SETTINGS.connect('changed::use-keybinding', () => {
keybindingSwitch.set_state(SETTINGS.get_boolean('use-keybinding'));
});
//----------------------------------------------------------------------
let alwaysShowSwitch = builder.get_object('always_show_switch');
alwaysShowSwitch.set_state(SETTINGS.get_boolean('always-show'));
alwaysShowSwitch.connect('notify::active', widget => {
if (widget.active) {
SETTINGS.set_boolean('always-show', true);
} else {
SETTINGS.set_boolean('always-show', false);
}
});
SETTINGS.connect('changed::always-show', () => {
alwaysShowSwitch.set_state(SETTINGS.get_boolean('always-show'));
});
},
//--------------------------------------------------------------------------
_loadAboutPage(builder) {
let version = _("version %s").replace('%s', Me.metadata.version.toString());
builder.get_object('version-label').set_label(version);
let translators_credits = builder.get_object('translators-credits').get_label();
if (translators_credits == 'translator-credits') {
builder.get_object('translators-label').set_label('');
builder.get_object('translators-credits').set_label('');
}
builder.get_object('link-btn').set_uri(Me.metadata.url.toString());
}
});
//------------------------------------------------------------------------------
function buildPrefsWidget() {
let widget = new EmojiSelectorSettingsWidget();
Mainloop.timeout_add(0, () => {
let headerBar = widget.prefs_stack.get_toplevel().get_titlebar();
headerBar.custom_title = widget.switcher;
return false;
});
widget.prefs_stack.show_all();
return widget.prefs_stack;
}
//------------------------------------------------------------------------------