rework of shortcuts.js
This commit is contained in:
parent
8277710510
commit
a06d318646
12
helper.js
12
helper.js
|
|
@ -31,7 +31,7 @@ const Tweener = imports.ui.tweener;
|
||||||
|
|
||||||
const Me = ExtensionUtils.getCurrentExtension();
|
const Me = ExtensionUtils.getCurrentExtension();
|
||||||
const Convenience = ExtensionUtils.getSettings ? ExtensionUtils : Me.imports.convenience;
|
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 _ = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||||
|
|
||||||
const GS_VERSION = Config.PACKAGE_VERSION;
|
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.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
|
||||||
this.vbox.add_child(new St.Label({ text: _("Internal") }));
|
this.vbox.add_child(new St.Label({ text: _("Internal") }));
|
||||||
|
|
||||||
Shortcuts.OTHERS.forEach((pairs, index) => {
|
Shortcuts.OTHERS.forEach((object, index) => {
|
||||||
if (index)
|
if (index)
|
||||||
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
|
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 });
|
let hbox = new St.BoxLayout({ vertical: false });
|
||||||
hbox.add_child(new St.Label({ text: pair[0] }));
|
hbox.add_child(new St.Label({ text: key }));
|
||||||
hbox.add_child(new St.Label({ text: pair[1], x_expand: true }));
|
hbox.add_child(new St.Label({ text: object[key], x_expand: true }));
|
||||||
hbox.get_children()[0].get_clutter_text().set_use_markup(true);
|
hbox.get_children()[0].get_clutter_text().set_use_markup(true);
|
||||||
this.vbox.add_child(hbox);
|
this.vbox.add_child(hbox);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
|
this.vbox.add_child(new St.BoxLayout({ vertical: false, style_class: 'draw-on-your-screen-helper-separator' }));
|
||||||
|
|
|
||||||
12
prefs.js
12
prefs.js
|
|
@ -30,7 +30,7 @@ const Gtk = imports.gi.Gtk;
|
||||||
const ExtensionUtils = imports.misc.extensionUtils;
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
const Me = ExtensionUtils.getCurrentExtension();
|
const Me = ExtensionUtils.getCurrentExtension();
|
||||||
const Convenience = ExtensionUtils.getSettings && ExtensionUtils.initTranslations ? ExtensionUtils : Me.imports.convenience;
|
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 gettext = imports.gettext.domain(Me.metadata['gettext-domain']).gettext;
|
||||||
const _ = function(string) {
|
const _ = function(string) {
|
||||||
if (!string)
|
if (!string)
|
||||||
|
|
@ -421,19 +421,19 @@ const PrefsPage = new GObject.Class({
|
||||||
listBox.get_style_context().add_class('background');
|
listBox.get_style_context().add_class('background');
|
||||||
internalFrame.add(listBox);
|
internalFrame.add(listBox);
|
||||||
|
|
||||||
Shortcuts.OTHERS.forEach((pairs, index) => {
|
Shortcuts.OTHERS.forEach((object, index) => {
|
||||||
if (index)
|
if (index)
|
||||||
listBox.add(new Gtk.Box(ROWBOX_MARGIN_PARAMS));
|
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 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);
|
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(otherLabel, true, true, 4);
|
||||||
otherBox.pack_start(otherLabel2, false, false, 4);
|
otherBox.pack_start(otherLabel2, false, false, 4);
|
||||||
listBox.add(otherBox);
|
listBox.add(otherBox);
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
listBox.add(new Gtk.Box(ROWBOX_MARGIN_PARAMS));
|
listBox.add(new Gtk.Box(ROWBOX_MARGIN_PARAMS));
|
||||||
|
|
|
||||||
100
shortcuts.js
100
shortcuts.js
|
|
@ -1,5 +1,5 @@
|
||||||
/* jslint esversion: 6 */
|
/* jslint esversion: 6 */
|
||||||
/* exported Shortcuts */
|
/* exported GLOBAL_KEYBINDINGS, INTERNAL_KEYBINDINGS, OTHERS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2019 Abakkk
|
* Copyright 2019 Abakkk
|
||||||
|
|
@ -36,16 +36,13 @@ const getKeyLabel = function(accel) {
|
||||||
return Gtk.accelerator_get_label(keyval, mods);
|
return Gtk.accelerator_get_label(keyval, mods);
|
||||||
};
|
};
|
||||||
|
|
||||||
// It is used by helper and prefs.
|
// The setting keys of the "org.gnome.shell.extensions.draw-on-your-screen" schema.
|
||||||
var Shortcuts = {
|
var GLOBAL_KEYBINDINGS = [
|
||||||
|
['toggle-drawing', 'toggle-modal', 'erase-drawings'],
|
||||||
|
];
|
||||||
|
|
||||||
// The setting keys of the "org.gnome.shell.extensions.draw-on-your-screen" schema.
|
// The setting keys of the "org.gnome.shell.extensions.draw-on-your-screen.internal-shortcuts" schema.
|
||||||
GLOBAL_KEYBINDINGS: [
|
var INTERNAL_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'],
|
['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-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'],
|
'select-text-shape', 'select-image-shape', 'select-move-tool', 'select-resize-tool', 'select-mirror-tool'],
|
||||||
|
|
@ -54,49 +51,52 @@ var Shortcuts = {
|
||||||
'switch-linejoin', 'switch-linecap', 'switch-dash'],
|
'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'],
|
['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'],
|
['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']
|
['open-next-json', 'open-previous-json', 'save-as-json', 'save-as-svg', 'open-preferences', 'toggle-help'],
|
||||||
],
|
];
|
||||||
|
|
||||||
// Use functions to get the translations "at runtime".
|
if (GS_VERSION < '3.36') {
|
||||||
_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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (GS_VERSION < '3.36')
|
|
||||||
// Remove 'open-preferences' keybinding.
|
// Remove 'open-preferences' keybinding.
|
||||||
Shortcuts.INTERNAL_KEYBINDINGS.forEach(settingKeys => {
|
INTERNAL_KEYBINDINGS.forEach(settingKeys => {
|
||||||
let index = settingKeys.indexOf('open-preferences');
|
let index = settingKeys.indexOf('open-preferences');
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
settingKeys.splice(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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue