mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-05-03 20:16:48 +00:00
Refactored autosave mechanism
Previously we were using a message `tw-auto-save-wiki` to trigger an autosave. The message was generated by certain UI actions such as saving a tiddler. The trouble was that the message was being processed before the wiki change event for the accompanying change had had a chance to percolate. The end result was that the dirty indicator was staying lit when using autosave. The new approach abandons the autosave message and instead triggers the autosave in the wiki change event when a relevant change occurs. One happy side effect of these changes is that the dirty indicator now works as expected with the client server edition - ie, when typing in a draft tiddler the dirty indicator will flash briefly, and then clear when the sync mechanism has completed saving the draft.
This commit is contained in:
@@ -28,7 +28,7 @@ function SaverHandler(options) {
|
||||
this.initSavers();
|
||||
}
|
||||
// Only do dirty tracking if required
|
||||
if(this.dirtyTracking) {
|
||||
if($tw.browser && this.dirtyTracking) {
|
||||
// Compile the dirty tiddler filter
|
||||
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
|
||||
// Count of tiddlers that have been changed but not yet saved
|
||||
@@ -43,6 +43,9 @@ function SaverHandler(options) {
|
||||
});
|
||||
self.numTasksInQueue += filteredChanges.length;
|
||||
self.updateDirtyStatus();
|
||||
if(self.numTasksInQueue > 0) {
|
||||
self.saveWiki({method: "autosave"});
|
||||
}
|
||||
});
|
||||
// Browser event handlers
|
||||
if($tw.browser) {
|
||||
@@ -65,13 +68,6 @@ function SaverHandler(options) {
|
||||
downloadType: "text/plain"
|
||||
});
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-auto-save-wiki",function(event) {
|
||||
self.saveWiki({
|
||||
method: "autosave",
|
||||
template: event.param,
|
||||
downloadType: "text/plain"
|
||||
});
|
||||
});
|
||||
$tw.rootWidget.addEventListener("tw-download-file",function(event) {
|
||||
self.saveWiki({
|
||||
method: "download",
|
||||
@@ -82,7 +78,7 @@ function SaverHandler(options) {
|
||||
}
|
||||
}
|
||||
|
||||
SaverHandler.prototype.titleSyncFilter = "$:/config/SyncFilter";
|
||||
SaverHandler.prototype.titleSyncFilter = "$:/config/SaverFilter";
|
||||
SaverHandler.prototype.titleAutoSave = "$:/config/AutoSave";
|
||||
SaverHandler.prototype.titleSavedNotification = "$:/language/Notifications/Save/Done";
|
||||
|
||||
@@ -115,7 +111,7 @@ SaverHandler.prototype.initSavers = function(moduleType) {
|
||||
|
||||
/*
|
||||
Save the wiki contents. Options are:
|
||||
method: "save" or "download"
|
||||
method: "save", "autosave" or "download"
|
||||
template: the tiddler containing the template to save
|
||||
downloadType: the content type for the saved file
|
||||
*/
|
||||
@@ -130,6 +126,11 @@ SaverHandler.prototype.saveWiki = function(options) {
|
||||
if(err) {
|
||||
alert("Error while saving:\n\n" + err);
|
||||
} else {
|
||||
// Clear the task queue if we're saving (rather than downloading)
|
||||
if(method !== "download") {
|
||||
self.numTasksInQueue = 0;
|
||||
self.updateDirtyStatus();
|
||||
}
|
||||
$tw.notifier.display(self.titleSavedNotification);
|
||||
if(options.callback) {
|
||||
options.callback();
|
||||
@@ -145,11 +146,6 @@ SaverHandler.prototype.saveWiki = function(options) {
|
||||
var saver = this.savers[t];
|
||||
if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback)) {
|
||||
this.logger.log("Saving wiki with method",method,"through saver",saver.info.name);
|
||||
// Clear the task queue if we're saving (rather than downloading)
|
||||
if(method !== "download") {
|
||||
this.numTasksInQueue = 0;
|
||||
this.updateDirtyStatus();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user