1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-10 06:15:45 +01:00

Make buffer.URL a string again. Use buffer.uri and buffer.documentURI internally. Fix loading Object stores.

This commit is contained in:
Kris Maglione
2011-01-16 12:14:43 -05:00
parent 7d178cfb34
commit 5b56624043
10 changed files with 42 additions and 35 deletions

View File

@@ -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.

View File

@@ -207,7 +207,7 @@ var AutoCommands = Module("autocommands", {
return void dactyl.echomsg("No matching autocommands");
let [event, url] = args;
let defaultURL = url || buffer.URL.spec;
let defaultURL = url || buffer.uri.spec;
let validEvents = Object.keys(config.autocommands);
// TODO: add command validators
@@ -224,7 +224,7 @@ var AutoCommands = Module("autocommands", {
for (let i = 0; i < tabs.count; i++) {
tabs.select(i);
// 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);

View File

@@ -134,7 +134,7 @@ var Bookmarks = Module("bookmarks", {
if (count > 0)
dactyl.echomsg({ domains: [util.getHost(url)], message: "Removed bookmark: " + url });
else {
let title = buffer.URL.spec == url && buffer.title || url;
let title = buffer.uri.spec == url && buffer.title || url;
let extra = "";
if (title != url)
extra = " (" + title + ")";
@@ -453,7 +453,7 @@ var Bookmarks = Module("bookmarks", {
post: args["-post"],
tags: args["-tags"] || [],
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)) {
@@ -523,7 +523,7 @@ var Bookmarks = Module("bookmarks", {
});
else {
if (!(args.length || args["-tags"] || args["-keyword"] || args["-title"]))
var deletedCount = bookmarks.remove(buffer.URL.spec);
var deletedCount = bookmarks.remove(buffer.uri.spec);
else {
let context = CompletionContext(args.join(" "));
context.fork("bookmark", 0, completion, "bookmark",
@@ -555,7 +555,7 @@ var Bookmarks = Module("bookmarks", {
function () {
let options = {};
let url = buffer.URL.spec;
let url = buffer.uri.spec;
let bmarks = bookmarks.get(url).filter(function (bmark) bmark.url == url);
if (bmarks.length == 1) {
@@ -572,20 +572,20 @@ var Bookmarks = Module("bookmarks", {
options["-tags"] = bmark.tags.join(", ");
}
else {
if (buffer.title != buffer.URL.spec)
if (buffer.title != buffer.uri.spec)
options["-title"] = buffer.title;
if (content.document.characterSet !== "UTF-8")
options["-charset"] = content.document.characterSet;
}
commandline.open(":",
commands.commandToString({ command: "bmark", options: options, arguments: [buffer.URL.spec] }),
commands.commandToString({ command: "bmark", options: options, arguments: [buffer.uri.spec] }),
modes.EX);
});
mappings.add(myModes, ["A"],
"Toggle bookmarked state of current URL",
function () { bookmarks.toggle(buffer.URL.spec); });
function () { bookmarks.toggle(buffer.uri.spec); });
},
options: function () {
options.add(["defsearch", "ds"],

View File

@@ -14,18 +14,18 @@
var Browser = Module("browser", {
}, {
climbUrlPath: function (count) {
let url = buffer.URI.clone();
let url = buffer.documentURI.clone();
dactyl.assert(url instanceof Ci.nsIURL);
while (count-- && url.path != "/")
url.path = url.path.replace(/[^\/]+\/*$/, "");
dactyl.assert(!url.equals(buffer.URI));
dactyl.assert(!url.equals(buffer.documentURI));
dactyl.open(url.spec);
},
incrementURL: function (count) {
let matches = buffer.URL.spec.match(/(.*?)(\d+)(\D*)$/);
let matches = buffer.uri.spec.match(/(.*?)(\d+)(\D*)$/);
dactyl.assert(matches);
let oldNum = matches[2];
@@ -66,7 +66,7 @@ var Browser = Module("browser", {
mappings: function () {
mappings.add([modes.NORMAL],
["y"], "Yank current location to the clipboard",
function () { dactyl.clipboardWrite(buffer.URL.spec, true); });
function () { dactyl.clipboardWrite(buffer.uri.spec, true); });
// opening websites
mappings.add([modes.NORMAL],
@@ -75,7 +75,7 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL], ["O"],
"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"],
"Open one or more URLs in a new tab",
@@ -83,7 +83,7 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL], ["T"],
"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"],
"Open one or more URLs in a new window",
@@ -91,7 +91,7 @@ var Browser = Module("browser", {
mappings.add([modes.NORMAL], ["W"],
"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],
["<C-a>"], "Increment last number in URL",

View File

@@ -387,15 +387,24 @@ var Buffer = Module("buffer", {
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.
*/
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.

View File

@@ -310,16 +310,16 @@ var CommandLine = Module("commandline", {
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"]))
if (storage.exists("history-" + name)) {
let ary = storage.newArray("history-" + name, { store: true, privateData: true });
this._store.set(name, [v for ([k, v] in ary)]);
ary.remove();
ary.delete();
this._store.changed();
}
this._store.changed();
this._messageHistory = { //{{{
_messages: [],

View File

@@ -1272,7 +1272,7 @@ var Events = Module("events", {
"Pass certain keys through directly for the given URLs",
"regexpmap", "", {
has: function (key) {
let url = buffer.URI.spec;
let url = buffer.documentURI.spec;
for (let re in values(this.value))
if (re.test(url) && re.result.some(function (k) k === key))
return true;

View File

@@ -144,7 +144,7 @@ var QuickMarks = Module("quickmarks", {
dactyl.assert(/^[a-zA-Z0-9]$/.test(args[0]),
"E191: Argument must be an ASCII letter or digit");
if (!args[1])
quickmarks.add(args[0], buffer.URL.spec);
quickmarks.add(args[0], buffer.uri.spec);
else
quickmarks.add(args[0], args[1]);
},
@@ -198,7 +198,7 @@ var QuickMarks = Module("quickmarks", {
["M"], "Add new QuickMark for current URL",
function ({ arg }) {
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 });
}

View File

@@ -120,7 +120,7 @@ var StatusLine = Module("statusline", {
* respectively.
*
* @param {string} url The URL to display.
* @default buffer.URL
* @default buffer.uri
*/
updateUrl: function updateUrl(url) {
// ripped from Firefox; modified
@@ -155,7 +155,7 @@ var StatusLine = Module("statusline", {
// TODO: this probably needs a more general solution.
if (url == null)
url = buffer.URL.spec;
url = buffer.uri.spec;
// when session information is available, add [+] when we can go
// backwards, [-] when we can go forwards
@@ -168,7 +168,7 @@ var StatusLine = Module("statusline", {
modified += "-";
}
if (modules.bookmarks) {
if (bookmarks.isBookmarked(buffer.URL))
if (bookmarks.isBookmarked(buffer.uri))
modified += UTF8("❤");
//modified += UTF8("♥");
}

View File

@@ -4,7 +4,6 @@
// given in the LICENSE.txt file included with this file.
"use strict";
var myObject = Object;
Components.utils.import("resource://dactyl/bootstrap.jsm");
defineModule("storage", {
exports: ["File", "storage"],
@@ -12,6 +11,7 @@ defineModule("storage", {
}, this);
var win32 = /^win(32|nt)$/i.test(services.runtime.OS);
var myObject = JSON.parse("{}").constructor;
function loadData(name, store, type) {
try {
@@ -55,7 +55,7 @@ var StoreBase = Class("StoreBase", {
this.fireEvent("change", null);
},
remove: function remove() {
delete: function delete() {
delete storage.keys[this.name];
delete storage[this.name];
storage.infoPath.child(this.name).remove(false);