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

Make more effort to get at the actual filename behind a URL in view-source and :*usage!.

This commit is contained in:
Kris Maglione
2010-12-09 22:09:05 -05:00
parent c5a1291eac
commit 4c9e73949c
3 changed files with 42 additions and 36 deletions

View File

@@ -296,15 +296,18 @@ const Template = Module("Template", {
<tr>
<td style="padding-right: 20px" highlight="Usage">{
let (name = item.name || item.names[0], frame = item.definedAt)
frame ? <><span highlight="Title">{name}</span>&#xa0;
<span highlight="LineInfo">
Defined at&#xa0;<a xmlns:dactyl={NS} dactyl:command="buffer.viewSource"
href={frame.filename} line={frame.lineNumber}
highlight="URL">{
frame.filename + ":" + frame.lineNumber}</a>
</span>
</>
: name
!frame ? name : /* Help... --Kris */
let (url = frame.filename.replace(/.* -> /, ""))
<><span highlight="Title">{name}</span>&#xa0;
<span highlight="LineInfo">
Defined at&#xa0;<a xmlns:dactyl={NS} dactyl:command="buffer.viewSource"
href={url} line={frame.lineNumber}
highlight="URL">{
(util.getFile(util.newURI(url)) || { path: url }).path
+ ":" + frame.lineNumber
}</a>
</span>
</>
}</td>
<td>{item.description}</td>
</tr>)

View File

@@ -12,7 +12,7 @@ Components.utils.import("resource://dactyl/base.jsm");
defineModule("util", {
exports: ["FailedAssertion", "Math", "NS", "Util", "XHTML", "XUL", "util"],
require: ["services"],
use: ["highlight", "template"]
use: ["highlight", "storage", "template"]
});
const XHTML = Namespace("html", "http://www.w3.org/1999/xhtml");
@@ -464,6 +464,21 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
return strNum[0] + " " + unitVal[unitIndex];
},
/**
* Returns the file which backs a given URL, if available.
*
* @param {nsIURI} uri The URI for which to find a file.
*/
getFile: function getFile(uri) {
if (uri instanceof Ci.nsIFileURL)
return File(uri.QueryInterface(Ci.nsIFileURL).file);
let channel = services.io.newChannelFromURI(uri);
channel.cancel(Cr.NS_BINDING_ABORTED);
if (channel instanceof Ci.nsIFileChannel)
return File(channel.QueryInterface(Ci.nsIFileChannel).file);
return null;
},
/**
* Returns the host for the given URL, or null if invalid.
*
@@ -626,7 +641,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @returns {nsIURI}
*/
// FIXME: createURI needed too?
newURI: function (uri, charset, base) services.io.newURI(uri, charset, base),
newURI: function (uri, charset, base) services.io.newURI(uri.replace(/.* -> /, ""), charset, base),
/**
* Pretty print a JavaScript object. Use HTML markup to color certain items