Add webjump integration with OpenSearch search engines
[conkeror.git] / modules / history.js
blob9d7829662b02f3049a193c04289cb628ec031b5d
3 const nav_history_service = Cc["@mozilla.org/browser/nav-history-service;1"]
4     .getService(Ci.nsINavHistoryService);
6 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks");
7 function history_completer() {
8     keywords(arguments)
9     var use_history = arguments.$use_history;
10     var use_bookmarks = arguments.$use_bookmarks;
11     return function (input, pos, conservative) {
12         if (conservative && input.length == 0)
13             return null;
14         var query = nav_history_service.getNewQuery();
15         query.searchTerms = input;
16         if (!use_history)
17             query.onlyBookmarked = true;
18         var options = nav_history_service.getNewQueryOptions();
19         options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
20         var root = nav_history_service.executeQuery(query, options).root;
21         root.containerOpen = true;
22         var history_count = root.childCount;
23         return {count: history_count,
24                 get_string: function (i) root.getChild(i).uri,
25                 get_description: function (i) root.getChild(i).title,
26                 get_input_state: function (i) [root.getChild(i).uri],
27                 destroy: function () { root.containerOpen = false; }
28                };
29     }
32 function url_completer() {
33     keywords(arguments);
34     var use_webjumps = arguments.$use_webjumps;
35     var use_history = arguments.$use_history;
36     var use_bookmarks = arguments.$use_bookmarks;
37     var completers = [];
38     completers.push(file_path_completer());
39     if(use_webjumps) {
40         completers.push(webjump_completer());
41     }
42     if(use_history || use_bookmarks) {
43         completers.push(history_completer($use_history = use_history,
44                                           $use_bookmarks = use_bookmarks));
45     }
46     return merge_completers(completers);
49 const nav_bookmarks_service = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
51 function add_bookmark(url, title) {
52     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
53                                          makeURL(url), -1, title);