From 3afa26b9a318d913ba162d93a63036cb4a94be59 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 12 Apr 2014 14:15:49 +0100 Subject: [PATCH] Require confirmation before abandoning edits Fixes #544 --- core/language/en-GB/Misc.multids | 1 + core/modules/widgets/navigator.js | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/language/en-GB/Misc.multids b/core/language/en-GB/Misc.multids index 0d41e89a3..e7dfd68c3 100644 --- a/core/language/en-GB/Misc.multids +++ b/core/language/en-GB/Misc.multids @@ -3,6 +3,7 @@ title: $:/language/ ClassicWarning/Hint: This tiddler is written in TiddlyWiki Classic wiki text format, which is not fully compatible with TiddlyWiki version 5. See http://tiddlywiki.com/static/Upgrading.html for more details. ClassicWarning/Upgrade/Caption: upgrade CloseAll/Button: close all +ConfirmCancelTiddler: Do you wish to discard changes to the tiddler "<$text text=<>/>"? ConfirmDeleteTiddler: Do you wish to delete the tiddler "<$text text=<<title>>/>"? ConfirmOverwriteTiddler: Do you wish to overwrite the tiddler "<$text text=<<title>>/>"? InvalidFieldName: Illegal characters in field name "<$text text=<<fieldName>>/>". Fields can only contain lowercase letters and the characters underscore (`_`), hyphen (`-`) and period (`.`) diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index 21fc35c73..c58caa2e3 100755 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -333,11 +333,23 @@ NavigatorWidget.prototype.handleCancelTiddlerEvent = function(event) { originalTitle = draftTiddler.fields["draft.of"], storyList = this.getStoryList(); if(draftTiddler && originalTitle) { + // Ask for confirmation if the tiddler text has changed + var isConfirmed = true; + if(this.wiki.getTiddlerText(draftTitle) !== this.wiki.getTiddlerText(originalTitle)) { + isConfirmed = confirm($tw.language.getString( + "ConfirmCancelTiddler", + {variables: + {title: draftTitle} + } + )); + } // Remove the draft tiddler - this.wiki.deleteTiddler(draftTitle); - this.replaceFirstTitleInStory(storyList,draftTitle,originalTitle); - this.addToHistory(originalTitle,event.navigateFromClientRect); - this.saveStoryList(storyList); + if(isConfirmed) { + this.wiki.deleteTiddler(draftTitle); + this.replaceFirstTitleInStory(storyList,draftTitle,originalTitle); + this.addToHistory(originalTitle,event.navigateFromClientRect); + this.saveStoryList(storyList); + } } return false; };