1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 08:27:59 +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

@@ -933,22 +933,16 @@ const Buffer = Module("buffer", {
* range. * range.
*/ */
viewSelectionSource: function () { viewSelectionSource: function () {
// copied (and tuned somebit) from browser.jar -> nsContextMenu.js // copied (and tuned somewhat) from browser.jar -> nsContextMenu.js
let focusedWindow = document.commandDispatcher.focusedWindow; let win = document.commandDispatcher.focusedWindow;
if (focusedWindow == window) if (win == window)
focusedWindow = buffer.focusedFrame; win = buffer.focusedFrame;
let docCharset = null; let charset = win ? "charset=" + win.document.characterSet : null;
if (focusedWindow)
docCharset = "charset=" + focusedWindow.document.characterSet;
let reference = null;
reference = focusedWindow.getSelection();
let docUrl = null;
window.openDialog("chrome://global/content/viewPartialSource.xul", window.openDialog("chrome://global/content/viewPartialSource.xul",
"_blank", "scrollbars,resizable,chrome,dialog=no", "_blank", "scrollbars,resizable,chrome,dialog=no",
docUrl, docCharset, reference, "selection"); null, charset, win.getSelection(), "selection");
}, },
/** /**
@@ -966,11 +960,10 @@ const Buffer = Module("buffer", {
if (isArray(url)) { if (isArray(url)) {
if (options.get("editor").has("l")) if (options.get("editor").has("l"))
this.viewSourceExternally(url[0] || doc, url[1]); this.viewSourceExternally(url[0] || doc, url[1]);
else { else
let chrome = "chrome://global/content/viewSource.xul"; window.openDialog("chrome://global/content/viewSource.xul",
window.openDialog(chrome, "_blank", "all,dialog=no", "_blank", "all,dialog=no",
url[0], null, null, url[1]); url[0], null, null, url[1]);
}
} }
else { else {
if (useExternalEditor) if (useExternalEditor)
@@ -1000,12 +993,6 @@ const Buffer = Module("buffer", {
* *
* @param {Document} doc The document to view. * @param {Document} doc The document to view.
*/ */
/*
* Derived from code in Mozilla, ©2005 Jason Barnabe,
* Tri-licensed under MPL 1.1/GPL 2.0/LGPL 2.1
* Portions copyright Kris Maglione licensable under the
* MIT license.
*/
viewSourceExternally: Class("viewSourceExternally", viewSourceExternally: Class("viewSourceExternally",
XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), { XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), {
init: function (doc, callback) { init: function (doc, callback) {
@@ -1024,8 +1011,9 @@ const Buffer = Module("buffer", {
this.callback(temp); this.callback(temp);
}, this); }, this);
if (uri.scheme == "file") let file = util.getFile(uri);
this.callback(File(uri.QueryInterface(Ci.nsIFileURL).file)); if (file)
this.callback(file);
else { else {
this.file = io.createTempFile(); this.file = io.createTempFile();
var webBrowserPersist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] var webBrowserPersist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]

View File

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

View File

@@ -12,7 +12,7 @@ Components.utils.import("resource://dactyl/base.jsm");
defineModule("util", { defineModule("util", {
exports: ["FailedAssertion", "Math", "NS", "Util", "XHTML", "XUL", "util"], exports: ["FailedAssertion", "Math", "NS", "Util", "XHTML", "XUL", "util"],
require: ["services"], require: ["services"],
use: ["highlight", "template"] use: ["highlight", "storage", "template"]
}); });
const XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); 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]; 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. * 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} * @returns {nsIURI}
*/ */
// FIXME: createURI needed too? // 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 * Pretty print a JavaScript object. Use HTML markup to color certain items