summaryrefslogtreecommitdiff
path: root/teledactyl/content/compose/compose.js
blob: 90293701b253d255a3ff64b05c6971bdc592d402 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2006-2009 by Martin Stubenschrott <stubenschrott@vimperator.org>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";

function Compose() { //{{{
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////// PRIVATE SECTION /////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////{{{

    config.features = ["addressbook"]; // the composer has no special features

    var stateListener = {
        QueryInterface: function (id) {
            if (id.equals(Ci.nsIDocumentStateListener))
                return this;
            throw Cr.NS_NOINTERFACE;
        },

        // this is (also) fired once the new compose window loaded the message for the first time
        NotifyDocumentStateChanged: function (nowDirty) {
            // only edit with external editor if this window was not cached!
            if (options["autoexternal"] && !window.messageWasEditedExternally/* && !gMsgCompose.recycledWindow*/) {
                window.messageWasEditedExternally = true;
                editor.editFieldExternally();
            }

        },
        NotifyDocumentCreated: function () {},
        NotifyDocumentWillBeDestroyed: function () {}
    };

    // XXX: Hack!
    window.document.addEventListener("load", function () {
        if (window.messageWasEditedExternally === undefined) {
            window.messageWasEditedExternally = false;
            GetCurrentEditor().addDocumentStateListener(stateListener);
        }
    }, true);

    window.addEventListener("compose-window-close", function () {
        window.messageWasEditedExternally = false;
    }, true);

    /*window.document.addEventListener("unload", function () {
        GetCurrentEditor().removeDocumentStateListener(config.stateListener);
    }, true);*/

    /////////////////////////////////////////////////////////////////////////////}}}
    ////////////////////// OPTIONS /////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////{{{

    /////////////////////////////////////////////////////////////////////////////}}}
    ////////////////////// MAPPINGS ////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////{{{

    /////////////////////////////////////////////////////////////////////////////}}}
    ////////////////////// COMMANDS ////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////{{{

    mappings.add([modes.COMPOSE],
        ["e"], "Edit message",
        function () { editor.editFieldExternally(); });

    mappings.add([modes.COMPOSE],
        ["y"], "Send message now",
        function () { window.goDoCommand("cmd_sendNow"); });

    mappings.add([modes.COMPOSE],
        ["Y"], "Send message later",
        function () { window.goDoCommand("cmd_sendLater"); });

    // FIXME: does not really work reliably
    mappings.add([modes.COMPOSE],
        ["t"], "Select To: field",
        function () { awSetFocus(0, awGetInputElement(1)); });

    mappings.add([modes.COMPOSE],
        ["s"], "Select Subject: field",
        function () { GetMsgSubjectElement().focus(); });

    mappings.add([modes.COMPOSE],
        ["i"], "Select message body",
        function () { SetMsgBodyFrameFocus(); });

    mappings.add([modes.COMPOSE],
        ["q"], "Close composer, ask when for unsaved changes",
        function () { DoCommandClose(); });

    mappings.add([modes.COMPOSE],
        ["Q", "ZQ"], "Force closing composer",
        function () { MsgComposeCloseWindow(true); /* cache window for better performance*/ });

    /////////////////////////////////////////////////////////////////////////////}}}
    ////////////////////// PUBLIC SECTION //////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////{{{

    return {};

    //}}}
} //}}}

// vim: set fdm=marker sw=4 ts=4 et: