mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 13:42:27 +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:
@@ -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);
|
||||
}
|
||||
};
|
||||
//}}}
|
||||
|
||||
@@ -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 = <table/>
|
||||
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.* +=
|
||||
<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)
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = <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);
|
||||
let list = template.generic(completion.buffer(filter)[2]);
|
||||
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||
},
|
||||
|
||||
|
||||
@@ -143,13 +143,14 @@ const template = {
|
||||
return this.generic(
|
||||
<table>
|
||||
<tr align="left" class="hl-Title">
|
||||
<th>{header}</th><th>URL</th>
|
||||
<th/><th>{header}</th><th>URL</th>
|
||||
</tr>
|
||||
{
|
||||
this.map(items, function (item)
|
||||
<tr>
|
||||
<td>{util.clip(item.title, 50)}</td>
|
||||
<td style="width: 100%">
|
||||
<ul class="hl-CompItem">
|
||||
<li class="hl-CompIcon"><img src={item.icon || ""}/></li>
|
||||
<li class="hl-CompResult">{util.clip(item.title || "", 50)}</li>
|
||||
<li style="width: 100%">
|
||||
<a href="#" class="hl-URL">{item.url}</a> 
|
||||
{
|
||||
!(item.extra && item.extra.length) ? "" :
|
||||
@@ -161,8 +162,8 @@ const template = {
|
||||
})
|
||||
</span>
|
||||
}
|
||||
</td>
|
||||
</tr>)
|
||||
</li>
|
||||
</ul>)
|
||||
}
|
||||
</table>);
|
||||
},
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user