From 3485424f6e72161aef139d9f5723cbd0760b38e2 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sun, 9 Jan 2011 15:36:10 -0500 Subject: Automagically grab form charset in ;S. --- common/content/bookmarks.js | 45 ++++++++++++++++++++++++++++++++------------ common/content/commands.js | 2 +- common/content/statusline.js | 5 ++--- 3 files changed, 36 insertions(+), 16 deletions(-) (limited to 'common/content') diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index b2304211..887187a7 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -58,7 +58,7 @@ var Bookmarks = Module("bookmarks", { add: function add(unfiled, title, url, keyword, tags, force) { // FIXME if (isObject(unfiled)) - var { unfiled, title, url, keyword, tags, post, force } = unfiled; + var { unfiled, title, url, keyword, tags, post, charset, force } = unfiled; try { let uri = util.createURI(url); @@ -82,13 +82,15 @@ var Bookmarks = Module("bookmarks", { if (!bmark) return false; + if (charset !== undefined) + bmark.charset = charset; if (post !== undefined) bmark.post = post; if (keyword) bmark.keyword = keyword; } catch (e) { - dactyl.log(e, 0); + util.reportError(e); return false; } @@ -102,10 +104,12 @@ var Bookmarks = Module("bookmarks", { * @param {Element} elem A form element for which to add a keyword. */ addSearchKeyword: function (elem) { - let [url, post] = util.parseForm(elem); + let [url, post, charset] = util.parseForm(elem); let options = { "-title": "Search " + elem.ownerDocument.title }; if (post != null) options["-post"] = post; + if (charset != null && charset !== "UTF-8") + options["-charset"] = charset; commandline.open(":", commands.commandToString({ command: "bmark", options: options, arguments: [url] }) + " -keyword ", @@ -134,7 +138,7 @@ var Bookmarks = Module("bookmarks", { let extra = ""; if (title != url) extra = " (" + title + ")"; - this.add(true, title, url); + this.add({ unfiled: true, title: title, url: url }); dactyl.echomsg({ domains: [util.getHost(url)], message: "Added bookmark: " + url + extra }); } }, @@ -179,8 +183,10 @@ var Bookmarks = Module("bookmarks", { } ids.forEach(function (id) { let bmark = bookmarkcache.bookmarks[id]; - if (bmark) - PlacesUtils.tagging.untagURI(util.newURI(bmark.url), null); + if (bmark) { + PlacesUtils.tagging.untagURI(bmark.uri, null); + bmark.charset = null; + } services.bookmarks.removeItem(id); }); return ids.length; @@ -302,6 +308,7 @@ var Bookmarks = Module("bookmarks", { let [shortcutURL, postData] = PlacesUtils.getURLAndPostDataForKeyword(keyword); if (!shortcutURL) return [url, null]; + let bmark = bookmarkcache.keywords[keyword]; let data = window.unescape(postData || ""); if (/%s/i.test(shortcutURL) || /%s/i.test(data)) { @@ -309,17 +316,16 @@ var Bookmarks = Module("bookmarks", { var matches = shortcutURL.match(/^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/); if (matches) [, shortcutURL, charset] = matches; - else { + else try { charset = services.history.getCharsetForURI(util.newURI(shortcutURL)); } catch (e) {} - } - var encodedParam; if (charset) - encodedParam = escape(window.convertFromUnicode(charset, param)); + var encodedParam = escape(window.convertFromUnicode(charset, param)); else - encodedParam = encodeURIComponent(param); + encodedParam = bmark.encodeURIComponent(param); + shortcutURL = shortcutURL.replace(/%s/g, encodedParam).replace(/%S/g, param); if (/%s/i.test(data)) postData = window.getPostDataStream(data, param, encodedParam, "application/x-www-form-urlencoded"); @@ -443,6 +449,7 @@ var Bookmarks = Module("bookmarks", { force: args.bang, unfiled: false, keyword: args["-keyword"] || null, + charset: args["-charset"], post: args["-post"], tags: args["-tags"] || [], title: args["-title"] || (args.length === 0 ? buffer.title : null), @@ -470,7 +477,15 @@ var Bookmarks = Module("bookmarks", { } completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] }); }, - options: [keyword, title, tags, post] + options: [keyword, title, tags, post, + { + names: ["-charset", "-c"], + description: "The character encoding of the bookmark", + type: CommandOption.STRING, + completer: function (context) completion.charset(context), + validator: Option.validateCompleter + } + ] }); commands.add(["bmarks"], @@ -547,14 +562,20 @@ var Bookmarks = Module("bookmarks", { let bmark = bmarks[0]; options["-title"] = bmark.title; + if (bmark.charset) + options["-charset"] = bmark.charset; if (bmark.keyword) options["-keyword"] = bmark.keyword; + if (bmark.post) + options["-post"] = bmark.post; if (bmark.tags.length > 0) options["-tags"] = bmark.tags.join(", "); } else { if (buffer.title != buffer.URL.spec) options["-title"] = buffer.title; + if (content.document.characterSet !== "UTF-8") + options["-charset"] = content.document.characterSet; } commandline.open(":", diff --git a/common/content/commands.js b/common/content/commands.js index 39b8f453..9b54f4d8 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -903,7 +903,7 @@ var Commands = Module("commands", { // we have a validator function if (typeof opt.validator == "function") { - if (opt.validator.call(this, arg, quoted) == false) { + if (opt.validator(arg, quoted) == false) { fail("Invalid argument for option: " + optname); if (complete) // Always true. complete.highlight(args.completeStart, count - 1, "SPELLCHECK"); diff --git a/common/content/statusline.js b/common/content/statusline.js index 2e0e6b1e..2bc9660b 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -232,9 +232,8 @@ var StatusLine = Module("statusline", { else if (progress < 1) { progress = Math.floor(progress * 20); progressStr = "[" - + "====================".substr(0, progress) - + ">" - + " ".substr(0, 19 - progress) + + "===================> " + .substr(20 - progress, 20) + "]"; } this.widgets.progress.value = progressStr; -- cgit v1.2.3