mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Merge pull request #471 from juliandescottes/GMartigny-issue_#447_dirty_state_on_replace
G martigny issue #447 dirty state on replace
This commit is contained in:
commit
e272fbe32f
@ -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);
|
||||
|
@ -46,7 +46,8 @@
|
||||
var state = {
|
||||
action : action,
|
||||
frameIndex : action.state ? action.state.frameIndex : this.piskelController.currentFrameIndex,
|
||||
layerIndex : action.state ? action.state.layerIndex : this.piskelController.currentLayerIndex
|
||||
layerIndex : action.state ? action.state.layerIndex : this.piskelController.currentLayerIndex,
|
||||
uuid: pskl.utils.Uuid.generate()
|
||||
};
|
||||
|
||||
var isSnapshot = action.type === ns.HistoryService.SNAPSHOT;
|
||||
@ -59,6 +60,15 @@
|
||||
$.publish(Events.HISTORY_STATE_SAVED);
|
||||
};
|
||||
|
||||
ns.HistoryService.prototype.getCurrentStateId = function () {
|
||||
var state = this.stateQueue[this.currentIndex];
|
||||
if (!state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return state.uuid;
|
||||
};
|
||||
|
||||
ns.HistoryService.prototype.undo = function () {
|
||||
this.loadState(this.currentIndex - 1);
|
||||
};
|
||||
|
@ -1,45 +1,31 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.service');
|
||||
|
||||
ns.SavedStatusService = function (piskelController) {
|
||||
ns.SavedStatusService = function (piskelController, historyService) {
|
||||
this.piskelController = piskelController;
|
||||
this.historyService = historyService;
|
||||
this.lastSavedStateIndex = '';
|
||||
|
||||
this.publishStatusUpdateEvent_ = this.publishStatusUpdateEvent_.bind(this);
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.init = function () {
|
||||
$.subscribe(Events.TOOL_RELEASED, this.onToolReleased.bind(this));
|
||||
$.subscribe(Events.PISKEL_RESET, this.onPiskelReset.bind(this));
|
||||
$.subscribe(Events.TOOL_RELEASED, this.publishStatusUpdateEvent_);
|
||||
$.subscribe(Events.PISKEL_RESET, this.publishStatusUpdateEvent_);
|
||||
$.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;
|
||||
}
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.onToolReleased = function () {
|
||||
this.updateDirtyStatus(true);
|
||||
this.lastSavedStateIndex = this.historyService.getCurrentStateId();
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.onPiskelSaved = function () {
|
||||
this.updateDirtyStatus(false);
|
||||
this.lastSavedStateIndex = this.historyService.getCurrentStateId();
|
||||
this.publishStatusUpdateEvent_();
|
||||
};
|
||||
|
||||
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.publishStatusUpdateEvent_ = 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.getCurrentStateId());
|
||||
};
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user