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