mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-23 15:36:52 +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:
parent
9d871309c2
commit
13c4e028b1
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,6 @@ exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
|
||||
$tw.wiki.deleteTiddler(title);
|
||||
}
|
||||
});
|
||||
// Trigger an autosave
|
||||
$tw.rootWidget.dispatchEvent({type: "tw-auto-save-wiki"});
|
||||
// Return a heartwarming confirmation
|
||||
return "Plugin " + title + " successfully saved";
|
||||
}
|
||||
|
@ -243,8 +243,6 @@ NavigatorWidget.prototype.handleDeleteTiddlerEvent = function(event) {
|
||||
// Remove the closed tiddler from the story
|
||||
this.removeTitleFromStory(storyList,title);
|
||||
this.saveStoryList(storyList);
|
||||
// Send a notification event
|
||||
this.dispatchEvent({type: "tw-auto-save-wiki"});
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -333,8 +331,6 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
|
||||
if(draftTitle !== this.storyTitle) {
|
||||
this.saveStoryList(storyList);
|
||||
}
|
||||
// Send a notification event
|
||||
this.dispatchEvent({type: "tw-auto-save-wiki"});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -376,13 +372,8 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
|
||||
var storyList = this.getStoryList();
|
||||
// Get the template tiddler if there is one
|
||||
var templateTiddler = this.wiki.getTiddler(event.param);
|
||||
// Create the new tiddler
|
||||
// Title the new tiddler
|
||||
var title = this.wiki.generateNewTitle((templateTiddler && templateTiddler.fields.title) || "New Tiddler");
|
||||
var tiddler = new $tw.Tiddler(this.wiki.getCreationFields(),{
|
||||
text: "Newly created tiddler",
|
||||
title: title
|
||||
},this.wiki.getModificationFields());
|
||||
this.wiki.addTiddler(tiddler);
|
||||
// Create the draft tiddler
|
||||
var draftTitle = this.generateDraftTitle(title),
|
||||
draftTiddler = new $tw.Tiddler({
|
||||
@ -487,8 +478,6 @@ NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
|
||||
}));
|
||||
// Navigate to the $:/Import tiddler
|
||||
this.addToHistory([IMPORT_TITLE]);
|
||||
// Send a notification event
|
||||
this.dispatchEvent({type: "tw-auto-save-wiki"});
|
||||
};
|
||||
|
||||
exports.navigator = NavigatorWidget;
|
||||
|
3
core/wiki/config/SaverFilter.tid
Normal file
3
core/wiki/config/SaverFilter.tid
Normal file
@ -0,0 +1,3 @@
|
||||
title: $:/config/SaverFilter
|
||||
|
||||
[!is[shadow]] -[[$:/HistoryList]] -[[$:/StoryList]] -[[$:/Import]] -[[$:/isEncrypted]] -[prefix[$:/status]] -[prefix[$:/state]] -[prefix[$:/temp]] -[has[draft.of]]
|
@ -183,7 +183,6 @@ $body$
|
||||
">>
|
||||
## <<toc-heading "Widget Messages" "
|
||||
## WidgetMessages
|
||||
## [[tw-auto-save-wiki|WidgetMessage: tw-auto-save-wiki]]
|
||||
## [[tw-cancel-tiddler|WidgetMessage: tw-cancel-tiddler]]
|
||||
## [[tw-clear-password|WidgetMessage: tw-clear-password]]
|
||||
## [[tw-close-all-tiddlers|WidgetMessage: tw-close-all-tiddlers]]
|
||||
|
@ -1,11 +0,0 @@
|
||||
created: 20140811112343634
|
||||
modified: 20140811114420597
|
||||
tags: message
|
||||
title: WidgetMessage: tw-auto-save-wiki
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
The autosave wiki message causes the current saver module to perform a background save if it is required.
|
||||
|
||||
The autosave wiki message should be generated whenever changes are made to the store. For example, the navigator widget generates the autosave wiki message as part of its handling of the [[WidgetMessage: tw-save-tiddler]], [[WidgetMessage: tw-delete-tiddler]] and [[WidgetMessage: tw-perform-import]].
|
||||
|
||||
The autosave wiki message is handled by the TiddlyWiki core SyncMechanism which invokes the current [[SaverModule|SaverModules]]. Not all SaverModules can handle autosaving.
|
@ -4,7 +4,7 @@ tags: message
|
||||
title: WidgetMessage: tw-save-wiki
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
The save wiki message causes the current saver module to perform a full save operation. The save operation can involve user interaction, unlike the [[WidgetMessage: tw-auto-save-wiki]]/
|
||||
The save wiki message causes the current saver module to perform a full save operation. The save operation can involve user interaction.
|
||||
|
||||
The save wiki message is usually generated by the ButtonWidget.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user