mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-04-03 08:43:31 +02:00
Make buffer.URL a string again. Use buffer.uri and buffer.documentURI internally. Fix loading Object stores.
This commit is contained in:
@@ -1,3 +1 @@
|
|||||||
- buffer.URL and buffer.URI are now instances of nsIURI rather than strings.
|
|
||||||
The former string representation may be obtained via the spec property.
|
|
||||||
See https://developer.mozilla.org/en/nsIURI for more details.
|
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ var AutoCommands = Module("autocommands", {
|
|||||||
return void dactyl.echomsg("No matching autocommands");
|
return void dactyl.echomsg("No matching autocommands");
|
||||||
|
|
||||||
let [event, url] = args;
|
let [event, url] = args;
|
||||||
let defaultURL = url || buffer.URL.spec;
|
let defaultURL = url || buffer.uri.spec;
|
||||||
let validEvents = Object.keys(config.autocommands);
|
let validEvents = Object.keys(config.autocommands);
|
||||||
|
|
||||||
// TODO: add command validators
|
// TODO: add command validators
|
||||||
@@ -224,7 +224,7 @@ var AutoCommands = Module("autocommands", {
|
|||||||
for (let i = 0; i < tabs.count; i++) {
|
for (let i = 0; i < tabs.count; i++) {
|
||||||
tabs.select(i);
|
tabs.select(i);
|
||||||
// if no url arg is specified use the current buffer's URL
|
// if no url arg is specified use the current buffer's URL
|
||||||
autocommands.trigger(event, { url: url || buffer.URL.spec });
|
autocommands.trigger(event, { url: url || buffer.uri.spec });
|
||||||
}
|
}
|
||||||
|
|
||||||
tabs.select(current);
|
tabs.select(current);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
if (count > 0)
|
if (count > 0)
|
||||||
dactyl.echomsg({ domains: [util.getHost(url)], message: "Removed bookmark: " + url });
|
dactyl.echomsg({ domains: [util.getHost(url)], message: "Removed bookmark: " + url });
|
||||||
else {
|
else {
|
||||||
let title = buffer.URL.spec == url && buffer.title || url;
|
let title = buffer.uri.spec == url && buffer.title || url;
|
||||||
let extra = "";
|
let extra = "";
|
||||||
if (title != url)
|
if (title != url)
|
||||||
extra = " (" + title + ")";
|
extra = " (" + title + ")";
|
||||||
@@ -453,7 +453,7 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
post: args["-post"],
|
post: args["-post"],
|
||||||
tags: args["-tags"] || [],
|
tags: args["-tags"] || [],
|
||||||
title: args["-title"] || (args.length === 0 ? buffer.title : null),
|
title: args["-title"] || (args.length === 0 ? buffer.title : null),
|
||||||
url: args.length === 0 ? buffer.URL.spec : args[0]
|
url: args.length === 0 ? buffer.uri.spec : args[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (bookmarks.add(opts)) {
|
if (bookmarks.add(opts)) {
|
||||||
@@ -523,7 +523,7 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
});
|
});
|
||||||
else {
|
else {
|
||||||
if (!(args.length || args["-tags"] || args["-keyword"] || args["-title"]))
|
if (!(args.length || args["-tags"] || args["-keyword"] || args["-title"]))
|
||||||
var deletedCount = bookmarks.remove(buffer.URL.spec);
|
var deletedCount = bookmarks.remove(buffer.uri.spec);
|
||||||
else {
|
else {
|
||||||
let context = CompletionContext(args.join(" "));
|
let context = CompletionContext(args.join(" "));
|
||||||
context.fork("bookmark", 0, completion, "bookmark",
|
context.fork("bookmark", 0, completion, "bookmark",
|
||||||
@@ -555,7 +555,7 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
function () {
|
function () {
|
||||||
let options = {};
|
let options = {};
|
||||||
|
|
||||||
let url = buffer.URL.spec;
|
let url = buffer.uri.spec;
|
||||||
let bmarks = bookmarks.get(url).filter(function (bmark) bmark.url == url);
|
let bmarks = bookmarks.get(url).filter(function (bmark) bmark.url == url);
|
||||||
|
|
||||||
if (bmarks.length == 1) {
|
if (bmarks.length == 1) {
|
||||||
@@ -572,20 +572,20 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
options["-tags"] = bmark.tags.join(", ");
|
options["-tags"] = bmark.tags.join(", ");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (buffer.title != buffer.URL.spec)
|
if (buffer.title != buffer.uri.spec)
|
||||||
options["-title"] = buffer.title;
|
options["-title"] = buffer.title;
|
||||||
if (content.document.characterSet !== "UTF-8")
|
if (content.document.characterSet !== "UTF-8")
|
||||||
options["-charset"] = content.document.characterSet;
|
options["-charset"] = content.document.characterSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
commandline.open(":",
|
commandline.open(":",
|
||||||
commands.commandToString({ command: "bmark", options: options, arguments: [buffer.URL.spec] }),
|
commands.commandToString({ command: "bmark", options: options, arguments: [buffer.uri.spec] }),
|
||||||
modes.EX);
|
modes.EX);
|
||||||
});
|
});
|
||||||
|
|
||||||
mappings.add(myModes, ["A"],
|
mappings.add(myModes, ["A"],
|
||||||
"Toggle bookmarked state of current URL",
|
"Toggle bookmarked state of current URL",
|
||||||
function () { bookmarks.toggle(buffer.URL.spec); });
|
function () { bookmarks.toggle(buffer.uri.spec); });
|
||||||
},
|
},
|
||||||
options: function () {
|
options: function () {
|
||||||
options.add(["defsearch", "ds"],
|
options.add(["defsearch", "ds"],
|
||||||
|
|||||||
@@ -14,18 +14,18 @@
|
|||||||
var Browser = Module("browser", {
|
var Browser = Module("browser", {
|
||||||
}, {
|
}, {
|
||||||
climbUrlPath: function (count) {
|
climbUrlPath: function (count) {
|
||||||
let url = buffer.URI.clone();
|
let url = buffer.documentURI.clone();
|
||||||
dactyl.assert(url instanceof Ci.nsIURL);
|
dactyl.assert(url instanceof Ci.nsIURL);
|
||||||
|
|
||||||
while (count-- && url.path != "/")
|
while (count-- && url.path != "/")
|
||||||
url.path = url.path.replace(/[^\/]+\/*$/, "");
|
url.path = url.path.replace(/[^\/]+\/*$/, "");
|
||||||
|
|
||||||
dactyl.assert(!url.equals(buffer.URI));
|
dactyl.assert(!url.equals(buffer.documentURI));
|
||||||
dactyl.open(url.spec);
|
dactyl.open(url.spec);
|
||||||
},
|
},
|
||||||
|
|
||||||
incrementURL: function (count) {
|
incrementURL: function (count) {
|
||||||
let matches = buffer.URL.spec.match(/(.*?)(\d+)(\D*)$/);
|
let matches = buffer.uri.spec.match(/(.*?)(\d+)(\D*)$/);
|
||||||
dactyl.assert(matches);
|
dactyl.assert(matches);
|
||||||
let oldNum = matches[2];
|
let oldNum = matches[2];
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ var Browser = Module("browser", {
|
|||||||
mappings: function () {
|
mappings: function () {
|
||||||
mappings.add([modes.NORMAL],
|
mappings.add([modes.NORMAL],
|
||||||
["y"], "Yank current location to the clipboard",
|
["y"], "Yank current location to the clipboard",
|
||||||
function () { dactyl.clipboardWrite(buffer.URL.spec, true); });
|
function () { dactyl.clipboardWrite(buffer.uri.spec, true); });
|
||||||
|
|
||||||
// opening websites
|
// opening websites
|
||||||
mappings.add([modes.NORMAL],
|
mappings.add([modes.NORMAL],
|
||||||
@@ -75,7 +75,7 @@ var Browser = Module("browser", {
|
|||||||
|
|
||||||
mappings.add([modes.NORMAL], ["O"],
|
mappings.add([modes.NORMAL], ["O"],
|
||||||
"Open one or more URLs, based on current location",
|
"Open one or more URLs, based on current location",
|
||||||
function () { commandline.open(":", "open " + buffer.URL.spec, modes.EX); });
|
function () { commandline.open(":", "open " + buffer.uri.spec, modes.EX); });
|
||||||
|
|
||||||
mappings.add([modes.NORMAL], ["t"],
|
mappings.add([modes.NORMAL], ["t"],
|
||||||
"Open one or more URLs in a new tab",
|
"Open one or more URLs in a new tab",
|
||||||
@@ -83,7 +83,7 @@ var Browser = Module("browser", {
|
|||||||
|
|
||||||
mappings.add([modes.NORMAL], ["T"],
|
mappings.add([modes.NORMAL], ["T"],
|
||||||
"Open one or more URLs in a new tab, based on current location",
|
"Open one or more URLs in a new tab, based on current location",
|
||||||
function () { commandline.open(":", "tabopen " + buffer.URL.spec, modes.EX); });
|
function () { commandline.open(":", "tabopen " + buffer.uri.spec, modes.EX); });
|
||||||
|
|
||||||
mappings.add([modes.NORMAL], ["w"],
|
mappings.add([modes.NORMAL], ["w"],
|
||||||
"Open one or more URLs in a new window",
|
"Open one or more URLs in a new window",
|
||||||
@@ -91,7 +91,7 @@ var Browser = Module("browser", {
|
|||||||
|
|
||||||
mappings.add([modes.NORMAL], ["W"],
|
mappings.add([modes.NORMAL], ["W"],
|
||||||
"Open one or more URLs in a new window, based on current location",
|
"Open one or more URLs in a new window, based on current location",
|
||||||
function () { commandline.open(":", "winopen " + buffer.URL.spec, modes.EX); });
|
function () { commandline.open(":", "winopen " + buffer.uri.spec, modes.EX); });
|
||||||
|
|
||||||
mappings.add([modes.NORMAL],
|
mappings.add([modes.NORMAL],
|
||||||
["<C-a>"], "Increment last number in URL",
|
["<C-a>"], "Increment last number in URL",
|
||||||
|
|||||||
@@ -387,15 +387,24 @@ var Buffer = Module("buffer", {
|
|||||||
set lastInputField(value) { this.localStore.lastInputField = value && Cu.getWeakReference(value); },
|
set lastInputField(value) { this.localStore.lastInputField = value && Cu.getWeakReference(value); },
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {string} The current top-level document's URL.
|
* @property {nsIURI} The current top-level document's URI.
|
||||||
*/
|
*/
|
||||||
get URL() util.newURI(content.location.href),
|
get uri() util.newURI(content.location.href),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {string} The current top-level document's URL, sans any
|
* @property {nsIURI} The current top-level document's URI, sans any
|
||||||
* fragment identifier.
|
* fragment identifier.
|
||||||
*/
|
*/
|
||||||
get URI() let (doc = content.document) doc.documentURIObject || util.newURI(doc.documentURI),
|
get documentURI() let (doc = content.document) doc.documentURIObject || util.newURI(doc.documentURI),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {string} The current top-level document's URL.
|
||||||
|
*/
|
||||||
|
get URL() {
|
||||||
|
let str = String(content.location.href);
|
||||||
|
for (let [k, v] in Iterator(util.newURI(content.location.href)))
|
||||||
|
str[k] = v;
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} The buffer's height in pixels.
|
* @property {number} The buffer's height in pixels.
|
||||||
|
|||||||
@@ -310,16 +310,16 @@ var CommandLine = Module("commandline", {
|
|||||||
|
|
||||||
this._callbacks = {};
|
this._callbacks = {};
|
||||||
|
|
||||||
this._store = storage.newMap("command-history", { store: true, privateData: true });
|
memoize(this, "_store", function () storage.newMap("command-history", { store: true, privateData: true }));
|
||||||
|
|
||||||
for (let name in values(["command", "search"]))
|
for (let name in values(["command", "search"]))
|
||||||
if (storage.exists("history-" + name)) {
|
if (storage.exists("history-" + name)) {
|
||||||
let ary = storage.newArray("history-" + name, { store: true, privateData: true });
|
let ary = storage.newArray("history-" + name, { store: true, privateData: true });
|
||||||
|
|
||||||
this._store.set(name, [v for ([k, v] in ary)]);
|
this._store.set(name, [v for ([k, v] in ary)]);
|
||||||
ary.remove();
|
ary.delete();
|
||||||
|
this._store.changed();
|
||||||
}
|
}
|
||||||
this._store.changed();
|
|
||||||
|
|
||||||
this._messageHistory = { //{{{
|
this._messageHistory = { //{{{
|
||||||
_messages: [],
|
_messages: [],
|
||||||
|
|||||||
@@ -1272,7 +1272,7 @@ var Events = Module("events", {
|
|||||||
"Pass certain keys through directly for the given URLs",
|
"Pass certain keys through directly for the given URLs",
|
||||||
"regexpmap", "", {
|
"regexpmap", "", {
|
||||||
has: function (key) {
|
has: function (key) {
|
||||||
let url = buffer.URI.spec;
|
let url = buffer.documentURI.spec;
|
||||||
for (let re in values(this.value))
|
for (let re in values(this.value))
|
||||||
if (re.test(url) && re.result.some(function (k) k === key))
|
if (re.test(url) && re.result.some(function (k) k === key))
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ var QuickMarks = Module("quickmarks", {
|
|||||||
dactyl.assert(/^[a-zA-Z0-9]$/.test(args[0]),
|
dactyl.assert(/^[a-zA-Z0-9]$/.test(args[0]),
|
||||||
"E191: Argument must be an ASCII letter or digit");
|
"E191: Argument must be an ASCII letter or digit");
|
||||||
if (!args[1])
|
if (!args[1])
|
||||||
quickmarks.add(args[0], buffer.URL.spec);
|
quickmarks.add(args[0], buffer.uri.spec);
|
||||||
else
|
else
|
||||||
quickmarks.add(args[0], args[1]);
|
quickmarks.add(args[0], args[1]);
|
||||||
},
|
},
|
||||||
@@ -198,7 +198,7 @@ var QuickMarks = Module("quickmarks", {
|
|||||||
["M"], "Add new QuickMark for current URL",
|
["M"], "Add new QuickMark for current URL",
|
||||||
function ({ arg }) {
|
function ({ arg }) {
|
||||||
dactyl.assert(/^[a-zA-Z0-9]$/.test(arg), "E191: Argument must be an ASCII letter or digit");
|
dactyl.assert(/^[a-zA-Z0-9]$/.test(arg), "E191: Argument must be an ASCII letter or digit");
|
||||||
quickmarks.add(arg, buffer.URL.spec);
|
quickmarks.add(arg, buffer.uri.spec);
|
||||||
},
|
},
|
||||||
{ arg: true });
|
{ arg: true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ var StatusLine = Module("statusline", {
|
|||||||
* respectively.
|
* respectively.
|
||||||
*
|
*
|
||||||
* @param {string} url The URL to display.
|
* @param {string} url The URL to display.
|
||||||
* @default buffer.URL
|
* @default buffer.uri
|
||||||
*/
|
*/
|
||||||
updateUrl: function updateUrl(url) {
|
updateUrl: function updateUrl(url) {
|
||||||
// ripped from Firefox; modified
|
// ripped from Firefox; modified
|
||||||
@@ -155,7 +155,7 @@ var StatusLine = Module("statusline", {
|
|||||||
|
|
||||||
// TODO: this probably needs a more general solution.
|
// TODO: this probably needs a more general solution.
|
||||||
if (url == null)
|
if (url == null)
|
||||||
url = buffer.URL.spec;
|
url = buffer.uri.spec;
|
||||||
|
|
||||||
// when session information is available, add [+] when we can go
|
// when session information is available, add [+] when we can go
|
||||||
// backwards, [-] when we can go forwards
|
// backwards, [-] when we can go forwards
|
||||||
@@ -168,7 +168,7 @@ var StatusLine = Module("statusline", {
|
|||||||
modified += "-";
|
modified += "-";
|
||||||
}
|
}
|
||||||
if (modules.bookmarks) {
|
if (modules.bookmarks) {
|
||||||
if (bookmarks.isBookmarked(buffer.URL))
|
if (bookmarks.isBookmarked(buffer.uri))
|
||||||
modified += UTF8("❤");
|
modified += UTF8("❤");
|
||||||
//modified += UTF8("♥");
|
//modified += UTF8("♥");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
// given in the LICENSE.txt file included with this file.
|
// given in the LICENSE.txt file included with this file.
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var myObject = Object;
|
|
||||||
Components.utils.import("resource://dactyl/bootstrap.jsm");
|
Components.utils.import("resource://dactyl/bootstrap.jsm");
|
||||||
defineModule("storage", {
|
defineModule("storage", {
|
||||||
exports: ["File", "storage"],
|
exports: ["File", "storage"],
|
||||||
@@ -12,6 +11,7 @@ defineModule("storage", {
|
|||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
var win32 = /^win(32|nt)$/i.test(services.runtime.OS);
|
var win32 = /^win(32|nt)$/i.test(services.runtime.OS);
|
||||||
|
var myObject = JSON.parse("{}").constructor;
|
||||||
|
|
||||||
function loadData(name, store, type) {
|
function loadData(name, store, type) {
|
||||||
try {
|
try {
|
||||||
@@ -55,7 +55,7 @@ var StoreBase = Class("StoreBase", {
|
|||||||
this.fireEvent("change", null);
|
this.fireEvent("change", null);
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function remove() {
|
delete: function delete() {
|
||||||
delete storage.keys[this.name];
|
delete storage.keys[this.name];
|
||||||
delete storage[this.name];
|
delete storage[this.name];
|
||||||
storage.infoPath.child(this.name).remove(false);
|
storage.infoPath.child(this.name).remove(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user