2 * (C) Copyright 2008 Eli Naeher
3 * (C) Copyright 2008 Jeremy Maitin-Shepard
5 * Use, modification, and distribution are subject to the terms specified in the
9 const nav_history_service = Cc["@mozilla.org/browser/nav-history-service;1"]
10 .getService(Ci.nsINavHistoryService);
12 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks");
13 function history_completer () {
15 var use_history = arguments.$use_history;
16 var use_bookmarks = arguments.$use_bookmarks;
17 return function (input, pos, conservative) {
18 if (conservative && input.length == 0)
20 var query = nav_history_service.getNewQuery();
21 query.searchTerms = input;
23 query.onlyBookmarked = true;
24 var options = nav_history_service.getNewQueryOptions();
25 options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
26 if (use_bookmarks && !use_history)
27 options.queryType = options.QUERY_TYPE_BOOKMARKS;
28 else if (use_history && !use_bookmarks)
29 options.queryType = options.QUERY_TYPE_HISTORY;
31 options.queryType = options.QUERY_TYPE_UNIFIED; //WTF: not implemented yet?
32 var root = nav_history_service.executeQuery(query, options).root;
33 root.containerOpen = true;
34 var history_count = root.childCount;
35 return {count: history_count,
36 get_string: function (i) root.getChild(i).uri,
37 get_description: function (i) root.getChild(i).title,
38 get_input_state: function (i) [root.getChild(i).uri],
39 destroy: function () { root.containerOpen = false; }
44 function url_completer() {
46 var use_webjumps = arguments.$use_webjumps;
47 var use_history = arguments.$use_history;
48 var use_bookmarks = arguments.$use_bookmarks;
50 completers.push(file_path_completer());
52 completers.push(webjump_completer());
54 if(use_history || use_bookmarks) {
55 completers.push(history_completer($use_history = use_history,
56 $use_bookmarks = use_bookmarks));
58 return merge_completers(completers);
61 const nav_bookmarks_service = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
63 function add_bookmark(url, title) {
64 nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
65 make_uri(url), -1, title);