]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/content/bookmarks.js
Import 1.0b7.1 supporting Firefox up to 8.*
[dactyl.git] / common / content / bookmarks.js
index ade210df2b7cac3033ced3a768d1ab1516a9ef21..1ce6ee11a1bd2ff156ade600f6e8230e218dbcdf 100644 (file)
@@ -11,6 +11,10 @@ var DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png";
 // also includes methods for dealing with keywords and search engines
 var Bookmarks = Module("bookmarks", {
     init: function () {
+        this.timer = Timer(0, 100, function () {
+            this.checkBookmarked(buffer.uri);
+        }, this);
+
         storage.addObserver("bookmark-cache", function (key, event, arg) {
             if (["add", "change", "remove"].indexOf(event) >= 0)
                 autocommands.trigger("Bookmark" + event[0].toUpperCase() + event.substr(1),
@@ -20,10 +24,17 @@ var Bookmarks = Module("bookmarks", {
                              valueOf: function () arg
                          }
                      }, arg));
-            statusline.updateStatus();
+            bookmarks.timer.tell();
         }, window);
     },
 
+    signals: {
+        "browser.locationChange": function (webProgress, request, uri) {
+            statusline.bookmarked = false;
+            this.checkBookmarked(uri);
+        }
+    },
+
     get format() ({
         anchored: false,
         title: ["URL", "Info"],
@@ -103,7 +114,7 @@ var Bookmarks = Module("bookmarks", {
      *
      * @param {Element} elem A form element for which to add a keyword.
      */
-    addSearchKeyword: function (elem) {
+    addSearchKeyword: function addSearchKeyword(elem) {
         if (elem instanceof HTMLFormElement || elem.form)
             var [url, post, charset] = util.parseForm(elem);
         else
@@ -119,6 +130,17 @@ var Bookmarks = Module("bookmarks", {
             commands.commandToString({ command: "bmark", options: options, arguments: [url] }) + " -keyword ");
     },
 
+    checkBookmarked: function checkBookmarked(uri) {
+        if (PlacesUtils.asyncGetBookmarkIds)
+            PlacesUtils.asyncGetBookmarkIds(uri, function (ids) {
+                statusline.bookmarked = ids.length;
+            });
+        else
+            this.timeout(function () {
+                statusline.bookmarked = bookmarkcache.isBookmarked(uri);
+            });
+    },
+
     /**
      * Toggles the bookmarked state of the given URL. If the URL is
      * bookmarked, all bookmarks for said URL are removed.
@@ -197,7 +219,7 @@ var Bookmarks = Module("bookmarks", {
             if (!alias)
                 alias = "search"; // for search engines which we can't find a suitable alias
 
-            if (set.has(aliases, alias))
+            if (Set.has(aliases, alias))
                 alias += ++aliases[alias];
             else
                 aliases[alias] = 0;
@@ -225,7 +247,7 @@ var Bookmarks = Module("bookmarks", {
     getSuggestions: function getSuggestions(engineName, query, callback) {
         const responseType = "application/x-suggestions+json";
 
-        let engine = set.has(this.searchEngines, engineName) && this.searchEngines[engineName];
+        let engine = Set.has(this.searchEngines, engineName) && this.searchEngines[engineName];
         if (engine && engine.supportsResponseType(responseType))
             var queryURI = engine.getSubmission(query, responseType).uri.spec;
         if (!queryURI)
@@ -274,7 +296,7 @@ var Bookmarks = Module("bookmarks", {
             param = query.substr(offset + 1);
         }
 
-        var engine = set.has(bookmarks.searchEngines, keyword) && bookmarks.searchEngines[keyword];
+        var engine = Set.has(bookmarks.searchEngines, keyword) && bookmarks.searchEngines[keyword];
         if (engine) {
             if (engine.searchForm && !param)
                 return engine.searchForm;
@@ -381,8 +403,8 @@ var Bookmarks = Module("bookmarks", {
             completer: function title(context, args) {
                 let frames = buffer.allFrames();
                 if (!args.bang)
-                    return  [
-                        [win.document.title, frames.length == 1 ? "Current Location" : "Frame: " + win.location.href]
+                    return [
+                        [win.document.title, frames.length == 1 ? /*L*/"Current Location" : /*L*/"Frame: " + win.location.href]
                         for ([, win] in Iterator(frames))];
                 context.keys.text = "title";
                 context.keys.description = "url";
@@ -442,7 +464,7 @@ var Bookmarks = Module("bookmarks", {
                         context.title = ["Page URL"];
                         let frames = buffer.allFrames();
                         context.completions = [
-                            [win.document.documentURI, frames.length == 1 ? "Current Location" : "Frame: " + win.document.title]
+                            [win.document.documentURI, frames.length == 1 ? /*L*/"Current Location" : /*L*/"Frame: " + win.document.title]
                             for ([, win] in Iterator(frames))];
                         return;
                     }
@@ -485,11 +507,11 @@ var Bookmarks = Module("bookmarks", {
             "Delete a bookmark",
             function (args) {
                 if (args.bang)
-                    commandline.input("This will delete all bookmarks. Would you like to continue? (yes/[no]) ",
+                    commandline.input(_("bookmark.prompt.deleteAll") + " ",
                         function (resp) {
                             if (resp && resp.match(/^y(es)?$/i)) {
                                 bookmarks.remove(Object.keys(bookmarkcache.bookmarks));
-                                dactyl.echomsg(_("bookmark.allGone"));
+                                dactyl.echomsg(_("bookmark.allDeleted"));
                             }
                         });
                 else {
@@ -499,7 +521,7 @@ var Bookmarks = Module("bookmarks", {
                         let context = CompletionContext(args.join(" "));
                         context.fork("bookmark", 0, completion, "bookmark",
                                      args["-tags"], { keyword: args["-keyword"], title: args["-title"] });
-                        var deletedCount = bookmarks.remove(context.allItems.items.map(function (item) item.item.id));
+                        deletedCount = bookmarks.remove(context.allItems.items.map(function (item) item.item.id));
                     }
 
                     dactyl.echomsg({ message: _("bookmark.deleted", deletedCount) });
@@ -604,7 +626,7 @@ var Bookmarks = Module("bookmarks", {
             if (item && item.url.indexOf("%s") > -1)
                 context.fork("keyword/" + keyword, keyword.length + space.length, null, function (context) {
                     context.format = history.format;
-                    context.title = [keyword + " Quick Search"];
+                    context.title = [/*L*/keyword + " Quick Search"];
                     // context.background = true;
                     context.compare = CompletionContext.Sort.unsorted;
                     context.generate = function () {
@@ -649,7 +671,7 @@ var Bookmarks = Module("bookmarks", {
                     return;
                 let ctxt = context.fork(name, 0);
 
-                ctxt.title = [engine.description + " Suggestions"];
+                ctxt.title = [/*L*/engine.description + " Suggestions"];
                 ctxt.keys = { text: util.identity, description: function () "" };
                 ctxt.compare = CompletionContext.Sort.unsorted;
                 ctxt.filterFunc = null;