diff --git a/core/modules/saver-handler.js b/core/modules/saver-handler.js index 9d5f9a973..98ff08bdb 100644 --- a/core/modules/saver-handler.js +++ b/core/modules/saver-handler.js @@ -15,43 +15,50 @@ The saver handler tracks changes to the store and handles saving the entire wiki /* Instantiate the saver handler with the following options: wiki: wiki to be synced +dirtyTracking: true if dirty tracking should be performed */ function SaverHandler(options) { var self = this; this.wiki = options.wiki; + this.dirtyTracking = options.dirtyTracking; // Make a logger this.logger = new $tw.utils.Logger("saver-handler"); // Initialise our savers if($tw.browser) { this.initSavers(); } - // 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 - this.numTasksInQueue = 0; - // Listen out for changes to tiddlers - this.wiki.addEventListener("change",function(changes) { - var filteredChanges = self.filterFn.call(self.wiki,function(callback) { - $tw.utils.each(changes,function(change,title) { - var tiddler = self.wiki.getTiddler(title); - callback(tiddler,title); + // Only do dirty tracking if required + if(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 + this.numTasksInQueue = 0; + // Listen out for changes to tiddlers + this.wiki.addEventListener("change",function(changes) { + var filteredChanges = self.filterFn.call(self.wiki,function(callback) { + $tw.utils.each(changes,function(change,title) { + var tiddler = self.wiki.getTiddler(title); + callback(tiddler,title); + }); }); + self.numTasksInQueue += filteredChanges.length; + self.updateDirtyStatus(); }); - self.numTasksInQueue += filteredChanges.length; - self.updateDirtyStatus(); - }); - // Browser event handlers + // Browser event handlers + if($tw.browser) { + // Set up our beforeunload handler + window.addEventListener("beforeunload",function(event) { + var confirmationMessage = undefined; + if(self.isDirty()) { + confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); + event.returnValue = confirmationMessage; // Gecko + } + return confirmationMessage; + }); + } + } + // Install the save action handlers if($tw.browser) { - // Set up our beforeunload handler - window.addEventListener("beforeunload",function(event) { - var confirmationMessage = undefined; - if(self.isDirty()) { - confirmationMessage = $tw.language.getString("UnsavedChangesWarning"); - event.returnValue = confirmationMessage; // Gecko - } - return confirmationMessage; - }); - // Install the save action handlers $tw.rootWidget.addEventListener("tw-save-wiki",function(event) { self.saveWiki({ template: event.param, diff --git a/core/modules/startup/startup.js b/core/modules/startup/startup.js index 67c3415c1..377974ad6 100755 --- a/core/modules/startup/startup.js +++ b/core/modules/startup/startup.js @@ -69,12 +69,12 @@ exports.startup = function() { $tw.syncadaptor = new module.adaptorClass({wiki: $tw.wiki}); } }); - // Set up the syncer object if we've got a syncadaptor, otherwise setup the saverhandler + // Set up the syncer object if we've got a syncadaptor if($tw.syncadaptor) { $tw.syncer = new $tw.Syncer({wiki: $tw.wiki, syncadaptor: $tw.syncadaptor}); - } else { - $tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki}); - } + } + // Setup the saver handler + $tw.saverHandler = new $tw.SaverHandler({wiki: $tw.wiki, dirtyTracking: !$tw.syncadaptor}); // Host-specific startup if($tw.browser) { // Install the popup manager diff --git a/core/ui/PageControls/SaveWikiButtonTemplate.tid b/core/ui/PageControls/SaveWikiButtonTemplate.tid new file mode 100644 index 000000000..1daafaaed --- /dev/null +++ b/core/ui/PageControls/SaveWikiButtonTemplate.tid @@ -0,0 +1,3 @@ +title: $:/config/SaveWikiButton/Template + +$:/core/save/all \ No newline at end of file diff --git a/core/ui/PageControls/savewiki.tid b/core/ui/PageControls/savewiki.tid index a463b0034..b41a18921 100644 --- a/core/ui/PageControls/savewiki.tid +++ b/core/ui/PageControls/savewiki.tid @@ -3,7 +3,7 @@ tags: $:/tags/PageControls caption: {{$:/core/images/save-button}} {{$:/language/Buttons/SaveWiki/Caption}} description: {{$:/language/Buttons/SaveWiki/Hint}} -<$button message="tw-save-wiki" title={{$:/language/Buttons/SaveWiki/Hint}} aria-label={{$:/language/Buttons/SaveWiki/Caption}} class=<>> +<$button message="tw-save-wiki" param={{$:/config/SaveWikiButton/Template}} title={{$:/language/Buttons/SaveWiki/Hint}} aria-label={{$:/language/Buttons/SaveWiki/Caption}} class=<>> <$list filter="[prefix[yes]]"> {{$:/core/images/save-button}} diff --git a/plugins/tiddlywiki/tiddlyweb/SaveWikiButtonTemplate.tid b/plugins/tiddlywiki/tiddlyweb/SaveWikiButtonTemplate.tid new file mode 100644 index 000000000..d44f09031 --- /dev/null +++ b/plugins/tiddlywiki/tiddlyweb/SaveWikiButtonTemplate.tid @@ -0,0 +1,3 @@ +title: $:/config/SaveWikiButton/Template + +$:/plugins/tiddlywiki/tiddlyweb/save/offline \ No newline at end of file diff --git a/plugins/tiddlywiki/tiddlyweb/save-all.tid b/plugins/tiddlywiki/tiddlyweb/save-offline.tid similarity index 85% rename from plugins/tiddlywiki/tiddlyweb/save-all.tid rename to plugins/tiddlywiki/tiddlyweb/save-offline.tid index 497db85a5..af6709d43 100644 --- a/plugins/tiddlywiki/tiddlyweb/save-all.tid +++ b/plugins/tiddlywiki/tiddlyweb/save-offline.tid @@ -1,4 +1,4 @@ -title: $:/core/save/all +title: $:/plugins/tiddlywiki/tiddlyweb/save/offline \define saveTiddlerFilter() [is[tiddler]] -[[$:/boot/boot.css]] -[[$:/HistoryList]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] +[sort[title]]