Anonymous avatar Anonymous committed 8b68c83

Not-yet-working impl of tb-autocomplete

Comments (0)

Files changed (2)

packages/tb-autocomplete/lib/main.js

+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is People.
+ *
+ * The Initial Developer of the Original Code is Mozilla.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Edward Lee <edilee@mozilla.com>
+ *   Michael Hanson <mhanson@mozilla.com>
+ *   Dan Mosedale <dmose@mozillamessaging.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+
+var port = 8777;
+var xhr = require("xhr");
+//var tabBrowser = require("tab-browser");
+var windowUtils = require("window-utils");
+
+// jetpack has issues with the one param form of Cu.import
+var jpworkaround = {};
+
+const Cm = Components.manager;
+Cu.import("resource://gre/modules/XPCOMUtils.jsm", jpworkaround);
+
+function acResult(searchString, result, resultList) {
+  this.searchResult = result;
+  this.searchString = searchString;
+  this._resultList = resultList; 
+} 
+acResult.prototype = {
+  get matchCount() resultList.length,
+  getValueAt: function(i) {
+    return "this is a value";
+  },
+  getCommentAt: function(i) {
+    return "this is a comment";
+  },
+  getImageAt: function(i) {
+    return null;
+  },
+  getStyleAt: function() "message",
+  removeValueAt: function() {},
+  QueryInterface: jpworkaround.XPCOMUtils.generateQI([Ci.nsIAutoCompleteResult])
+};
+
+
+// nsIAutoCompleteSearch to put keyword results from the db into autocomplete
+let showKeywords = let (T = {
+  startSearch: function(searchString, searchParam, previous, listener) {
+    
+    console.log("startSearch called");
+    
+    let keyword = searchString.toLowerCase();
+    
+    var req = new xhr.XMLHttpRequest();
+    //req.open("GET", "http://localhost:" + port + "/search-for-messages?string=" 
+    //         + keyword, true);
+    req.onreadystatechange = function () {
+      if (req.readyState == 4) {
+        if(req.status == 200)
+          console.log(req.responseText);  
+        else
+          console.log("Error loading page\n");  
+      }
+    };
+    //req.send(null);
+
+    let result = new acResult(searchString, 
+                              Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
+                              [1]);
+    // Inform the listener of the result
+    let done = function() listener.onSearchResult(T, result);
+
+    // If we got a search engine, inform the listener right away
+    if (true)
+      done();
+    // No matches, so wait a little to prevent other searches from stopping
+    else {
+      T.stopSearch();
+      result.searchResult = Ci.nsIAutoCompleteResult.RESULT_NOMATCH;
+      T.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+      T.timer.initWithCallback({ notify: done }, 500, T.timer.TYPE_ONE_SHOT);
+    }
+  },
+
+  // Cancel the nomatch timer if it hasn't triggered yet
+  stopSearch: function() {
+    if (T.timer == null)
+      return;
+    T.timer.cancel();
+    T.timer = null;
+  },
+
+  createInstance: function(outer, iid) showKeywords.QueryInterface(iid),
+  QueryInterface: jpworkaround.XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAutoCompleteSearch])
+}) T;
+
+// Register the keywords autocomplete search engine
+Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(
+  Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).
+  generateUUID(), "Thunderbird AutoCompleteSearch",
+  "@mozilla.org/autocomplete/search;1?name=tb-autocomplete", showKeywords);
+
+
+// a singleton to register our autocomplete component once per browser window
+function trackerDelegate() {
+}
+trackerDelegate.onTrack = function (window) {
+  console.log("onTrack called\n");
+  let urlbar = window.document.getElementById("urlbar");
+  console.log("urlbar = " + urlbar);  
+  urlbar.setAttribute("autocompletesearch", "tb-autocomplete " +
+    urlbar.getAttribute("autocompletesearch"));
+  console.log("autocomplete should have been registered");
+  console.log("acs: " + urlbar.getAttribute("autocompletesearch"));
+} 
+trackerDelegate.onUntrack = function(window) {
+  console.log("onUntrack called\n");
+}
+// new tracker
+var tracker = new windowUtils.WindowTracker(trackerDelegate);
+
+
+exports.main = function facescrape_main(options, callbacks) {
+  console.log("tb-autocomplete is running, yo!");
+}

packages/tb-autocomplete/package.json

+{
+    "id": "jid0-1gK2A5LmqVSjEyEIcQbk9BpFttw", 
+    "dependencies": [
+        "jetpack-core", 
+        "misc"
+    ], 
+    "description": "Make Firefox autocomplete pull results from Tb REST API", 
+    "author": "Dan Mosedale, Atul Varma, et al"
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.