diff --git a/content/bookmarks.js b/content/bookmarks.js index 5a0481a8..8e564211 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -68,7 +68,7 @@ function Bookmarks() //{{{ let uri = ioService.newURI(node.uri, null, null); let keyword = bookmarksService.getKeywordForBookmark(node.itemId); let tags = taggingService.getTagsForURI(uri, {}) || []; - let icon = faviconService.getFaviconImageForPage(uri).spec; + let icon = faviconService.getFaviconImageForPage(uri).spec; // for performance reasons, use this rather than getFavicon return bookmarks.push(new Bookmark(node.uri, node.title, icon, keyword, tags, node.itemId)); } @@ -183,6 +183,18 @@ function Bookmarks() //{{{ bookmarksService.addObserver(observer, false); } + function getFavicon(uri) + { + try + { + return faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec; + } + catch (e) + { + return ""; + } + } + let bookmarkObserver = function (key, event, arg) { if (event == "add") @@ -319,8 +331,8 @@ function Bookmarks() //{{{ { if (bypassCache) // Is this really necessary anymore? cache.load(); - return completion.cached("bookmarks", filter, function () cache.bookmarks, - "filterURLArray", tags); + + return completion.cached("bookmarks", filter, function () cache.bookmarks, "filterURLArray", tags); }, // if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder @@ -425,6 +437,8 @@ function Bookmarks() //{{{ return count.value; }, + getFavicon: function (url) { return getFavicon(url); }, + // TODO: add filtering // also ensures that each search engine has a Vimperator-friendly alias getSearchEngines: function () @@ -515,10 +529,11 @@ function Bookmarks() //{{{ { url: item.url, title: item.title, + icon: getFavicon(item.url), extra: [['keyword', item.keyword, "hl-Keyword"], ['tags', item.tags.join(', '), "hl-Tag"] ].filter(function (i) i[1]) - } for each (item in items))); + } for each ([i, item] in Iterator(items)) if (i < 1000))); commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } }; @@ -533,14 +548,6 @@ function History() //{{{ const historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"] .getService(Components.interfaces.nsINavHistoryService); - const ioService = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - const faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"] - .getService(Components.interfaces.nsIFaviconService); - function getIcon(uri) - { - return faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec; - } var placesHistory; var cachedHistory = []; // add pages here after loading the initial Places history @@ -564,7 +571,7 @@ function History() //{{{ var node = rootNode.getChild(i); // liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type); if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark - placesHistory.push([node.uri, node.title || "[No title]", getIcon(node.uri)]); + placesHistory.push([node.uri, node.title || "[No title]"]); } // close a container after using it! @@ -747,10 +754,11 @@ function History() //{{{ } else cachedHistory = cachedHistory.filter(filter); + if (placesHistory.some(function (h) h[0] == url)) placesHistory = placesHistory.filter(filter); - cachedHistory.unshift([url, title || "[No title]", getIcon(url)]); + cachedHistory.unshift([url, title || "[No title]"]); return true; }, @@ -812,18 +820,16 @@ function History() //{{{ } if (openItems) - { return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB); - } - else - { - let list = template.bookmarks("title", ( - { - title: item[1], - url: item[0] - } for each (item in items))); - commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); - } + + // TODO: is there a faster way to limit to max. 1000 items? + let list = template.bookmarks("title", ( + { + url: item[0], + title: item[1], + icon: bookmarks.getFavicon(item[0]), + } for each ([i, item] in Iterator(items)) if (i < 1000))); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } }; //}}} diff --git a/content/completion.js b/content/completion.js index 52be594b..ceea59a5 100644 --- a/content/completion.js +++ b/content/completion.js @@ -529,6 +529,8 @@ function Completion() //{{{ }; let javascript = new Javascript(); + // FIXME: unused, remove? If not, document, what it does. + // Those one liners might be convinient to write, but not to read --mst function filterFavicon(array, want) { return want ? array : [a[2] ? a.slice(0, 2) : a for ([i, a] in Iterator(array))]; @@ -782,11 +784,20 @@ function Completion() //{{{ buffer: function buffer(filter) { - let items = []; // FIXME: liberator.has("tabs") + let items = []; + let xml = + filter = filter || ""; for (let [i, browser] in tabs.browsers) { + if (i == tabs.index()) + indicator = "%" + else if (i == tabs.index(tabs.alternate)) + indicator = "#"; + else + indicator = " "; + i = i + 1; let title = ""; try @@ -802,14 +813,28 @@ function Completion() //{{{ { if (title == "") title = "(Untitled)"; + items.push([[i + ": " + title, i + ": " + url], url]); + + let icon = ""; + if (liberator.has("bookmarks")) + icon = bookmarks.getFavicon(url); + + xml.* += + ; } } if (!filter) - return [0, items.map(function ([a, b]) [a[0], b])]; + return [0, items.map(function ([a, b]) [a[0], b]), xml]; - return [0, buildLongestCommonSubstring(items, filter)]; + return [0, buildLongestCommonSubstring(items, filter), xml]; }, colorScheme: function colorScheme(filter) diff --git a/content/style.js b/content/style.js index 287b8ab6..39be9a40 100644 --- a/content/style.js +++ b/content/style.js @@ -30,7 +30,7 @@ function Highlights(name, store, serial) CompItem CompItem[selected] background: yellow; CompItem>* padding: 0 .5ex; - CompIcon width: 16px; + CompIcon width: 16px; min-width: 16px; CompIcon>img max-width: 16px; max-height: 16px; vertical-align: middle; CompResult width: 45%; overflow: hidden; CompDesc color: gray; diff --git a/content/tabs.js b/content/tabs.js index 793d76a7..2c4e5d62 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -735,32 +735,9 @@ function Tabs() //{{{ return getBrowser().mTabContainer.selectedItem; }, - // TODO: shouldn't that have a filter argument? - list: function () + list: function (filter) { - // TODO: move this to tabs.get() - - let items =
- for (let [i, item] in Iterator(completion.buffer("")[1])) - { - if (i == tabs.index()) - indicator = "%" - else if (i == tabs.index(tabs.alternate)) - indicator = "#"; - else - indicator = " "; - - let [number, title] = item[0].split(/:\s+/, 2); - items.* += - - - - - - ; - } - - let list = template.generic(items); + let list = template.generic(completion.buffer(filter)[2]); commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, diff --git a/content/template.js b/content/template.js index f1ce0707..7c28b663 100644 --- a/content/template.js +++ b/content/template.js @@ -143,13 +143,14 @@ const template = { return this.generic(
{number} {indicator} {title}{item[1]}
- + { this.map(items, function (item) - - - - ) + + ) }
{header}URL{header}URL
{util.clip(item.title, 50)} +
    +
  • +
  • {util.clip(item.title || "", 50)}
  • +
  • {item.url}  { !(item.extra && item.extra.length) ? "" : @@ -161,8 +162,8 @@ const template = { }) } -
); }, diff --git a/content/util.js b/content/util.js index fafb83e6..e040c42c 100644 --- a/content/util.js +++ b/content/util.js @@ -26,6 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ + const util = { //{{{ Array: {