mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-27 06:35:45 +01:00
macros ≡ macros.
This commit is contained in:
@@ -101,7 +101,7 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
|
|||||||
|
|
||||||
if (isinstance(value, [Ci.nsIDOMRange, Ci.nsIDOMNode, Ci.nsISelection]))
|
if (isinstance(value, [Ci.nsIDOMRange, Ci.nsIDOMNode, Ci.nsISelection]))
|
||||||
value = DOM.stringify(value);
|
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 == '"')
|
if (name == '"')
|
||||||
name = 0;
|
name = 0;
|
||||||
@@ -1310,6 +1310,20 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
|
|||||||
context.keys = { text: util.identity, description: util.identity };
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -120,10 +120,13 @@ var Events = Module("events", {
|
|||||||
this._macroKeys = [];
|
this._macroKeys = [];
|
||||||
this._lastMacro = "";
|
this._lastMacro = "";
|
||||||
|
|
||||||
this._macros = storage.newMap("macros", { privateData: true, store: true });
|
this._macros = storage.newMap("registers", { privateData: true, store: true });
|
||||||
for (let [k, m] in this._macros)
|
if (storage.exists("macros")) {
|
||||||
if (isString(m))
|
util.dump(storage.newMap("macros", { store: true }));
|
||||||
m = { keys: m, timeRecorded: Date.now() };
|
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 = {
|
this.popups = {
|
||||||
active: [],
|
active: [],
|
||||||
@@ -255,17 +258,14 @@ var Events = Module("events", {
|
|||||||
|
|
||||||
if (/[A-Z]/.test(macro)) { // Append.
|
if (/[A-Z]/.test(macro)) { // Append.
|
||||||
macro = macro.toLowerCase();
|
macro = macro.toLowerCase();
|
||||||
this._macroKeys = DOM.Event.iterKeys((this._macros.get(macro) || { keys: "" }).keys)
|
this._macroKeys = DOM.Event.iterKeys(editor.getRegister(macro))
|
||||||
.toArray();
|
.toArray();
|
||||||
}
|
}
|
||||||
else if (macro) { // Record afresh.
|
else if (macro) { // Record afresh.
|
||||||
this._macroKeys = [];
|
this._macroKeys = [];
|
||||||
}
|
}
|
||||||
else if (this.recording) { // Save.
|
else if (this.recording) { // Save.
|
||||||
this._macros.set(this.recording, {
|
editor.setRegister(this.recording, this._macroKeys.join(""));
|
||||||
keys: this._macroKeys.join(""),
|
|
||||||
timeRecorded: Date.now()
|
|
||||||
});
|
|
||||||
|
|
||||||
dactyl.log(_("macro.recorded", this.recording, this._macroKeys.join("")), 9);
|
dactyl.log(_("macro.recorded", this.recording, this._macroKeys.join("")), 9);
|
||||||
dactyl.echomsg(_("macro.recorded", this.recording));
|
dactyl.echomsg(_("macro.recorded", this.recording));
|
||||||
@@ -280,27 +280,24 @@ var Events = Module("events", {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
playMacro: function (macro) {
|
playMacro: function (macro) {
|
||||||
let res = false;
|
dactyl.assert(/^[a-zA-Z0-9@]$/.test(macro),
|
||||||
dactyl.assert(/^[a-zA-Z0-9@]$/.test(macro), _("macro.invalid", macro));
|
_("macro.invalid", macro));
|
||||||
|
|
||||||
if (macro == "@")
|
if (macro == "@")
|
||||||
dactyl.assert(this._lastMacro, _("macro.noPrevious"));
|
dactyl.assert(this._lastMacro, _("macro.noPrevious"));
|
||||||
else
|
else
|
||||||
this._lastMacro = macro.toLowerCase(); // XXX: sets last played macro, even if it does not yet exist
|
this._lastMacro = macro.toLowerCase(); // XXX: sets last played macro, even if it does not yet exist
|
||||||
|
|
||||||
if (this._macros.get(this._lastMacro)) {
|
let keys = editor.getRegister(this._lastMacro);
|
||||||
try {
|
if (keys)
|
||||||
modes.replaying = true;
|
return modes.withSavedValues(["replaying"], function () {
|
||||||
res = events.feedkeys(this._macros.get(this._lastMacro).keys, { noremap: true });
|
this.replaying = true;
|
||||||
}
|
return events.feedkeys(keys, { noremap: true });
|
||||||
finally {
|
});
|
||||||
modes.replaying = false;
|
|
||||||
}
|
// TODO: ignore this like Vim?
|
||||||
}
|
dactyl.echoerr(_("macro.noSuch", this._lastMacro));
|
||||||
else
|
return false;
|
||||||
// TODO: ignore this like Vim?
|
|
||||||
dactyl.echoerr(_("macro.noSuch", this._lastMacro));
|
|
||||||
return res;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -311,7 +308,7 @@ var Events = Module("events", {
|
|||||||
*/
|
*/
|
||||||
getMacros: function (filter) {
|
getMacros: function (filter) {
|
||||||
let re = RegExp(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) {
|
deleteMacros: function (filter) {
|
||||||
let re = RegExp(filter || "");
|
let re = RegExp(filter || "");
|
||||||
for (let [item, ] in this._macros) {
|
for (let [item, ] in editor.registers) {
|
||||||
if (!filter || re.test(item))
|
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"],
|
options.add(["timeoutlen", "tmol"],
|
||||||
"Maximum time (milliseconds) to wait for a longer key command when a shorter one exists",
|
"Maximum time (milliseconds) to wait for a longer key command when a shorter one exists",
|
||||||
"number", 1000);
|
"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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -178,17 +178,20 @@ var Modes = Module("modes", {
|
|||||||
// when recording a macro
|
// when recording a macro
|
||||||
let macromode = "";
|
let macromode = "";
|
||||||
if (this.recording)
|
if (this.recording)
|
||||||
macromode = " recording " + this.recording;
|
macromode = "recording " + this.recording + " ";
|
||||||
else if (this.replaying)
|
else if (this.replaying)
|
||||||
macromode = " replaying";
|
macromode = "replaying";
|
||||||
|
|
||||||
if (!options.get("showmode").getKey(this.main.allBases, false))
|
if (!options.get("showmode").getKey(this.main.allBases, false))
|
||||||
return macromode;
|
return macromode;
|
||||||
|
|
||||||
let val = this._modeMap[this._main].display();
|
let modeName = this._modeMap[this._main].display();
|
||||||
if (val)
|
if (!modeName)
|
||||||
return "-- " + val + " --" + macromode;
|
return macromode;
|
||||||
return macromode;
|
|
||||||
|
if (macromode)
|
||||||
|
macromode = " " + macromode;
|
||||||
|
return "-- " + modeName + " --" + macromode;
|
||||||
},
|
},
|
||||||
|
|
||||||
NONE: 0,
|
NONE: 0,
|
||||||
|
|||||||
@@ -57,6 +57,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<dl>
|
<dl>
|
||||||
|
<!-- TODO: autogenerate -->
|
||||||
<dt>all </dt> <dd>All items</dd>
|
<dt>all </dt> <dd>All items</dd>
|
||||||
<dt>cache </dt> <dd>Cache</dd>
|
<dt>cache </dt> <dd>Cache</dd>
|
||||||
<dt>commandline </dt> <dd>Command-line history</dd>
|
<dt>commandline </dt> <dd>Command-line history</dd>
|
||||||
@@ -66,11 +67,11 @@
|
|||||||
<dt>history </dt> <dd>Browsing history</dd>
|
<dt>history </dt> <dd>Browsing history</dd>
|
||||||
<dt>host </dt> <dd>All data from the given host</dd>
|
<dt>host </dt> <dd>All data from the given host</dd>
|
||||||
<dt>marks </dt> <dd>Local and URL marks</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>messages </dt> <dd>Saved <ex>:messages</ex></dd>
|
||||||
<dt>offlineapps </dt> <dd>Offline website data</dd>
|
<dt>offlineapps </dt> <dd>Offline website data</dd>
|
||||||
<dt>options </dt> <dd>Options containing hostname data</dd>
|
<dt>options </dt> <dd>Options containing hostname data</dd>
|
||||||
<dt>passwords </dt> <dd>Saved passwords</dd>
|
<dt>passwords </dt> <dd>Saved passwords</dd>
|
||||||
|
<dt>registers </dt> <dd>Register values</dd>
|
||||||
<dt>sessions </dt> <dd>Authenticated sessions</dd>
|
<dt>sessions </dt> <dd>Authenticated sessions</dd>
|
||||||
<dt>sitesettings</dt> <dd>Site preferences</dd>
|
<dt>sitesettings</dt> <dd>Site preferences</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|||||||
@@ -204,7 +204,17 @@ var Storage = Module("Storage", {
|
|||||||
File(IO.runtimePath.replace(/,.*/, ""))
|
File(IO.runtimePath.replace(/,.*/, ""))
|
||||||
.child("info").child(config.profileName)),
|
.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) {
|
newObject: function newObject(key, constructor, params) {
|
||||||
if (params == null || !isObject(params))
|
if (params == null || !isObject(params))
|
||||||
|
|||||||
Reference in New Issue
Block a user