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