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",
14 function history_completer () {
16 var use_history = arguments.$use_history;
17 var use_bookmarks = arguments.$use_bookmarks;
18 let match_required = arguments.$match_required;
19 return function (input, pos, conservative) {
20 if (conservative && input.length == 0)
22 var query = nav_history_service.getNewQuery();
23 query.searchTerms = input;
25 query.onlyBookmarked = true;
26 var options = nav_history_service.getNewQueryOptions();
27 options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
28 if (use_bookmarks && !use_history)
29 options.queryType = options.QUERY_TYPE_BOOKMARKS;
30 else if (use_history && !use_bookmarks)
31 options.queryType = options.QUERY_TYPE_HISTORY;
33 options.queryType = options.QUERY_TYPE_UNIFIED; //WTF: not implemented yet?
34 var root = nav_history_service.executeQuery(query, options).root;
35 root.containerOpen = true;
36 var history_count = root.childCount;
37 return {count: history_count,
38 get_string: function (i) root.getChild(i).uri,
39 get_description: function (i) root.getChild(i).title,
40 get_input_state: function (i) [root.getChild(i).uri],
41 destroy: function () { root.containerOpen = false; },
42 get_match_required: function() match_required
47 function url_completer() {
49 var use_webjumps = arguments.$use_webjumps;
50 var use_history = arguments.$use_history;
51 var use_bookmarks = arguments.$use_bookmarks;
53 completers.push(file_path_completer());
55 completers.push(webjump_completer());
57 if(use_history || use_bookmarks) {
58 completers.push(history_completer($use_history = use_history,
59 $use_bookmarks = use_bookmarks));
61 return merge_completers(completers);
64 const nav_bookmarks_service = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
66 function add_bookmark(url, title) {
67 nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
68 make_uri(url), -1, title);