Prepare the Debian package upload (update release and timestamp in changelog)
[conkeror.git] / modules / history.js
blob84ae26a1c034290f19ca956bba1872ea64bdc1f0
1 /**
2  * (C) Copyright 2008 Eli Naeher
3  * (C) Copyright 2008 Jeremy Maitin-Shepard
4  * (C) Copyright 2011 John J. Foerch
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 in_module(null);
12 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks",
13                 "$match_required", "$sort_order");
14 function history_completer () {
15     keywords(arguments, $sort_order = "visitcount_descending");
16     var use_history = arguments.$use_history;
17     var use_bookmarks = arguments.$use_bookmarks;
18     let match_required = arguments.$match_required;
19     var sort_order = Ci.nsINavHistoryQueryOptions[
20         "SORT_BY_" + arguments.$sort_order.toUpperCase()];
21     return function (input, pos, conservative) {
22         if (conservative && input.length == 0)
23             return null;
24         var query = nav_history_service.getNewQuery();
25         query.searchTerms = input;
26         if (!use_history)
27             query.onlyBookmarked = true;
28         var options = nav_history_service.getNewQueryOptions();
29         options.sortingMode = sort_order;
30         if (use_bookmarks && !use_history)
31             options.queryType = options.QUERY_TYPE_BOOKMARKS;
32         else if (use_history && !use_bookmarks)
33             options.queryType = options.QUERY_TYPE_HISTORY;
34         else
35             options.queryType = options.QUERY_TYPE_UNIFIED; //WTF: not implemented yet?
36         var root = nav_history_service.executeQuery(query, options).root;
37         root.containerOpen = true;
38         var history_count = root.childCount;
39         return {count: history_count,
40                 get_string: function (i) root.getChild(i).uri,
41                 get_description: function (i) root.getChild(i).title,
42                 get_input_state: function (i) [root.getChild(i).uri],
43                 destroy: function () { root.containerOpen = false; },
44                 get_match_required: function() match_required
45                };
46     }
49 function url_completer () {
50     keywords(arguments, $sort_order = "visitcount_descending");
51     var use_webjumps = arguments.$use_webjumps;
52     var use_history = arguments.$use_history;
53     var use_bookmarks = arguments.$use_bookmarks;
54     var sort_order = arguments.$sort_order;
55     var completers = [];
56     completers.push(file_path_completer());
57     if(use_webjumps) {
58         completers.push(webjump_completer());
59     }
60     /* Do queries separately (which can lead to duplicates).  The
61      * queries can be combined when QUERY_TYPE_UNIFIED is implemented. */
62     if (use_bookmarks)
63         completers.push(history_completer($use_bookmarks = true,
64                                           $sort_order = sort_order));
65     if (use_history)
66         completers.push(history_completer($use_history = true,
67                                           $sort_order = sort_order));
68     return merge_completers(completers);
72 function add_bookmark (url, title) {
73     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
74                                          make_uri(url), -1, title);
77 provide("history");