1 // Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
2 // Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
3 // Copyright (c) 2008-2011 by Kris Maglione <maglione.k at Gmail>
5 // This work is licensed for reuse under an MIT license. Details are
6 // given in the LICENSE.txt file included with this file.
9 var Config = Module("config", ConfigBase, {
11 appName: "Pentadactyl",
12 idName: "PENTADACTYL",
16 commandContainer: "browser-bottombox",
18 Local: function Local(dactyl, modules, window)
19 let ({ config } = modules) ({
21 completers: Class.memoize(function () update({ sidebar: "sidebar", window: "window" }, this.__proto__.completers)),
24 about: ["About Firefox",
25 function () { window.openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
26 addbookmark: ["Add bookmark for the current page",
27 function () { window.PlacesCommandHook.bookmarkCurrentPage(true, window.PlacesUtils.bookmarksRootId); }],
28 addons: ["Manage Add-ons",
29 function () { window.BrowserOpenAddonsMgr(); }],
30 bookmarks: ["List your bookmarks",
31 function () { window.openDialog("chrome://browser/content/bookmarks/bookmarksPanel.xul", "Bookmarks", "dialog,centerscreen,width=600,height=600"); }],
32 checkupdates: ["Check for updates",
33 function () { window.checkForUpdates(); },
34 function () "checkForUpdates" in window],
35 cookies: ["List your cookies",
36 function () { window.toOpenWindowByType("Browser:Cookies", "chrome://browser/content/preferences/cookies.xul", "chrome,dialog=no,resizable"); }],
37 console: ["JavaScript console",
38 function () { window.toJavaScriptConsole(); }],
39 customizetoolbar: ["Customize the Toolbar",
40 function () { window.BrowserCustomizeToolbar(); }],
41 dominspector: ["DOM Inspector",
42 function () { window.inspectDOMDocument(window.content.document); },
43 function () "inspectDOMDocument" in window],
44 downloads: ["Manage Downloads",
45 function () { window.toOpenWindowByType("Download:Manager", "chrome://mozapps/content/downloads/downloads.xul", "chrome,dialog=no,resizable"); }],
46 history: ["List your history",
47 function () { window.openDialog("chrome://browser/content/history/history-panel.xul", "History", "dialog,centerscreen,width=600,height=600"); }],
48 import: ["Import Preferences, Bookmarks, History, etc. from other browsers",
49 function () { window.BrowserImport(); }],
50 openfile: ["Open the file selector dialog",
51 function () { window.BrowserOpenFileWindow(); }],
52 pageinfo: ["Show information about the current page",
53 function () { window.BrowserPageInfo(); }],
54 pagesource: ["View page source",
55 function () { window.BrowserViewSourceOfDocument(window.content.document); }],
56 passwords: ["Passwords dialog",
57 function () { window.openDialog("chrome://passwordmgr/content/passwordManager.xul"); }],
58 places: ["Places Organizer: Manage your bookmarks and history",
59 function () { window.PlacesCommandHook.showPlacesOrganizer(window.ORGANIZER_ROOT_BOOKMARKS); }],
60 preferences: ["Show Firefox preferences dialog",
61 function () { window.openPreferences(); }],
62 printpreview: ["Preview the page before printing",
63 function () { window.PrintUtils.printPreview(window.PrintPreviewListener || window.onEnterPrintPreview, window.onExitPrintPreview); }],
64 printsetup: ["Setup the page size and orientation before printing",
65 function () { window.PrintUtils.showPageSetup(); }],
66 print: ["Show print dialog",
67 function () { window.PrintUtils.print(); }],
68 saveframe: ["Save frame to disk",
69 function () { window.saveFrameDocument(); }],
70 savepage: ["Save page to disk",
71 function () { window.saveDocument(window.content.document); }],
72 searchengines: ["Manage installed search engines",
73 function () { window.openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
74 selectionsource: ["View selection source",
75 function () { modules.buffer.viewSelectionSource(); }],
76 venkman: ["The JavaScript debugger",
77 function () { dactyl.assert("start_venkman" in window, "Venkman is not installed"); window.start_venkman() },
78 function () "start_venkman" in window]
81 removeTab: function removeTab(tab) {
82 if (this.tabbrowser.mTabs.length > 1)
83 this.tabbrowser.removeTab(tab);
85 if (modules.buffer.uri.spec !== "about:blank" || window.getWebNavigation().sessionHistory.count > 0) {
86 dactyl.open("about:blank", dactyl.NEW_BACKGROUND_TAB);
87 this.tabbrowser.removeTab(tab);
95 let prefix = this.name;
97 prefix += "-" + window.content.document.location.hostname;
101 return prefix + ".tmp";
105 overlayChrome: ["chrome://browser/content/browser.xul"],
107 styleableChrome: ["chrome://browser/content/browser.xul"],
110 BookmarkAdd: "Triggered after a page is bookmarked",
111 BookmarkChange: "Triggered after a page's bookmark is changed",
112 BookmarkRemove: "Triggered after a page's bookmark is removed",
113 ColorScheme: "Triggered after a color scheme has been loaded",
114 DOMLoad: "Triggered when a page's DOM content has fully loaded",
115 DownloadPost: "Triggered when a download has completed",
116 Fullscreen: "Triggered when the browser's fullscreen state changes",
117 LocationChange: "Triggered when changing tabs or when navigation to a new location",
118 PageLoadPre: "Triggered after a page load is initiated",
119 PageLoad: "Triggered when a page gets (re)loaded/opened",
120 PrivateMode: "Triggered when private mode is activated or deactivated",
121 Sanitize: "Triggered when a sanitizeable item is cleared",
122 ShellCmdPost: "Triggered after executing a shell command with :!cmd",
123 Enter: "Triggered after Firefox starts",
124 LeavePre: "Triggered before exiting Firefox, just before destroying each module",
125 Leave: "Triggered before exiting Firefox"
131 showtabline: "always",
132 titlestring: "Pentadactyl"
136 "bookmarks", "hints", "history", "marks", "quickmarks", "sanitizer",
137 "session", "tabs", "tabs_undo", "windows"
141 m: ["Menubar", ["toolbar-menubar"]],
142 T: ["Toolbar", ["nav-bar"]],
143 B: ["Bookmark bar", ["PersonalToolbar"]]
159 viewAddons: ["Add-ons", "A", "chrome://mozapps/content/extensions/extensions.xul"],
160 viewConsole: ["Console", "C", "chrome://global/content/console.xul"],
161 viewDownloads: ["Downloads", "D", "chrome://mozapps/content/downloads/downloads.xul"],
162 viewPreferences: ["Preferences", "P", "about:config"]
166 commands: function (dactyl, modules, window) {
167 const { commands, completion, config } = modules;
168 const { document } = window;
170 commands.add(["winon[ly]"],
171 "Close all other windows",
173 dactyl.windows.forEach(function (win) {
180 commands.add(["pref[erences]", "prefs"],
181 "Show " + config.host + " preferences",
183 if (args.bang) // open Firefox settings GUI dialog
184 dactyl.open("about:config", { from: "prefs" });
186 window.openPreferences();
193 commands.add(["sbcl[ose]"],
194 "Close the sidebar window",
196 if (!document.getElementById("sidebar-box").hidden)
197 window.toggleSidebar();
201 commands.add(["sideb[ar]", "sb[ar]", "sbop[en]"],
202 "Open the sidebar window",
204 function compare(a, b) util.compareIgnoreCase(a, b) == 0
205 let title = document.getElementById("sidebar-title");
207 dactyl.assert(args.length || title.value || args.bang && config.lastSidebar,
208 "Argument required");
211 return window.toggleSidebar(title.value ? null : config.lastSidebar);
213 // focus if the requested sidebar is already open
214 if (compare(title.value, args[0])) {
216 return window.toggleSidebar();
217 return dactyl.focus(document.getElementById("sidebar-box"));
220 let menu = document.getElementById("viewSidebarMenu");
222 for (let [, panel] in Iterator(menu.childNodes))
223 if (compare(panel.getAttribute("label"), args[0])) {
224 let elem = document.getElementById(panel.observes);
230 return dactyl.echoerr("No sidebar " + args[0] + " found");
235 completer: function (context) {
236 context.ignoreCase = true;
237 return completion.sidebar(context);
242 commands.add(["wind[ow]"],
243 "Execute a command and tell it to output in a new window",
245 dactyl.withSavedValues(["forceNewWindow"], function () {
246 this.forceNewWindow = true;
247 this.execute(args[0], null, true);
252 completer: function (context) completion.ex(context),
257 commands.add(["winc[lose]", "wc[lose]"],
259 function () { window.close(); },
262 commands.add(["wino[pen]", "wo[pen]"],
263 "Open one or more URLs in a new window",
266 dactyl.open(args[0], dactyl.NEW_WINDOW);
268 dactyl.open("about:blank", dactyl.NEW_WINDOW);
271 completer: function (context) completion.url(context),
272 domains: function (args) commands.get("open").domains(args),
277 completion: function (dactyl, modules, window) {
278 const { CompletionContext, bookmarkcache, completion } = modules;
279 const { document } = window;
281 var searchRunning = null; // only until Firefox fixes https://bugzilla.mozilla.org/show_bug.cgi?id=510589
282 completion.location = function location(context) {
283 if (!services.autoCompleteSearch)
287 searchRunning.completions = searchRunning.completions;
288 searchRunning.cancel();
291 context.anchored = false;
292 context.compare = CompletionContext.Sort.unsorted;
293 context.filterFunc = null;
295 let words = context.filter.toLowerCase().split(/\s+/g);
296 context.hasItems = true;
297 context.completions = context.completions.filter(function ({ url, title })
298 words.every(function (w) (url + " " + title).toLowerCase().indexOf(w) >= 0))
299 context.incomplete = true;
301 context.format = modules.bookmarks.format;
302 context.keys.extra = function (item) (bookmarkcache.get(item.url) || {}).extra;
303 context.title = ["Smart Completions"];
305 context.cancel = function () {
306 this.incomplete = false;
307 if (searchRunning === this) {
308 services.autoCompleteSearch.stopSearch();
309 searchRunning = null;
313 services.autoCompleteSearch.startSearch(context.filter, "", context.result, {
314 onSearchResult: function onSearchResult(search, result) {
315 if (result.searchResult <= result.RESULT_SUCCESS)
316 searchRunning = null;
318 context.incomplete = result.searchResult >= result.RESULT_NOMATCH_ONGOING;
319 context.completions = [
320 { url: result.getValueAt(i), title: result.getCommentAt(i), icon: result.getImageAt(i) }
321 for (i in util.range(0, result.matchCount))
324 get onUpdateSearchResult() this.onSearchResult
326 searchRunning = context;
329 completion.addUrlCompleter("l",
330 "Firefox location bar entries (bookmarks and history sorted in an intelligent way)",
331 completion.location);
333 completion.sidebar = function sidebar(context) {
334 let menu = document.getElementById("viewSidebarMenu");
335 context.title = ["Sidebar Panel"];
336 context.completions = Array.map(menu.childNodes, function (n) [n.getAttribute("label"), ""]);
339 events: function (dactyl, modules, window) {
340 modules.events.listen(window, "SidebarFocused", function (event) {
341 modules.config.lastSidebar = window.document.getElementById("sidebar-box")
342 .getAttribute("sidebarcommand");
345 mappings: function initMappings(dactyl, modules, window) {
346 const { Events, mappings, modes } = modules;
347 mappings.add([modes.NORMAL],
348 ["<Return>", "<Space>", "<Up>", "<Down>"],
349 "Handled by " + config.host,
350 function () Events.PASS_THROUGH);
352 modes: function (dactyl, modules, window) {
353 const { modes } = modules;
354 config.modes.forEach(function (mode) { modes.addMode.apply(this, mode); });
356 options: function (dactyl, modules, window) {
357 modules.options.add(["online"],
358 "Set the 'work offline' option",
361 setter: function (value) {
362 if (services.io.offline == value)
363 window.BrowserOffline.toggleOfflineStatus();
366 getter: function () !services.io.offline
371 // vim: set fdm=marker sw=4 ts=4 et: