Skip to content

Instantly share code, notes, and snippets.

@itzexor
Created May 17, 2017 20:49
Show Gist options
  • Save itzexor/9859ec48c76b541b608926bd1470c561 to your computer and use it in GitHub Desktop.
Save itzexor/9859ec48c76b541b608926bd1470c561 to your computer and use it in GitHub Desktop.
/**
* FILE:cinnamonShortcutsDialog.js
* @short_description: A dialog that shows common cinnamon shortcuts.
*
* Shows a dialog with the current common shortcuts.
*/
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const St = imports.gi.St;
const Cinnamon = imports.gi.Cinnamon;
const Util = imports.misc.util;
const ModalDialog = imports.ui.modalDialog;
const KB_SCHEMA = "org.cinnamon.desktop.keybindings";
const KB_MK_SCHEMA = KB_SCHEMA + ".media-keys";
const KB_WM_SCHEMA = KB_SCHEMA + ".wm";
//list item format: [settings key, display name, schema(kb|mk|wm)]
const GENERAL_LIST = [
["screensaver", _("Lock the screen"), "mk"],
["home", _("Open the home folder"), "mk"],
["terminal", _("Open a terminal window"), "mk"],
["panel-run-dialog", _("Show the run command prompt"), "wm"],
["show-desktop", _("Show the desktop"), "wm"],
["video-rotation-lock", _("Toggle automatic screen rotation"), "mk"]
];
const WINDOWS_LIST = [
["close", _("Close current window"), "wm"],
["switch-windows", _("Switch between open windows"), "wm"]
];
const TROUBLESHOOT_LIST = [];
function CinnamonShortcutsDialog() {
this._init();
}
CinnamonShortcutsDialog.prototype = {
__proto__: ModalDialog.ModalDialog.prototype,
_init: function() {
ModalDialog.ModalDialog.prototype._init.call(this);
let contentBox = new St.BoxLayout({style_class: "shortcuts-dialog", vertical:true});
this.contentLayout.add_actor(contentBox);
let settings = {
kb: Gio.Settings.new(KB_SCHEMA),
mk: Gio.Settings.new(KB_MK_SCHEMA),
wm: Gio.Settings.new(KB_WM_SCHEMA)
};
let generalBox = new St.BoxLayout({vertical: true});
contentBox.add_actor(generalBox);
for (let item of GENERAL_LIST) {
let keybinding = settings[item[2]].get_value(item[0]);
if (keybinding != null) {
let typeString = keybinding.get_type_string();
if (typeString === "as") {
keybinding = keybinding.deep_unpack()[0];
} else if (typeString === "s") {
keybinding = keybinding.unpack();
} else {
continue;
}
let label = new St.Label();
label.set_text(keybinding + ": " + item[1]);
generalBox.add(label);
}
}
this.setButtons([
{
label: _("Settings"),
action: Lang.bind(this, function() {
Util.spawnCommandLine("cinnamon-settings keyboard");
this.destroy();
})
},
{
label: _("Close"),
action: Lang.bind(this, this.destroy)
}
]);
this.open(global.get_current_time());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment