calendar/base/content/calendar-menus.xml
author Geoff Lankow <geoff@darktrojan.net>
Wed, 10 Oct 2018 18:57:25 +1300
changeset 33346 7deb26911a65c11d59d4fa8366ff92cf7e081a44
parent 32866 7973e4623106e0a0360f416156ea872ded1d8c8e
child 34398 6e514874b3267dcff87456dff8620f7c51dc1f5c
permissions -rw-r--r--
No bug - fix some white-space issues in calendar; rs=white-space-only

<?xml version="1.0"?>
<!-- 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/. -->

<!DOCTYPE bindings SYSTEM "chrome://calendar/locale/calendar.dtd">

<bindings id="calendar-menu-bindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="task-menupopup" extends="xul:menupopup">
    <implementation>
      <field name="mType">null</field>;
      <field name="mPopupHandler">null</field>
      <field name="mParentMenuPopup">null</field>

      <constructor><![CDATA[
          const { cal } = ChromeUtils.import("resource://calendar/modules/calUtils.jsm", null);

          this.mPopupHandler = () => { this.changeMenuByPropertyName(); };
          this.mParentMenuPopup = cal.view.getParentNodeOrThis(this, "menupopup");
          this.mParentMenuPopup.addEventListener("popupshowing", this.mPopupHandler, true);
      ]]></constructor>

      <destructor><![CDATA[
          this.mParentMenuPopup.removeEventListener("popupshowing", this.mPopupHandler, true);
      ]]></destructor>

      <!-- This method checks a command which naming follows
           the notation 'calendar_' +  mType + ' + '-' + propertyValue + 'command',
           when its propertyValue part matches the propertyValue of the selected tasks
           as long as the selected tasks share common propertyValues. -->
      <method name="changeMenuByPropertyName">
        <body><![CDATA[
            let liveList = document.getAnonymousNodes(this);
            for (let item of liveList) {
                let commandName = item.getAttribute("command");
                let command = document.getElementById(commandName);
                if (command) {
                    command.setAttribute("checked", "false");
                    item.setAttribute("checked", "false");
                }
            }
            let propertyValue;
            if (gTabmail && gTabmail.currentTabInfo.mode.type == "calendarTask") {
                // We are in a task tab (editing a single task).
                propertyValue = gConfig[this.mType];
            } else {
                // We are in the Tasks tab.
                let tasks = getSelectedTasks();
                let tasksSelected = (tasks != null) && (tasks.length > 0);
                if (tasksSelected) {
                    if (tasks.every(task => task[this.mType] == tasks[0][this.mType])) {
                        propertyValue = tasks[0][this.mType];
                    }
                } else {
                    let sibling = this.firstChild;

                    while (sibling) {
                        let domObject = sibling;

                        if (domObject.hasAttribute("command")) {
                            let commandName = domObject.getAttribute("command");
                            let command = document.getElementById(commandName);
                            if (command) {
                                domObject = command;
                            }
                        }

                        domObject.setAttribute("disabled", false);
                        sibling = sibling.nextSibling;
                    }
                }
            }
            if (propertyValue || propertyValue == 0) {
                let command = document.getElementById("calendar_" + this.mType + "-" + propertyValue + "_command");
                if (command) {
                    command.setAttribute("checked", "true");
                }
            }
        ]]></body>
      </method>
    </implementation>
  </binding>

  <binding id="task-progress-menupopup" extends="chrome://calendar/content/calendar-menus.xml#task-menupopup">
    <content>
      <xul:menuitem anonid="percent-0-menuitem"
                type="checkbox"
                label="&progress.level.0;"
                accesskey="&progress.level.0.accesskey;"
                observes="calendar_percentComplete-0_command"
                command="calendar_percentComplete-0_command"/>
      <xul:menuitem anonid="percent-25-menuitem"
                type="checkbox"
                label="&progress.level.25;"
                accesskey="&progress.level.25.accesskey;"
                observes="calendar_percentComplete-25_command"
                command="calendar_percentComplete-25_command"/>
      <xul:menuitem anonid="percent-50-menuitem"
                type="checkbox"
                label="&progress.level.50;"
                accesskey="&progress.level.50.accesskey;"
                observes="calendar_percentComplete-50_command"
                command="calendar_percentComplete-50_command"/>
      <xul:menuitem anonid="percent-75-menuitem"
                type="checkbox"
                label="&progress.level.75;"
                accesskey="&progress.level.75.accesskey;"
                observes="calendar_percentComplete-75_command"
                command="calendar_percentComplete-75_command"/>
      <xul:menuitem anonid="percent-100-menuitem"
                type="checkbox"
                label="&progress.level.100;"
                accesskey="&progress.level.100.accesskey;"
                observes="calendar_percentComplete-100_command"
                command="calendar_percentComplete-100_command"/>
      <children/>
    </content>
    <implementation>
      <constructor><![CDATA[
          this.mType = "percentComplete";
          this.changeMenuByPropertyName();
      ]]></constructor>
    </implementation>
  </binding>

  <binding id="task-priority-menupopup" extends="chrome://calendar/content/calendar-menus.xml#task-menupopup">
    <content>
      <xul:menuitem id="priority-0-menuitem"
                    type="checkbox"
                    label="&priority.level.none;"
                    accesskey="&priority.level.none.accesskey;"
                    command="calendar_priority-0_command"
                    observes="calendar_priority-0_command"/>
      <xul:menuitem id="priority-9-menuitem"
                    type="checkbox"
                    label="&priority.level.low;"
                    accesskey="&priority.level.low.accesskey;"
                    command="calendar_priority-9_command"
                    observes="calendar_priority-9_command"/>
      <xul:menuitem id="priority-5-menuitem"
                    type="checkbox"
                    label="&priority.level.normal;"
                    accesskey="&priority.level.normal.accesskey;"
                    command="calendar_priority-5_command"
                    observes="calendar_priority-5_command"/>
      <xul:menuitem id="priority-1-menuitem"
                type="checkbox"
                label="&priority.level.high;"
                accesskey="&priority.level.high.accesskey;"
                command="calendar_priority-1_command"
                observes="calendar_priority-1_command"/>
      <children/>
    </content>
    <implementation>
      <constructor><![CDATA[
          this.mType = "priority";
          this.changeMenuByPropertyName();
      ]]></constructor>
    </implementation>
  </binding>
</bindings>