]> git.donarmstrong.com Git - dactyl.git/blob - pentadactyl/content/config.js
8c10f837e3f352f252d88136b3bf5c2d7648700d
[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                 function () "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: ["JavaScript console",
28                 function () { window.toJavaScriptConsole(); }],
29             customizetoolbar: ["Customize the Toolbar",
30                 function () { window.BrowserCustomizeToolbar(); }],
31             dominspector: ["DOM Inspector",
32                 function () { window.inspectDOMDocument(window.content.document); },
33                 function () "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                 function () "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         get tempFile() {
85             let prefix = this.name;
86             try {
87                 prefix += "-" + window.content.document.location.hostname;
88             }
89             catch (e) {}
90
91             return prefix + ".txt";
92         }
93     })
94
95 }, {
96 }, {
97     commands: function initCommands(dactyl, modules, window) {
98         const { commands, completion, config } = modules;
99         const { document } = window;
100
101         commands.add(["winon[ly]"],
102             "Close all other windows",
103             function () {
104                 dactyl.windows.forEach(function (win) {
105                     if (win != window)
106                         win.close();
107                 });
108             },
109             { argCount: "0" });
110
111         commands.add(["pref[erences]", "prefs"],
112             "Show " + config.host + " preferences",
113             function (args) {
114                 if (args.bang) // open Firefox settings GUI dialog
115                     dactyl.open("about:config", { from: "prefs" });
116                 else
117                     window.openPreferences();
118             },
119             {
120                 argCount: "0",
121                 bang: true
122             });
123
124         commands.add(["sbcl[ose]"],
125             "Close the sidebar window",
126             function () {
127                 if (!document.getElementById("sidebar-box").hidden)
128                     window.toggleSidebar();
129             },
130             { argCount: "0" });
131
132         commands.add(["sideb[ar]", "sb[ar]", "sbop[en]"],
133             "Open the sidebar window",
134             function (args) {
135                 function compare(a, b) util.compareIgnoreCase(a, b) == 0
136                 let title = document.getElementById("sidebar-title");
137
138                 dactyl.assert(args.length || title.value || args.bang && config.lastSidebar,
139                               _("error.argumentRequired"));
140
141                 if (!args.length)
142                     return window.toggleSidebar(title.value ? null : config.lastSidebar);
143
144                 // focus if the requested sidebar is already open
145                 if (compare(title.value, args[0])) {
146                     if (args.bang)
147                         return window.toggleSidebar();
148                     return dactyl.focus(document.getElementById("sidebar-box"));
149                 }
150
151                 let menu = document.getElementById("viewSidebarMenu");
152
153                 for (let [, panel] in Iterator(menu.childNodes))
154                     if (compare(panel.getAttribute("label"), args[0])) {
155                         let elem = document.getElementById(panel.observes);
156                         if (elem)
157                             elem.doCommand();
158                         return;
159                     }
160
161                 return dactyl.echoerr(_("error.invalidArgument", args[0]));
162             },
163             {
164                 argCount: "?",
165                 bang: true,
166                 completer: function (context) {
167                     context.ignoreCase = true;
168                     return completion.sidebar(context);
169                 },
170                 literal: 0
171             });
172
173         commands.add(["wind[ow]"],
174             "Execute a command and tell it to output in a new window",
175             function (args) {
176                 dactyl.withSavedValues(["forceTarget"], function () {
177                     this.forceTarget = dactyl.NEW_WINDOW;
178                     this.execute(args[0], null, true);
179                 });
180             },
181             {
182                 argCount: "1",
183                 completer: function (context) completion.ex(context),
184                 literal: 0,
185                 subCommand: 0
186             });
187
188         commands.add(["winc[lose]", "wc[lose]"],
189             "Close window",
190             function () { window.close(); },
191             { argCount: "0" });
192
193         commands.add(["wino[pen]", "wo[pen]"],
194             "Open one or more URLs in a new window",
195             function (args) {
196                 if (args[0])
197                     dactyl.open(args[0], dactyl.NEW_WINDOW);
198                 else
199                     dactyl.open("about:blank", dactyl.NEW_WINDOW);
200             },
201             {
202                 completer: function (context) completion.url(context),
203                 domains: function (args) commands.get("open").domains(args),
204                 literal: 0,
205                 privateData: true
206             });
207     },
208     completion: function initCompletion(dactyl, modules, window) {
209         const { CompletionContext, bookmarkcache, completion } = modules;
210         const { document } = window;
211
212         completion.location = function location(context) {
213             completion.autocomplete("history", context);
214             context.title = ["Smart Completions"];
215         };
216
217         completion.addUrlCompleter("location",
218             "Firefox location bar entries (bookmarks and history sorted in an intelligent way)",
219             completion.location);
220
221         completion.sidebar = function sidebar(context) {
222             let menu = document.getElementById("viewSidebarMenu");
223             context.title = ["Sidebar Panel"];
224             context.completions = Array.map(menu.childNodes, function (n) [n.getAttribute("label"), ""]);
225         };
226     },
227     events: function initEvents(dactyl, modules, window) {
228         modules.events.listen(window, "SidebarFocused", function (event) {
229             modules.config.lastSidebar = window.document.getElementById("sidebar-box")
230                                                .getAttribute("sidebarcommand");
231         }, false);
232     },
233     mappings: function initMappings(dactyl, modules, window) {
234         const { Events, mappings, modes } = modules;
235         mappings.add([modes.NORMAL],
236                      ["<Return>", "<Up>", "<Down>"],
237                      "Handled by " + config.host,
238                      function () Events.PASS_THROUGH);
239     },
240     options: function initOptions(dactyl, modules, window) {
241         modules.options.add(["online"],
242             "Enables or disables offline mode",
243             "boolean", true,
244             {
245                 setter: function (value) {
246                     if (services.io.offline == value)
247                         window.BrowserOffline.toggleOfflineStatus();
248                     return value;
249                 },
250                 getter: function () !services.io.offline
251             });
252     }
253 });
254
255 // vim: set fdm=marker sw=4 ts=4 et: