1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-02 18:55:45 +01:00

Update bookmarked status asynchronously.

This commit is contained in:
Kris Maglione
2011-03-15 19:45:04 -04:00
parent eeb24d07a3
commit 4a552b14aa
2 changed files with 30 additions and 7 deletions

View File

@@ -11,6 +11,10 @@ var DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png";
// also includes methods for dealing with keywords and search engines // also includes methods for dealing with keywords and search engines
var Bookmarks = Module("bookmarks", { var Bookmarks = Module("bookmarks", {
init: function () { init: function () {
this.timer = Timer(0, 100, function () {
this.checkBookmarked(buffer.uri);
}, this);
storage.addObserver("bookmark-cache", function (key, event, arg) { storage.addObserver("bookmark-cache", function (key, event, arg) {
if (["add", "change", "remove"].indexOf(event) >= 0) if (["add", "change", "remove"].indexOf(event) >= 0)
autocommands.trigger("Bookmark" + event[0].toUpperCase() + event.substr(1), autocommands.trigger("Bookmark" + event[0].toUpperCase() + event.substr(1),
@@ -20,10 +24,16 @@ var Bookmarks = Module("bookmarks", {
valueOf: function () arg valueOf: function () arg
} }
}, arg)); }, arg));
statusline.updateStatus(); bookmarks.timer.tell();
}, window); }, window);
}, },
signals: {
"browser.locationChange": function (webProgress, request, uri) {
this.checkBookmarked(uri);
}
},
get format() ({ get format() ({
anchored: false, anchored: false,
title: ["URL", "Info"], title: ["URL", "Info"],
@@ -103,7 +113,7 @@ var Bookmarks = Module("bookmarks", {
* *
* @param {Element} elem A form element for which to add a keyword. * @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) if (elem instanceof HTMLFormElement || elem.form)
var [url, post, charset] = util.parseForm(elem); var [url, post, charset] = util.parseForm(elem);
else else
@@ -119,6 +129,17 @@ var Bookmarks = Module("bookmarks", {
commands.commandToString({ command: "bmark", options: options, arguments: [url] }) + " -keyword "); 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 * Toggles the bookmarked state of the given URL. If the URL is
* bookmarked, all bookmarks for said URL are removed. * bookmarked, all bookmarks for said URL are removed.

View File

@@ -96,7 +96,7 @@ var StatusLine = Module("statusline", {
signals: { signals: {
"browser.locationChange": function (webProgress, request, uri) { "browser.locationChange": function (webProgress, request, uri) {
let win = webProgress.DOMWindow; let win = webProgress.DOMWindow;
this.updateStatus(); this.status = uri;
this.progress = uri && win && win.dactylProgress || ""; this.progress = uri && win && win.dactylProgress || "";
// if this is not delayed we get the position of the old buffer // if this is not delayed we get the position of the old buffer
@@ -235,10 +235,7 @@ var StatusLine = Module("statusline", {
modified += "+"; modified += "+";
if (sh && sh.index < sh.count - 1) if (sh && sh.index < sh.count - 1)
modified += "-"; modified += "-";
} if (this.bookmarked)
if (modules.bookmarkcache) {
if (bookmarkcache.isBookmarked(uri))
modified += UTF8("❤"); modified += UTF8("❤");
} }
@@ -262,7 +259,12 @@ var StatusLine = Module("statusline", {
this.widgets.url.value = url; this.widgets.url.value = url;
this._status = uri; this._status = uri;
},
get bookmarked() this._bookmarked,
set bookmarked(val) {
this._bookmarked = val;
this.status = this.status;
}, },
updateStatus: function updateStatus() { updateStatus: function updateStatus() {