From 495dd8d9d992d60f917590adfef84c14e4f3b26b Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 27 Jun 2011 14:51:59 +1000 Subject: [PATCH] Prompt before running :sanitize all. --HG-- extra : rebase_source : 7a66e541ba326e72416bff85085003f97d607454 --- common/locale/en-US/messages.properties | 4 +++ common/modules/sanitizer.jsm | 38 +++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/common/locale/en-US/messages.properties b/common/locale/en-US/messages.properties index a5c8c40b..4bd6b213 100644 --- a/common/locale/en-US/messages.properties +++ b/common/locale/en-US/messages.properties @@ -93,6 +93,8 @@ command.let.undefinedVar-1 = E121: Undefined variable: %S command.let.unexpectedChar = E18: Unexpected characters in :let command.run.noPrevious = E34: No previous command command.sanitize.privateMode = Cannot sanitize items in private mode +command.sanitize.allDeleted = All items sanitized +command.sanitize.noneDeleted = No items sanitized command.scriptnames.none = No sourced scripts found command.set.errorParsing-1 = Error parsing :set command: %S command.set.numberRequired-2 = E521: Number required after =: %S=%S @@ -274,6 +276,8 @@ quickmark.notSet = QuickMark not set quickmark.invalid = Argument must be an ASCII letter or digit quickmark.added-2 = Added Quick Mark '%S': %S +sanitize.prompt.deleteAll = This will sanitize all items. Would you like to continue? (yes/[no]): + save.invalidDestination-1 = Invalid destination: %S sort.ascending = ascending diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index 44924899..f51100a9 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -427,20 +427,34 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef else dactyl.assert(modules.options.get("sanitizeitems").validator(items), _("error.invalidArgument")); - if (items.indexOf("all") >= 0) - items = Object.keys(sanitizer.itemMap).filter(function (k) items.indexOf(k) === -1); - - sanitizer.range = range.native; - sanitizer.ignoreTimespan = range.min == null; - sanitizer.sanitizing = true; - if (args["-host"]) { - args["-host"].forEach(function (host) { - sanitizer.sanitizing = true; - sanitizer.sanitizeItems(items, range, host); - }); + function sanitize(items) { + sanitizer.range = range.native; + sanitizer.ignoreTimespan = range.min == null; + sanitizer.sanitizing = true; + if (args["-host"]) { + args["-host"].forEach(function (host) { + sanitizer.sanitizing = true; + sanitizer.sanitizeItems(items, range, host); + }); + } + else + sanitizer.sanitize(items, range); } + + if (items.indexOf("all") >= 0) + modules.commandline.input(_("sanitize.prompt.deleteAll") + " ", + function (resp) { + if (resp.match(/^y(es)?$/i)) { + items = Object.keys(sanitizer.itemMap).filter(function (k) items.indexOf(k) === -1); + sanitize(items); + dactyl.echo(_("command.sanitize.allDeleted")); + } + else + dactyl.echo(_("command.sanitize.noneDeleted")); + }); else - sanitizer.sanitize(items, range); + sanitize(items); + }, { argCount: "*", // FIXME: should be + and 0