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

First work towards cleaning up the commandline.js rat's nest. Don't expect any of these new interfaces to stay remotely as they are.

--HG--
branch : key-processing
This commit is contained in:
Kris Maglione
2011-01-26 01:24:54 -05:00
parent a66864d077
commit c284e1ced8
18 changed files with 829 additions and 790 deletions

View File

@@ -314,7 +314,7 @@ var AddonList = Class("AddonList", {
if (addon && addon.id in this.addons)
this.addons[addon.id].update();
if (this.ready)
this.modules.commandline.updateOutputHeight(false);
this.modules.mow.resize(false);
},
onDisabled: function (addon) { this.update(addon); },

View File

@@ -985,9 +985,10 @@ let StructBase = Class("StructBase", Array, {
});
var Timer = Class("Timer", {
init: function (minInterval, maxInterval, callback) {
init: function (minInterval, maxInterval, callback, self) {
this._timer = services.Timer();
this.callback = callback;
this.self = self || this;
this.minInterval = minInterval;
this.maxInterval = maxInterval;
this.doneAt = 0;
@@ -1004,7 +1005,7 @@ var Timer = Class("Timer", {
// minInterval is the time between the completion of the command and the next firing
this.doneAt = Date.now() + this.minInterval;
this.callback(this.arg);
this.callback.call(this.self, this.arg);
}
catch (e) {
if (typeof util === "undefined")
@@ -1042,8 +1043,8 @@ var Timer = Class("Timer", {
this.doneAt = 0;
},
flush: function () {
if (this.doneAt == -1)
flush: function (force) {
if (this.doneAt == -1 || force)
this.notify();
}
});

View File

@@ -296,7 +296,7 @@ var DownloadList = Class("DownloadList",
else {
this.addDownload(download.id);
this.modules.commandline.updateOutputHeight(false);
this.modules.mow.resize(false);
this.nodes.list.scrollIntoView(false);
}
this.update();

View File

@@ -15,20 +15,22 @@ var RangeFinder = Module("rangefinder", {
Local: function (dactyl, modules, window) ({
init: function () {
this.dactyl = dactyl;
this.commandline = modules.commandline;
this.modes = modules.modes;
this.modules = modules;
this.window = window;
this.options = modules.options;
this.lastFindPattern = "";
},
get commandline() this.modules.commandline,
get modes() this.modules.modes,
get options() this.modules.options(),
get rangeFind() modules.buffer.localStore.rangeFind,
set rangeFind(val) modules.buffer.localStore.rangeFind = val
}),
openPrompt: function (mode) {
let backwards = mode == this.modes.FIND_BACKWARD;
this.commandline.open(backwards ? "?" : "/", "", mode);
this.CommandMode(mode).open(backwards ? "?" : "/");
if (this.rangeFind && this.rangeFind.window.get() === this.window)
this.rangeFind.reset();
@@ -184,15 +186,6 @@ var RangeFinder = Module("rangefinder", {
input: true
}, { history: "search" });
},
commandline: function (dactyl, modules, window) {
const { commandline, modes, rangefinder } = modules;
commandline.registerCallback("change", modes.FIND_FORWARD, rangefinder.closure.onKeyPress);
commandline.registerCallback("submit", modes.FIND_FORWARD, rangefinder.closure.onSubmit);
commandline.registerCallback("cancel", modes.FIND_FORWARD, rangefinder.closure.onCancel);
commandline.registerCallback("change", modes.FIND_BACKWARD, rangefinder.closure.onKeyPress);
commandline.registerCallback("submit", modes.FIND_BACKWARD, rangefinder.closure.onSubmit);
commandline.registerCallback("cancel", modes.FIND_BACKWARD, rangefinder.closure.onCancel);
},
commands: function (dactyl, modules, window) {
const { commands, rangefinder } = modules;
commands.add(["noh[lfind]"],
@@ -200,6 +193,17 @@ var RangeFinder = Module("rangefinder", {
function () { rangefinder.clear(); },
{ argCount: "0" });
},
commandline: function (dactyl, modules, window) {
this.CommandMode = modules.CommandMode("CommandFindMode", {
init: function init(mode) {
this.mode = mode;
},
historyKey: "find",
onCancel: rangefinder.closure.onCancel,
onChange: rangefinder.closure.onKeyPress,
onSubmit: rangefinder.closure.onSubmit
});
},
mappings: function (dactyl, modules, window) {
const { buffer, config, mappings, modes, rangefinder } = modules;
var myModes = config.browserModes.concat([modes.CARET]);

View File

@@ -61,6 +61,27 @@ var IO = Module("io", {
services.downloadManager.addListener(this.downloadListener);
},
CommandFileMode: Class("CommandFileMode", modules.CommandMode, {
init: function init(prompt, params) {
init.supercall(this);
this.prompt = isArray(prompt) ? prompt : ["Question", prompt];
update(this, params);
},
historyKey: "file",
get mode() modules.modes.FILE_INPUT,
complete: function (context) {
if (this.completer)
this.completer(context);
context = context.fork("files", 0);
modules.completion.file(context);
context.filters = context.filters.concat(this.filters || []);
}
}),
destroy: function destroy() {
services.downloadManager.removeListener(this.downloadListener);
for (let [, plugin] in Iterator(plugins.contexts))
@@ -1002,6 +1023,16 @@ unlet s:cpo_save
}]);
},
modes: function (dactyl, modules, window) {
const { commandline, modes } = modules;
modes.addMode("FILE_INPUT", {
extended: true,
description: "Active when selecting a file",
bases: [modes.COMMAND_LINE],
input: true
});
},
options: function (dactyl, modules, window) {
const { options } = modules;

View File

@@ -176,6 +176,7 @@ var Overlay = Module("Overlay", {
"io",
"mappings",
"marks",
"mow",
"options",
"statusline",
"styles",

View File

@@ -138,7 +138,9 @@ var Template = Module("Template", {
init.supercall(this, node);
let obj = params.eventTarget;
for (let [event, handler] in Iterator(obj[this.getAttribute("events") || "events"]))
let events = obj[this.getAttribute("events") || "events"];
for (let [event, handler] in Iterator(events))
node.addEventListener(event, obj.closure(handler), false);
}
})