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