whitespace
[conkeror/arlinius.git] / modules / history.js
blob2d43c88f3554d905bbde821409ec03283b42f96c
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 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks",
10                 "$match_required");
11 function history_completer () {
12     keywords(arguments);
13     var use_history = arguments.$use_history;
14     var use_bookmarks = arguments.$use_bookmarks;
15     let match_required = arguments.$match_required;
16     return function (input, pos, conservative) {
17         if (conservative && input.length == 0)
18             return null;
19         var query = nav_history_service.getNewQuery();
20         query.searchTerms = input;
21         if (!use_history)
22             query.onlyBookmarked = true;
23         var options = nav_history_service.getNewQueryOptions();
24         options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
25         if (use_bookmarks && !use_history)
26             options.queryType = options.QUERY_TYPE_BOOKMARKS;
27         else if (use_history && !use_bookmarks)
28             options.queryType = options.QUERY_TYPE_HISTORY;
29         else
30             options.queryType = options.QUERY_TYPE_UNIFIED; //WTF: not implemented yet?
31         var root = nav_history_service.executeQuery(query, options).root;
32         root.containerOpen = true;
33         var history_count = root.childCount;
34         return {count: history_count,
35                 get_string: function (i) root.getChild(i).uri,
36                 get_description: function (i) root.getChild(i).title,
37                 get_input_state: function (i) [root.getChild(i).uri],
38                 destroy: function () { root.containerOpen = false; },
39                 get_match_required: function() match_required
40                };
41     }
44 function url_completer() {
45     keywords(arguments);
46     var use_webjumps = arguments.$use_webjumps;
47     var use_history = arguments.$use_history;
48     var use_bookmarks = arguments.$use_bookmarks;
49     var completers = [];
50     completers.push(file_path_completer());
51     if(use_webjumps) {
52         completers.push(webjump_completer());
53     }
54     if(use_history || use_bookmarks) {
55         completers.push(history_completer($use_history = use_history,
56                                           $use_bookmarks = use_bookmarks));
57     }
58     return merge_completers(completers);
62 function add_bookmark(url, title) {
63     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
64                                          make_uri(url), -1, title);