]> git.donarmstrong.com Git - dactyl.git/blob - pentadactyl/content/config.js
finalize changelog for 7904
[dactyl.git] / pentadactyl / content / config.js
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>
4 //
5 // This work is licensed for reuse under an MIT license. Details are
6 // given in the LICENSE.txt file included with this file.
7 "use strict";
8
9 var Config = Module("config", ConfigBase, {
10     Local: function Local(dactyl, modules, window)
11         let ({ config } = modules) ({
12
13         dialogs: {
14             about: ["About Firefox",
15                 function () { window.openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
16             addbookmark: ["Add bookmark for the current page",
17                 function () { window.PlacesCommandHook.bookmarkCurrentPage(true, window.PlacesUtils.bookmarksRootId); }],
18             addons: ["Manage Add-ons",
19                 function () { window.BrowserOpenAddonsMgr(); }],
20             bookmarks: ["List your bookmarks",
21                 function () { window.openDialog("chrome://browser/content/bookmarks/bookmarksPanel.xul", "Bookmarks", "dialog,centerscreen,width=600,height=600"); }],
22             checkupdates: ["Check for updates",
23                 function () { window.checkForUpdates(); },
24                 () => "checkForUpdates" in window],
25             cookies: ["List your cookies",
26                 function () { window.toOpenWindowByType("Browser:Cookies", "chrome://browser/content/preferences/cookies.xul", "chrome,dialog=no,resizable"); }],
27             console: ["Browser console",
28                 function () { window.HUDService.toggleBrowserConsole(); }],
29             customizetoolbar: ["Customize the Toolbar",
30                 function () { window.BrowserCustomizeToolbar(); }],
31             dominspector: ["DOM Inspector",
32                 function () { window.inspectDOMDocument(window.content.document); },
33                 () => "inspectDOMDocument" in window],
34             downloads: ["Manage Downloads",
35                 function () { window.BrowserDownloadsUI(); }],
36             history: ["List your history",
37                 function () { window.openDialog("chrome://browser/content/history/history-panel.xul", "History", "dialog,centerscreen,width=600,height=600"); }],
38             openfile: ["Open the file selector dialog",
39                 function () { window.BrowserOpenFileWindow(); }],
40             pageinfo: ["Show information about the current page",
41                 function () { window.BrowserPageInfo(); }],
42             pagesource: ["View page source",
43                 function () { window.BrowserViewSourceOfDocument(window.content.document); }],
44             passwords: ["Passwords dialog",
45                 function () { window.openDialog("chrome://passwordmgr/content/passwordManager.xul"); }],
46             places: ["Places Organizer: Manage your bookmarks and history",
47                 function () { window.PlacesCommandHook.showPlacesOrganizer(window.ORGANIZER_ROOT_BOOKMARKS); }],
48             preferences: ["Show Firefox preferences dialog",
49                 function () { window.openPreferences(); }],
50             printpreview: ["Preview the page before printing",
51                 function () { window.PrintUtils.printPreview(window.PrintPreviewListener || window.onEnterPrintPreview, window.onExitPrintPreview); }],
52             printsetup: ["Setup the page size and orientation before printing",
53                 function () { window.PrintUtils.showPageSetup(); }],
54             print: ["Show print dialog",
55                 function () { window.PrintUtils.print(); }],
56             saveframe: ["Save frame to disk",
57                 function () { window.saveFrameDocument(); }],
58             savepage: ["Save page to disk",
59                 function () { window.saveDocument(window.content.document); }],
60             searchengines: ["Manage installed search engines",
61                 function () { window.openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
62             selectionsource: ["View selection source",
63                 function () { modules.buffer.viewSelectionSource(); }],
64             venkman: ["The JavaScript debugger",
65                 function () { dactyl.assert("start_venkman" in window, "Venkman is not installed"); window.start_venkman() },
66                 () => "start_venkman" in window]
67         },
68
69         removeTab: function removeTab(tab) {
70             if (window.gInPrintPreviewMode)
71                 window.PrintUtils.exitPrintPreview();
72             else if (this.tabbrowser.mTabs.length > 1)
73                 this.tabbrowser.removeTab(tab);
74             else {
75                 if (modules.buffer.uri.spec !== "about:blank" || window.getWebNavigation().sessionHistory.count > 0) {
76                     dactyl.open("about:blank", dactyl.NEW_BACKGROUND_TAB);
77                     this.tabbrowser.removeTab(tab);
78                 }
79                 else
80                     dactyl.beep();
81             }
82         }
83     })
84
85 }, {
86 }, {
87     commands: function initCommands(dactyl, modules, window) {
88         const { commands, completion, config } = modules;
89         const { document } = window;
90
91         commands.add(["winon[ly]"],
92             "Close all other windows",
93             function () {
94                 dactyl.windows.forEach(function (win) {
95                     if (win != window)
96                         win.close();
97                 });
98             },
99             { argCount: "0" });
100
101         commands.add(["pref[erences]", "prefs"],
102             "Show " + config.host + " preferences",
103             function (args) {
104                 if (args.bang) // open Firefox settings GUI dialog
105                     dactyl.open("about:config", { from: "prefs" });
106                 else
107                     window.openPreferences();
108             },
109             {
110                 argCount: "0",
111                 bang: true
112             });
113
114         commands.add(["sbcl[ose]"],
115             "Close the sidebar window",
116             function () {
117                 if (!document.getElementById("sidebar-box").hidden)
118                     window.toggleSidebar();
119             },
120             { argCount: "0" });
121
122         commands.add(["sideb[ar]", "sb[ar]", "sbop[en]"],
123             "Open the sidebar window",
124             function (args) {
125                 function compare(a, b) util.compareIgnoreCase(a, b) == 0
126                 let title = document.getElementById("sidebar-title");
127
128                 dactyl.assert(args.length || title.value || args.bang && config.lastSidebar,
129                               _("error.argumentRequired"));
130
131                 if (!args.length)
132                     return window.toggleSidebar(title.value ? null : config.lastSidebar);
133
134                 // focus if the requested sidebar is already open
135                 if (compare(title.value, args[0])) {
136                     if (args.bang)
137                         return window.toggleSidebar();
138                     return dactyl.focus(document.getElementById("sidebar-box"));
139                 }
140
141                 let menu = document.getElementById("viewSidebarMenu");
142
143                 for (let [, panel] in Iterator(menu.childNodes))
144                     if (compare(panel.getAttribute("label"), args[0])) {
145                         let elem = document.getElementById(panel.observes);
146                         if (elem)
147                             elem.doCommand();
148                         return;
149                     }
150
151                 return dactyl.echoerr(_("error.invalidArgument", args[0]));
152             },
153             {
154                 argCount: "?",
155                 bang: true,
156                 completer: function (context) {
157                     context.ignoreCase = true;
158                     return completion.sidebar(context);
159                 },
160                 literal: 0
161             });
162
163         commands.add(["wind[ow]"],
164             "Execute a command and tell it to output in a new window",
165             function (args) {
166                 dactyl.withSavedValues(["forceTarget"], function () {
167                     this.forceTarget = dactyl.NEW_WINDOW;
168                     this.execute(args[0], null, true);
169                 });
170             },
171             {
172                 argCount: "1",
173                 completer: function (context) completion.ex(context),
174                 literal: 0,
175                 subCommand: 0
176             });
177
178         commands.add(["winc[lose]", "wc[lose]"],
179             "Close window",
180             function () { window.close(); },
181             { argCount: "0" });
182
183         commands.add(["wino[pen]", "wo[pen]"],
184             "Open one or more URLs in a new window",
185             function (args) {
186                 if (args[0])
187                     dactyl.open(args[0], dactyl.NEW_WINDOW);
188                 else
189                     dactyl.open("about:blank", dactyl.NEW_WINDOW);
190             },
191             {
192                 completer: function (context) completion.url(context),
193                 domains: function (args) commands.get("open").domains(args),
194                 literal: 0,
195                 privateData: true
196             });
197     },
198     completion: function initCompletion(dactyl, modules, window) {
199         const { CompletionContext, bookmarkcache, completion } = modules;
200         const { document } = window;
201
202         completion.location = function location(context) {
203             completion.autocomplete("history", context);
204             context.title = ["Smart Completions"];
205         };
206
207         completion.addUrlCompleter("location",
208             "Firefox location bar entries (bookmarks and history sorted in an intelligent way)",
209             completion.location);
210
211         completion.sidebar = function sidebar(context) {
212             let menu = document.getElementById("viewSidebarMenu");
213             context.title = ["Sidebar Panel"];
214             context.completions = Array.filter(menu.childNodes, n => n.hasAttribute("label"))
215                                        .map(n => [n.getAttribute("label"), ""]);
216         };
217     },
218     events: function initEvents(dactyl, modules, window) {
219         modules.events.listen(window, "SidebarFocused", function (event) {
220             modules.config.lastSidebar = window.document.getElementById("sidebar-box")
221                                                .getAttribute("sidebarcommand");
222         }, false);
223     },
224     mappings: function initMappings(dactyl, modules, window) {
225         const { Events, mappings, modes } = modules;
226         mappings.add([modes.NORMAL],
227                      ["<Return>", "<Up>", "<Down>"],
228                      "Handled by " + config.host,
229                      () => Events.PASS_THROUGH);
230     },
231     options: function initOptions(dactyl, modules, window) {
232         modules.options.add(["online"],
233             "Enables or disables offline mode",
234             "boolean", true,
235             {
236                 setter: function (value) {
237                     if (services.io.offline == value)
238                         window.BrowserOffline.toggleOfflineStatus();
239                     return value;
240                 },
241                 getter: function () !services.io.offline
242             });
243     }
244 });
245
246 // vim: set fdm=marker sw=4 sts=4 ts=8 et: