mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 23:37:58 +01:00
Simplify bookmark loading code.
This commit is contained in:
@@ -35,15 +35,19 @@ var History = Module("history", {
|
|||||||
|
|
||||||
let root = services.history.executeQuery(query, options).root;
|
let root = services.history.executeQuery(query, options).root;
|
||||||
root.containerOpen = true;
|
root.containerOpen = true;
|
||||||
let items = iter(util.range(0, root.childCount)).map(function (i) {
|
try {
|
||||||
let node = root.getChild(i);
|
let items = iter(util.range(0, root.childCount)).map(function (i) {
|
||||||
return {
|
let node = root.getChild(i);
|
||||||
url: node.uri,
|
return {
|
||||||
title: node.title,
|
url: node.uri,
|
||||||
icon: node.icon ? node.icon : DEFAULT_FAVICON
|
title: node.title,
|
||||||
};
|
icon: node.icon ? node.icon : DEFAULT_FAVICON
|
||||||
}).toArray();
|
};
|
||||||
root.containerOpen = false;
|
}).toArray();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
root.containerOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
|
|||||||
|
|
||||||
__iterator__: function () (val for ([, val] in Iterator(bookmarkcache.bookmarks))),
|
__iterator__: function () (val for ([, val] in Iterator(bookmarkcache.bookmarks))),
|
||||||
|
|
||||||
get bookmarks() Class.replaceProperty(this, "bookmarks", this.load()),
|
bookmarks: Class.Memoize(function () this.load()),
|
||||||
|
|
||||||
keywords: Class.Memoize(function () array.toObject([[b.keyword, b] for (b in this) if (b.keyword)])),
|
keywords: Class.Memoize(function () array.toObject([[b.keyword, b] for (b in this) if (b.keyword)])),
|
||||||
|
|
||||||
@@ -88,9 +88,13 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
|
|||||||
_loadBookmark: function loadBookmark(node) {
|
_loadBookmark: function loadBookmark(node) {
|
||||||
if (node.uri == null) // How does this happen?
|
if (node.uri == null) // How does this happen?
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
let uri = newURI(node.uri);
|
let uri = newURI(node.uri);
|
||||||
let keyword = services.bookmarks.getKeywordForBookmark(node.itemId);
|
let keyword = services.bookmarks.getKeywordForBookmark(node.itemId);
|
||||||
let tags = services.tagging.getTagsForURI(uri, {}) || [];
|
|
||||||
|
let tags = tags in node ? (node.tags ? node.tags.split(/, /g) : [])
|
||||||
|
: services.tagging.getTagsForURI(uri, {}) || [];
|
||||||
|
|
||||||
let post = BookmarkCache.getAnnotation(node.itemId, this.POST);
|
let post = BookmarkCache.getAnnotation(node.itemId, this.POST);
|
||||||
let charset = BookmarkCache.getAnnotation(node.itemId, this.CHARSET);
|
let charset = BookmarkCache.getAnnotation(node.itemId, this.CHARSET);
|
||||||
return Bookmark(node.uri, node.title, node.icon && node.icon.spec, post, keyword, tags, charset, node.itemId);
|
return Bookmark(node.uri, node.title, node.icon && node.icon.spec, post, keyword, tags, charset, node.itemId);
|
||||||
@@ -163,27 +167,23 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
|
|||||||
load: function load() {
|
load: function load() {
|
||||||
let bookmarks = {};
|
let bookmarks = {};
|
||||||
|
|
||||||
let folders = this.rootFolders.slice();
|
|
||||||
let query = services.history.getNewQuery();
|
let query = services.history.getNewQuery();
|
||||||
let options = services.history.getNewQueryOptions();
|
let options = services.history.getNewQueryOptions();
|
||||||
while (folders.length > 0) {
|
options.queryType = options.QUERY_TYPE_BOOKMARKS;
|
||||||
query.setFolders(folders, 1);
|
options.excludeItemIfParentHasAnnotation = "livemark/feedURI";
|
||||||
folders.shift();
|
|
||||||
let result = services.history.executeQuery(query, options);
|
|
||||||
let folder = result.root;
|
|
||||||
folder.containerOpen = true;
|
|
||||||
|
|
||||||
|
let { root } = services.history.executeQuery(query, options);
|
||||||
|
root.containerOpen = true;
|
||||||
|
try {
|
||||||
// iterate over the immediate children of this folder
|
// iterate over the immediate children of this folder
|
||||||
for (let i = 0; i < folder.childCount; i++) {
|
for (let i = 0; i < root.childCount; i++) {
|
||||||
let node = folder.getChild(i);
|
let node = root.getChild(i);
|
||||||
if (node.type == node.RESULT_TYPE_FOLDER) // folder
|
if (node.type == node.RESULT_TYPE_URI) // bookmark
|
||||||
folders.push(node.itemId);
|
|
||||||
else if (node.type == node.RESULT_TYPE_URI) // bookmark
|
|
||||||
bookmarks[node.itemId] = this._loadBookmark(node);
|
bookmarks[node.itemId] = this._loadBookmark(node);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// close a container after using it!
|
finally {
|
||||||
folder.containerOpen = false;
|
root.containerOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bookmarks;
|
return bookmarks;
|
||||||
|
|||||||
Reference in New Issue
Block a user