1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-01 17:42:25 +01:00

Added :sty chrome to style the main window, moved a bunch of inline styles to CSS, fixed some completion bugs, removed util.blankDocument

This commit is contained in:
Kris Maglione
2008-10-05 23:38:31 +00:00
parent 2be0219384
commit 0a8252fb2a
10 changed files with 143 additions and 99 deletions

View File

@@ -4,3 +4,4 @@ resource vimperator modules/
locale vimperator en-US locale/en-US/
skin vimperator classic/1.0 skin/
overlay chrome://browser/content/browser.xul chrome://vimperator/content/vimperator.xul

View File

@@ -504,8 +504,8 @@ liberator.Bookmarks = function () //{{{
{
url: item[0],
title: item[1],
extra: [['keyword', item[2], 'red'],
['tags', (item[3]||[]).join(', '), 'blue']].filter(function (i) i[1])
extra: [['keyword', item[2], "hl-Keyword"],
['tags', (item[3]||[]).join(', '), "hl-Tag"]].filter(function (i) i[1])
} for each (item in items)));
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
},

View File

@@ -46,6 +46,7 @@ liberator.Buffer = function () //{{{
const consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
const sleep = liberator.sleep;
const storage = liberator.storage;
function Styles(name, store, serial)
{
const XHTML = "http://www.w3.org/1999/xhtml";
@@ -56,11 +57,22 @@ liberator.Buffer = function () //{{{
let cssUri = function (css) "data:text/css," + encodeURI(css);
let sheets = [];
this.__iterator__ = function () Iterator(sheets);
let userSheets = [];
let systemSheets = [];
this.addSheet = function (filter, css)
this.__iterator__ = function () Iterator(userSheets);
this.__defineGetter__("systemSheets", function () Iterator(systemSheets));
this.__defineGetter__("chromeCSS", function ()
{
let css = [v[1] for ([k, v] in this) if (v[0].indexOf("chrome") >= 0)];
return cssUri(css.join("\n/**/\n"));
});
this.addSheet = function (filter, css, system)
{
let sheets = system ? systemSheets : userSheets;
let errors = checkSyntax(css);
if (errors.length)
return errors.map(function (e) "CSS: " + filter + ": " + e).join("\n");
@@ -70,11 +82,16 @@ liberator.Buffer = function () //{{{
filter = filter.split(",");
sheets.push([filter, css]);
this.registerSheet(cssUri(wrapCSS(filter, css)));
if (filter.indexOf("chrome") > -1)
storage.fireEvent(name, "chrome-added")
return null;
}
this.removeSheet = function (filter, index)
this.removeSheet = function (filter, index, system)
{
let sheets = system ? systemSheets : userSheets;
if (filter == undefined)
filter = "";
/* Find all sheets which match the filter */
@@ -87,15 +104,25 @@ liberator.Buffer = function () //{{{
else if (index)
matches = [m for each (m in matches) if (m[1][1] == index)];
let foundChrome = false;
for (let [,[i, sheet]] in Iterator(matches.reverse()))
{
let sites = sheet[0];
this.unregisterSheet(cssUri(wrapCSS(sheet[0], sheet[1])));
sheet[0] = sheet[0].filter(function (f) f != filter);
sheet[0] = sites.filter(function (f) f != filter);
if (sheet[0].length && isNaN(filter))
this.registerSheet(cssUri(wrapCSS(sheet[0], sheet[1])));
else
sheets.splice(i, 1);
/* Crazy, I know. If we had chrome before, and either we don't have it now, or we've removed
* the whole entry, we've found chrome.
* Perhaps we out to just refresh the chrome stylesheet any time anything is removed.
*/
if (!foundChrome && sites.indexOf("chrome") > -1 && (sheet[0].indexOf("chrome") == -1 || !isNaN(filter)))
foundChrome = true;
}
if (foundChrome)
storage.fireEvent(name, "chrome-removed");
return true;
}
@@ -184,6 +211,15 @@ liberator.Buffer = function () //{{{
let styles = liberator.storage.newObject("styles", Styles, false);
let stylesheet = document.createProcessingInstruction("xml-stylesheet", "");
document.insertBefore(stylesheet, document.firstChild);
let chromeObserver = function () { stylesheet.data = 'type="text/css" href="' + styles.chromeCSS + '"' };
storage.addObserver("styles", chromeObserver);
liberator.registerObserver("shutdown", function () {
liberator.storage.removeObserver("styles", chromeObserver)
});
/* FIXME: This doesn't belong here. */
let mainWindowID = liberator.config.mainWindowID || "main-window";
let fontSize = document.defaultView.getComputedStyle(document.getElementById(mainWindowID), null)
@@ -192,7 +228,7 @@ liberator.Buffer = function () //{{{
let name = liberator.config.name.toLowerCase();
styles.registerSheet("chrome://" + name + "/skin/vimperator.css");
let error = styles.addSheet("chrome://" + name + "/content/buffer.xhtml",
"body { font-size: " + fontSize + "}");
"body { font-size: " + fontSize + "}", true);
function setZoom(value, fullZoom)
{
@@ -862,7 +898,7 @@ liberator.Buffer = function () //{{{
nFeed++;
var type = feedTypes[feed.type] || feedTypes["application/rss+xml"];
if (verbose)
yield [feed.title, liberator.util.highlightURL(feed.href, true) + <span style="color: gray;"> ({type})</span>];
yield [feed.title, liberator.util.highlightURL(feed.href, true) + <span class="extra-info"> ({type})</span>];
}
}
}
@@ -1947,10 +1983,10 @@ liberator.template = {
<a href="#" class="hl-URL">{item.url}</a>&#160;
{
!(item.extra && item.extra.length) ? "" :
<span style="color: gray;">
<span class="extra-info">
({
liberator.template.map(item.extra, function (e)
<>{e[0]}: <span style={"color: " + e[2]}>{e[1]}</span></>,
<>{e[0]}: <span class={e[2]}>{e[1]}</span></>,
<![CDATA[ ]]>/* Non-breaking space */)
})
</span>
@@ -1971,7 +2007,7 @@ liberator.template = {
{
this.map2(elems, function (idx, val)
<tr>
<td style="color: blue;">{idx == index ? ">" : ""}</td>
<td class="indicator">{idx == index ? ">" : ""}</td>
<td>{Math.abs(idx - index)}</td>
<td style="width: 250px; max-width: 500px; overflow: hidden;">{val.title}</td>
<td><a href="#" class="hl-URL jump-list">{val.URI.spec}</a></td>
@@ -1992,7 +2028,7 @@ liberator.template = {
<tr>
<td>
<span style={opt.isDefault ? "" : "font-weight: bold"}>{opt.pre}{opt.name}{opt.value}</span>
{opt.isDefault || opt.default == null ? "" : <span style="color: gray"> (default: {opt.default})</span>}
{opt.isDefault || opt.default == null ? "" : <span class="extra-info"> (default: {opt.default})</span>}
</td>
</tr>)
}

View File

@@ -454,9 +454,9 @@ const liberator = (function () //{{{
<tr class="hl-Title" align="left">
<th colspan="3">Code execution summary</th>
</tr>
<tr><td>  Executed:</td><td align="right"><span style="color: green">{count}</span></td><td>times</td></tr>
<tr><td>  Average time:</td><td align="right"><span style="color: green">{each.toFixed(2)}</span></td><td>{eachUnits}</td></tr>
<tr><td>  Total time:</td><td align="right"><span style="color: red">{total.toFixed(2)}</span></td><td>{totalUnits}</td></tr>
<tr><td>  Executed:</td><td align="right"><span class="times-executed">{count}</span></td><td>times</td></tr>
<tr><td>  Average time:</td><td align="right"><span class="time-average">{each.toFixed(2)}</span></td><td>{eachUnits}</td></tr>
<tr><td>  Total time:</td><td align="right"><span class="time-total">{total.toFixed(2)}</span></td><td>{totalUnits}</td></tr>
</table>);
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}
@@ -685,6 +685,18 @@ const liberator = (function () //{{{
dump(liberator.config.name.toLowerCase() + ": " + message);
},
dumpStack: function (msg)
{
try
{
someStatisticallyImprobableVariableName.foo = 1;
}
catch (e)
{
liberator.dump((msg || "") + e.stack);
}
},
// with (liberator) means, liberator is the default namespace "inside" eval
eval: function (str)
{

View File

@@ -80,12 +80,14 @@ the terms of any one of the MPL, the GPL or the LGPL.
oncommandupdate="if (typeof liberator.events != 'undefined') liberator.events.onSelectionChange(event);"/>
<vbox class="liberator-container" hidden="false" collapsed="true">
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="false"
<iframe id="liberator-multiline-output" src="chrome://muttator/content/buffer.xhtml"
flex="1" height="10px" hidden="false" collapsed="false"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/>
</vbox>
<vbox class="liberator-container" hidden="false" collapsed="true">
<iframe id="liberator-completions" src="about:blank" flex="1" height="250px" hidden="false" collapsed="false"
<iframe id="liberator-completions" src="chrome://muttator/content/buffer.xhtml"
flex="1" height="250px" hidden="false" collapsed="false"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/>
</vbox>

View File

@@ -89,12 +89,14 @@ the terms of any one of the MPL, the GPL or the LGPL.
</statusbar>
<vbox class="liberator-container" hidden="false" collapsed="true">
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="false"
<iframe id="liberator-multiline-output" "chrome://muttator/content/buffer.xhtml"
flex="1" height="10px" hidden="false" collapsed="false"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/>
</vbox>
<vbox class="liberator-container" hidden="false" collapsed="true">
<iframe id="liberator-completions" src="about:blank" flex="1" height="250px" hidden="false" collapsed="false"
<iframe id="liberator-completions" src="chrome://muttator/content/buffer.xhtml"
flex="1" height="250px" hidden="false" collapsed="false"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/>
</vbox>

View File

@@ -724,7 +724,7 @@ liberator.Tabs = function () //{{{
items.* +=
<tr>
<td align="right"> {number}</td>
<td><span style="color: blue"> {indicator} </span></td>
<td><span class="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>;

View File

@@ -105,7 +105,7 @@ liberator.CommandLine = function () //{{{
var wildIndex = 0; // keep track how often we press <Tab> in a row
var startHints = false; // whether we're waiting to start hints mode
var statusTimer = new liberator.util.Timer(50, 100, function ()
var statusTimer = new liberator.util.Timer(51, 100, function ()
liberator.statusline.updateProgress("match " + (completionIndex + 1) + " of " + completions.length));
var autocompleteTimer = new liberator.util.Timer(50, 100, function (command) {
let res = liberator.completion.ex(command);
@@ -121,7 +121,7 @@ liberator.CommandLine = function () //{{{
// the widget used for multiline output
var multilineOutputWidget = document.getElementById("liberator-multiline-output");
liberator.util.blankDocument(multilineOutputWidget, "liberator-multiline-output-content");
multilineOutputWidget.contentDocument.body.id = "liberator-multiline-output-content";
var outputContainer = multilineOutputWidget.parentNode;
@@ -1193,15 +1193,17 @@ liberator.ItemList = function (id) //{{{
return;
}
var doc;
var doc = iframe.contentDocument;
var container = iframe.parentNode;
liberator.util.blankDocument(iframe, id + "-content");
doc.body.id = id + "-content";
var completions = []; // a reference to the Array of completions
var listOffset = -1; // how many items is the displayed list shifted from the internal tab index
var listIndex = -1; // listOffset + listIndex = completions[item]
var selectedElement = null;
var startIndex = -1; // The index of the first displayed item
var endIndex = -1; // The index one *after* the last displayed item
var selIndex = -1; // The index of the currently selected element
var completionBody = null;
var completionElements = null;
var minHeight = 0;
// TODO: temporary, to be changed/removed
@@ -1231,9 +1233,9 @@ liberator.ItemList = function (id) //{{{
if (completionElements.length == 0)
return Math.max(minHeight, doc.height);
var wanted = Math.min(maxItems + listOffset,
completionElements.length);
minHeight = Math.max(minHeight, completionElements[wanted - 1].getBoundingClientRect().bottom);
minHeight = Math.max(minHeight,
completionElements[completionElements.length - 1]
.getBoundingClientRect().bottom);
return minHeight;
}
@@ -1252,38 +1254,34 @@ liberator.ItemList = function (id) //{{{
*/
function fill(offset)
{
if (listOffset == offset || offset < 0 || offset >= completions.length && completions.length)
let diff = offset - startIndex;
if (diff == 0 || offset < 0 || completions.length && offset >= completions.length)
return;
if (listIndex > -1 && offset == listOffset + 1)
startIndex = offset;
endIndex = Math.min(startIndex + maxItems, completions.length);
if (selIndex > -1 && Math.abs(diff) == 1) /* Scroll one position */
{
let item = completions[offset + maxItems - 1];
listOffset = offset;
var row = createRow(item[0], item[1], item[2], true);
var e = doc.getElementsByTagName("tbody");
e = e[e.length - 1];
let tbody = completionBody;
e.removeChild(e.firstChild);
e.appendChild(row);
completionElements = e.children;
return;
if (diff == 1) /* Scroll down */
{
let item = completions[endIndex - 1];
let row = createRow(item[0], item[1], item[2], true);
tbody.removeChild(tbody.firstChild);
tbody.appendChild(row);
}
else if (listIndex > -1 && offset == listOffset - 1)
else /* Scroll up */
{
let item = completions[offset];
listOffset = offset;
var row = createRow(item[0], item[1], item[2], true);
var e = doc.getElementsByTagName("tbody");
e = e[e.length - 1];
e.removeChild(e.lastChild);
e.insertBefore(row, e.firstChild);
completionElements = e.children;
let row = createRow(item[0], item[1], item[2], true);
tbody.removeChild(tbody.lastChild);
tbody.insertBefore(row, tbody.firstChild);
}
return;
}
listOffset = offset;
// do a full refill of the list:
doc.body.innerHTML = "";
@@ -1292,18 +1290,20 @@ liberator.ItemList = function (id) //{{{
<span class="hl-Title" style="font-weight: bold">Completions:</span>
<table width="100%" style="table-layout: fixed; width: 100%"><tbody/></table>
</div>;
let tbody = div..tbody;
for (let i in liberator.util.range(offset, Math.min(offset + maxItems,
completions.length)))
let tbody = div..tbody;
for (let i in liberator.util.range(offset, endIndex))
{
let elem = completions[i];
tbody.* += createRow(elem[0], elem[1], elem[2]);
}
doc.body.appendChild(liberator.util.xmlToDom(div, doc));
let dom = liberator.util.xmlToDom(div, doc);
doc.body.appendChild(dom);
completionBody = dom.getElementsByTagName("tbody")[0];
completionElements = completionBody.childNodes;
completionElements = doc.getElementsByClassName("compitem");
autoSize();
}
@@ -1332,8 +1332,7 @@ liberator.ItemList = function (id) //{{{
// if @param selectedItem is given, show the list and select that item
setItems: function (items, selectedItem)
{
doc = iframe.contentDocument;
listOffset = listIndex = -1;
startIndex = endIndex = selIndex = -1;
completions = items || [];
if (typeof selectedItem == "number")
{
@@ -1350,37 +1349,31 @@ liberator.ItemList = function (id) //{{{
if (index == -1 || index == completions.length) // wrapped around
{
if (listIndex >= 0)
completionElements[listIndex - listOffset].style.backgroundColor = "";
if (selIndex >= 0)
completionElements[selIndex - startIndex].removeAttribute("selected");
else // list is shown the first time
fill(0);
listIndex = index;
selIndex = -1;
return;
}
// find start index
var newOffset = 0;
if (index >= listOffset + maxItems - CONTEXT_LINES)
newOffset = index - maxItems + CONTEXT_LINES + 1;
else if (index <= listOffset + CONTEXT_LINES)
let newOffset = startIndex;
if (index >= endIndex - CONTEXT_LINES)
newOffset = index + CONTEXT_LINES - maxItems + 1;
else if (index <= startIndex + CONTEXT_LINES)
newOffset = index - CONTEXT_LINES;
else
newOffset = listOffset;
if (newOffset + maxItems > completions.length)
newOffset = completions.length - maxItems;
if (newOffset < 0)
newOffset = 0;
newOffset = Math.min(newOffset, completions.length - maxItems);
newOffset = Math.max(newOffset, 0);
if (selIndex > -1)
completionElements[selIndex - startIndex].removeAttribute("selected");
fill(newOffset);
selIndex = index;
completionElements[index - startIndex].setAttribute("selected", "true");
if (selectedElement)
selectedElement.removeAttribute("selected");
selectedElement = completionElements[index - newOffset];
selectedElement.setAttribute("selected", "true");
listIndex = index;
return;
},

View File

@@ -45,16 +45,18 @@ liberator.util = { //{{{
{
if (arg !== undefined)
this.arg = arg;
let now = Date.now();
if (this.doneAt == -1)
timer.cancel();
else if (Date.now() >= this.doneAt)
else if (now >= this.doneAt || now >= this.latest)
return this.notify();
let timeout = minInterval;
if (this.latest)
timeout = Math.min(minInterval, this.latest - Date.now());
timeout = Math.min(minInterval, this.latest - now);
else
this.latest = Date.now() + maxInterval;
this.latest = now + maxInterval;
timer.initWithCallback(this, timeout, timer.TYPE_ONE_SHOT);
this.doneAt = -1;
}
@@ -77,12 +79,6 @@ liberator.util = { //{{{
yield ary[i];
},
blankDocument: function (iframe, bodyId)
{
iframe.addEventListener("load", function () { iframe.contentDocument.body.setAttribute("id", bodyId) }, true);
iframe.setAttribute("src", "chrome://" + liberator.config.name.toLowerCase() + "/content/buffer.xhtml");
},
clip: function (str, length)
{
return str.length <= length ? str : str.substr(0, length - 3) + "...";
@@ -100,22 +96,22 @@ liberator.util = { //{{{
{
if (type == "number")
{
return <span style="color: red;">{arg}</span>;
return <span class="hl-Number">{arg}</span>;
}
else if (type == "string")
{
if (processStrings)
arg = <>"{arg.replace(/\n/, "\\n")}"</>;
return <span style="color: green;">{arg}</span>;
return <span class="hl-String">{arg}</span>;
}
else if (type == "boolean")
{
return <span style="color: blue;">{arg}</span>;
return <span class="hl-Boolean">{arg}</span>;
}
else if (arg == null || arg == "undefined")
{
return <span style="color: blue;">{arg}</span>;
return <span class="hl-Null">{arg}</span>;
}
else if (type == "object" || type == "function")
{

View File

@@ -81,12 +81,14 @@ the terms of any one of the MPL, the GPL or the LGPL.
<!-- As of Firefox 3.1pre, <iframe>.height changes do not seem to have immediate effect,
therefore we need to put them into a <vbox> for which that works just fine -->
<vbox class="liberator-container" hidden="false" collapsed="true">
<iframe id="liberator-multiline-output" src="about:blank" flex="1" hidden="false" collapsed="false"
<iframe id="liberator-multiline-output" src="chrome://vimperator/content/buffer.xhtml"
flex="1" hidden="false" collapsed="false"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/>
</vbox>
<vbox class="liberator-container" hidden="false" collapsed="true">
<iframe id="liberator-completions" src="about:blank" flex="1" hidden="false" collapsed="false"
<iframe id="liberator-completions" src="chrome://vimperator/content/buffer.xhtml"
flex="1" hidden="false" collapsed="false"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/>
</vbox>