kill_buffer: go to about:blank instead of erroring when killing last buffer
[conkeror.git] / modules / history.js
blobb0cb6239c4d2d909f464a9c3911bad91816ff4e3
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 provide("history");