rework of shortcuts.js

This commit is contained in:
abakkk 2020-09-10 15:55:19 +02:00
parent 8277710510
commit a06d318646
3 changed files with 70 additions and 70 deletions

View File

@ -31,7 +31,7 @@ const Tweener = imports.ui.tweener;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = ExtensionUtils.getSettings ? ExtensionUtils : Me.imports.convenience;
const Shortcuts = Me.imports.shortcuts.Shortcuts;
const Shortcuts = Me.imports.shortcuts;
const _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
const GS_VERSION = Config.PACKAGE_VERSION;
@ -106,17 +106,17 @@ var DrawingHelper = new Lang.Class({
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
this.vbox.add_child(new St.Label({ text: _("Internal") }));
Shortcuts.OTHERS.forEach((pairs, index) => {
Shortcuts.OTHERS.forEach((object, index) => {
if (index)
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
pairs.forEach(pair => {
for (let key in object) {
let hbox = new St.BoxLayout({ vertical: false });
hbox.add_child(new St.Label({ text: pair[0] }));
hbox.add_child(new St.Label({ text: pair[1], x_expand: true }));
hbox.add_child(new St.Label({ text: key }));
hbox.add_child(new St.Label({ text: object[key], x_expand: true }));
hbox.get_children()[0].get_clutter_text().set_use_markup(true);
this.vbox.add_child(hbox);
});
}
});
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));

View File

@ -30,7 +30,7 @@ const Gtk = imports.gi.Gtk;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = ExtensionUtils.getSettings && ExtensionUtils.initTranslations ? ExtensionUtils : Me.imports.convenience;
const Shortcuts = Me.imports.shortcuts.Shortcuts;
const Shortcuts = Me.imports.shortcuts;
const gettext = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
const _ = function(string) {
if (!string)
@ -421,19 +421,19 @@ const PrefsPage = new GObject.Class({
listBox.get_style_context().add_class('background');
internalFrame.add(listBox);
Shortcuts.OTHERS.forEach((pairs, index) => {
Shortcuts.OTHERS.forEach((object, index) => {
if (index)
listBox.add(new Gtk.Box(ROWBOX_MARGIN_PARAMS));
pairs.forEach(pair => {
for (let key in object) {
let otherBox = new Gtk.Box({ margin_left: MARGIN, margin_right: MARGIN });
let otherLabel = new Gtk.Label({ label: pair[0], use_markup: true });
let otherLabel = new Gtk.Label({ label: key, use_markup: true });
otherLabel.set_halign(1);
let otherLabel2 = new Gtk.Label({ label: pair[1] });
let otherLabel2 = new Gtk.Label({ label: object[key] });
otherBox.pack_start(otherLabel, true, true, 4);
otherBox.pack_start(otherLabel2, false, false, 4);
listBox.add(otherBox);
});
}
});
listBox.add(new Gtk.Box(ROWBOX_MARGIN_PARAMS));

View File

@ -1,5 +1,5 @@
/* jslint esversion: 6 */
/* exported Shortcuts */
/* exported GLOBAL_KEYBINDINGS, INTERNAL_KEYBINDINGS, OTHERS */
/*
* Copyright 2019 Abakkk
@ -36,67 +36,67 @@ const getKeyLabel = function(accel) {
return Gtk.accelerator_get_label(keyval, mods);
};
// It is used by helper and prefs.
var Shortcuts = {
// The setting keys of the "org.gnome.shell.extensions.draw-on-your-screen" schema.
GLOBAL_KEYBINDINGS: [
['toggle-drawing', 'toggle-modal', 'erase-drawings']
],
// The setting keys of the "org.gnome.shell.extensions.draw-on-your-screen.internal-shortcuts" schema.
INTERNAL_KEYBINDINGS: [
['undo', 'redo', 'delete-last-element', 'smooth-last-element'],
['select-none-shape', 'select-line-shape', 'select-ellipse-shape', 'select-rectangle-shape', 'select-polygon-shape', 'select-polyline-shape',
'select-text-shape', 'select-image-shape', 'select-move-tool', 'select-resize-tool', 'select-mirror-tool'],
['switch-fill', 'switch-fill-rule', 'switch-color-palette', 'switch-color-palette-reverse'],
['increment-line-width', 'increment-line-width-more', 'decrement-line-width', 'decrement-line-width-more',
'switch-linejoin', 'switch-linecap', 'switch-dash'],
['switch-font-family', 'switch-font-family-reverse', 'switch-font-weight', 'switch-font-style', 'switch-text-alignment', 'switch-image-file'],
['toggle-panel-and-dock-visibility', 'toggle-background', 'toggle-grid', 'toggle-square-area'],
['open-next-json', 'open-previous-json', 'save-as-json', 'save-as-svg', 'open-preferences', 'toggle-help']
],
// The setting keys of the "org.gnome.shell.extensions.draw-on-your-screen" schema.
var GLOBAL_KEYBINDINGS = [
['toggle-drawing', 'toggle-modal', 'erase-drawings'],
];
// Use functions to get the translations "at runtime".
_otherFunctions: [[
() => [_("Draw"), _("Left click")],
() => [_("Menu"), _("Right click")],
() => [internalShortcutsSchema.get_key('switch-fill').get_summary(), _("Center click")],
() => [_("Increment/decrement line width"), _("Scroll")],
// Translators: %s are key labels (Ctrl+F1 and Ctrl+F9)
() => [_("Select color"), _("%s … %s").format(getKeyLabel('<Primary>1'), getKeyLabel('<Primary>9'))],
// Translators: %s is a key label
() => [_("Ignore pointer movement"), _("%s held").format(getKeyLabel('space'))],
() => [_("Leave"), getKeyLabel('Escape')],
], [
() => [_("Select eraser <span alpha=\"50%\">(while starting drawing)</span>"), getKeyLabel('<Shift>')],
() => [_("Duplicate <span alpha=\"50%\">(while starting handling)</span>"), getKeyLabel('<Shift>')],
() => [_("Rotate rectangle, polygon, polyline"), getKeyLabel('<Primary>')],
() => [_("Extend circle to ellipse"), getKeyLabel('<Primary>')],
() => [_("Curve line"), getKeyLabel('<Primary>')],
() => [_("Smooth free drawing outline"), getKeyLabel('<Primary>')],
() => [_("Rotate <span alpha=\"50%\">(while moving)</span>"), getKeyLabel('<Primary>')],
() => [_("Stretch <span alpha=\"50%\">(while resizing)</span>"), getKeyLabel('<Primary>')],
() => [_("Inverse <span alpha=\"50%\">(while mirroring)</span>"), getKeyLabel('<Primary>')],
]],
get OTHERS() {
if (!this._others) {
this._others = [];
this._otherFunctions.forEach(getPairFunctions => {
let pairs = [];
getPairFunctions.forEach(getPairFunction => pairs.push(getPairFunction()));
this._others.push(pairs);
});
}
return this._others;
}
};
// The setting keys of the "org.gnome.shell.extensions.draw-on-your-screen.internal-shortcuts" schema.
var INTERNAL_KEYBINDINGS = [
['undo', 'redo', 'delete-last-element', 'smooth-last-element'],
['select-none-shape', 'select-line-shape', 'select-ellipse-shape', 'select-rectangle-shape', 'select-polygon-shape', 'select-polyline-shape',
'select-text-shape', 'select-image-shape', 'select-move-tool', 'select-resize-tool', 'select-mirror-tool'],
['switch-fill', 'switch-fill-rule', 'switch-color-palette', 'switch-color-palette-reverse'],
['increment-line-width', 'increment-line-width-more', 'decrement-line-width', 'decrement-line-width-more',
'switch-linejoin', 'switch-linecap', 'switch-dash'],
['switch-font-family', 'switch-font-family-reverse', 'switch-font-weight', 'switch-font-style', 'switch-text-alignment', 'switch-image-file'],
['toggle-panel-and-dock-visibility', 'toggle-background', 'toggle-grid', 'toggle-square-area'],
['open-next-json', 'open-previous-json', 'save-as-json', 'save-as-svg', 'open-preferences', 'toggle-help'],
];
if (GS_VERSION < '3.36')
if (GS_VERSION < '3.36') {
// Remove 'open-preferences' keybinding.
Shortcuts.INTERNAL_KEYBINDINGS.forEach(settingKeys => {
INTERNAL_KEYBINDINGS.forEach(settingKeys => {
let index = settingKeys.indexOf('open-preferences');
if (index != -1)
settingKeys.splice(index, 1);
});
}
const getOthers = function() {
return [
{
[_("Draw")]: _("Left click"),
[_("Menu")]: _("Right click"),
[internalShortcutsSchema.get_key('switch-fill').get_summary()]: _("Center click"),
[_("Increment/decrement line width")]: _("Scroll"),
// Translators: %s are key labels (Ctrl+F1 and Ctrl+F9)
[_("Select color")]: _("%s … %s").format(getKeyLabel('<Primary>1'), getKeyLabel('<Primary>9')),
// Translators: %s is a key label
[_("Ignore pointer movement")]: _("%s held").format(getKeyLabel('space')),
[_("Leave")]: getKeyLabel('Escape'),
}, {
[_("Select eraser <span alpha=\"50%\">(while starting drawing)</span>")]: getKeyLabel('<Shift>'),
[_("Duplicate <span alpha=\"50%\">(while starting handling)</span>")]: getKeyLabel('<Shift>'),
[_("Rotate rectangle, polygon, polyline")]: getKeyLabel('<Primary>'),
[_("Extend circle to ellipse")]: getKeyLabel('<Primary>'),
[_("Curve line")]: getKeyLabel('<Primary>'),
[_("Smooth free drawing outline")]: getKeyLabel('<Primary>'),
[_("Rotate <span alpha=\"50%\">(while moving)</span>")]: getKeyLabel('<Primary>'),
[_("Stretch <span alpha=\"50%\">(while resizing)</span>")]: getKeyLabel('<Primary>'),
[_("Inverse <span alpha=\"50%\">(while mirroring)</span>")]: getKeyLabel('<Primary>'),
},
];
};
let _OTHERS;
// Equivalent to "var OTHERS = [[ ... ]]", but as a getter so the translations are got after the initTranslations call.
// 'this' is the module.
Object.defineProperty(this, 'OTHERS', {
get: function() {
if (!_OTHERS)
_OTHERS = getOthers();
return _OTHERS;
}
});