1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 15:22:26 +01:00

Fix completions, among other things (sorry)

This commit is contained in:
Kris Maglione
2008-11-05 00:59:02 +00:00
parent 654bd0c2ea
commit 0da30a4dc3
7 changed files with 51 additions and 70 deletions

View File

@@ -45,6 +45,11 @@ function Bookmarks() //{{{
const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id");
const Keyword = new Struct("keyword", "title", "icon", "url");
Bookmark.defaultValue("icon", function () getFavicon(this.url));
Bookmark.prototype.__defineGetter__("extra", function () [
['keyword', this.keyword, "hl-Keyword"],
['tags', this.tags.join(', '), "hl-Tag"]
].filter(function (item) item[1]));
const storage = modules.storage;
function Cache(name, store, serial)
@@ -68,8 +73,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; // 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, null, keyword, tags, node.itemId));
}
function readBookmark(id)
@@ -529,15 +533,7 @@ function Bookmarks() //{{{
if (openItems)
return liberator.open([i.url for each (i in items)], liberator.NEW_TAB);
let list = template.bookmarks("title", (
{
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 ([i, item] in Iterator(items)) if (i < 1000)));
let list = template.bookmarks("title", items);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}
};
@@ -553,6 +549,10 @@ function History() //{{{
const historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService);
const History = new Struct("url", "title", "icon");
History.defaultValue("title", function () "[No Title]");
History.defaultValue("icon", function () bookmarks.getFavicon(this.url));
var placesHistory;
var cachedHistory = []; // add pages here after loading the initial Places history
@@ -575,7 +575,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]"]);
placesHistory.push(History(node.uri, node.title))
}
// close a container after using it!
@@ -766,7 +766,7 @@ function History() //{{{
if (placesHistory.some(function (h) h[0] == url))
placesHistory = placesHistory.filter(filter);
cachedHistory.unshift([url, title || "[No title]"]);
cachedHistory.unshift(History(url, title));
return true;
},
@@ -831,12 +831,7 @@ function History() //{{{
return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB);
// 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)));
let list = template.bookmarks("title", items);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
}
};

View File

@@ -201,7 +201,7 @@ function Buffer() //{{{
{
if (mappings.repeat)
{
for (let i in util.rangeInterruptable(0, count > 1 ? count : 1, 100))
for (let i in util.rangeInterruptable(0, Math.max(count, 1), 100))
mappings.repeat();
}
},

View File

@@ -529,13 +529,6 @@ 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))];
}
function buildSubstrings(str, filter)
{
if (filter == "")

View File

@@ -71,17 +71,20 @@ function IO() //{{{
function expandPathList(list) list.split(",").map(io.expandPath).join(",")
function replacePathSep(path)
{
if (WINDOWS)
return path.replace("/", "\\");
return path;
}
// TODO: why are we passing around so many strings? I know that the XPCOM
// file API is limited but...
function joinPaths(head, tail)
{
let pathSeparator = WINDOWS ? "\\" : "/";
let sep = pathSeparator.replace("\\", "\\\\");
head = head.replace(RegExp(sep + "$"), "");
tail = tail.replace(RegExp("^" + sep), "");
return head + pathSeparator + tail;
let path = ioManager.getFile(head);
path.appendRelativePath(tail);
return path;
}
var downloadListener = {
@@ -170,7 +173,7 @@ function IO() //{{{
}
else
{
var directories = options["cdpath"].replace(/^,$|^,,|,,$/, "").split(",");
var directories = options["cdpath"].split(",");
// empty 'cdpath' items mean the current directory
directories = directories.map(
@@ -179,9 +182,9 @@ function IO() //{{{
var directoryFound = false;
for (let i = 0; i < directories.length; i++)
for (let [,dir] in Iterator(directories))
{
var dir = joinPaths(directories[i], args);
dir = joinPaths(dir, args).path;
if (io.setCurrentDirectory(dir))
{
// FIXME: we're just overwriting the error message from
@@ -372,20 +375,19 @@ function IO() //{{{
home = environmentService.get("USERPROFILE") ||
environmentService.get("HOMEDRIVE") + environmentService.get("HOMEPATH");
path = path.replace("~", home);
path = home + path.substr(1);
}
// expand any $ENV vars - this is naive but so is Vim and we like to be compatible
// TODO: Vim does not expand variables set to an empty string, nor does it recognise
// ${VAR} on WINDOWS - are we just matching bugs?
// Yes. --Kris
path = path.replace(
RegExp("(?:\\$(\\w+)\\b|" + (WINDOWS ? "%(\\w+)%" : "\\${(\\w+)}") + ")", "g"),
WINDOWS ? /\$(\w+)\b|%(\w+)%/g : /\$(\w+)\b|\${(\w+)}/g,
function (m, n1, n2, i, s) environmentService.get((n1 || n2), "$1")
);
path = path.replace("\\ ", " ", "g");
return path;
return path.replace("\\ ", " ", "g");
},
// TODO: there seems to be no way, short of a new component, to change
@@ -430,9 +432,8 @@ function IO() //{{{
{
let dirs = options["runtimepath"].split(",");
dirs = dirs.map(function (dir) io.getFile(joinPaths(dir, specialDirectory)))
dirs = dirs.map(function (dir) joinPaths(dir, specialDirectory))
.filter(function (dir) dir.exists() && dir.isDirectory() && dir.isReadable());
return dirs;
},
@@ -440,8 +441,8 @@ function IO() //{{{
{
dir = dir || "~";
let rcFile1 = ioManager.getFile(joinPaths(dir, "/." + EXTENSION_NAME + "rc"));
let rcFile2 = ioManager.getFile(joinPaths(dir, "/_" + EXTENSION_NAME + "rc"));
let rcFile1 = joinPaths(dir, "." + EXTENSION_NAME + "rc");
let rcFile2 = joinPaths(dir, "_" + EXTENSION_NAME + "rc");
if (WINDOWS)
[rcFile1, rcFile2] = [rcFile2, rcFile1];
@@ -457,7 +458,7 @@ function IO() //{{{
// return a nsILocalFile for path where you can call isDirectory(), etc. on
// caller must check with .exists() if the returned file really exists
// also expands relative paths
getFile: function (path)
getFile: function (path, noCheckPWD)
{
let file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
@@ -472,10 +473,10 @@ function IO() //{{{
{
let expandedPath = ioManager.expandPath(path);
if (!/^([a-zA-Z]:|\/)/.test(expandedPath)) // doesn't start with /, C:
expandedPath = joinPaths(ioManager.getCurrentDirectory().path, expandedPath);
file.initWithPath(expandedPath);
if (!/^([a-zA-Z]:|\/)/.test(expandedPath) && !noCheckPWD) // doesn't start with /, C:
file = joinPaths(ioManager.getCurrentDirectory().path, expandedPath);
else
file.initWithPath(expandedPath);
}
return file;
@@ -603,9 +604,6 @@ function IO() //{{{
run: function (program, args, blocking)
{
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
if (!args)
args = [];
@@ -614,18 +612,17 @@ function IO() //{{{
try
{
file.initWithPath(program);
var file = ioManager.getFile(program, !WINDOWS);
}
catch (e)
{
var dirs = environmentService.get("PATH").split(WINDOWS ? ";" : ":");
lookup:
for (let i = 0; i < dirs.length; i++)
for (let [,dir] in Iterator(dirs))
{
var path = joinPaths(dirs[i], program);
file = joinPaths(dir, program);
try
{
file.initWithPath(path);
if (file.exists())
break;
@@ -633,11 +630,10 @@ lookup:
// automatically try to add the executable path extensions on windows
if (WINDOWS)
{
var extensions = environmentService.get("PATHEXT").split(";");
for (let j = 0; j < extensions.length; j++)
let extensions = environmentService.get("PATHEXT").split(";");
for (let [,extension] in Iterator(extension))
{
path = joinPaths(dirs[i], program) + extensions[j];
file.initWithPath(path);
file = joinPaths(dir, program + extension);
if (file.exists())
break lookup;
}
@@ -726,7 +722,7 @@ lookup:
{
for (let [,path] in Iterator(paths))
{
let file = io.getFile(joinPaths(runtimeDir, path));
let file = joinPaths(runtimeDir, path);
liberator.echomsg("Searching for \"" + file.path, 3);
@@ -778,7 +774,7 @@ lookup:
liberator.echomsg("sourcing \"" + filename + "\"", 2);
let str = ioManager.readFile(file);
let uri = util.createURI(file.path);
let uri = makeFileURI(file);
// handle pure javascript files specially
if (/\.js$/.test(filename))

View File

@@ -66,7 +66,6 @@ function Highlights(name, store, serial)
Bell,#liberator-visualbell border: none; background-color: black;
Hint,.liberator-hint,* {
z-index: 5000;
font-family: monospace;
font-size: 10px;
font-weight: bold;
@@ -76,10 +75,8 @@ function Highlights(name, store, serial)
border-width: 0px;
border-style: solid;
padding: 0px 1px 0px 1px;
position: absolute;
}
Search,.liberator-search,* {
display: inline;
font-size: inherit;
padding: 0;
color: black;

View File

@@ -1387,8 +1387,8 @@ function ItemList(id) //{{{
let dom = util.xmlToDom(div, doc);
completionBody = dom.getElementsByClassName("hl-Completions")[0];
//completionElements = completionBody.childNodes;
completionElements = dom.getElementsByClassName("hl-CompItem");
completionElements = completionBody.childNodes;
//completionElements = dom.getElementsByClassName("hl-CompItem");
doc.body.replaceChild(dom, doc.body.firstChild);
}

View File

@@ -505,7 +505,7 @@ function Struct()
ConStructor.defaultValue = function (key, val)
{
let i = args.indexOf(key);
ConStructor.prototype.__defineGetter__(i, val);
ConStructor.prototype.__defineGetter__(i, function () this[i] = val.call(this));
ConStructor.prototype.__defineSetter__(i, function (val) {
let value = val;
this.__defineGetter__(i, function () value);