mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-03 23:05:50 +01:00
Update bookmarked status asynchronously.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user