]> git.donarmstrong.com Git - dactyl.git/blob - teledactyl/content/compose/compose.js
Initial import of 1.0~b6
[dactyl.git] / teledactyl / content / compose / compose.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 Compose = Module("compose", {
8     init: function init() {
9         var stateListener = {
10             QueryInterface: function (id) {
11                 if (id.equals(Ci.nsIDocumentStateListener))
12                     return this;
13                 throw Cr.NS_NOINTERFACE;
14             },
15
16             // this is (also) fired once the new compose window loaded the message for the first time
17             NotifyDocumentStateChanged: function (nowDirty) {
18                 // only edit with external editor if this window was not cached!
19                 if (options["autoexternal"] && !window.messageWasEditedExternally/* && !gMsgCompose.recycledWindow*/) {
20                     window.messageWasEditedExternally = true;
21                     editor.editFieldExternally();
22                 }
23
24             },
25             NotifyDocumentCreated: function () {},
26             NotifyDocumentWillBeDestroyed: function () {}
27         };
28
29         events.listen(window.document, "load", function () {
30                 if (window.messageWasEditedExternally === undefined) {
31                     window.messageWasEditedExternally = false;
32                     GetCurrentEditor().addDocumentStateListener(stateListener);
33                 }
34             }, true);
35
36         events.listen(window, "compose-window-close", function () {
37             window.messageWasEditedExternally = false;
38         }, true);
39     }
40 }, {
41 }, {
42     mappings: function initMappings(dactyl, modules, window) {
43         mappings.add([modes.COMPOSE],
44             ["e"], "Edit message",
45             function () { editor.editFieldExternally(); });
46
47         mappings.add([modes.COMPOSE],
48             ["y"], "Send message now",
49             function () { window.goDoCommand("cmd_sendNow"); });
50
51         mappings.add([modes.COMPOSE],
52             ["Y"], "Send message later",
53             function () { window.goDoCommand("cmd_sendLater"); });
54
55         // FIXME: does not really work reliably
56         mappings.add([modes.COMPOSE],
57             ["t"], "Select To: field",
58             function () { awSetFocus(0, awGetInputElement(1)); });
59
60         mappings.add([modes.COMPOSE],
61             ["s"], "Select Subject: field",
62             function () { GetMsgSubjectElement().focus(); });
63
64         mappings.add([modes.COMPOSE],
65             ["i"], "Select message body",
66             function () { SetMsgBodyFrameFocus(); });
67
68         mappings.add([modes.COMPOSE],
69             ["q"], "Close composer, ask when for unsaved changes",
70             function () { DoCommandClose(); });
71
72         mappings.add([modes.COMPOSE],
73             ["Q", "ZQ"], "Force closing composer",
74             function () { MsgComposeCloseWindow(true); /* cache window for better performance*/ });
75     },
76     modes: function initModes(dactyl, modules, window) {
77         modes.addMode("COMPOSE", {
78             insert: true
79         });
80     }
81 });
82
83 // vim: set fdm=marker sw=4 ts=4 et: