From 0da30a4dc331ab8ea032e7ec6c85af28409e1a04 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 5 Nov 2008 00:59:02 +0000 Subject: [PATCH] Fix completions, among other things (sorry) --- content/bookmarks.js | 33 +++++++++----------- content/buffer.js | 2 +- content/completion.js | 7 ----- content/io.js | 70 ++++++++++++++++++++----------------------- content/style.js | 3 -- content/ui.js | 4 +-- content/util.js | 2 +- 7 files changed, 51 insertions(+), 70 deletions(-) diff --git a/content/bookmarks.js b/content/bookmarks.js index b41cb6b7..8d470c78 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -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); } }; diff --git a/content/buffer.js b/content/buffer.js index 6edc9748..7fefe835 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -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(); } }, diff --git a/content/completion.js b/content/completion.js index fe03b5ab..d62e1321 100644 --- a/content/completion.js +++ b/content/completion.js @@ -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 == "") diff --git a/content/io.js b/content/io.js index 2a710382..5a91a281 100644 --- a/content/io.js +++ b/content/io.js @@ -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)) diff --git a/content/style.js b/content/style.js index c414d059..6b0e3372 100644 --- a/content/style.js +++ b/content/style.js @@ -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; diff --git a/content/ui.js b/content/ui.js index dd47727f..e123bf0b 100644 --- a/content/ui.js +++ b/content/ui.js @@ -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); } diff --git a/content/util.js b/content/util.js index 89548b32..da580861 100644 --- a/content/util.js +++ b/content/util.js @@ -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);