1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 07:07:58 +01:00

Another attempt at revision 8613b76cff40.

This commit is contained in:
Kris Maglione
2011-02-03 09:48:10 -05:00
parent e470de350c
commit d48dcd8723
16 changed files with 149 additions and 111 deletions

View File

@@ -62,7 +62,7 @@ var Bookmarks = Module("bookmarks", {
try { try {
let uri = util.createURI(url); let uri = util.createURI(url);
if (!force && this.isBookmarked(uri)) if (!force && bookmarkcache.isBookmarked(uri))
for (var bmark in bookmarkcache) for (var bmark in bookmarkcache)
if (bmark.url == uri.spec) { if (bmark.url == uri.spec) {
if (title) if (title)
@@ -146,26 +146,7 @@ var Bookmarks = Module("bookmarks", {
} }
}, },
/** isBookmarked: deprecated("bookmarkcache.isBookmarked", { get: function isBookmarked() bookmarkcache.closure.isBookmarked }),
* Returns true if the given URL is bookmarked and that bookmark is
* not a Live Bookmark.
*
* @param {nsIURI|string} url The URL of which to check the bookmarked
* state.
* @returns {boolean}
*/
isBookmarked: function isBookmarked(uri) {
if (isString(uri))
uri = util.newURI(uri);
try {
return services.bookmarks
.getBookmarkIdsForURI(uri, {})
.some(bookmarkcache.closure.isRegularBookmark);
}
catch (e) {
return false;
}
},
/** /**
* Remove a bookmark or bookmarks. If *ids* is an array, removes the * Remove a bookmark or bookmarks. If *ids* is an array, removes the

View File

@@ -1008,7 +1008,7 @@ var Buffer = Module("buffer", {
function (opt) template.map(buffer.pageInfo[opt][0](), util.identity, ", "), function (opt) template.map(buffer.pageInfo[opt][0](), util.identity, ", "),
", "); ", ");
if (bookmarks.isBookmarked(this.URL)) if (bookmarkcache.isBookmarked(this.URL))
info += ", bookmarked"; info += ", bookmarked";
let pageInfoText = <>{file.quote()} [{info}] {title}</>; let pageInfoText = <>{file.quote()} [{info}] {title}</>;
@@ -1640,9 +1640,9 @@ var Buffer = Module("buffer", {
}; };
}, },
events: function () { events: function () {
events.addSessionListener(config.browser, "DOMContentLoaded", this.closure.onDOMContentLoaded, true); events.addSessionListener(config.browser, "DOMContentLoaded", buffer.closure.onDOMContentLoaded, true);
events.addSessionListener(config.browser, "load", this.closure.onPageLoad, true); events.addSessionListener(config.browser, "load", buffer.closure.onPageLoad, true);
events.addSessionListener(config.browser, "scroll", this.closure._updateBufferPosition, false); events.addSessionListener(config.browser, "scroll", buffer.closure._updateBufferPosition, false);
}, },
mappings: function () { mappings: function () {
var myModes = config.browserModes; var myModes = config.browserModes;

View File

@@ -468,7 +468,7 @@ var Commands = Module("commands", {
_addCommand: function (args, replace) { _addCommand: function (args, replace) {
if (!args[3]) if (!args[3])
args[3] = {}; args[3] = {};
args[3].definedAt = commands.getCaller(Components.stack.caller.caller); args[3].definedAt = Commands.getCaller(Components.stack.caller.caller);
let names = array.flatten(Command.parseSpecs(args[0])); let names = array.flatten(Command.parseSpecs(args[0]));
args.parsedSpecs = names; args.parsedSpecs = names;
@@ -659,23 +659,6 @@ var Commands = Module("commands", {
return this._exCommands.filter(function (cmd) cmd.user); return this._exCommands.filter(function (cmd) cmd.user);
}, },
/**
* Returns a frame object describing the currently executing
* command, if applicable, otherwise returns the passed frame.
*
* @param {nsIStackFrame} frame
*/
getCaller: function (frame) {
if (io.sourcing)
return {
__proto__: frame,
filename: io.sourcing.file[0] == "[" ? io.sourcing.file :
services.io.newFileURI(File(io.sourcing.file)).spec,
lineNumber: io.sourcing.line
};
return frame;
},
/** /**
* Returns true if a command invocation contains a URL referring to the * Returns true if a command invocation contains a URL referring to the
* domain *host*. * domain *host*.
@@ -1179,6 +1162,23 @@ var Commands = Module("commands", {
delete this._exMap[name]; delete this._exMap[name];
} }
}, { }, {
/**
* Returns a frame object describing the currently executing
* command, if applicable, otherwise returns the passed frame.
*
* @param {nsIStackFrame} frame
*/
getCaller: function (frame) {
if (io.sourcing)
return {
__proto__: frame,
filename: io.sourcing.file[0] == "[" ? io.sourcing.file :
services.io.newFileURI(File(io.sourcing.file)).spec,
lineNumber: io.sourcing.line
};
return frame;
},
// returns [count, parsed_argument] // returns [count, parsed_argument]
parseArg: function parseArg(str, sep, keepQuotes) { parseArg: function parseArg(str, sep, keepQuotes) {
let arg = ""; let arg = "";
@@ -1552,7 +1552,7 @@ var Commands = Module("commands", {
}); });
}, },
javascript: function () { javascript: function () {
JavaScript.setCompleter([this.get, this.removeUserCommand], JavaScript.setCompleter([commands.get, commands.removeUserCommand],
[function () ([c.name, c.description] for (c in commands))]); [function () ([c.name, c.description] for (c in commands))]);
}, },
mappings: function () { mappings: function () {

View File

@@ -2023,52 +2023,51 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
dactyl.log("All modules loaded", 3); dactyl.log("All modules loaded", 3);
try { dactyl.timeout(function () {
var args = services.fuel && services.fuel.storage.get("dactyl.commandlineArgs", null) try {
|| services.commandLineHandler.optionValue; var args = services.fuel && services.fuel.storage.get("dactyl.commandlineArgs", null)
if (isString(args)) || services.commandLineHandler.optionValue;
args = dactyl.parseCommandLine(args); if (isString(args))
args = dactyl.parseCommandLine(args);
if (args) { if (args) {
dactyl.commandLineOptions.rcFile = args["+u"]; dactyl.commandLineOptions.rcFile = args["+u"];
dactyl.commandLineOptions.noPlugins = "++noplugin" in args; dactyl.commandLineOptions.noPlugins = "++noplugin" in args;
dactyl.commandLineOptions.postCommands = args["+c"]; dactyl.commandLineOptions.postCommands = args["+c"];
dactyl.commandLineOptions.preCommands = args["++cmd"]; dactyl.commandLineOptions.preCommands = args["++cmd"];
util.dump("Processing command-line option: " + args.string); util.dump("Processing command-line option: " + args.string);
}
}
catch (e) {
dactyl.echoerr("Parsing command line options: " + e);
} }
}
catch (e) {
dactyl.echoerr("Parsing command line options: " + e);
}
dactyl.log("Command-line options: " + util.objectToString(dactyl.commandLineOptions), 3); dactyl.log("Command-line options: " + util.objectToString(dactyl.commandLineOptions), 3);
// first time intro message // first time intro message
const firstTime = "extensions." + config.name + ".firsttime"; const firstTime = "extensions." + config.name + ".firsttime";
if (prefs.get(firstTime, true)) { if (prefs.get(firstTime, true)) {
dactyl.timeout(function () { dactyl.timeout(function () {
this.withSavedValues(["forceNewTab"], function () { this.withSavedValues(["forceNewTab"], function () {
this.forceNewTab = true; this.forceNewTab = true;
this.help(); this.help();
prefs.set(firstTime, false); prefs.set(firstTime, false);
});
}, 1000);
}
// TODO: we should have some class where all this guioptions stuff fits well
// Dactyl.hideGUI();
if (dactyl.userEval("typeof document", null, "test.js") === "undefined")
jsmodules.__proto__ = XPCSafeJSObjectWrapper(window);
if (dactyl.commandLineOptions.preCommands)
dactyl.commandLineOptions.preCommands.forEach(function (cmd) {
dactyl.execute(cmd);
}); });
}, 1000);
}
// TODO: we should have some class where all this guioptions stuff fits well // finally, read the RC file and source plugins
// Dactyl.hideGUI();
if (dactyl.userEval("typeof document", null, "test.js") === "undefined")
jsmodules.__proto__ = XPCSafeJSObjectWrapper(window);
if (dactyl.commandLineOptions.preCommands)
dactyl.commandLineOptions.preCommands.forEach(function (cmd) {
dactyl.execute(cmd);
});
// finally, read the RC file and source plugins
// make sourcing asynchronous, otherwise commands that open new tabs won't work
util.timeout(function () {
let init = services.environment.get(config.idName + "_INIT"); let init = services.environment.get(config.idName + "_INIT");
let rcFile = io.getRCFile("~"); let rcFile = io.getRCFile("~");
@@ -2121,7 +2120,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
dactyl.fullyInitialized = true; dactyl.fullyInitialized = true;
dactyl.triggerObserver("enter", null); dactyl.triggerObserver("enter", null);
autocommands.trigger("Enter", {}); autocommands.trigger("Enter", {});
}, 0); }, 100);
statusline.update(); statusline.update();
dactyl.log(config.appName + " fully initialized", 0); dactyl.log(config.appName + " fully initialized", 0);

View File

@@ -172,7 +172,7 @@ var MapHive = Class("MapHive", {
extra = extra || {}; extra = extra || {};
let map = Map(modes, keys, description, action, extra); let map = Map(modes, keys, description, action, extra);
map.definedAt = commands.getCaller(Components.stack.caller); map.definedAt = Commands.getCaller(Components.stack.caller);
map.hive = this; map.hive = this;
if (this.name !== "builtin") if (this.name !== "builtin")
@@ -344,7 +344,7 @@ var Mappings = Module("mappings", {
*/ */
add: function () { add: function () {
let map = this.builtin.add.apply(this.builtin, arguments); let map = this.builtin.add.apply(this.builtin, arguments);
map.definedAt = commands.getCaller(Components.stack.caller); map.definedAt = Commands.getCaller(Components.stack.caller);
return map; return map;
}, },
@@ -361,7 +361,7 @@ var Mappings = Module("mappings", {
*/ */
addUserMap: function () { addUserMap: function () {
let map = this.user.add.apply(this.user, arguments); let map = this.user.add.apply(this.user, arguments);
map.definedAt = commands.getCaller(Components.stack.caller); map.definedAt = Commands.getCaller(Components.stack.caller);
return map; return map;
}, },

View File

@@ -208,7 +208,7 @@ var Marks = Module("marks", {
events: function () { events: function () {
let appContent = document.getElementById("appcontent"); let appContent = document.getElementById("appcontent");
if (appContent) if (appContent)
events.addSessionListener(appContent, "load", this.closure._onPageLoad, true); events.addSessionListener(appContent, "load", marks.closure._onPageLoad, true);
}, },
mappings: function () { mappings: function () {
var myModes = config.browserModes; var myModes = config.browserModes;

View File

@@ -660,7 +660,7 @@ var Options = Module("options", {
if (!extraInfo) if (!extraInfo)
extraInfo = {}; extraInfo = {};
extraInfo.definedAt = commands.getCaller(Components.stack.caller); extraInfo.definedAt = Commands.getCaller(Components.stack.caller);
let name = names[0]; let name = names[0];
if (name in this._optionMap) { if (name in this._optionMap) {
@@ -973,7 +973,7 @@ var Options = Module("options", {
} }
if (res) if (res)
dactyl.echoerr(res); dactyl.echoerr(res);
option.setFrom = commands.getCaller(null); option.setFrom = Commands.getCaller(null);
} }
} }
flushList(); flushList();

View File

@@ -168,8 +168,8 @@ var StatusLine = Module("statusline", {
if (sh && sh.index < sh.count - 1) if (sh && sh.index < sh.count - 1)
modified += "-"; modified += "-";
} }
if (modules.bookmarks) { if (modules.bookmarkcache) {
if (bookmarks.isBookmarked(buffer.uri)) if (bookmarkcache.isBookmarked(buffer.uri))
modified += UTF8("❤"); modified += UTF8("❤");
//modified += UTF8("♥"); //modified += UTF8("♥");
} }

View File

@@ -875,7 +875,7 @@ var Tabs = Module("tabs", {
} }
for (let event in values(["TabMove", "TabOpen", "TabClose"])) for (let event in values(["TabMove", "TabOpen", "TabClose"]))
events.addSessionListener(tabContainer, event, callback, false); events.addSessionListener(tabContainer, event, callback, false);
events.addSessionListener(tabContainer, "TabSelect", this.closure._onTabSelect, false); events.addSessionListener(tabContainer, "TabSelect", tabs.closure._onTabSelect, false);
}, },
mappings: function () { mappings: function () {
mappings.add([modes.NORMAL], ["g0", "g^"], mappings.add([modes.NORMAL], ["g0", "g^"],

View File

@@ -147,6 +147,9 @@ defineModule.modules = [];
defineModule.times = { all: 0 }; defineModule.times = { all: 0 };
defineModule.time = function time(major, minor, func, self) { defineModule.time = function time(major, minor, func, self) {
let time = Date.now(); let time = Date.now();
if (typeof func !== "function")
func = self[func];
try { try {
var res = func.apply(self, Array.slice(arguments, 4)); var res = func.apply(self, Array.slice(arguments, 4));
} }
@@ -913,7 +916,7 @@ Module.INIT = {
for (let i in locals) for (let i in locals)
module = objs[i] = Object.create(module); module = objs[i] = Object.create(module);
modules[this.constructor.className] = module; modules.jsmodules[this.constructor.className] = module;
locals.reverse().forEach(function (fn, i) update(objs[i], fn.apply(module, args))) locals.reverse().forEach(function (fn, i) update(objs[i], fn.apply(module, args)))
module.instance = module; module.instance = module;
module.init(); module.init();

View File

@@ -117,6 +117,28 @@ var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
isBookmark: function (id) this.rootFolders.indexOf(this.findRoot(id)) >= 0, isBookmark: function (id) this.rootFolders.indexOf(this.findRoot(id)) >= 0,
/**
* Returns true if the given URL is bookmarked and that bookmark is
* not a Live Bookmark.
*
* @param {nsIURI|string} url The URL of which to check the bookmarked
* state.
* @returns {boolean}
*/
isBookmarked: function isBookmarked(uri) {
if (isString(uri))
uri = util.newURI(uri);
try {
return services.bookmarks
.getBookmarkIdsForURI(uri, {})
.some(this.closure.isRegularBookmark);
}
catch (e) {
return false;
}
},
isRegularBookmark: function isRegularBookmark(id) { isRegularBookmark: function isRegularBookmark(id) {
do { do {
var root = id; var root = id;

View File

@@ -844,7 +844,7 @@ var Completion = Module("completion", {
get setFunctionCompleter() JavaScript.setCompleter, // Backward compatibility get setFunctionCompleter() JavaScript.setCompleter, // Backward compatibility
Local: function (dactyl, modules, window) ({ Local: function (dactyl, modules, window) ({
options: modules.options, get options() modules.options,
// FIXME // FIXME
_runCompleter: function _runCompleter(name, filter, maxItems) { _runCompleter: function _runCompleter(name, filter, maxItems) {

View File

@@ -162,7 +162,7 @@ var RangeFinder = Module("rangefinder", {
}, { }, {
}, { }, {
modes: function (dactyl, modules, window) { modes: function (dactyl, modules, window) {
const { commandline, modes } = modules; const { modes } = modules;
modes.addMode("FIND", { modes.addMode("FIND", {
extended: true, extended: true,
description: "Find mode, active when typing search input", description: "Find mode, active when typing search input",

View File

@@ -679,9 +679,11 @@ var JavaScript = Module("javascript", {
init.superapply(this, arguments); init.superapply(this, arguments);
}, },
completion: function (dactyl, modules, window) { completion: function (dactyl, modules, window) {
const { completion, javascript } = modules; const { completion } = modules;
completion.javascript = javascript.closure.complete; update(modules.completion, {
completion.javascriptCompleter = JavaScript; // Backwards compatibility. get javascript() modules.javascript.closure.complete,
javascriptCompleter: JavaScript // Backwards compatibility
});
}, },
options: function (dactyl, modules, window) { options: function (dactyl, modules, window) {
modules.options.add(["jsdebugger", "jsd"], modules.options.add(["jsdebugger", "jsd"],

View File

@@ -246,9 +246,11 @@ var Overlay = Module("Overlay", {
defineModule.loadLog.push(" from: " + util.fixURI(frame.filename) + ":" + frame.lineNumber); defineModule.loadLog.push(" from: " + util.fixURI(frame.filename) + ":" + frame.lineNumber);
delete modules[module.className]; delete modules[module.className];
// util.dump("INIT: " + module.className);
modules[module.className] = defineModule.time(module.className, "init", module); modules[module.className] = defineModule.time(module.className, "init", module);
frob(module.className);
init(modules[module.className]); // init(modules[module.className]);
} }
catch (e) { catch (e) {
util.dump("Loading " + (module && module.className) + ":"); util.dump("Loading " + (module && module.className) + ":");
@@ -257,16 +259,45 @@ var Overlay = Module("Overlay", {
return modules[module.className]; return modules[module.className];
} }
for each (let module in defineModule.modules) Module.list.forEach(function (mod) {
if (module.INIT.init) Object.keys(mod.prototype.INIT).forEach(function (name) {
defineModule.time(module.constructor.className, "init", deferredInit[name] = deferredInit[name] || [];
module.INIT.init, module, deferredInit[name].push(function () {
modules.dactyl, modules, window); // util.dump("INIT: " + mod.className + ":" + name);
defineModule.time(mod.className, name,
name, mod.prototype.INIT,
modules.dactyl, modules, window);
});
});
});
defineModule.modules.forEach(function (mod) {
Object.keys(mod.INIT).forEach(function (name) {
deferredInit[name] = deferredInit[name] || [];
deferredInit[name].push(function () {
// util.dump("INIT: " + mod.constructor.className + ":" + name);
defineModule.time(mod.constructor.className, name,
mod.INIT[name], mod,
modules.dactyl, modules, window);
});
});
});
defineModule.modules.map(init); function frob(name) {
// util.dump(" ======================== FROB " + name + " ======================== ");
(deferredInit[name] || []).forEach(call);
}
Module.list.forEach(load); frob("init");
deferredInit["load"].forEach(call); defineModule.modules.forEach(function ({ constructor: { className } }) {
modules.__defineGetter__(className, function () {
delete modules[className];
frob(className);
return modules[className];
});
});
// Module.list.forEach(load);
frob("load");
modules.times = update({}, defineModule.times); modules.times = update({}, defineModule.times);
defineModule.loadLog.push("Loaded in " + (Date.now() - start) + "ms"); defineModule.loadLog.push("Loaded in " + (Date.now() - start) + "ms");

View File

@@ -278,7 +278,7 @@ var Config = Module("config", ConfigBase, {
}); });
}, },
completion: function (dactyl, modules, window) { completion: function (dactyl, modules, window) {
const { CompletionContext, bookmarkcache, bookmarks, completion } = modules; const { CompletionContext, bookmarkcache, completion } = modules;
const { document } = window; const { document } = window;
var searchRunning = null; // only until Firefox fixes https://bugzilla.mozilla.org/show_bug.cgi?id=510589 var searchRunning = null; // only until Firefox fixes https://bugzilla.mozilla.org/show_bug.cgi?id=510589
@@ -297,7 +297,7 @@ var Config = Module("config", ConfigBase, {
context.hasItems = context.completions.length > 0; // XXX context.hasItems = context.completions.length > 0; // XXX
context.incomplete = true; context.incomplete = true;
context.format = bookmarks.format; context.format = modules.bookmarks.format;
context.keys.extra = function (item) (bookmarkcache.get(item.url) || {}).extra; context.keys.extra = function (item) (bookmarkcache.get(item.url) || {}).extra;
context.title = ["Smart Completions"]; context.title = ["Smart Completions"];