/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/**
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
**/
const Gtk = imports.gi.Gtk;
const GObject = imports.gi.GObject;
const Gettext = imports.gettext.domain('gnome-shell-extensions-middleclickclose');
const _ = Gettext.gettext;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const ExtensionUtils = imports.misc.extensionUtils;
let gsettings;
let settings;
function init() {
ExtensionUtils.initTranslations();
gsettings = ExtensionUtils.getSettings();
settings = {
close_button: {
type: "e",
label: _("Mouse button to close"),
help: _("Which mouse button triggers closing in overview."),
list: [
{ nick: "left", name: _("Left"), id: 0 },
{ nick: "middle", name: _("Middle"), id: 1 },
{ nick: "right", name: _("Right"), id: 2 },
{ nick: "button 4", name: _("Button 4"), id: 3 },
{ nick: "button 5", name: _("Button 5"), id: 4 },
{ nick: "button 6", name: _("Button 6"), id: 5 },
{ nick: "button 7", name: _("Button 7"), id: 6 },
{ nick: "button 8", name: _("Button 8"), id: 7 },
{ nick: "button 9", name: _("Button 9"), id: 8 }
],
default: 'middle'
},
rearrange_delay: {
type: "i",
label: _("Rearrange delay"),
help: _("How much time must pass with the pointer not moving for windows in overview to rearrange after one was closed."),
step: 50,
default: 750
}
};
}
function buildPrefsWidget() {
let frame = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL,
'margin-top': 10,
'margin-end': 10,
'margin-bottom': 10,
'margin-start': 10});
let vbox = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL,
'margin-top': 10,
'margin-end': 20,
'margin-bottom': 20,
'margin-start': 20});
for (setting in settings) {
hbox = buildHbox(settings, setting);
vbox.append(hbox);
}
frame.append(vbox);
return frame;
}
function buildHbox(settings, setting) {
let hbox;
if (settings[setting].type == 's')
hbox = createStringSetting(settings, setting);
if (settings[setting].type == "i")
hbox = createIntSetting(settings, setting);
if (settings[setting].type == "b")
hbox = createBoolSetting(settings, setting);
if (settings[setting].type == "r")
hbox = createRangeSetting(settings, setting);
if (settings[setting].type == "e")
hbox = createEnumSetting(settings, setting);
return hbox;
}
function createEnumSetting(settings, setting) {
let hbox = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL,
'margin-top': 5,
spacing: 10});
let setting_label = new Gtk.Label({label: settings[setting].label,
xalign: 0 });
let model = new Gtk.ListStore();
model.set_column_types([GObject.TYPE_INT, GObject.TYPE_STRING]);
let setting_enum = new Gtk.ComboBox({model: model});
setting_enum.get_style_context().add_class('raised');
let renderer = new Gtk.CellRendererText();
setting_enum.pack_start(renderer, true);
setting_enum.add_attribute(renderer, 'text', 1);
for (let i=0; i