input_handle_command: allow event to be a string
[conkeror/arlinius.git] / modules / history.js
blobdfebf4eec33e427bc2a9b1e7149752b467b7d5e5
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     /* Do queries separately (which can lead to duplicates).  The
55      * queries can be combined when QUERY_TYPE_UNIFIED is implemented. */
56     if (use_bookmarks)
57         completers.push(history_completer($use_bookmarks = true));
58     if (use_history)
59         completers.push(history_completer($use_history = true));
60     return merge_completers(completers);
64 function add_bookmark(url, title) {
65     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
66                                          make_uri(url), -1, title);