1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-20 14:35:45 +01:00

Save option restore data until add-on is disabled. Cleanup preferences on uninstall.

This commit is contained in:
Kris Maglione
2011-07-29 05:29:06 -04:00
parent c165fd95be
commit a0de5d9e24
9 changed files with 180 additions and 130 deletions

View File

@@ -329,6 +329,7 @@ var Abbreviations = Module("abbreviations", {
args["-group"].add(modes, lhs, rhs);
}
}, {
identifier: "abbreviate",
completer: function (context, args) {
if (args.length == 1)
return completion.abbreviation(context, modes, args["-group"]);

View File

@@ -70,21 +70,36 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
autocommands.trigger("Leave", {});
},
// initially hide all GUI elements, they are later restored unless the user
// has :set go= or something similar in his config
hideGUI: function () {
let guioptions = config.guioptions;
for (let option in guioptions) {
guioptions[option].forEach(function (elem) {
try {
document.getElementById(elem).collapsed = true;
}
catch (e) {}
});
}
},
observers: {
"dactyl-cleanup": function dactyl_cleanup() {
"dactyl-cleanup": function dactyl_cleanup(subject, reason) {
let modules = dactyl.modules;
for (let mod in values(modules.moduleList.reverse())) {
mod.stale = true;
if ("cleanup" in mod)
this.trapErrors("cleanup", mod);
this.trapErrors("cleanup", mod, reason);
if ("destroy" in mod)
this.trapErrors("destroy", mod);
this.trapErrors("destroy", mod, reason);
}
for (let mod in values(modules.ownPropertyValues.reverse()))
if (mod instanceof Class && "INIT" in mod && "cleanup" in mod.INIT)
this.trapErrors(mod.cleanup, mod, dactyl, modules, window);
this.trapErrors(mod.cleanup, mod, dactyl, modules, window, reason);
for (let name in values(Object.getOwnPropertyNames(modules).reverse()))
try {
@@ -1547,19 +1562,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
get windows() [win for (win in iter(services.windowMediator.getEnumerator("navigator:browser"))) if (win.dactyl)],
}, {
// initially hide all GUI elements, they are later restored unless the user
// has :set go= or something similar in his config
hideGUI: function () {
let guioptions = config.guioptions;
for (let option in guioptions) {
guioptions[option].forEach(function (elem) {
try {
document.getElementById(elem).collapsed = true;
}
catch (e) {}
});
}
}
toolbarHidden: function hidden(elem) (elem.getAttribute("autohide") || elem.getAttribute("collapsed")) == "true"
}, {
events: function () {
events.listen(window, "click", dactyl.closure.onClick, true);
@@ -1664,7 +1667,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
// FIXME: cleanup
cleanupValue: config.cleanups.guioptions ||
"r" + [k for ([k, v] in iter(groups[1].opts))
if (!document.getElementById(v[1][0]).collapsed)].join(""),
if (!Dactyl.toolbarHidden(document.getElementById(v[1][0])))].join(""),
values: array(groups).map(function (g) [[k, v[0]] for ([k, v] in Iterator(g.opts))]).flatten(),
@@ -1938,8 +1941,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
var toolbox = document.getElementById("navigator-toolbox");
if (toolbox) {
let hidden = function hidden(elem) (elem.getAttribute("autohide") || elem.getAttribute("collapsed")) == "true";
let toolbarCommand = function (names, desc, action, filter) {
commands.add(names, desc,
function (args) {
@@ -1960,12 +1961,12 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
toolbarCommand(["toolbars[how]", "tbs[how]"], "Show the named toolbar",
function (toolbar) dactyl.setNodeVisible(toolbar, true),
function ({ item }) hidden(item));
function ({ item }) Dactyl.toolbarHidden(item));
toolbarCommand(["toolbarh[ide]", "tbh[ide]"], "Hide the named toolbar",
function (toolbar) dactyl.setNodeVisible(toolbar, false),
function ({ item }) !hidden(item));
function ({ item }) !Dactyl.toolbarHidden(item));
toolbarCommand(["toolbart[oggle]", "tbt[oggle]"], "Toggle the named toolbar",
function (toolbar) dactyl.setNodeVisible(toolbar, hidden(toolbar)));
function (toolbar) dactyl.setNodeVisible(toolbar, Dactyl.toolbarHidden(toolbar)));
}
commands.add(["time"],
@@ -2171,7 +2172,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
}
// TODO: we should have some class where all this guioptions stuff fits well
// Dactyl.hideGUI();
// dactyl.hideGUI();
if (dactyl.userEval("typeof document", null, "test.js") === "undefined")
jsmodules.__proto__ = XPCSafeJSObjectWrapper(window);

View File

@@ -507,86 +507,87 @@ var Mappings = Module("mappings", {
}
const opts = {
completer: function (context, args) {
let mapmodes = array.uniq(args["-modes"].map(findMode));
if (args.length == 1)
return completion.userMapping(context, mapmodes, args["-group"]);
if (args.length == 2) {
if (args["-javascript"])
return completion.javascript(context);
if (args["-ex"])
return completion.ex(context);
}
},
hereDoc: true,
literal: 1,
options: [
{
names: ["-arg", "-a"],
description: "Accept an argument after the requisite key press",
},
{
names: ["-builtin", "-b"],
description: "Execute this mapping as if there were no user-defined mappings"
},
{
names: ["-count", "-c"],
description: "Accept a count before the requisite key press"
},
{
names: ["-description", "-desc", "-d"],
description: "A description of this mapping",
default: /*L*/"User-defined mapping",
type: CommandOption.STRING
},
{
names: ["-ex", "-e"],
description: "Execute this mapping as an Ex command rather than keys"
},
contexts.GroupFlag("mappings"),
{
names: ["-javascript", "-js", "-j"],
description: "Execute this mapping as JavaScript rather than keys"
},
update({}, modeFlag, {
names: ["-modes", "-mode", "-m"],
type: CommandOption.LIST,
description: "Create this mapping in the given modes",
default: mapmodes || ["n", "v"]
}),
{
names: ["-nopersist", "-n"],
description: "Do not save this mapping to an auto-generated RC file"
},
{
names: ["-silent", "-s", "<silent>", "<Silent>"],
description: "Do not echo any generated keys to the command line"
}
],
serialize: function () {
return this.name != "map" ? [] :
array(mappings.userHives)
.filter(function (h) h.persist)
.map(function (hive) [
{
command: "map",
options: array([
hive.name !== "user" && ["-group", hive.name],
["-modes", uniqueModes(map.modes)],
["-description", map.description],
map.silent && ["-silent"]])
.filter(util.identity)
.toObject(),
arguments: [map.names[0]],
literalArg: map.rhs,
ignoreDefaults: true
}
for (map in userMappings(hive))
if (map.persist)
])
.flatten().array;
identifier: "map",
completer: function (context, args) {
let mapmodes = array.uniq(args["-modes"].map(findMode));
if (args.length == 1)
return completion.userMapping(context, mapmodes, args["-group"]);
if (args.length == 2) {
if (args["-javascript"])
return completion.javascript(context);
if (args["-ex"])
return completion.ex(context);
}
},
hereDoc: true,
literal: 1,
options: [
{
names: ["-arg", "-a"],
description: "Accept an argument after the requisite key press",
},
{
names: ["-builtin", "-b"],
description: "Execute this mapping as if there were no user-defined mappings"
},
{
names: ["-count", "-c"],
description: "Accept a count before the requisite key press"
},
{
names: ["-description", "-desc", "-d"],
description: "A description of this mapping",
default: /*L*/"User-defined mapping",
type: CommandOption.STRING
},
{
names: ["-ex", "-e"],
description: "Execute this mapping as an Ex command rather than keys"
},
contexts.GroupFlag("mappings"),
{
names: ["-javascript", "-js", "-j"],
description: "Execute this mapping as JavaScript rather than keys"
},
update({}, modeFlag, {
names: ["-modes", "-mode", "-m"],
type: CommandOption.LIST,
description: "Create this mapping in the given modes",
default: mapmodes || ["n", "v"]
}),
{
names: ["-nopersist", "-n"],
description: "Do not save this mapping to an auto-generated RC file"
},
{
names: ["-silent", "-s", "<silent>", "<Silent>"],
description: "Do not echo any generated keys to the command line"
}
],
serialize: function () {
return this.name != "map" ? [] :
array(mappings.userHives)
.filter(function (h) h.persist)
.map(function (hive) [
{
command: "map",
options: array([
hive.name !== "user" && ["-group", hive.name],
["-modes", uniqueModes(map.modes)],
["-description", map.description],
map.silent && ["-silent"]])
.filter(util.identity)
.toObject(),
arguments: [map.names[0]],
literalArg: map.rhs,
ignoreDefaults: true
}
for (map in userMappings(hive))
if (map.persist)
])
.flatten().array;
}
};
function userMappings(hive) {
let seen = {};
@@ -629,6 +630,7 @@ var Mappings = Module("mappings", {
dactyl.echoerr(_("map.noSuch", args[0]));
},
{
identifier: "unmap",
argCount: "?",
bang: true,
completer: opts.completer,