summaryrefslogtreecommitdiffstats
path: root/comm/mail/base/content/macMessengerMenu.js
blob: 3ee6ba4872dcc766629849287483d166be2fdd2f (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
/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* import-globals-from mailCore.js */

var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

// Load and add the menu item to the OS X Dock icon menu.
addEventListener(
  "load",
  function () {
    let dockMenuElement = document.getElementById("menu_mac_dockmenu");
    let nativeMenu = Cc[
      "@mozilla.org/widget/standalonenativemenu;1"
    ].createInstance(Ci.nsIStandaloneNativeMenu);

    nativeMenu.init(dockMenuElement);

    let dockSupport = Cc["@mozilla.org/widget/macdocksupport;1"].getService(
      Ci.nsIMacDockSupport
    );
    dockSupport.dockMenu = nativeMenu;
  },
  false
);

/**
 * When the Preferences window is actually loaded, this Listener is called.
 * Not doing this way could make DOM elements not available.
 */
function loadListener(event) {
  setTimeout(function () {
    let prefWin = Services.wm.getMostRecentWindow("Mail:Preferences");
    prefWin.gSubDialog.open(
      "chrome://messenger/content/preferences/dockoptions.xhtml"
    );
  });
}

/**
 * When the Preferences window is opened/closed, this observer will be called.
 * This is done so subdialog opens as a child of it.
 */
function PrefWindowObserver() {
  this.observe = function (aSubject, aTopic, aData) {
    if (aTopic == "domwindowopened") {
      aSubject.addEventListener("load", loadListener, {
        capture: false,
        once: true,
      });
    }
    Services.ww.unregisterNotification(this);
  };
}

/**
 * Show the Dock Options sub-dialog hanging from the Preferences window.
 * If Preference window was already opened, this will select General pane before
 * opening Dock Options sub-dialog.
 */
function openDockOptions() {
  let win = Services.wm.getMostRecentWindow("Mail:Preferences");

  if (win) {
    openOptionsDialog("paneGeneral");
    win.gSubDialog("chrome://messenger/content/preferences/dockoptions.xhtml");
  } else {
    Services.ww.registerNotification(new PrefWindowObserver());
    openOptionsDialog("paneGeneral");
  }
}

/**
 * Open a new window for writing a new message
 */
function writeNewMessageDock() {
  // Default identity will be used as sender for the new message.
  MailServices.compose.OpenComposeWindow(
    null,
    null,
    null,
    Ci.nsIMsgCompType.New,
    Ci.nsIMsgCompFormat.Default,
    null,
    null,
    null
  );
}

/**
 * Open the address book window
 */
function openAddressBookDock() {
  toAddressBook();
}