From 4a552b14aa5f871240203a0343969242972c5f02 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 15 Mar 2011 19:45:04 -0400 Subject: [PATCH] Update bookmarked status asynchronously. --- common/content/bookmarks.js | 25 +++++++++++++++++++++++-- common/content/statusline.js | 12 +++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 688c35e0..3f267249 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -11,6 +11,10 @@ var DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png"; // also includes methods for dealing with keywords and search engines var Bookmarks = Module("bookmarks", { init: function () { + this.timer = Timer(0, 100, function () { + this.checkBookmarked(buffer.uri); + }, this); + storage.addObserver("bookmark-cache", function (key, event, arg) { if (["add", "change", "remove"].indexOf(event) >= 0) autocommands.trigger("Bookmark" + event[0].toUpperCase() + event.substr(1), @@ -20,10 +24,16 @@ var Bookmarks = Module("bookmarks", { valueOf: function () arg } }, arg)); - statusline.updateStatus(); + bookmarks.timer.tell(); }, window); }, + signals: { + "browser.locationChange": function (webProgress, request, uri) { + this.checkBookmarked(uri); + } + }, + get format() ({ anchored: false, title: ["URL", "Info"], @@ -103,7 +113,7 @@ var Bookmarks = Module("bookmarks", { * * @param {Element} elem A form element for which to add a keyword. */ - addSearchKeyword: function (elem) { + addSearchKeyword: function addSearchKeyword(elem) { if (elem instanceof HTMLFormElement || elem.form) var [url, post, charset] = util.parseForm(elem); else @@ -119,6 +129,17 @@ var Bookmarks = Module("bookmarks", { commands.commandToString({ command: "bmark", options: options, arguments: [url] }) + " -keyword "); }, + checkBookmarked: function checkBookmarked(uri) { + if (PlacesUtils.asyncGetBookmarkIds) + PlacesUtils.asyncGetBookmarkIds(uri, function (ids) { + statusline.bookmarked = ids.length; + }); + else + this.timeout(function () { + statusline.bookmarked = bookmarkcache.isBookmarked(uri); + }); + }, + /** * Toggles the bookmarked state of the given URL. If the URL is * bookmarked, all bookmarks for said URL are removed. diff --git a/common/content/statusline.js b/common/content/statusline.js index 14f9b4e3..a839fb67 100644 --- a/common/content/statusline.js +++ b/common/content/statusline.js @@ -96,7 +96,7 @@ var StatusLine = Module("statusline", { signals: { "browser.locationChange": function (webProgress, request, uri) { let win = webProgress.DOMWindow; - this.updateStatus(); + this.status = uri; this.progress = uri && win && win.dactylProgress || ""; // if this is not delayed we get the position of the old buffer @@ -235,10 +235,7 @@ var StatusLine = Module("statusline", { modified += "+"; if (sh && sh.index < sh.count - 1) modified += "-"; - } - - if (modules.bookmarkcache) { - if (bookmarkcache.isBookmarked(uri)) + if (this.bookmarked) modified += UTF8("❤"); } @@ -262,7 +259,12 @@ var StatusLine = Module("statusline", { this.widgets.url.value = url; this._status = uri; + }, + get bookmarked() this._bookmarked, + set bookmarked(val) { + this._bookmarked = val; + this.status = this.status; }, updateStatus: function updateStatus() {