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

Move macro storage to the storage module.

This commit is contained in:
Kris Maglione
2008-09-11 22:39:28 +00:00
parent fc36dcf01e
commit 5608c04d00
2 changed files with 19 additions and 27 deletions

View File

@@ -340,10 +340,7 @@ liberator.Completion = function () //{{{
macro: function (filter) macro: function (filter)
{ {
var macros = []; var macros = [item for (item in liberator.events.getMacros())]
for (var item in liberator.events.getMacros())
macros.push([item, tmp[item]]);
return [0, liberator.completion.filter(macros, filter)]; return [0, liberator.completion.filter(macros, filter)];
}, },

View File

@@ -255,7 +255,9 @@ liberator.Events = function () //{{{
var inputBufferLength = 0; // count the number of keys in v.input.buffer (can be different from v.input.buffer.length) var inputBufferLength = 0; // count the number of keys in v.input.buffer (can be different from v.input.buffer.length)
var skipMap = false; // while feeding the keys (stored in v.input.buffer | no map found) - ignore mappings var skipMap = false; // while feeding the keys (stored in v.input.buffer | no map found) - ignore mappings
var macros = {}; liberator.storage.newObject('macros', false);
var macros = liberator.storage.macros;
var currentMacro = ""; var currentMacro = "";
var lastMacro = ""; var lastMacro = "";
@@ -546,8 +548,8 @@ liberator.Events = function () //{{{
continue; continue;
var name = file.leafName.replace(/\.vimp$/i, ""); var name = file.leafName.replace(/\.vimp$/i, "");
macros[name] = liberator.io.readFile(file).split(/\n/)[0]; macros.set(name, liberator.io.readFile(file).split(/\n/)[0]);
liberator.log("Macro " + name + " added: " + macros[name], 5); liberator.log("Macro " + name + " added: " + macros.get(name), 5);
} }
} }
catch (e) catch (e)
@@ -629,9 +631,9 @@ liberator.Events = function () //{{{
{ {
var str = "<table>"; var str = "<table>";
var macroRef = liberator.events.getMacros(args); var macroRef = liberator.events.getMacros(args);
for (var item in macroRef) for (var [macro, keys] in macroRef)
str += "<tr><td> " + item + " &nbsp; </td><td>" + str += "<tr><td> " + macro + " &nbsp; </td><td>" +
liberator.util.escapeHTML(macroRef[item]) + "</td></tr>"; liberator.util.escapeHTML(keys) + "</td></tr>";
str += "</table>"; str += "</table>";
@@ -693,13 +695,13 @@ liberator.Events = function () //{{{
if (/[A-Z]/.test(macro)) // uppercase (append) if (/[A-Z]/.test(macro)) // uppercase (append)
{ {
currentMacro = macro.toLowerCase(); currentMacro = macro.toLowerCase();
if (!macros[currentMacro]) if (!macros.get(currentMacro))
macros[currentMacro] = ""; // initialize if it does not yet exist macros.set(currentMacro, ""); // initialize if it does not yet exist
} }
else else
{ {
currentMacro = macro; currentMacro = macro;
macros[currentMacro] = ""; macros.set(currentMacro, "");
} }
}, },
@@ -727,7 +729,7 @@ liberator.Events = function () //{{{
lastMacro = macro; // e.g. long names are case sensitive lastMacro = macro; // e.g. long names are case sensitive
} }
if (macros[lastMacro]) if (macros.get(lastMacro))
{ {
liberator.modes.isReplaying = true; liberator.modes.isReplaying = true;
@@ -739,7 +741,7 @@ liberator.Events = function () //{{{
catch (e) {} catch (e) {}
liberator.buffer.loaded = 1; // even if not a full page load, assume it did load correctly before starting the macro liberator.buffer.loaded = 1; // even if not a full page load, assume it did load correctly before starting the macro
liberator.events.feedkeys(macros[lastMacro], true); // true -> noremap liberator.events.feedkeys(macros.get(lastMacro), true); // true -> noremap
liberator.modes.isReplaying = false; liberator.modes.isReplaying = false;
} }
else else
@@ -757,25 +759,18 @@ liberator.Events = function () //{{{
if (!filter) if (!filter)
return macros; return macros;
var filtered = {};
var re = new RegExp(filter); var re = new RegExp(filter);
return ([macro, keys] for ([macro, keys] in macros) if (re.test(macro)));
for (var item in macros)
{
if (re.test(item))
filtered[item] = macros[item];
}
return filtered; //XXX: returns a real copy, since this is only a 'var ..'?
}, },
deleteMacros: function (filter) deleteMacros: function (filter)
{ {
var re = new RegExp(filter); var re = new RegExp(filter);
for (var item in macros) for (var [item,] in macros)
{ {
if (re.test(item)) if (re.test(item))
delete macros[item]; macros.remove(item);
} }
}, },
@@ -1130,7 +1125,7 @@ liberator.Events = function () //{{{
if (key == "q") // TODO: should not be hardcoded if (key == "q") // TODO: should not be hardcoded
{ {
liberator.modes.isRecording = false; liberator.modes.isRecording = false;
liberator.log("Recorded " + currentMacro + ": " + macros[currentMacro], 9); liberator.log("Recorded " + currentMacro + ": " + macros.get(currentMacro), 9);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;
@@ -1138,7 +1133,7 @@ liberator.Events = function () //{{{
else if (!(liberator.modes.extended & liberator.modes.INACTIVE_HINT) && else if (!(liberator.modes.extended & liberator.modes.INACTIVE_HINT) &&
!liberator.mappings.hasMap(liberator.mode, liberator.input.buffer + key)) !liberator.mappings.hasMap(liberator.mode, liberator.input.buffer + key))
{ {
macros[currentMacro] += key; macros.set(currentMacro, macros.get(currentMacro) + key);
} }
} }