1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-23 12:15:46 +01:00

Handle sane shells on Windows somewhat better.

This commit is contained in:
Kris Maglione
2010-11-05 13:36:30 -04:00
parent 7815a85d7d
commit 97589ce40b
8 changed files with 46 additions and 44 deletions

View File

@@ -155,8 +155,8 @@ const Browser = Module("browser", {
commands.add(["redr[aw]"], commands.add(["redr[aw]"],
"Redraw the screen", "Redraw the screen",
function () { function () {
window.QueryInterface(Ci.nsIInterfaceRequestor) window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils)
.getInterface(Ci.nsIDOMWindowUtils).redraw(); .redraw();
statusline.updateUrl(); statusline.updateUrl();
commandline.clear(); commandline.clear();
}, },

View File

@@ -660,8 +660,7 @@ const Buffer = Module("buffer", {
* controller. * controller.
*/ */
get selectionController() config.browser.docShell get selectionController() config.browser.docShell
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsISelectionDisplay)
.getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsISelectionController), .QueryInterface(Ci.nsISelectionController),
/** /**
@@ -1483,12 +1482,9 @@ const Buffer = Module("buffer", {
config.browser.addProgressListener(this.progressListener, Ci.nsIWebProgress.NOTIFY_ALL); config.browser.addProgressListener(this.progressListener, Ci.nsIWebProgress.NOTIFY_ALL);
window.XULBrowserWindow = this.progressListener; window.XULBrowserWindow = this.progressListener;
window.QueryInterface(Ci.nsIInterfaceRequestor) window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.getInterface(Ci.nsIWebNavigation) .QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
.QueryInterface(Ci.nsIDocShellTreeItem) .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIXULWindow)
.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow)
.XULBrowserWindow = this.progressListener; .XULBrowserWindow = this.progressListener;
let appContent = document.getElementById("appcontent"); let appContent = document.getElementById("appcontent");

View File

@@ -594,8 +594,7 @@ const RangeFind = Class("RangeFind", {
this.range = range; this.range = range;
this.document = range.startContainer.ownerDocument; this.document = range.startContainer.ownerDocument;
this.window = this.document.defaultView; this.window = this.document.defaultView;
this.docShell = this.window.QueryInterface(Ci.nsIInterfaceRequestor) this.docShell = this.window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell); .QueryInterface(Ci.nsIDocShell);
if (this.selection == null) if (this.selection == null)
@@ -629,8 +628,7 @@ const RangeFind = Class("RangeFind", {
}, },
get selectionController() this.docShell get selectionController() this.docShell
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsISelectionDisplay)
.getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsISelectionController), .QueryInterface(Ci.nsISelectionController),
get selection() { get selection() {
try { try {

View File

@@ -263,7 +263,7 @@ lookup:
} }
let process = services.create("process"); let process = services.create("process");
let isMain = services.get("threadManager").isMainThread; let isMain = services.get("threading").isMainThread;
process.init(file); process.init(file);
process.run(blocking && !isMain, args.map(String), args.length); process.run(blocking && !isMain, args.map(String), args.length);
@@ -294,7 +294,7 @@ lookup:
let dirs = options["runtimepath"]; let dirs = options["runtimepath"];
let found = false; let found = false;
dactyl.echomsg("Searching for " + paths.join(" ").quote() + " in " + options.get("runtimepath").value, 2); dactyl.echomsg("Searching for " + paths.join(" ").quote() + " in " + options.get("runtimepath").stringValue, 2);
outer: outer:
for (let [, dir] in Iterator(dirs)) { for (let [, dir] in Iterator(dirs)) {
@@ -407,7 +407,7 @@ lookup:
stdin.write(input); stdin.write(input);
// TODO: implement 'shellredir' // TODO: implement 'shellredir'
if (util.isOS("WINNT")) { if (util.isOS("WINNT") && !/sh/.test(options["shell"])) {
command = "cd /D " + this.cwd + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path; command = "cd /D " + this.cwd + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path;
var res = this.run(options["shell"], options["shellcmdflag"].split(/\s+/).concat(command), true); var res = this.run(options["shell"], options["shellcmdflag"].split(/\s+/).concat(command), true);
} }
@@ -421,10 +421,8 @@ lookup:
let output = stdout.read(); let output = stdout.read();
if (res > 0) if (res > 0)
output += "\nshell returned " + res; output += "\nshell returned " + res;
// if there is only one \n at the end, chop it off else if (output)
else if (output && output.indexOf("\n") == output.length - 1) output = output.replace(/^(.*)\n$/, "$1");
output = output.substr(0, output.length - 1);
return output; return output;
}) || ""; }) || "";
}, },
@@ -442,14 +440,13 @@ lookup:
*/ */
withTempFiles: function (func, self) { withTempFiles: function (func, self) {
let args = util.map(util.range(0, func.length), this.createTempFile); let args = util.map(util.range(0, func.length), this.createTempFile);
if (!args.every(util.identity))
return false;
try { try {
if (!args.every(util.identity))
return false;
return func.apply(self || this, args); return func.apply(self || this, args);
} }
finally { finally {
args.forEach(function (f) f.remove(false)); args.forEach(function (f) f && f.remove(false));
} }
} }
}, { }, {
@@ -731,8 +728,6 @@ lookup:
var shell, shellcmdflag; var shell, shellcmdflag;
if (util.isOS("WINNT")) { if (util.isOS("WINNT")) {
shell = "cmd.exe"; shell = "cmd.exe";
// TODO: setting 'shell' to "something containing sh" updates
// 'shellcmdflag' appropriately at startup on Windows in Vim
shellcmdflag = "/c"; shellcmdflag = "/c";
} }
else { else {
@@ -768,7 +763,14 @@ lookup:
options.add(["shellcmdflag", "shcf"], options.add(["shellcmdflag", "shcf"],
"Flag passed to shell when executing :! and :run commands", "Flag passed to shell when executing :! and :run commands",
"string", shellcmdflag); "string", shellcmdflag,
{
getter: function (value) {
if (this.hasChanged || !util.isOS("WINNT"))
return value;
return /sh/.test(options["shell"]) ? "-c" : "/c";
}
});
options.add(["wildignore", "wig"], options.add(["wildignore", "wig"],
"List of file patterns to ignore when completing files", "List of file patterns to ignore when completing files",

View File

@@ -661,7 +661,8 @@ const JavaScript = Module("javascript", {
"Use the JavaScript debugger service for JavaScript completion", "Use the JavaScript debugger service for JavaScript completion",
"boolean", false, { "boolean", false, {
setter: function (value) { setter: function (value) {
services.get("debugger")[value ? "on" : "off"](); if (services.get("debugger").isOn != value)
services.get("debugger")[value ? "on" : "off"]();
}, },
getter: function () services.get("debugger").isOn getter: function () services.get("debugger").isOn
}); });

View File

@@ -597,8 +597,8 @@ function curry(fn, length, self, acc) {
*/ */
function requiresMainThread(callback) function requiresMainThread(callback)
function wrapper() { function wrapper() {
let mainThread = services.get("threadManager").mainThread; let mainThread = services.get("threading").mainThread;
if (services.get("threadManager").isMainThread) if (services.get("threading").isMainThread)
callback.apply(this, arguments); callback.apply(this, arguments);
else else
mainThread.dispatch(Runnable(this, callback, arguments), mainThread.DISPATCH_NORMAL); mainThread.dispatch(Runnable(this, callback, arguments), mainThread.DISPATCH_NORMAL);

View File

@@ -50,7 +50,7 @@ const Services = Module("Services", {
this.add("stylesheet", "@mozilla.org/content/style-sheet-service;1", Ci.nsIStyleSheetService); this.add("stylesheet", "@mozilla.org/content/style-sheet-service;1", Ci.nsIStyleSheetService);
this.add("subscriptLoader", "@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader); this.add("subscriptLoader", "@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader);
this.add("tagging", "@mozilla.org/browser/tagging-service;1", Ci.nsITaggingService); this.add("tagging", "@mozilla.org/browser/tagging-service;1", Ci.nsITaggingService);
this.add("threadManager", "@mozilla.org/thread-manager;1", Ci.nsIThreadManager); this.add("threading", "@mozilla.org/thread-manager;1", Ci.nsIThreadManager);
this.add("urifixup", "@mozilla.org/docshell/urifixup;1", Ci.nsIURIFixup); this.add("urifixup", "@mozilla.org/docshell/urifixup;1", Ci.nsIURIFixup);
this.add("windowMediator", "@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator); this.add("windowMediator", "@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator);
this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher); this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher);
@@ -69,7 +69,14 @@ const Services = Module("Services", {
_create: function (classes, ifaces, meth) { _create: function (classes, ifaces, meth) {
try { try {
let res = Cc[classes][meth || "getService"](); for (let i = 0; !res && i < 15; i++) // FIXME: Hack.
try {
var res = Cc[classes][meth || "getService"]();
}
catch (e if e.result === Cr.NS_ERROR_XPC_BAD_OP_ON_WN_PROTO) {
util.dump(String(e));
}
if (!ifaces) if (!ifaces)
return res.wrappedJSObject; return res.wrappedJSObject;
Array.concat(ifaces).forEach(function (iface) res.QueryInterface(iface)); Array.concat(ifaces).forEach(function (iface) res.QueryInterface(iface));

View File

@@ -106,8 +106,8 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @returns {function} * @returns {function}
*/ */
callInMainThread: function (callback, self) { callInMainThread: function (callback, self) {
let mainThread = services.get("threadManager").mainThread; let mainThread = services.get("threading").mainThread;
if (services.get("threadManager").isMainThread) if (services.get("threading").isMainThread)
callback.call(self); callback.call(self);
else else
mainThread.dispatch(Runnable(self, callback, Array.slice(arguments, 2)), mainThread.DISPATCH_NORMAL); mainThread.dispatch(Runnable(self, callback, Array.slice(arguments, 2)), mainThread.DISPATCH_NORMAL);
@@ -125,7 +125,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* *
*/ */
callAsync: function (thread, self, func) { callAsync: function (thread, self, func) {
thread = thread || services.get("threadManager").newThread(0); thread = thread || services.get("threading").newThread(0);
thread.dispatch(Runnable(self, func, Array.slice(arguments, 3)), thread.DISPATCH_NORMAL); thread.dispatch(Runnable(self, func, Array.slice(arguments, 3)), thread.DISPATCH_NORMAL);
}, },
@@ -141,7 +141,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @param {function} func The function to execute. * @param {function} func The function to execute.
*/ */
callInThread: function (thread, func) { callInThread: function (thread, func) {
thread = thread || services.get("threadManager").newThread(0); thread = thread || services.get("threading").newThread(0);
thread.dispatch(Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC); thread.dispatch(Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC);
}, },
@@ -593,7 +593,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
return ary; return ary;
}, },
newThread: function () services.get("threadManager").newThread(0), newThread: function () services.get("threading").newThread(0),
/** /**
* Converts a URI string into a URI object. * Converts a URI string into a URI object.
@@ -940,10 +940,8 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @returns {nsISelectionController} * @returns {nsISelectionController}
*/ */
selectionController: function (win) selectionController: function (win)
win.QueryInterface(Ci.nsIInterfaceRequestor) win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
.getInterface(Ci.nsIWebNavigation) .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsISelectionController), .QueryInterface(Ci.nsISelectionController),
/** /**
@@ -955,7 +953,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @param {number} delay The time period for which to sleep in milliseconds. * @param {number} delay The time period for which to sleep in milliseconds.
*/ */
sleep: function (delay) { sleep: function (delay) {
let mainThread = services.get("threadManager").mainThread; let mainThread = services.get("threading").mainThread;
let end = Date.now() + delay; let end = Date.now() + delay;
while (Date.now() < end) while (Date.now() < end)
@@ -1034,7 +1032,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
}, },
threadYield: function (flush, interruptable) { threadYield: function (flush, interruptable) {
let mainThread = services.get("threadManager").mainThread; let mainThread = services.get("threading").mainThread;
/* FIXME */ /* FIXME */
util.interrupted = false; util.interrupted = false;
do { do {