1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-03 16:05:46 +01:00

Add Bookmark{Change,Remove} autocommands. Fix tags arg of BookmarkAdd, but keyword will still need BookmarkChange.

--HG--
extra : rebase_source : 2a3a37c3bf1743274ca875afbe110d85f70517d7
This commit is contained in:
Kris Maglione
2010-09-27 10:04:52 -04:00
parent 22594b6127
commit 3d5f29fa59
5 changed files with 27 additions and 17 deletions

View File

@@ -12,8 +12,8 @@ const DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png";
const Bookmarks = Module("bookmarks", {
init: function () {
storage.addObserver("bookmark-cache", function (key, event, arg) {
if (event == "add")
autocommands.trigger("BookmarkAdd", arg);
if (["add", "change", "remove"].indexOf(event) >= 0)
autocommands.trigger("Bookmark" + event[0].toUpperCase() + event.substr(1), arg);
statusline.updateUrl();
}, window);
},
@@ -43,6 +43,10 @@ const Bookmarks = Module("bookmarks", {
break;
}
if (tags) {
PlacesUtils.tagging.untagURI(uri, null);
PlacesUtils.tagging.tagURI(uri, tags);
}
if (id == undefined)
id = services.get("bookmarks").insertBookmark(
services.get("bookmarks")[starOnly ? "unfiledBookmarksFolder" : "bookmarksMenuFolder"],
@@ -52,10 +56,6 @@ const Bookmarks = Module("bookmarks", {
if (keyword)
services.get("bookmarks").setKeywordForBookmark(id, keyword);
if (tags) {
PlacesUtils.tagging.untagURI(uri, null);
PlacesUtils.tagging.tagURI(uri, tags);
}
}
catch (e) {
dactyl.log(e, 0);

View File

@@ -38,8 +38,13 @@ const BookmarkCache = Module("BookmarkCache", {
_deleteBookmark: function deleteBookmark(id) {
let length = this.bookmarks.length;
this.bookmarks = this.bookmarks.filter(function (item) item.id != id);
return this.bookmarks.length < length;
let result;
this.bookmarks = this.bookmarks.filter(function (item) {
if (item.id == id)
result = item;
return item.id != id;
});
return result;
},
_loadBookmark: function loadBookmark(node) {
@@ -126,8 +131,9 @@ const BookmarkCache = Module("BookmarkCache", {
}
},
onItemRemoved: function onItemRemoved(itemId, folder, index) {
if (this._deleteBookmark(itemId))
storage.fireEvent(name, "remove", itemId);
let result = this._deleteBookmark(itemId);
if (result)
storage.fireEvent(name, "remove", result);
},
onItemChanged: function onItemChanged(itemId, property, isAnnotation, value) {
if (isAnnotation)
@@ -136,9 +142,10 @@ const BookmarkCache = Module("BookmarkCache", {
if (bookmark) {
if (property == "tags")
value = tagging.getTagsForURI(util.newURI(bookmark.url), {});
if (property in bookmark)
if (property in bookmark) {
bookmark[property] = value;
storage.fireEvent(name, "change", itemId);
storage.fireEvent(name, "change", { __proto__: bookmark, changed: property });
}
}
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])

View File

@@ -27,8 +27,6 @@ BUGS:
- messages is still broken in several ways - needs testing.
=> it often overwrites the open command line while editing etc.
- <tags> and <keyword> autocmd 'keywords' are not available when adding a
bookmark - they're being set after the observer triggers the autocmd event.
- :messages is _very_ slow for message history of several thousand lines ->
Unresponsive Script: util.js:79 (sometimes xmlToDom() and elsewhere)

View File

@@ -11,6 +11,8 @@ const Config = Module("config", ConfigBase, {
autocommands: {
BookmarkAdd: "Triggered after a page is bookmarked",
BookmarkChange: "Triggered after a page's bookmark is changed",
BookmarkRemove: "Triggered after a page's bookmark is removed",
ColorScheme: "Triggered after a color scheme has been loaded",
DOMLoad: "Triggered when a page's DOM content has fully loaded",
DownloadPost: "Triggered when a download has completed",

View File

@@ -9,6 +9,8 @@
<dl tag="autocommand-list" replace="autocommand-list">
<dt>BookmarkAdd</dt> <dd>Triggered after a page is bookmarked</dd>
<dt>BookmarkChange</dt> <dd>Triggered after a page's bookmark is changed</dd>
<dt>BookmarkRemove</dt> <dd>Triggered after a page's bookmark is removed</dd>
<dt>ColorScheme</dt> <dd>Triggered after a color scheme has been loaded</dd>
<dt>DOMLoad</dt> <dd>Triggered when a page's DOM content has fully loaded</dd>
<dt>DownloadPost</dt> <dd>Triggered when a download has completed</dd>
@@ -29,9 +31,10 @@
<dt>&lt;title></dt> <dd>The page, bookmark or download title.</dd>
<dt>&lt;doc></dt> <dd>The document for which the event occurred. Only for <em>DOMLoad</em>, <em>PageLoad</em> and <em>PageLoadPre</em>.</dd>
<dt>&lt;tab></dt> <dd>The tab in which the event occurred. Only for <em>DOMLoad</em>, <em>PageLoad</em> and <em>PageLoadPre</em>.</dd>
<dt>&lt;tags></dt> <dd>The tags applied to &lt;url>. Only for <em>BookmarkAdd</em>.</dd>
<dt>&lt;keyword></dt> <dd>The keywords applied to the bookmark. Only for <em>BookmarkAdd</em>.</dd>
<dt>&lt;icon></dt> <dd>The icon associated with &lt;url>. Only for <em>BookmarkAdd</em>.</dd>
<dt>&lt;changed></dt> <dd>The name of the property that has changed. Only for <em>BookmarkChange</em>.</dd>
<dt>&lt;tags></dt> <dd>The tags applied to &lt;url>. Only for <em>Bookmark*</em>.</dd>
<dt>&lt;keyword></dt> <dd>The keywords applied to the bookmark. Only for <em>BookmarkChange</em>, <em>BookmarkRemove</em>.</dd>
<dt>&lt;icon></dt> <dd>The icon associated with &lt;url>. Only for <em>Bookmark*</em>.</dd>
<dt>&lt;size></dt> <dd>The size of a downloaded file. Only for <em>DownloadPost</em>.</dd>
<dt>&lt;file></dt> <dd>The target destination of a download. Only for <em>DownloadPost</em>.</dd>
<dt>&lt;state></dt> <dd>The new state. Only for "Fullscreen" and <em>PrivateMode</em>.</dd>