1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-31 23:42:27 +01:00

macros ≡ macros.

This commit is contained in:
Kris Maglione
2011-10-06 08:56:13 -04:00
parent 0cf53f8181
commit 40104c2b8b
5 changed files with 61 additions and 48 deletions

View File

@@ -101,7 +101,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
if (isinstance(value, [Ci.nsIDOMRange, Ci.nsIDOMNode, Ci.nsISelection]))
value = DOM.stringify(value);
value = { text: value, isLine: modes.extended & modes.LINE };
value = { text: value, isLine: modes.extended & modes.LINE, timestamp: Date.now() * 1000 };
if (name == '"')
name = 0;
@@ -1310,6 +1310,20 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
context.keys = { text: util.identity, description: util.identity };
}
});
},
sanitizer: function () {
sanitizer.addItem("registers", {
description: "Register values",
persistent: true,
action: function (timespan, host) {
if (!host) {
for (let [k, v] in editor.registers)
if (timespan.contains(v.timestamp))
editor.registers.remove(k);
editor.registerRing.truncate(0);
}
}
});
}
});

View File

@@ -120,10 +120,13 @@ var Events = Module("events", {
this._macroKeys = [];
this._lastMacro = "";
this._macros = storage.newMap("macros", { privateData: true, store: true });
for (let [k, m] in this._macros)
if (isString(m))
m = { keys: m, timeRecorded: Date.now() };
this._macros = storage.newMap("registers", { privateData: true, store: true });
if (storage.exists("macros")) {
util.dump(storage.newMap("macros", { store: true }));
for (let [k, m] in storage.newMap("macros", { store: true }))
this._macros.set(k, { text: m.keys, timestamp: m.timeRecorded * 1000 });
storage.remove("macros");
}
this.popups = {
active: [],
@@ -255,17 +258,14 @@ var Events = Module("events", {
if (/[A-Z]/.test(macro)) { // Append.
macro = macro.toLowerCase();
this._macroKeys = DOM.Event.iterKeys((this._macros.get(macro) || { keys: "" }).keys)
this._macroKeys = DOM.Event.iterKeys(editor.getRegister(macro))
.toArray();
}
else if (macro) { // Record afresh.
this._macroKeys = [];
}
else if (this.recording) { // Save.
this._macros.set(this.recording, {
keys: this._macroKeys.join(""),
timeRecorded: Date.now()
});
editor.setRegister(this.recording, this._macroKeys.join(""));
dactyl.log(_("macro.recorded", this.recording, this._macroKeys.join("")), 9);
dactyl.echomsg(_("macro.recorded", this.recording));
@@ -280,27 +280,24 @@ var Events = Module("events", {
* @returns {boolean}
*/
playMacro: function (macro) {
let res = false;
dactyl.assert(/^[a-zA-Z0-9@]$/.test(macro), _("macro.invalid", macro));
dactyl.assert(/^[a-zA-Z0-9@]$/.test(macro),
_("macro.invalid", macro));
if (macro == "@")
dactyl.assert(this._lastMacro, _("macro.noPrevious"));
else
this._lastMacro = macro.toLowerCase(); // XXX: sets last played macro, even if it does not yet exist
if (this._macros.get(this._lastMacro)) {
try {
modes.replaying = true;
res = events.feedkeys(this._macros.get(this._lastMacro).keys, { noremap: true });
}
finally {
modes.replaying = false;
}
}
else
// TODO: ignore this like Vim?
dactyl.echoerr(_("macro.noSuch", this._lastMacro));
return res;
let keys = editor.getRegister(this._lastMacro);
if (keys)
return modes.withSavedValues(["replaying"], function () {
this.replaying = true;
return events.feedkeys(keys, { noremap: true });
});
// TODO: ignore this like Vim?
dactyl.echoerr(_("macro.noSuch", this._lastMacro));
return false;
},
/**
@@ -311,7 +308,7 @@ var Events = Module("events", {
*/
getMacros: function (filter) {
let re = RegExp(filter || "");
return ([k, m.keys] for ([k, m] in events._macros) if (re.test(k)));
return ([k, m.text] for ([k, m] in editor.registers) if (re.test(k)));
},
/**
@@ -322,9 +319,9 @@ var Events = Module("events", {
*/
deleteMacros: function (filter) {
let re = RegExp(filter || "");
for (let [item, ] in this._macros) {
for (let [item, ] in editor.registers) {
if (!filter || re.test(item))
this._macros.remove(item);
editor.registers.remove(item);
}
},
@@ -1172,18 +1169,6 @@ var Events = Module("events", {
options.add(["timeoutlen", "tmol"],
"Maximum time (milliseconds) to wait for a longer key command when a shorter one exists",
"number", 1000);
},
sanitizer: function () {
sanitizer.addItem("macros", {
description: "Saved macros",
persistent: true,
action: function (timespan, host) {
if (!host)
for (let [k, m] in events._macros)
if (timespan.contains(m.timeRecorded * 1000))
events._macros.remove(k);
}
});
}
});

View File

@@ -178,17 +178,20 @@ var Modes = Module("modes", {
// when recording a macro
let macromode = "";
if (this.recording)
macromode = " recording " + this.recording;
macromode = "recording " + this.recording + " ";
else if (this.replaying)
macromode = " replaying";
macromode = "replaying";
if (!options.get("showmode").getKey(this.main.allBases, false))
return macromode;
let val = this._modeMap[this._main].display();
if (val)
return "-- " + val + " --" + macromode;
return macromode;
let modeName = this._modeMap[this._main].display();
if (!modeName)
return macromode;
if (macromode)
macromode = " " + macromode;
return "-- " + modeName + " --" + macromode;
},
NONE: 0,

View File

@@ -57,6 +57,7 @@
</p>
<dl>
<!-- TODO: autogenerate -->
<dt>all </dt> <dd>All items</dd>
<dt>cache </dt> <dd>Cache</dd>
<dt>commandline </dt> <dd>Command-line history</dd>
@@ -66,11 +67,11 @@
<dt>history </dt> <dd>Browsing history</dd>
<dt>host </dt> <dd>All data from the given host</dd>
<dt>marks </dt> <dd>Local and URL marks</dd>
<dt>macros </dt> <dd>Saved macros</dd>
<dt>messages </dt> <dd>Saved <ex>:messages</ex></dd>
<dt>offlineapps </dt> <dd>Offline website data</dd>
<dt>options </dt> <dd>Options containing hostname data</dd>
<dt>passwords </dt> <dd>Saved passwords</dd>
<dt>registers </dt> <dd>Register values</dd>
<dt>sessions </dt> <dd>Authenticated sessions</dd>
<dt>sitesettings</dt> <dd>Site preferences</dd>
</dl>

View File

@@ -204,7 +204,17 @@ var Storage = Module("Storage", {
File(IO.runtimePath.replace(/,.*/, ""))
.child("info").child(config.profileName)),
exists: function exists(name) this.infoPath.child(name).exists(),
exists: function exists(key) this.infoPath.child(key).exists(),
remove: function remove(key) {
if (this.exists(key)) {
if (this[key] && this[key].timer)
this[key].timer.flush();
delete this[key];
delete this.keys[key];
this.infoPath.child(key).remove(false);
}
},
newObject: function newObject(key, constructor, params) {
if (params == null || !isObject(params))