unfocus: show a message in the minibuffer
[conkeror.git] / modules / history.js
blob19510c57e8da16a14a3d2e0f79c83aa653ffcb35
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 function history_completer() {
14     keywords(arguments)
15     var use_history = arguments.$use_history;
16     var use_bookmarks = arguments.$use_bookmarks;
17     return function (input, pos, conservative) {
18         if (conservative && input.length == 0)
19             return null;
20         var query = nav_history_service.getNewQuery();
21         query.searchTerms = input;
22         if (!use_history)
23             query.onlyBookmarked = true;
24         var options = nav_history_service.getNewQueryOptions();
25         options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING;
26         var root = nav_history_service.executeQuery(query, options).root;
27         root.containerOpen = true;
28         var history_count = root.childCount;
29         return {count: history_count,
30                 get_string: function (i) root.getChild(i).uri,
31                 get_description: function (i) root.getChild(i).title,
32                 get_input_state: function (i) [root.getChild(i).uri],
33                 destroy: function () { root.containerOpen = false; }
34                };
35     }
38 function url_completer() {
39     keywords(arguments);
40     var use_webjumps = arguments.$use_webjumps;
41     var use_history = arguments.$use_history;
42     var use_bookmarks = arguments.$use_bookmarks;
43     var completers = [];
44     completers.push(file_path_completer());
45     if(use_webjumps) {
46         completers.push(webjump_completer());
47     }
48     if(use_history || use_bookmarks) {
49         completers.push(history_completer($use_history = use_history,
50                                           $use_bookmarks = use_bookmarks));
51     }
52     return merge_completers(completers);
55 const nav_bookmarks_service = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
57 function add_bookmark(url, title) {
58     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
59                                          makeURL(url), -1, title);