mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-28 15:45:46 +01:00
Constify certain script global properties. Provide 'unload' method.
--HG-- branch : groups
This commit is contained in:
@@ -157,6 +157,8 @@ var Contexts = Module("contexts", {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
Context: modules.Script = function Context(file, group, args) {
|
Context: modules.Script = function Context(file, group, args) {
|
||||||
|
function Const(val) Class.Property({ enumerable: true, value: val });
|
||||||
|
|
||||||
let isPlugin = io.getRuntimeDirectories("plugins")
|
let isPlugin = io.getRuntimeDirectories("plugins")
|
||||||
.some(function (dir) dir.contains(file, false))
|
.some(function (dir) dir.contains(file, false))
|
||||||
|
|
||||||
@@ -167,9 +169,18 @@ var Contexts = Module("contexts", {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self = update(modules.newContext.apply(null, args || [userContext]), {
|
self = update(modules.newContext.apply(null, args || [userContext]), {
|
||||||
NAME: file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()),
|
NAME: Const(file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase())),
|
||||||
PATH: file.path,
|
PATH: Const(file.path),
|
||||||
CONTEXT: self
|
CONTEXT: Const(self),
|
||||||
|
unload: Const(function unload() {
|
||||||
|
if (plugins[this.NAME] === this || plugins[this.PATH] === this)
|
||||||
|
if (this.onUnload)
|
||||||
|
this.onUnload();
|
||||||
|
if (plugins[this.NAME] === this)
|
||||||
|
delete plugins[this.NAME];
|
||||||
|
if (plugins[this.PATH] === this)
|
||||||
|
delete plugins[this.PATH];
|
||||||
|
})
|
||||||
});
|
});
|
||||||
Class.replaceProperty(plugins, file.path, self);
|
Class.replaceProperty(plugins, file.path, self);
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ var IO = Module("io", {
|
|||||||
params = params || {};
|
params = params || {};
|
||||||
|
|
||||||
let time = Date.now();
|
let time = Date.now();
|
||||||
contexts.withSavedValues(["context"], function _source() {
|
return contexts.withSavedValues(["context"], function _source() {
|
||||||
contexts.context = null;
|
contexts.context = null;
|
||||||
try {
|
try {
|
||||||
var file = util.getFile(filename) || io.File(filename);
|
var file = util.getFile(filename) || io.File(filename);
|
||||||
@@ -172,7 +172,8 @@ var IO = Module("io", {
|
|||||||
// handle pure JavaScript files specially
|
// handle pure JavaScript files specially
|
||||||
if (/\.js$/.test(filename)) {
|
if (/\.js$/.test(filename)) {
|
||||||
try {
|
try {
|
||||||
dactyl.loadScript(uri.spec, Contexts.Script(file, params.group));
|
var context = Contexts.Script(file, params.group);
|
||||||
|
dactyl.loadScript(uri.spec, context);
|
||||||
dactyl.helpInitialized = false;
|
dactyl.helpInitialized = false;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
@@ -190,7 +191,7 @@ var IO = Module("io", {
|
|||||||
else if (/\.css$/.test(filename))
|
else if (/\.css$/.test(filename))
|
||||||
styles.registerSheet(uri.spec, false, true);
|
styles.registerSheet(uri.spec, false, true);
|
||||||
else {
|
else {
|
||||||
let context = Contexts.Context(file, params.group);
|
context = Contexts.Context(file, params.group);
|
||||||
modules.commands.execute(file.read(), null, params.silent || "loud",
|
modules.commands.execute(file.read(), null, params.silent || "loud",
|
||||||
null, {
|
null, {
|
||||||
context: context,
|
context: context,
|
||||||
@@ -206,6 +207,7 @@ var IO = Module("io", {
|
|||||||
dactyl.echomsg("finished sourcing " + filename.quote(), 2);
|
dactyl.echomsg("finished sourcing " + filename.quote(), 2);
|
||||||
|
|
||||||
dactyl.log("Sourced: " + filename, 3);
|
dactyl.log("Sourced: " + filename, 3);
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (!(e instanceof FailedAssertion))
|
if (!(e instanceof FailedAssertion))
|
||||||
|
|||||||
Reference in New Issue
Block a user