Enhancement : #169 : Use several meta for shortcut

- can now use shift+ctrl+alt in shortcut definition
- paste opaque for selection remapped to ctrl+shift+V
This commit is contained in:
jdescottes 2014-04-24 13:28:21 +02:00
parent cf2c0e7045
commit a060e32b15
2 changed files with 29 additions and 22 deletions

View File

@ -19,7 +19,7 @@
$.subscribe(Events.SELECTION_MOVE_REQUEST, $.proxy(this.onSelectionMoved_, this));
pskl.app.shortcutService.addShortcut('ctrl+V', this.paste.bind(this));
pskl.app.shortcutService.addShortcut('shift+V', this.pasteOpaqueOnly.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+shift+V', this.pasteOpaqueOnly.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+X', this.cut.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+C', this.copy.bind(this));
pskl.app.shortcutService.addShortcut('del', this.erase.bind(this));

View File

@ -47,20 +47,31 @@
};
ns.ShortcutService.prototype.parseKey_ = function (key) {
var meta = 'normal';
if (key.indexOf('ctrl+') === 0) {
meta = 'ctrl';
key = key.replace('ctrl+', '');
} else if (key.indexOf('shift+') === 0) {
meta = 'shift';
key = key.replace('shift+', '');
} else if (key.indexOf('alt+') === 0) {
meta = 'alt';
key = key.replace('alt+', '');
}
var meta = this.getMetaKey_({
alt : key.indexOf('alt+') != -1,
shift : key.indexOf('shift+') != -1,
ctrl : key.indexOf('ctrl+') != -1
});
var parts = key.split('+');
key = parts[parts.length-1];
return {meta : meta, key : key};
};
ns.ShortcutService.prototype.getMetaKey_ = function (meta) {
var keyBuffer = [];
['alt', 'ctrl', 'shift'].forEach(function (metaKey) {
if (meta[metaKey]) {
keyBuffer.push(metaKey);
}
});
if (keyBuffer.length > 0) {
return keyBuffer.join('+');
} else {
return 'normal';
}
};
/**
* @private
*/
@ -73,16 +84,12 @@
var keyShortcuts = this.shortcuts_[charkey];
if(keyShortcuts) {
var cb;
if (this.isCtrlKeyPressed_(evt)) {
cb = keyShortcuts.ctrl;
} else if (this.isShiftKeyPressed_(evt)) {
cb = keyShortcuts.shift;
} else if (this.isAltKeyPressed_(evt)) {
cb = keyShortcuts.alt;
} else {
cb = keyShortcuts.normal;
}
var meta = this.getMetaKey_({
alt : this.isAltKeyPressed_(evt),
shift : this.isShiftKeyPressed_(evt),
ctrl : this.isCtrlKeyPressed_(evt)
});
var cb = keyShortcuts[meta];
if(cb) {
var bubble = cb(charkey);