mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
f0ef016309
+ added shortcuts for all tools in ToolController + modified structure of tools in Controller to Array of descriptors to allow to declare shortcuts directly when setting up the tool controller
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
(function () {
|
|
var ns = $.namespace("pskl.service");
|
|
|
|
ns.KeyboardEventService = function () {
|
|
this.keyboardActions_ = {
|
|
"ctrl" : {
|
|
"z" : Events.UNDO,
|
|
"y" : Events.REDO,
|
|
"x" : Events.CUT,
|
|
"c" : Events.COPY,
|
|
"v" : Events.PASTE
|
|
}
|
|
};
|
|
|
|
// See ToolController
|
|
// TODO : Allow for other classes to register new shortcuts
|
|
var toolKeys = 'pveblrcmzso'.split('');
|
|
toolKeys.forEach(function (key) {
|
|
this.keyboardActions_[key] = Events.SELECT_TOOL;
|
|
}.bind(this));
|
|
};
|
|
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
ns.KeyboardEventService.prototype.init = function() {
|
|
$(document.body).keydown($.proxy(this.onKeyUp_, this));
|
|
};
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
ns.KeyboardEventService.prototype.onKeyUp_ = function(evt) {
|
|
var eventToTrigger;
|
|
|
|
// jquery names FTW ...
|
|
var keycode = evt.which;
|
|
var charkey = pskl.service.keyboard.KeycodeTranslator.toChar(keycode);
|
|
|
|
if(charkey) {
|
|
if (this.isCtrlKeyPressed_(evt)) {
|
|
eventToTrigger = this.keyboardActions_.ctrl[charkey];
|
|
} else {
|
|
eventToTrigger = this.keyboardActions_[charkey];
|
|
}
|
|
|
|
if(eventToTrigger) {
|
|
$.publish(eventToTrigger, charkey);
|
|
evt.preventDefault();
|
|
}
|
|
}
|
|
};
|
|
|
|
ns.KeyboardEventService.prototype.isCtrlKeyPressed_ = function (evt) {
|
|
return this.isMac_() ? evt.metaKey : evt.ctrlKey;
|
|
};
|
|
|
|
ns.KeyboardEventService.prototype.isMac_ = function () {
|
|
return navigator.appVersion.indexOf("Mac") != -1;
|
|
};
|
|
})();
|