From 3d5f29fa59d77408c772a877e0dfdefd41452530 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 27 Sep 2010 10:04:52 -0400 Subject: [PATCH] Add Bookmark{Change,Remove} autocommands. Fix tags arg of BookmarkAdd, but keyword will still need BookmarkChange. --HG-- extra : rebase_source : 2a3a37c3bf1743274ca875afbe110d85f70517d7 --- common/content/bookmarks.js | 12 ++++++------ common/modules/bookmarkcache.jsm | 19 +++++++++++++------ pentadactyl/TODO | 2 -- pentadactyl/content/config.js | 2 ++ pentadactyl/locale/en-US/autocommands.xml | 9 ++++++--- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 70677a64..0b311cd8 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -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); diff --git a/common/modules/bookmarkcache.jsm b/common/modules/bookmarkcache.jsm index 4ebbe3d3..31301f12 100644 --- a/common/modules/bookmarkcache.jsm +++ b/common/modules/bookmarkcache.jsm @@ -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]) diff --git a/pentadactyl/TODO b/pentadactyl/TODO index 8e61ac82..eb7dd72e 100644 --- a/pentadactyl/TODO +++ b/pentadactyl/TODO @@ -27,8 +27,6 @@ BUGS: - messages is still broken in several ways - needs testing. => it often overwrites the open command line while editing etc. -- and 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) diff --git a/pentadactyl/content/config.js b/pentadactyl/content/config.js index a025b6da..7ad14109 100644 --- a/pentadactyl/content/config.js +++ b/pentadactyl/content/config.js @@ -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", diff --git a/pentadactyl/locale/en-US/autocommands.xml b/pentadactyl/locale/en-US/autocommands.xml index 96e71dec..e28799c9 100644 --- a/pentadactyl/locale/en-US/autocommands.xml +++ b/pentadactyl/locale/en-US/autocommands.xml @@ -9,6 +9,8 @@
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
@@ -29,9 +31,10 @@
<title>
The page, bookmark or download title.
<doc>
The document for which the event occurred. Only for DOMLoad, PageLoad and PageLoadPre.
<tab>
The tab in which the event occurred. Only for DOMLoad, PageLoad and PageLoadPre.
-
<tags>
The tags applied to <url>. Only for BookmarkAdd.
-
<keyword>
The keywords applied to the bookmark. Only for BookmarkAdd.
-
<icon>
The icon associated with <url>. Only for BookmarkAdd.
+
<changed>
The name of the property that has changed. Only for BookmarkChange.
+
<tags>
The tags applied to <url>. Only for Bookmark*.
+
<keyword>
The keywords applied to the bookmark. Only for BookmarkChange, BookmarkRemove.
+
<icon>
The icon associated with <url>. Only for Bookmark*.
<size>
The size of a downloaded file. Only for DownloadPost.
<file>
The target destination of a download. Only for DownloadPost.
<state>
The new state. Only for "Fullscreen" and PrivateMode.