mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-25 15:55:46 +01:00
Added :bmark -id, changed updating semantincs, update URLs in cache, and reported updates as updates rather than additions.
This commit is contained in:
@@ -63,49 +63,54 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
* Otherwise, if a bookmark for the given URL exists it is
|
* Otherwise, if a bookmark for the given URL exists it is
|
||||||
* updated instead.
|
* updated instead.
|
||||||
* @optional
|
* @optional
|
||||||
* @returns {boolean} True if the bookmark was added or updated
|
* @returns {boolean} True if the bookmark was updated, false if a
|
||||||
* successfully.
|
* new bookmark was added.
|
||||||
*/
|
*/
|
||||||
add: function add(unfiled, title, url, keyword, tags, force) {
|
add: function add(unfiled, title, url, keyword, tags, force) {
|
||||||
// FIXME
|
// FIXME
|
||||||
if (isObject(unfiled))
|
if (isObject(unfiled))
|
||||||
var { unfiled, title, url, keyword, tags, post, charset, force } = unfiled;
|
var { id, unfiled, title, url, keyword, tags, post, charset, force } = unfiled;
|
||||||
|
|
||||||
try {
|
let uri = util.createURI(url);
|
||||||
let uri = util.createURI(url);
|
if (id != null)
|
||||||
if (!force && bookmarkcache.isBookmarked(uri))
|
var bmark = bookmarkcache.bookmarks[id];
|
||||||
for (var bmark in bookmarkcache)
|
else if (!force) {
|
||||||
if (bmark.url == uri.spec) {
|
if (keyword && Set.has(bookmarkcache.keywords, keyword))
|
||||||
if (title)
|
bmark = bookmarkcache.keywords[keyword];
|
||||||
bmark.title = title;
|
else if (bookmarkcache.isBookmarked(uri))
|
||||||
|
for (bmark in bookmarkcache)
|
||||||
|
if (bmark.url == uri.spec)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (tags) {
|
|
||||||
PlacesUtils.tagging.untagURI(uri, null);
|
|
||||||
PlacesUtils.tagging.tagURI(uri, tags);
|
|
||||||
}
|
|
||||||
if (bmark == undefined)
|
|
||||||
bmark = bookmarkcache.bookmarks[
|
|
||||||
services.bookmarks.insertBookmark(
|
|
||||||
services.bookmarks[unfiled ? "unfiledBookmarksFolder" : "bookmarksMenuFolder"],
|
|
||||||
uri, -1, title || url)];
|
|
||||||
if (!bmark)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (charset !== undefined)
|
|
||||||
bmark.charset = charset;
|
|
||||||
if (post !== undefined)
|
|
||||||
bmark.post = post;
|
|
||||||
if (keyword)
|
|
||||||
bmark.keyword = keyword;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
util.reportError(e);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
if (tags) {
|
||||||
|
PlacesUtils.tagging.untagURI(uri, null);
|
||||||
|
PlacesUtils.tagging.tagURI(uri, tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
let updated = !!bmark;
|
||||||
|
if (bmark == undefined)
|
||||||
|
bmark = bookmarkcache.bookmarks[
|
||||||
|
services.bookmarks.insertBookmark(
|
||||||
|
services.bookmarks[unfiled ? "unfiledBookmarksFolder" : "bookmarksMenuFolder"],
|
||||||
|
uri, -1, title || url)];
|
||||||
|
else {
|
||||||
|
if (title)
|
||||||
|
bmark.title = title;
|
||||||
|
if (!uri.equals(bmark.uri))
|
||||||
|
bmark.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
util.assert(bmark);
|
||||||
|
|
||||||
|
if (charset !== undefined)
|
||||||
|
bmark.charset = charset;
|
||||||
|
if (post !== undefined)
|
||||||
|
bmark.post = post;
|
||||||
|
if (keyword)
|
||||||
|
bmark.keyword = keyword;
|
||||||
|
|
||||||
|
return updated;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,6 +168,7 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
let extra = "";
|
let extra = "";
|
||||||
if (title != url)
|
if (title != url)
|
||||||
extra = " (" + title + ")";
|
extra = " (" + title + ")";
|
||||||
|
|
||||||
this.add({ unfiled: true, title: title, url: url });
|
this.add({ unfiled: true, title: title, url: url });
|
||||||
dactyl.echomsg({ domains: [util.getHost(url)], message: _("bookmark.added", url + extra) });
|
dactyl.echomsg({ domains: [util.getHost(url)], message: _("bookmark.added", url + extra) });
|
||||||
}
|
}
|
||||||
@@ -438,9 +444,13 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
commands.add(["bma[rk]"],
|
commands.add(["bma[rk]"],
|
||||||
"Add a bookmark",
|
"Add a bookmark",
|
||||||
function (args) {
|
function (args) {
|
||||||
|
dactyl.assert(!args.bang || args["-id"] == null,
|
||||||
|
_("bookmark.bangOrID"));
|
||||||
|
|
||||||
let opts = {
|
let opts = {
|
||||||
force: args.bang,
|
force: args.bang,
|
||||||
unfiled: false,
|
unfiled: false,
|
||||||
|
id: args["-id"],
|
||||||
keyword: args["-keyword"] || null,
|
keyword: args["-keyword"] || null,
|
||||||
charset: args["-charset"],
|
charset: args["-charset"],
|
||||||
post: args["-post"],
|
post: args["-post"],
|
||||||
@@ -449,13 +459,13 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
url: args.length === 0 ? buffer.uri.spec : args[0]
|
url: args.length === 0 ? buffer.uri.spec : args[0]
|
||||||
};
|
};
|
||||||
|
|
||||||
if (bookmarks.add(opts)) {
|
let updated = bookmarks.add(opts);
|
||||||
let extra = (opts.title == opts.url) ? "" : " (" + opts.title + ")";
|
let action = updated ? "updated" : "added";
|
||||||
dactyl.echomsg({ domains: [util.getHost(opts.url)], message: _("bookmark.added", opts.url + extra) },
|
|
||||||
1, commandline.FORCE_SINGLELINE);
|
let extra = (opts.title == opts.url) ? "" : " (" + opts.title + ")";
|
||||||
}
|
|
||||||
else
|
dactyl.echomsg({ domains: [util.getHost(opts.url)], message: _("bookmark." + action, opts.url + extra) },
|
||||||
dactyl.echoerr(_("bookmark.cantAdd", opts.title.quote()));
|
1, commandline.FORCE_SINGLELINE);
|
||||||
}, {
|
}, {
|
||||||
argCount: "?",
|
argCount: "?",
|
||||||
bang: true,
|
bang: true,
|
||||||
@@ -477,6 +487,11 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
type: CommandOption.STRING,
|
type: CommandOption.STRING,
|
||||||
completer: function (context) completion.charset(context),
|
completer: function (context) completion.charset(context),
|
||||||
validator: Option.validateCompleter
|
validator: Option.validateCompleter
|
||||||
|
},
|
||||||
|
{
|
||||||
|
names: ["-id"],
|
||||||
|
description: "The ID of the bookmark to update",
|
||||||
|
type: CommandOption.INT
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -553,6 +568,7 @@ var Bookmarks = Module("bookmarks", {
|
|||||||
if (bmarks.length == 1) {
|
if (bmarks.length == 1) {
|
||||||
let bmark = bmarks[0];
|
let bmark = bmarks[0];
|
||||||
|
|
||||||
|
options["-id"] = bmark.id;
|
||||||
options["-title"] = bmark.title;
|
options["-title"] = bmark.title;
|
||||||
if (bmark.charset)
|
if (bmark.charset)
|
||||||
options["-charset"] = bmark.charset;
|
options["-charset"] = bmark.charset;
|
||||||
|
|||||||
@@ -52,6 +52,10 @@
|
|||||||
sites that require query parameters in encodings other than
|
sites that require query parameters in encodings other than
|
||||||
UTF-8 (short name <em>-c</em>).
|
UTF-8 (short name <em>-c</em>).
|
||||||
</dd>
|
</dd>
|
||||||
|
<dt>-id</dt>
|
||||||
|
<dd>
|
||||||
|
The numerical ID of a bookmark to update.
|
||||||
|
</dd>
|
||||||
<dt>-keyword</dt>
|
<dt>-keyword</dt>
|
||||||
<dd>
|
<dd>
|
||||||
A keyword which may be used to open the bookmark via
|
A keyword which may be used to open the bookmark via
|
||||||
@@ -88,7 +92,7 @@
|
|||||||
<p>
|
<p>
|
||||||
If <oa>!</oa> is present, a new bookmark is always
|
If <oa>!</oa> is present, a new bookmark is always
|
||||||
added. Otherwise, the first bookmark matching
|
added. Otherwise, the first bookmark matching
|
||||||
<oa>url</oa> is updated.
|
<oa>id</oa>, <oa>keyword</oa>, or <oa>url</oa> is updated.
|
||||||
</p>
|
</p>
|
||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -33,10 +33,12 @@ bookmark.noMatching-2 = No bookmarks matching tags %S and string %S
|
|||||||
bookmark.noMatchingTags-1 = No bookmarks matching tags %S
|
bookmark.noMatchingTags-1 = No bookmarks matching tags %S
|
||||||
bookmark.noMatchingString-1 = No bookmarks matching string %S
|
bookmark.noMatchingString-1 = No bookmarks matching string %S
|
||||||
bookmark.none = No bookmarks set
|
bookmark.none = No bookmarks set
|
||||||
|
bookmark.bangOrID = Only one of ! or -id may be given
|
||||||
bookmark.cantAdd-1 = Could not add bookmark %S
|
bookmark.cantAdd-1 = Could not add bookmark %S
|
||||||
bookmark.allDeleted = All bookmarks deleted
|
bookmark.allDeleted = All bookmarks deleted
|
||||||
bookmark.removed-1 = Removed bookmark: %S
|
bookmark.removed-1 = Removed bookmark: %S
|
||||||
bookmark.added-1 = Added bookmark: %S
|
bookmark.added-1 = Added bookmark: %S
|
||||||
|
bookmark.updated-1 = Updated bookmark: %S
|
||||||
bookmark.deleted-1 = %S bookmark(s) deleted
|
bookmark.deleted-1 = %S bookmark(s) deleted
|
||||||
bookmark.prompt.deleteAll = This will delete all bookmarks. Would you like to continue? (yes/[no]):
|
bookmark.prompt.deleteAll = This will delete all bookmarks. Would you like to continue? (yes/[no]):
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ update(Bookmark.prototype, {
|
|||||||
].filter(function (item) item[1]),
|
].filter(function (item) item[1]),
|
||||||
|
|
||||||
get uri() util.newURI(this.url),
|
get uri() util.newURI(this.url),
|
||||||
|
set uri(uri) {
|
||||||
|
let tags = this.tags;
|
||||||
|
this.tags = null;
|
||||||
|
services.bookmarks.changeBookmarkURI(this.id, uri);
|
||||||
|
this.tags = tags;
|
||||||
|
},
|
||||||
|
|
||||||
encodeURIComponent: function _encodeURIComponent(str) {
|
encodeURIComponent: function _encodeURIComponent(str) {
|
||||||
if (!this.charset || this.charset === "UTF-8")
|
if (!this.charset || this.charset === "UTF-8")
|
||||||
@@ -28,15 +34,9 @@ update(Bookmark.prototype, {
|
|||||||
return escape(conv.ConvertFromUnicode(str) + conv.Finish());
|
return escape(conv.ConvertFromUnicode(str) + conv.Finish());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Bookmark.prototype.members.uri = Bookmark.prototype.members.url;
|
||||||
Bookmark.setter = function (key, func) this.prototype.__defineSetter__(key, func);
|
Bookmark.setter = function (key, func) this.prototype.__defineSetter__(key, func);
|
||||||
Bookmark.setter("url", function (val) {
|
Bookmark.setter("url", function (val) { this.uri = isString(val) ? util.newURI(val) : val; });
|
||||||
if (isString(val))
|
|
||||||
val = util.newURI(val);
|
|
||||||
let tags = this.tags;
|
|
||||||
this.tags = null;
|
|
||||||
services.bookmarks.changeBookmarkURI(this.id, val);
|
|
||||||
this.tags = tags;
|
|
||||||
});
|
|
||||||
Bookmark.setter("title", function (val) { services.bookmarks.setItemTitle(this.id, val); });
|
Bookmark.setter("title", function (val) { services.bookmarks.setItemTitle(this.id, val); });
|
||||||
Bookmark.setter("post", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.POST, val); });
|
Bookmark.setter("post", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.POST, val); });
|
||||||
Bookmark.setter("charset", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.CHARSET, val); });
|
Bookmark.setter("charset", function (val) { bookmarkcache.annotate(this.id, bookmarkcache.CHARSET, val); });
|
||||||
|
|||||||
@@ -741,7 +741,9 @@ var DOM = Class("DOM", {
|
|||||||
let win = this.document.defaultView;
|
let win = this.document.defaultView;
|
||||||
|
|
||||||
if (force || !(rect && rect.bottom <= win.innerHeight && rect.top >= 0 && rect.left < win.innerWidth && rect.right > 0))
|
if (force || !(rect && rect.bottom <= win.innerHeight && rect.top >= 0 && rect.left < win.innerWidth && rect.right > 0))
|
||||||
elem.scrollIntoView(alignWithTop !== undefined ? alignWithTop
|
elem.scrollIntoView(alignWithTop !== undefined ? alignWithTop :
|
||||||
|
rect.bottom < 0 ? true :
|
||||||
|
rect.top > win.innerHeight ? false
|
||||||
: Math.abs(rect.top) < Math.abs(win.innerHeight - rect.bottom));
|
: Math.abs(rect.top) < Math.abs(win.innerHeight - rect.bottom));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -105,6 +105,7 @@
|
|||||||
- :style now supports regexp site-filters on Firefox 6+. [b7]
|
- :style now supports regexp site-filters on Firefox 6+. [b7]
|
||||||
- :qa closes only the current window, per Vim. [b7]
|
- :qa closes only the current window, per Vim. [b7]
|
||||||
- Added :background command. [b8]
|
- Added :background command. [b8]
|
||||||
|
- Added -id flag to :bmark command and changed updating semantics. [b8]
|
||||||
- Added :exit command. [b7]
|
- Added :exit command. [b7]
|
||||||
- Added :dlclear command. [b7]
|
- Added :dlclear command. [b7]
|
||||||
- :extensions has been replaced with a more powerful :addons. [b6]
|
- :extensions has been replaced with a more powerful :addons. [b6]
|
||||||
|
|||||||
Reference in New Issue
Block a user