2012-09-07 02:18:59 +04:00
|
|
|
(function () {
|
|
|
|
var ns = $.namespace("pskl");
|
2012-09-11 01:26:12 +04:00
|
|
|
ns.HistoryManager = function (framesheet) {
|
|
|
|
this.framesheet = framesheet;
|
|
|
|
};
|
2012-09-07 02:18:59 +04:00
|
|
|
|
|
|
|
ns.HistoryManager.prototype.init = function () {
|
2012-09-11 01:26:12 +04:00
|
|
|
document.body.addEventListener('keyup', this.onKeyup.bind(this));
|
|
|
|
$.subscribe(Events.TOOL_RELEASED, this.saveState.bind(this));
|
2012-09-07 02:18:59 +04:00
|
|
|
};
|
|
|
|
|
2012-09-11 01:26:12 +04:00
|
|
|
ns.HistoryManager.prototype.saveState = function () {
|
|
|
|
this.framesheet.getCurrentFrame().saveState();
|
|
|
|
};
|
2012-09-07 02:18:59 +04:00
|
|
|
|
|
|
|
ns.HistoryManager.prototype.onKeyup = function (evt) {
|
2012-09-11 01:26:12 +04:00
|
|
|
if (evt.ctrlKey && evt.keyCode == 90) { // CTRL + Z
|
|
|
|
this.undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (evt.ctrlKey && evt.keyCode == 89) { // CTRL+ Y
|
|
|
|
this.redo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.HistoryManager.prototype.undo = function () {
|
|
|
|
this.framesheet.getCurrentFrame().loadPreviousState();
|
|
|
|
this.redraw();
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.HistoryManager.prototype.redo = function () {
|
|
|
|
this.framesheet.getCurrentFrame().loadNextState();
|
|
|
|
this.redraw();
|
|
|
|
};
|
|
|
|
|
|
|
|
ns.HistoryManager.prototype.redraw = function () {
|
|
|
|
this.framesheet.drawingController.renderFrame();
|
|
|
|
this.framesheet.previewsController.createPreviews();
|
|
|
|
};
|
2012-09-07 02:18:59 +04:00
|
|
|
})();
|