spawn-process: Better error information in case of timeout
[conkeror.git] / modules / history.js
blob15695fa65179f7cd6a5fc58d9434f9b378c9ed72
1 /**
2  * (C) Copyright 2008 Eli Naeher
3  * (C) Copyright 2008 Jeremy Maitin-Shepard
4  * (C) Copyright 2011-2012 John J. Foerch
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 function history_completions (completer, root) {
11     completions.call(this, completer);
12     this.root = root;
13     this.root.containerOpen = true;
14     this.count = this.root.childCount;
16 history_completions.prototype = {
17     constructor: history_completions,
18     __proto__: completions.prototype,
19     toString: function () "#<history_completions>",
20     root: null,
21     destroy: function () { this.root.containerOpen = false; },
22     get_string: function (i) this.root.getChild(i).uri,
23     get_description: function (i) this.root.getChild(i).title,
24     get_value: function (i) this.root.getChild(i),
28 define_keywords("$use_history", "$use_bookmarks", "$sort_order");
29 function history_completer () {
30     keywords(arguments,
31              $use_history = false,
32              $use_bookmarks = false,
33              $sort_order = "visitcount_descending");
34     completer.call(this);
35     this.use_history = arguments.$use_history;
36     this.use_bookmarks = arguments.$use_bookmarks;
37     this.sort_order = arguments.$sort_order;
39 history_completer.prototype = {
40     constructor: history_completer,
41     __proto__: completer.prototype,
42     toString: function () "#<history_completer>",
43     use_history: false,
44     use_bookmarks: false,
45     sort_order: null,
46     complete: function (input, pos) {
47         var query = nav_history_service.getNewQuery();
48         query.searchTerms = input;
49         if (! this.use_history)
50             query.onlyBookmarked = true;
51         var options = nav_history_service.getNewQueryOptions();
52         options.sortingMode = Ci.nsINavHistoryQueryOptions[
53             "SORT_BY_" + this.sort_order.toUpperCase()];
54         if (this.use_bookmarks && ! this.use_history)
55             options.queryType = options.QUERY_TYPE_BOOKMARKS;
56         else if (this.use_history && ! this.use_bookmarks)
57             options.queryType = options.QUERY_TYPE_HISTORY;
58         else
59             options.queryType = options.QUERY_TYPE_UNIFIED; //XXX: not implemented yet
60         var root = nav_history_service.executeQuery(query, options).root;
61         return new history_completions(this, root);
62     }
65 define_keywords("$use_webjumps");
66 function url_completer () {
67     keywords(arguments, $sort_order = "visitcount_descending");
68     var sort_order = arguments.$sort_order;
69     var completers = [];
70     completers.push(new file_path_completer());
71     if (arguments.$use_webjumps)
72         completers.push(new webjump_completer());
73     // Do queries separately (which can lead to duplicates).  The queries
74     // can be combined when QUERY_TYPE_UNIFIED is implemented.
75     if (arguments.$use_bookmarks)
76         completers.push(new history_completer($use_bookmarks = true,
77                                               $sort_order = sort_order));
78     if (arguments.$use_history)
79         completers.push(new history_completer($use_history = true,
80                                               $sort_order = sort_order));
81     merged_completer.call(this, completers);
83 url_completer.prototype = {
84     constructor: url_completer,
85     __proto__: merged_completer.prototype,
86     toString: function () "#<url_completer>"
90 function add_bookmark (url, title) {
91     nav_bookmarks_service.insertBookmark(nav_bookmarks_service.unfiledBookmarksFolder,
92                                          make_uri(url), -1, title);
95 // See
96 // http://mxr.mozilla.org/mozilla-central/source/browser/base/content/sanitize.js
97 // for the Firefox implementation for clearing various history information.
99 function clear_form_history() {
100     var FormHistory = Components.utils.import("resource://gre/modules/FormHistory.jsm", null).FormHistory;
101     // This is asynchronous, but we don't care about waiting for it to finish.
102     FormHistory.update( { op: "remove" } );
104 interactive("clear-form-history", "Permanently delete all form autocomplete history.",
105           function (I) {
106               clear_form_history();
107               I.minibuffer.message("Form history cleared.");
108           });
110 function clear_history() {
111     var PlacesUtils = Components.utils.import("resource://gre/modules/PlacesUtils.jsm").PlacesUtils;
112     PlacesUtils.history.removeAllPages();
114 interactive("clear-history", "Permanently delete all location history.",
115           function (I) {
116               clear_history();
117               I.minibuffer.message("Location history cleared.");
118           });
120 provide("history");