2 * (C) Copyright 2008 Eli Naeher
3 * (C) Copyright 2008 Jeremy Maitin-Shepard
4 * (C) Copyright 2011 John J. Foerch
6 * Use, modification, and distribution are subject to the terms specified in the
10 define_keywords("$use_webjumps", "$use_history", "$use_bookmarks",
11 "$match_required", "$sort_order");
12 function history_completer () {
13 keywords(arguments
, $sort_order
= "visitcount_descending");
14 var use_history
= arguments
.$use_history
;
15 var use_bookmarks
= arguments
.$use_bookmarks
;
16 let match_required
= arguments
.$match_required
;
17 var sort_order
= Ci
.nsINavHistoryQueryOptions
[
18 "SORT_BY_" + arguments
.$sort_order
.toUpperCase()];
19 return function (input
, pos
, conservative
) {
20 if (conservative
&& input
.length
== 0)
22 var query
= nav_history_service
.getNewQuery();
23 query
.searchTerms
= input
;
25 query
.onlyBookmarked
= true;
26 var options
= nav_history_service
.getNewQueryOptions();
27 options
.sortingMode
= sort_order
;
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
;
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
47 function url_completer () {
48 keywords(arguments
, $sort_order
= "visitcount_descending");
49 var use_webjumps
= arguments
.$use_webjumps
;
50 var use_history
= arguments
.$use_history
;
51 var use_bookmarks
= arguments
.$use_bookmarks
;
52 var sort_order
= arguments
.$sort_order
;
54 completers
.push(file_path_completer());
56 completers
.push(webjump_completer());
57 // Do queries separately (which can lead to duplicates). The queries
58 // can be combined when QUERY_TYPE_UNIFIED is implemented.
60 completers
.push(history_completer($use_bookmarks
= true,
61 $sort_order
= sort_order
));
63 completers
.push(history_completer($use_history
= true,
64 $sort_order
= sort_order
));
65 return merge_completers(completers
);
69 function add_bookmark (url
, title
) {
70 nav_bookmarks_service
.insertBookmark(nav_bookmarks_service
.unfiledBookmarksFolder
,
71 make_uri(url
), -1, title
);