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