mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
17bf7b3807
* new file : HistoryManager.js * can undo (ctrl-z) and redo (ctrl-y) changes performed through the tools * history states are recorded per frame * a new state is recorder each time a tool is released (introduced TOOL_RELEASED event for this purpose) * a duplicated frame doesn't inherit the history states of the original frame * there is no limit to the number of states that can be stored per frame * actions such as creating/duplicating/deleting a frame are not concerned by this update
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
(function () {
|
|
var ns = $.namespace("pskl");
|
|
ns.HistoryManager = function () {};
|
|
|
|
ns.HistoryManager.prototype.init = function () {
|
|
document.body.addEventListener('keyup', this.onKeyup.bind(this));
|
|
$.subscribe(Events.TOOL_RELEASED, this.saveState.bind(this));
|
|
};
|
|
|
|
ns.HistoryManager.prototype.saveState = function () {
|
|
piskel.getCurrentFrame().saveState();
|
|
};
|
|
|
|
ns.HistoryManager.prototype.onKeyup = function (evt) {
|
|
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 () {
|
|
piskel.getCurrentFrame().loadPreviousState();
|
|
this.redraw();
|
|
};
|
|
|
|
ns.HistoryManager.prototype.redo = function () {
|
|
piskel.getCurrentFrame().loadNextState();
|
|
this.redraw();
|
|
};
|
|
|
|
ns.HistoryManager.prototype.redraw = function () {
|
|
piskel.drawingController.renderFrame();
|
|
piskel.previewsController.createPreviews();
|
|
};
|
|
|
|
ns.HistoryManager = new ns.HistoryManager();
|
|
})(); |