2 * (C) Copyright 2008 Eli Naeher
3 * (C) Copyright 2008 Jeremy Maitin-Shepard
5 * Use, modification, and distribution are subject to the terms specified in the
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() {
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)
20 var query = nav_history_service.getNewQuery();
21 query.searchTerms = input;
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; }
38 function url_completer() {
40 var use_webjumps = arguments.$use_webjumps;
41 var use_history = arguments.$use_history;
42 var use_bookmarks = arguments.$use_bookmarks;
44 completers.push(file_path_completer());
46 completers.push(webjump_completer());
48 if(use_history || use_bookmarks) {
49 completers.push(history_completer($use_history = use_history,
50 $use_bookmarks = use_bookmarks));
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);