Added support for generating URLs with fragment indentifiers (eg #foo).
[conkeror/arlinius.git] / modules / history.js
blob8eb8686d8bb3f183d3ee212391027b967560c794
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 const nav_history_service = Cc["@mozilla.org/browser/nav-history-service;1"]
10     .getService(Ci.nsINavHistoryService);
12 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks",
13                 "$match_required");
14 function history_completer () {
15     keywords(arguments);
16     var use_history = arguments.$use_history;
17     var use_bookmarks = arguments.$use_bookmarks;
18     let match_required = arguments.$match_required;
19     return function (input, pos, conservative) {
20         if (conservative && input.length == 0)
21             return null;
22         var query = nav_history_service.getNewQuery();
23         query.searchTerms = input;
24         if (!use_history)
25             query.onlyBookmarked = true;
26         var options = nav_history_service.getNewQueryOptions();
27         options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
28         if (use_bookmarks && !use_history)
29             options.queryType = options.QUERY_TYPE_BOOKMARKS;
30         else if (use_history && !use_bookmarks)
31             options.queryType = options.QUERY_TYPE_HISTORY;
32         else
33             options.queryType = options.QUERY_TYPE_UNIFIED; //WTF: not implemented yet?
34         var root = nav_history_service.executeQuery(query, options).root;
35         root.containerOpen = true;
36         var history_count = root.childCount;
37         return {count: history_count,
38                 get_string: function (i) root.getChild(i).uri,
39                 get_description: function (i) root.getChild(i).title,
40                 get_input_state: function (i) [root.getChild(i).uri],
41                 destroy: function () { root.containerOpen = false; },
42                 get_match_required: function() match_required
43                };
44     }
47 function url_completer() {
48     keywords(arguments);
49     var use_webjumps = arguments.$use_webjumps;
50     var use_history = arguments.$use_history;
51     var use_bookmarks = arguments.$use_bookmarks;
52     var completers = [];
53     completers.push(file_path_completer());
54     if(use_webjumps) {
55         completers.push(webjump_completer());
56     }
57     if(use_history || use_bookmarks) {
58         completers.push(history_completer($use_history = use_history,
59                                           $use_bookmarks = use_bookmarks));
60     }
61     return merge_completers(completers);
64 const nav_bookmarks_service = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
66 function add_bookmark(url, title) {
67     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
68                                          make_uri(url), -1, title);