-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprefs.js
231 lines (180 loc) · 7.03 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
//
// Web Search is a GNOME Shell extension to search by a click.
// Copyright (C) 2011 Stefano Ciancio
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const ExtensionUtils = imports.misc.extensionUtils;
const Lang = imports.lang;
const Gettext = imports.gettext.domain('gnome-shell-websearch');
const _ = Gettext.gettext;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
let settings = null;
const SHOWTEXTBOX_SHORTCUT_KEY = 'ws-show-textbox';
const SEARCH_SHORTCUT_KEY = 'ws-search';
const SHIFTSEARCHENGINE_SHORTCUT_KEY = 'ws-shift-searchengine';
const WebsearchWindowSettingsWidget = new GObject.Class({
Name: 'WebSearchWindow.Prefs.WebsearchWindowSettingsWidget',
GTypeName: 'WebsearchtWindowSettingsWidget',
Extends: Gtk.Grid,
_init : function(params) {
this.parent(params);
this.orientation = Gtk.Orientation.VERTICAL;
this.expand = true;
this.column_homogeneous = true;
this.set_margin_left(5);
this.set_margin_right(5);
this.set_row_spacing(2);
// Bool Settings
this._createBoolSetting("Switch right/left button mouse:",
"Default->OFF: right button open textbox; left button start search",
'ws-switch-button');
this._createBoolSetting("Search primary or clipboard selection:",
"Default->OFF: search clipboard selection",
'ws-clipboard');
// Combo Settings
this._createComboSetting("Choose your preferred search engine",
"You can choose your search engine",
'ws-searchengine', Convenience.getSearchEngine());
// Keybindings Settings
let bindings = {
"ws-search": "Search!",
"ws-show-textbox": "Open the text box",
"ws-shift-searchengine": "Change your search engine"
};
this._createKeyboardConfig("Keyboard Shortcuts", bindings);
},
/*
* Create Keybindings Widget
*/
_createKeyboardConfig: function(label, bindings) {
let model = new Gtk.ListStore();
let name;
model.set_column_types([
GObject.TYPE_STRING,
GObject.TYPE_STRING,
GObject.TYPE_INT,
GObject.TYPE_INT
]);
for (name in bindings) {
let [key, mods] = Gtk.accelerator_parse(settings.get_strv(name)[0]);
let row = model.insert(10);
model.set(row, [0, 1, 2, 3], [name, bindings[name], mods, key ]);
}
let treeview = new Gtk.TreeView({
'expand': true,
'model': model
});
// Action column
let cellrend = new Gtk.CellRendererText();
let col = new Gtk.TreeViewColumn({ 'title': 'Action', 'expand': true });
col.pack_start(cellrend, true);
col.add_attribute(cellrend, 'text', 1);
treeview.append_column(col);
// keybinding column
cellrend = new Gtk.CellRendererAccel({
'editable': true,
'accel-mode': Gtk.CellRendererAccelMode.GTK
});
cellrend.connect('accel-edited', function(rend, iter, key, mods) {
let value = Gtk.accelerator_name(key, mods);
let [succ, iterator ] = model.get_iter_from_string(iter);
if(!succ) {
throw new Error("Error updating Keybinding");
}
let name = model.get_value(iterator, 0);
model.set(iterator, [ 2, 3], [ mods, key ]);
settings.set_strv(name, [value]);
});
col = new Gtk.TreeViewColumn({'title': 'Modify'});
col.pack_end(cellrend, false);
col.add_attribute(cellrend, 'accel-mods', 2);
col.add_attribute(cellrend, 'accel-key', 3);
treeview.append_column(col);
let keyExpander = new Gtk.Expander();
keyExpander.set_label(label);
keyExpander.add(treeview);
this.attach(keyExpander, 0, 4, 2, 1);
},
/*
* Create Combo Widget
*/
_createComboSetting : function(label, tooltip, setting, values) {
let labelwidget = new Gtk.Label({
halign: Gtk.Align.START,
label: label,
tooltip_text: tooltip,
});
this.add(labelwidget);
this._model = new Gtk.ListStore();
this._model.set_column_types([GObject.TYPE_STRING, GObject.TYPE_STRING]);
let myCombo = new Gtk.ComboBox({ model: this._model, halign: Gtk.Align.END});
let currentValue = settings.get_int(setting, 0);
let selectMe = null;
for (let i=0; i< values.length; i++) {
let iter = this._model.append();
this._model.set(iter, [0, 1], [values[i][0],values[i][1]]);
if (values[i][0] == currentValue) {
selectMe = iter;
}
}
if (selectMe != null) {
myCombo.set_active_iter(selectMe);
}
let renderer = new Gtk.CellRendererText();
myCombo.pack_start(renderer, true);
myCombo.add_attribute(renderer, 'text', 1);
myCombo.connect("changed", Lang.bind(this,
function(obj) {
let[success, iter] = obj.get_active_iter();
if (!success) {
return;
}
settings.set_int(setting, this._model.get_value(iter, 0));
})
);
this.attach_next_to(myCombo, labelwidget, Gtk.PositionType.RIGHT, 1, 1);
},
/*
* Create Boolean Button Widget
*/
_createBoolSetting : function(label, tooltip, setting) {
let labelwidget = new Gtk.Label({
halign: Gtk.Align.START,
label: label,
tooltip_text: tooltip,
});
this.add(labelwidget);
let mySwitch = new Gtk.Switch({
active: settings.get_boolean(setting),
sensitive: true,
halign: Gtk.Align.END });
mySwitch.connect('notify::active', function(button) {
settings.set_boolean(setting, button.active);
});
this.attach_next_to(mySwitch, labelwidget, Gtk.PositionType.RIGHT, 1, 1);
},
})
function init() {
settings = Convenience.getSettings();
}
function buildPrefsWidget() {
let widget = new WebsearchWindowSettingsWidget();
widget.show_all();
return widget;
};