]> git.donarmstrong.com Git - dactyl.git/blob - teledactyl/content/config.js
Import 1.0rc1 supporting Firefox up to 11.*
[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     // to allow Vim to :set ft=mail automatically
122     tempFile: "teledactyl.eml"
123 }, {
124 }, {
125     commands: function initCommands(dactyl, modules, window) {
126         const { commands } = modules;
127
128         commands.add(["pref[erences]", "prefs"],
129             "Show " + config.host + " preferences",
130             function () { window.openOptionsDialog(); },
131             { argCount: "0" });
132     },
133     modes: function initModes(dactyl, modules, window) {
134         const { modes } = modules;
135
136         this.ignoreKeys = {
137             "<Return>": modes.NORMAL | modes.INSERT,
138             "<Space>": modes.NORMAL | modes.INSERT,
139             "<Up>": modes.NORMAL | modes.INSERT,
140             "<Down>": modes.NORMAL | modes.INSERT
141         };
142     },
143     options: function initOptions(dactyl, modules, window) {
144         const { options } = modules;
145
146         // FIXME: comment obviously incorrect
147         // 0: never automatically edit externally
148         // 1: automatically edit externally when message window is shown the first time
149         // 2: automatically edit externally, once the message text gets focus (not working currently)
150         options.add(["autoexternal", "ae"],
151             "Edit message with external editor by default",
152             "boolean", false);
153
154         options.add(["online"],
155             "Set the 'work offline' option",
156             "boolean", true,
157             {
158                 setter: function (value) {
159                     if (window.MailOfflineMgr.isOnline() != value)
160                         window.MailOfflineMgr.toggleOfflineStatus();
161                     return value;
162                 },
163                 getter: function () window.MailOfflineMgr.isOnline()
164             });
165     }
166 });
167
168 // vim: set fdm=marker sw=4 ts=4 et: