1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 11:27:58 +01:00

Favicon support in :bmarks/:history and :ls and fixed very slow vimperator loading with a large history by NOT loading all favicons at startup.

Also fixed :restart by accident showhow.
This commit is contained in:
Martin Stubenschrott
2008-11-02 04:49:37 +00:00
parent b334f2538d
commit 70ea0eb34e
6 changed files with 70 additions and 60 deletions

View File

@@ -68,7 +68,7 @@ function Bookmarks() //{{{
let uri = ioService.newURI(node.uri, null, null); let uri = ioService.newURI(node.uri, null, null);
let keyword = bookmarksService.getKeywordForBookmark(node.itemId); let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
let tags = taggingService.getTagsForURI(uri, {}) || []; 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)); return bookmarks.push(new Bookmark(node.uri, node.title, icon, keyword, tags, node.itemId));
} }
@@ -183,6 +183,18 @@ function Bookmarks() //{{{
bookmarksService.addObserver(observer, false); 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) let bookmarkObserver = function (key, event, arg)
{ {
if (event == "add") if (event == "add")
@@ -319,8 +331,8 @@ function Bookmarks() //{{{
{ {
if (bypassCache) // Is this really necessary anymore? if (bypassCache) // Is this really necessary anymore?
cache.load(); 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 // if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder
@@ -425,6 +437,8 @@ function Bookmarks() //{{{
return count.value; return count.value;
}, },
getFavicon: function (url) { return getFavicon(url); },
// TODO: add filtering // TODO: add filtering
// also ensures that each search engine has a Vimperator-friendly alias // also ensures that each search engine has a Vimperator-friendly alias
getSearchEngines: function () getSearchEngines: function ()
@@ -515,10 +529,11 @@ function Bookmarks() //{{{
{ {
url: item.url, url: item.url,
title: item.title, title: item.title,
icon: getFavicon(item.url),
extra: [['keyword', item.keyword, "hl-Keyword"], extra: [['keyword', item.keyword, "hl-Keyword"],
['tags', item.tags.join(', '), "hl-Tag"] ['tags', item.tags.join(', '), "hl-Tag"]
].filter(function (i) i[1]) ].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); 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"] const historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService); .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 placesHistory;
var cachedHistory = []; // add pages here after loading the initial Places history var cachedHistory = []; // add pages here after loading the initial Places history
@@ -564,7 +571,7 @@ function History() //{{{
var node = rootNode.getChild(i); var node = rootNode.getChild(i);
// liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type); // liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type);
if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark 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! // close a container after using it!
@@ -747,10 +754,11 @@ function History() //{{{
} }
else else
cachedHistory = cachedHistory.filter(filter); cachedHistory = cachedHistory.filter(filter);
if (placesHistory.some(function (h) h[0] == url)) if (placesHistory.some(function (h) h[0] == url))
placesHistory = placesHistory.filter(filter); placesHistory = placesHistory.filter(filter);
cachedHistory.unshift([url, title || "[No title]", getIcon(url)]); cachedHistory.unshift([url, title || "[No title]"]);
return true; return true;
}, },
@@ -812,18 +820,16 @@ function History() //{{{
} }
if (openItems) if (openItems)
{
return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB); return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB);
}
else // TODO: is there a faster way to limit to max. 1000 items?
{ let list = template.bookmarks("title", (
let list = template.bookmarks("title", ( {
{ url: item[0],
title: item[1], title: item[1],
url: item[0] icon: bookmarks.getFavicon(item[0]),
} for each (item in items))); } for each ([i, item] in Iterator(items)) if (i < 1000)));
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}
} }
}; };
//}}} //}}}

View File

@@ -529,6 +529,8 @@ function Completion() //{{{
}; };
let javascript = new Javascript(); 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) function filterFavicon(array, want)
{ {
return want ? array : [a[2] ? a.slice(0, 2) : a for ([i, a] in Iterator(array))]; 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) buffer: function buffer(filter)
{ {
let items = [];
// FIXME: liberator.has("tabs") // FIXME: liberator.has("tabs")
let items = [];
let xml = <table/>
filter = filter || "";
for (let [i, browser] in tabs.browsers) 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; i = i + 1;
let title = ""; let title = "";
try try
@@ -802,14 +813,28 @@ function Completion() //{{{
{ {
if (title == "") if (title == "")
title = "(Untitled)"; title = "(Untitled)";
items.push([[i + ": " + title, i + ": " + url], url]); items.push([[i + ": " + title, i + ": " + url], url]);
let icon = "";
if (liberator.has("bookmarks"))
icon = bookmarks.getFavicon(url);
xml.* +=
<ul class="hl-CompItem">
<li align="right"> {i}</li>
<li><span class="hl-Indicator"> {indicator} </span></li>
<li class="hl-CompIcon">{icon ? <img src={icon}/> : <></>}</li>
<li class="hl-CompResult" style="width: 250px; max-width: 500px; overflow: hidden">{title}</li>
<li class="hl-CompDesc"><a href="#" class="hl-URL buffer-list">{url}</a></li>
</ul>;
} }
} }
if (!filter) 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) colorScheme: function colorScheme(filter)

View File

@@ -30,7 +30,7 @@ function Highlights(name, store, serial)
CompItem CompItem
CompItem[selected] background: yellow; CompItem[selected] background: yellow;
CompItem>* padding: 0 .5ex; CompItem>* padding: 0 .5ex;
CompIcon width: 16px; CompIcon width: 16px; min-width: 16px;
CompIcon>img max-width: 16px; max-height: 16px; vertical-align: middle; CompIcon>img max-width: 16px; max-height: 16px; vertical-align: middle;
CompResult width: 45%; overflow: hidden; CompResult width: 45%; overflow: hidden;
CompDesc color: gray; CompDesc color: gray;

View File

@@ -735,32 +735,9 @@ function Tabs() //{{{
return getBrowser().mTabContainer.selectedItem; return getBrowser().mTabContainer.selectedItem;
}, },
// TODO: shouldn't that have a filter argument? list: function (filter)
list: function ()
{ {
// TODO: move this to tabs.get() let list = template.generic(completion.buffer(filter)[2]);
let items = <table/>
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.* +=
<tr>
<td align="right"> {number}</td>
<td><span class="hl-Indicator"> {indicator} </span></td>
<td style="width: 250px; max-width: 500px; overflow: hidden">{title}</td>
<td><a href="#" class="hl-URL buffer-list">{item[1]}</a></td>
</tr>;
}
let list = template.generic(items);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}, },

View File

@@ -143,13 +143,14 @@ const template = {
return this.generic( return this.generic(
<table> <table>
<tr align="left" class="hl-Title"> <tr align="left" class="hl-Title">
<th>{header}</th><th>URL</th> <th/><th>{header}</th><th>URL</th>
</tr> </tr>
{ {
this.map(items, function (item) this.map(items, function (item)
<tr> <ul class="hl-CompItem">
<td>{util.clip(item.title, 50)}</td> <li class="hl-CompIcon"><img src={item.icon || ""}/></li>
<td style="width: 100%"> <li class="hl-CompResult">{util.clip(item.title || "", 50)}</li>
<li style="width: 100%">
<a href="#" class="hl-URL">{item.url}</a>&#160; <a href="#" class="hl-URL">{item.url}</a>&#160;
{ {
!(item.extra && item.extra.length) ? "" : !(item.extra && item.extra.length) ? "" :
@@ -161,8 +162,8 @@ const template = {
}) })
</span> </span>
} }
</td> </li>
</tr>) </ul>)
} }
</table>); </table>);
}, },

View File

@@ -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. the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/ }}} ***** END LICENSE BLOCK *****/
const util = { //{{{ const util = { //{{{
Array: { Array: {