mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Dirty status compare last save state index and current state index
Signed-off-by:Guillaume Martigny <guillaume.martigny@gmail.com>
This commit is contained in:
parent
9b6d45e8ed
commit
58a1a6b043
@ -127,7 +127,7 @@
|
||||
this.imageUploadService = new pskl.service.ImageUploadService();
|
||||
this.imageUploadService.init();
|
||||
|
||||
this.savedStatusService = new pskl.service.SavedStatusService(this.piskelController);
|
||||
this.savedStatusService = new pskl.service.SavedStatusService(this.piskelController, this.historyService);
|
||||
this.savedStatusService.init();
|
||||
|
||||
this.backupService = new pskl.service.BackupService(this.piskelController);
|
||||
|
@ -1,45 +1,37 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.service');
|
||||
|
||||
ns.SavedStatusService = function (piskelController) {
|
||||
ns.SavedStatusService = function (piskelController, historyService) {
|
||||
this.piskelController = piskelController;
|
||||
this.historyService = historyService;
|
||||
this.lastSavedStateIndex = '';
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.init = function () {
|
||||
$.subscribe(Events.TOOL_RELEASED, this.onToolReleased.bind(this));
|
||||
$.subscribe(Events.PISKEL_RESET, this.onPiskelReset.bind(this));
|
||||
$.subscribe(Events.PISKEL_SAVED, this.onPiskelSaved.bind(this));
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.onPiskelReset = function () {
|
||||
var piskel = this.piskelController.getPiskel();
|
||||
// A first PISKEL_RESET is triggered during the load of a new Piskel, it should be ignored
|
||||
// putting a firstResetDone flag as a nasty workaround for this
|
||||
if (piskel.firstResetDone_) {
|
||||
this.updateDirtyStatus(true);
|
||||
} else {
|
||||
piskel.firstResetDone_ = true;
|
||||
}
|
||||
this.lastSavedStateIndex = this.historyService.getCurrentStateIndex();
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.onToolReleased = function () {
|
||||
this.updateDirtyStatus(true);
|
||||
this.updateDirtyStatus();
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.onPiskelReset = function () {
|
||||
this.updateDirtyStatus();
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.onPiskelSaved = function () {
|
||||
this.updateDirtyStatus(false);
|
||||
this.lastSavedStateIndex = this.historyService.getCurrentStateIndex();
|
||||
$.publish(Events.PISKEL_SAVED_STATUS_UPDATE);
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.updateDirtyStatus = function (status) {
|
||||
var piskel = this.piskelController.getPiskel();
|
||||
if (piskel.isDirty_ != status) {
|
||||
piskel.isDirty_ = status;
|
||||
$.publish(Events.PISKEL_SAVED_STATUS_UPDATE);
|
||||
}
|
||||
ns.SavedStatusService.prototype.updateDirtyStatus = function () {
|
||||
$.publish(Events.PISKEL_SAVED_STATUS_UPDATE);
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.isDirty = function (evt) {
|
||||
var piskel = this.piskelController.getPiskel();
|
||||
return piskel.isDirty_;
|
||||
ns.SavedStatusService.prototype.isDirty = function () {
|
||||
return (this.lastSavedStateIndex != this.historyService.getCurrentStateIndex());
|
||||
};
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user