1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 16:52:25 +01:00

fixed :qmarks/:hs/:bmarks display, add a new template.genericTable() method

This commit is contained in:
Martin Stubenschrott
2008-11-21 12:44:54 +00:00
parent 52038db7ae
commit 5c8b17cc58
5 changed files with 60 additions and 63 deletions

View File

@@ -77,7 +77,14 @@ function Bookmarks() //{{{
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
let tags = taggingService.getTagsForURI(uri, {}) || [];
//return bookmarks.push(new Bookmark(node.uri, node.title, null, keyword, tags, node.itemId));
return bookmarks.push({ url: node.uri, title: node.title, get icon() getFavicon(node.uri), keyword: keyword, tags: tags, id: node.itemId});
return bookmarks.push({ url: node.uri,
title: node.title,
get icon() getFavicon(node.uri), // TODO; must be a direct way to get the icon
keyword: keyword,
tags: tags,
id: node.itemId,
get xml() template.bookmarkItem(this)});
}
function readBookmark(id)
@@ -537,7 +544,7 @@ function Bookmarks() //{{{
if (openItems)
return liberator.open([i.url for each (i in items)], liberator.NEW_TAB);
let list = template.bookmarks("title", items);
let list = template.genericTable(["", "title", "URL"], items);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}
};
@@ -718,7 +725,10 @@ function History() //{{{
{
let node = root.getChild(i);
if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark
items.push({ url: node.uri, title: node.title, icon: node.icon ? node.icon.spec : DEFAULT_FAVICON });
items.push({ url: node.uri,
title: node.title,
icon: node.icon ? node.icon.spec : DEFAULT_FAVICON,
get xml() template.bookmarkItem(this)});
}
root.containerOpen = false; // close a container after using it!
@@ -770,7 +780,7 @@ function History() //{{{
if (openItems)
return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB);
let list = template.bookmarks("title", items);
let list = template.genericTable(["", "title", "URL"], items);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}
};
@@ -944,9 +954,12 @@ function QuickMarks() //{{{
}
}
let items = ({ title: String(mark), url: qmarks.get(mark) } for each (mark in marks));
// TODO: template.bookmarks is not the best for quickmarks
let list = template.bookmarks("QuickMark", items);
let items = ({ title: String(mark),
url: qmarks.get(mark),
get xml() <tr><td>&#xa0;&#xa0;{this.title}</td><td>{this.url}</td></tr>
} for each (mark in marks));
let list = template.genericTable(["QuickMark", "URL"], items);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}
};

View File

@@ -809,34 +809,6 @@ function Completion() //{{{
bookmark: function (filter)
{
// TODO: move to template.js?
function createHtml(item)
{
var extra = [];
if (item.keyword)
extra.push(['keyword', item.keyword, "hl-Keyword"]);
if (item.tags.length > 0)
extra.push(["tags", item.tags.join(","), "hl-Tag"]); // no space, otherwise it looks strange, since we just have spaces to seperate tags from keywords
return <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>&#160;
{
!(extra.length) ? "" :
<span class="extra-info">
({
template.map(extra, function (e)
<>{e[0]}: <span class={e[2]}>{e[1]}</span></>,
<>&#xa0;</>/* Non-breaking space */)
})
</span>
}
</li>
</ul>
}
return {
start: 0,
get items() {
@@ -846,28 +818,9 @@ function Completion() //{{{
bmark[1] = bmark.title;
bmark.text = bmark.url;
bmark.__defineGetter__("html", function () createHtml(bmark));
return bmark;
});
},
createRow: function (item)
<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>&#160;
{
!(item.extra && item.extra.length) ? "" :
<span class="extra-info">
({
template.map(item.extra, function (e)
<>{e[0]}: <span class={e[2]}>{e[1]}</span></>,
<>&#xa0;</>/* Non-breaking space */)
})
</span>
}
</li>
</ul>
};
},

View File

@@ -616,8 +616,8 @@ function Mail() //{{{
"Toggle HTML message display",
function ()
{
var want_html = (gPrefBranch.getIntPref("mailnews.display.html_as", 1) == 1);
mail.setHTML(want_html ? 1 : 0);
let wantHtml = (gPrefBranch.getIntPref("mailnews.display.html_as", 1) == 1);
mail.setHTML(wantHtml ? 1 : 0);
});
// YANKING TEXT

View File

@@ -138,20 +138,51 @@ const template = {
return <>:{commandline.getCommand()}<br/></> + xml;
},
bookmarks: function (header, items)
// every item must have a .xml property which defines how to draw itself
// @param headers is an array of strings, the text for the header columns
genericTable: function (headers, items)
{
let createRow = completion.bookmark("").createRow;
return this.generic(
<table>
<tr align="left" class="hl-Title">
<th/><th>{header}</th><th>URL</th>
{
headers.reduce(function (prev, cur) prev + <th>{cur}</th>, <></>)
}
</tr>
{
this.map(items, function (item) createRow(item))
this.map(items, function (item) item.xml)
}
</table>);
},
// returns a single row for a bookmark or history item
bookmarkItem: function (item)
{
var extra = [];
if (item.keyword)
extra.push(['keyword', item.keyword, "hl-Keyword"]);
if (item.tags && item.tags.length > 0)
extra.push(["tags", item.tags.join(","), "hl-Tag"]); // no space, otherwise it looks strange, since we just have spaces to seperate tags from keywords
return <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>&#160;
{
!(extra.length) ? "" :
<span class="extra-info">
({
template.map(extra, function (e)
<>{e[0]}: <span class={e[2]}>{e[1]}</span></>,
<>&#xa0;</>/* Non-breaking space */)
})
</span>
}
</li>
</ul>
},
jumps: function (index, elems)
{
return this.generic(

View File

@@ -1381,14 +1381,14 @@ function ItemList(id) //{{{
if (diff == 1) /* Scroll down */
{
let item = items[endIndex - 1];
let row = "html" in item ? util.xmlToDom(item.html, doc) : createDefaultRow(item, true);
let row = "xml" in item ? util.xmlToDom(item.html, doc) : createDefaultRow(item, true);
tbody.removeChild(tbody.firstChild);
tbody.appendChild(row);
}
else /* Scroll up */
{
let item = items[offset];
let row = "html" in item ? util.xmlToDom(item.html, doc) : createDefaultRow(item, true);
let row = "xml" in item ? util.xmlToDom(item.html, doc) : createDefaultRow(item, true);
tbody.removeChild(tbody.lastChild);
tbody.insertBefore(row, tbody.firstChild);
}
@@ -1402,7 +1402,7 @@ function ItemList(id) //{{{
<div class="hl-Completions">
{
template.map(util.range(offset, endIndex), function (i)
"html" in items[i] ? items[i].html : createDefaultRow(items[i]))
"xml" in items[i] ? items[i].html : createDefaultRow(items[i]))
}
</div>
<div class="hl-Completions">