From 40104c2b8bfd7068f3dec6e4a0a1f7291fab6db3 Mon Sep 17 00:00:00 2001
From: Kris Maglione
Date: Thu, 6 Oct 2011 08:56:13 -0400
Subject: [PATCH] =?UTF-8?q?macros=20=E2=89=A1=20macros.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
common/content/editor.js | 16 ++++++++-
common/content/events.js | 63 +++++++++++++--------------------
common/content/modes.js | 15 ++++----
common/locale/en-US/privacy.xml | 3 +-
common/modules/storage.jsm | 12 ++++++-
5 files changed, 61 insertions(+), 48 deletions(-)
diff --git a/common/content/editor.js b/common/content/editor.js
index 9d33f5d9..4b647985 100644
--- a/common/content/editor.js
+++ b/common/content/editor.js
@@ -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);
+ }
+ }
+ });
}
});
diff --git a/common/content/events.js b/common/content/events.js
index 1b655253..b10f4594 100644
--- a/common/content/events.js
+++ b/common/content/events.js
@@ -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);
- }
- });
}
});
diff --git a/common/content/modes.js b/common/content/modes.js
index c923c6bf..e24911b6 100644
--- a/common/content/modes.js
+++ b/common/content/modes.js
@@ -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,
diff --git a/common/locale/en-US/privacy.xml b/common/locale/en-US/privacy.xml
index 5ab2a402..ca89c756 100644
--- a/common/locale/en-US/privacy.xml
+++ b/common/locale/en-US/privacy.xml
@@ -57,6 +57,7 @@
+
- all
- All items
- cache
- Cache
- commandline
- Command-line history
@@ -66,11 +67,11 @@
- history
- Browsing history
- host
- All data from the given host
- marks
- Local and URL marks
- - macros
- Saved macros
- messages
- Saved :messages
- offlineapps
- Offline website data
- options
- Options containing hostname data
- passwords
- Saved passwords
+ - registers
- Register values
- sessions
- Authenticated sessions
- sitesettings
- Site preferences
diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm
index 8604d2e6..b7e31fe7 100644
--- a/common/modules/storage.jsm
+++ b/common/modules/storage.jsm
@@ -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))