piskel/js/service/HistoryService.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

(function () {
var ns = $.namespace("pskl.service");
ns.HistoryService = function (piskelController) {
this.piskelController = piskelController;
2013-12-11 00:25:36 +04:00
this.saveState__b = this.saveState.bind(this);
};
ns.HistoryService.prototype.init = function () {
2013-12-11 00:25:36 +04:00
$.subscribe(Events.PISKEL_RESET, this.saveState__b);
$.subscribe(Events.TOOL_RELEASED, this.saveState__b);
pskl.app.shortcutService.addShortcut('ctrl+Z', this.undo.bind(this));
pskl.app.shortcutService.addShortcut('ctrl+Y', this.redo.bind(this));
};
2012-09-16 15:10:05 +04:00
ns.HistoryService.prototype.saveState = function () {
this.piskelController.getCurrentFrame().saveState();
};
2012-09-16 15:10:05 +04:00
ns.HistoryService.prototype.undo = function () {
this.piskelController.getCurrentFrame().loadPreviousState();
2013-12-11 00:25:36 +04:00
$.unsubscribe(Events.PISKEL_RESET, this.saveState__b);
$.publish(Events.PISKEL_RESET);
2013-12-11 00:25:36 +04:00
$.subscribe(Events.PISKEL_RESET, this.saveState__b);
};
2012-09-16 15:10:05 +04:00
ns.HistoryService.prototype.redo = function () {
this.piskelController.getCurrentFrame().loadNextState();
2013-12-11 00:25:36 +04:00
$.unsubscribe(Events.PISKEL_RESET, this.saveState__b);
$.publish(Events.PISKEL_RESET);
2013-12-11 00:25:36 +04:00
$.subscribe(Events.PISKEL_RESET, this.saveState__b);
};
})();