]> git.donarmstrong.com Git - dactyl.git/blob - teledactyl/content/config.js
67586e81f1ab3783e5874a2e404146bf02b9117f
[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 const Config = Module("config", ConfigBase, {
8     name: "teledactyl",
9     appName: "Teledactyl",
10     idName: "TELEDACTYL",
11     host: "Thunderbird",
12     hostbin: "thunderbird",
13
14     Local: function Local(dactyl, modules, window)
15         let ({ config } = modules, { document } = window) {
16         init: function init() {
17             init.superapply(this, arguments);
18
19             modules.__defineGetter__("content", function () window.content);
20
21             util.overlayWindow(window, { append: <><hbox id="statusTextBox" flex=""/></> });
22         },
23
24         get browser() window.getBrowser(),
25
26         get commandContainer() document.documentElement.id,
27
28         tabbrowser: {
29             __proto__: Class.makeClosure.call(window.document.getElementById("tabmail")),
30             get mTabContainer() this.tabContainer,
31             get mTabs() this.tabContainer.childNodes,
32             get mCurrentTab() this.tabContainer.selectedItem,
33             get mStrip() this.tabStrip,
34             get browsers() [browser for (browser in Iterator(this.mTabs))],
35
36             loadOneTab: function loadOneTab(uri) {
37                 return this.openTab("contentTab", { contentPage: uri });
38             },
39             loadURIWithFlags: function loadURIWithFlags() {
40                 return this.mCurrentTab.loadURIWithFlags.apply(this.mCurrentTab, arguments);
41             }
42         },
43
44         get hasTabbrowser() !this.isComposeWindow,
45
46         get tabStip() this.tabbrowser.tabContainer,
47
48         get isComposeWindow() window.wintype == "msgcompose",
49
50         get mainWidget() this.isComposeWindow ? document.getElementById("content-frame") : window.GetThreadTree(),
51
52         get mainWindowId() this.isComposeWindow ? "msgcomposeWindow" : "messengerWindow",
53         get browserModes() [modules.modes.MESSAGE],
54         get mailModes() [modules.modes.NORMAL],
55
56         // NOTE: as I don't use TB I have no idea how robust this is. --djk
57         get outputHeight() {
58             if (!this.isComposeWindow) {
59                 let container = document.getElementById("tabpanelcontainer").boxObject;
60                 let deck      = document.getElementById("displayDeck");
61                 let box       = document.getElementById("messagepanebox");
62                 let splitter  = document.getElementById("threadpane-splitter").boxObject;
63
64                 if (splitter.width > splitter.height)
65                     return container.height - deck.minHeight - box.minHeight- splitter.height;
66                 else
67                     return container.height - Math.max(deck.minHeight, box.minHeight);
68             }
69             else
70                 return document.getElementById("appcontent").boxObject.height;
71         },
72
73         removeTab: function removeTab(tab) {
74             if (this.tabbrowser.mTabs.length > 1)
75                 this.tabbrowser.removeTab(tab);
76             else
77                 dactyl.beep();
78         },
79
80         completers: Class.memoize(function () update({ mailfolder: "mailFolder" }, this.__proto__.completers)),
81
82         dialogs: {
83             about: ["About Thunderbird",
84                 function () { window.openAboutDialog(); }],
85             addons: ["Manage Add-ons",
86                 function () { window.openAddonsMgr(); }],
87             addressbook: ["Address book",
88                 function () { window.toAddressBook(); }],
89             checkupdates: ["Check for updates",
90                 function () { window.checkForUpdates(); }],
91             console: ["JavaScript console",
92                 function () { window.toJavaScriptConsole(); }],
93             dominspector: ["DOM Inspector",
94                 function () { window.inspectDOMDocument(content.document); }],
95             downloads: ["Manage Downloads",
96                 function () { window.toOpenWindowByType('Download:Manager', 'chrome://mozapps/content/downloads/downloads.xul', 'chrome,dialog=no,resizable'); }],
97             preferences: ["Show Thunderbird preferences dialog",
98                 function () { window.openOptionsDialog(); }],
99             printsetup: ["Setup the page size and orientation before printing",
100                 function () { window.PrintUtils.showPageSetup(); }],
101             print: ["Show print dialog",
102                 function () { window.PrintUtils.print(); }],
103             saveframe: ["Save frame to disk",
104                 function () { window.saveFrameDocument(); }],
105             savepage: ["Save page to disk",
106                 function () { window.saveDocument(window.content.document); }],
107         },
108
109         focusChange: function focusChange(win) {
110             const { modes } = modules;
111
112             // we switch to -- MESSAGE -- mode for Teledactyl when the main HTML widget gets focus
113             if (win && win.document instanceof Ci.nsIHTMLDocument || dactyl.focus instanceof Ci.nsIHTMLAnchorElement) {
114                 if (this.isComposeWindow)
115                     modes.set(modes.INSERT, modes.TEXT_EDIT);
116                 else if (dactyl.mode != modes.MESSAGE)
117                     modes.main = modes.MESSAGE;
118             }
119         }
120     },
121
122     autocommands: {
123         DOMLoad: "Triggered when a page's DOM content has fully loaded",
124         FolderLoad: "Triggered after switching folders in Thunderbird",
125         PageLoadPre: "Triggered after a page load is initiated",
126         PageLoad: "Triggered when a page gets (re)loaded/opened",
127         Enter: "Triggered after Thunderbird starts",
128         Leave: "Triggered before exiting Thunderbird",
129         LeavePre: "Triggered before exiting Thunderbird"
130     },
131
132     defaults: {
133         guioptions: "bCfrs",
134         complete: "f",
135         showtabline: 1,
136         titlestring: "Teledactyl"
137     },
138
139     /*** optional options, there are checked for existence and a fallback provided  ***/
140     features: Class.memoize(function () set(
141         this.isComposeWindow ? ["addressbook"]
142                              : ["hints", "mail", "marks", "addressbook", "tabs"])),
143
144     guioptions: {
145         m: ["MenuBar",            ["mail-toolbar-menubar2"]],
146         T: ["Toolbar" ,           ["mail-bar2"]],
147         f: ["Folder list",        ["folderPaneBox", "folderpane_splitter"]],
148         F: ["Folder list header", ["folderPaneHeader"]]
149     },
150
151     // they are sorted by relevance, not alphabetically
152     helpFiles: ["intro.html", "version.html"],
153
154     modes: [
155         ["MESSAGE", { char: "m" }],
156         ["COMPOSE"]
157     ],
158
159     get scripts() this.isComposeWindow ? ["compose/compose"] : [
160         "addressbook",
161         "mail",
162         "tabs",
163     ],
164
165     overlayChrome: ["chrome://messenger/content/messenger.xul",
166                       "chrome://messenger/content/messengercompose/messengercompose.xul"],
167     styleableChrome: ["chrome://messenger/content/messenger.xul",
168                       "chrome://messenger/content/messengercompose/messengercompose.xul"],
169
170     // to allow Vim to :set ft=mail automatically
171     tempFile: "teledactyl.eml"
172 }, {
173 }, {
174     commands: function initCommands(dactyl, modules, window) {
175         const { commands } = modules;
176
177         commands.add(["pref[erences]", "prefs"],
178             "Show " + config.host + " preferences",
179             function () { window.openOptionsDialog(); },
180             { argCount: "0" });
181     },
182     modes: function initModes(dactyl, modules, window) {
183         const { modes } = modules;
184
185         this.ignoreKeys = {
186             "<Return>": modes.NORMAL | modes.INSERT,
187             "<Space>": modes.NORMAL | modes.INSERT,
188             "<Up>": modes.NORMAL | modes.INSERT,
189             "<Down>": modes.NORMAL | modes.INSERT
190         };
191     },
192     options: function initOptions(dactyl, modules, window) {
193         const { options } = modules;
194
195         // FIXME: comment obviously incorrect
196         // 0: never automatically edit externally
197         // 1: automatically edit externally when message window is shown the first time
198         // 2: automatically edit externally, once the message text gets focus (not working currently)
199         options.add(["autoexternal", "ae"],
200             "Edit message with external editor by default",
201             "boolean", false);
202
203         options.add(["online"],
204             "Set the 'work offline' option",
205             "boolean", true,
206             {
207                 setter: function (value) {
208                     if (window.MailOfflineMgr.isOnline() != value)
209                         window.MailOfflineMgr.toggleOfflineStatus();
210                     return value;
211                 },
212                 getter: function () window.MailOfflineMgr.isOnline()
213             });
214     }
215 });
216
217 // vim: set fdm=marker sw=4 ts=4 et: