]> git.donarmstrong.com Git - dactyl.git/blob - teledactyl/content/config.js
Import r6948 from upstream hg supporting Firefox up to 24.*
[dactyl.git] / teledactyl / content / config.js
1 // Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
2 //
3 // This work is licensed for reuse under an MIT license. Details are
4 // given in the LICENSE.txt file included with this file.
5 "use strict";
6
7 var Config = Module("config", ConfigBase, {
8     Local: function Local(dactyl, modules, window)
9         let ({ config } = modules, { document } = window) {
10         init: function init() {
11             init.superapply(this, arguments);
12
13             if (!("content" in modules))
14                 modules.__defineGetter__("content", function () window.content);
15
16             util.overlayWindow(window, { append: <><hbox id="statusTextBox" flex=""/></> });
17         },
18
19         get browser()
20             let (tabmail = document.getElementById('tabmail'))
21                 tabmail && tabmail.tabInfo.length ? tabmail.getBrowserForSelectedTab()
22                                                   : document.getElementById("messagepane"),
23
24         tabbrowser: {
25             __proto__: Class.makeClosure.call(window.document.getElementById("tabmail")),
26             get mTabContainer() this.tabContainer,
27             get mTabs() this.tabContainer.childNodes,
28             get mCurrentTab() this.tabContainer.selectedItem,
29             get mStrip() this.tabStrip,
30             get browsers() [browser for (browser in Iterator(this.mTabs))],
31
32             removeTab: function removeTab(tab) this.closeTab(tab),
33
34             loadOneTab: function loadOneTab(uri) {
35                 return this.openTab("contentTab", { contentPage: uri });
36             },
37             loadURIWithFlags: function loadURIWithFlags() {
38                 return this.mCurrentTab.loadURIWithFlags.apply(this.mCurrentTab, arguments);
39             }
40         },
41
42         get tabStip() this.tabbrowser.tabContainer,
43
44         get mainWidget() this.isComposeWindow ? document.getElementById("content-frame") : window.GetThreadTree(),
45
46         get browserModes() [modules.modes.MESSAGE],
47
48         get mailModes() [modules.modes.NORMAL],
49
50         // NOTE: as I don't use TB I have no idea how robust this is. --djk
51         get outputHeight() {
52             if (!this.isComposeWindow) {
53                 let container = document.getElementById("tabpanelcontainer").boxObject;
54                 let deck      = document.getElementById("displayDeck");
55                 let box       = document.getElementById("messagepanebox");
56                 let splitter  = document.getElementById("threadpane-splitter").boxObject;
57
58                 if (splitter.width > splitter.height)
59                     return container.height - deck.minHeight - box.minHeight- splitter.height;
60                 else
61                     return container.height - Math.max(deck.minHeight, box.minHeight);
62             }
63             else
64                 return document.getElementById("appcontent").boxObject.height;
65         },
66
67         removeTab: function removeTab(tab) {
68             if (this.tabbrowser.mTabs.length > 1)
69                 this.tabbrowser.removeTab(tab);
70             else
71                 dactyl.beep();
72         },
73
74         completers: Class.Memoize(function () update({ mailfolder: "mailFolder" }, this.__proto__.completers)),
75
76         dialogs: {
77             about: ["About Thunderbird",
78                 function () { window.openAboutDialog(); }],
79             addons: ["Manage Add-ons",
80                 function () { window.openAddonsMgr(); }],
81             addressbook: ["Address book",
82                 function () { window.toAddressBook(); }],
83             checkupdates: ["Check for updates",
84                 function () { window.checkForUpdates(); }],
85             console: ["JavaScript console",
86                 function () { window.toJavaScriptConsole(); }],
87             dominspector: ["DOM Inspector",
88                 function () { window.inspectDOMDocument(content.document); }],
89             downloads: ["Manage Downloads",
90                 function () { window.toOpenWindowByType('Download:Manager', 'chrome://mozapps/content/downloads/downloads.xul', 'chrome,dialog=no,resizable'); }],
91             preferences: ["Show Thunderbird preferences dialog",
92                 function () { window.openOptionsDialog(); }],
93             printsetup: ["Setup the page size and orientation before printing",
94                 function () { window.PrintUtils.showPageSetup(); }],
95             print: ["Show print dialog",
96                 function () { window.PrintUtils.print(); }],
97             saveframe: ["Save frame to disk",
98                 function () { window.saveFrameDocument(); }],
99             savepage: ["Save page to disk",
100                 function () { window.saveDocument(window.content.document); }],
101         },
102
103         focusChange: function focusChange(win) {
104             const { modes } = modules;
105
106             if (win.top == window)
107                 return;
108
109             // we switch to -- MESSAGE -- mode for Teledactyl when the main HTML widget gets focus
110             if (win && win.document instanceof Ci.nsIDOMHTMLDocument
111                     || dactyl.focusedElement instanceof Ci.nsIDOMHTMLAnchorElement) {
112
113                 if (this.isComposeWindow)
114                     modes.set(modes.INSERT, modes.TEXT_EDIT);
115                 else if (dactyl.mode != modes.MESSAGE)
116                     modes.main = modes.MESSAGE;
117             }
118         }
119     }
120 }, {
121 }, {
122     commands: function initCommands(dactyl, modules, window) {
123         const { commands } = modules;
124
125         commands.add(["pref[erences]", "prefs"],
126             "Show " + config.host + " preferences",
127             function () { window.openOptionsDialog(); },
128             { argCount: "0" });
129     },
130     modes: function initModes(dactyl, modules, window) {
131         const { modes } = modules;
132
133         this.ignoreKeys = {
134             "<Return>": modes.NORMAL | modes.INSERT,
135             "<Space>": modes.NORMAL | modes.INSERT,
136             "<Up>": modes.NORMAL | modes.INSERT,
137             "<Down>": modes.NORMAL | modes.INSERT
138         };
139     },
140     options: function initOptions(dactyl, modules, window) {
141         const { options } = modules;
142
143         // FIXME: comment obviously incorrect
144         // 0: never automatically edit externally
145         // 1: automatically edit externally when message window is shown the first time
146         // 2: automatically edit externally, once the message text gets focus (not working currently)
147         options.add(["autoexternal", "ae"],
148             "Edit message with external editor by default",
149             "boolean", false);
150
151         options.add(["online"],
152             "Set the 'work offline' option",
153             "boolean", true,
154             {
155                 setter: function (value) {
156                     if (window.MailOfflineMgr.isOnline() != value)
157                         window.MailOfflineMgr.toggleOfflineStatus();
158                     return value;
159                 },
160                 getter: function () window.MailOfflineMgr.isOnline()
161             });
162     }
163 });
164
165 // vim: set fdm=marker sw=4 sts=4 ts=8 et: