Fix bug 351870 - unable to unselect single event from a group of selected events in main view. a=philipp
authorMarkus Adrario <Mozilla@Adrario.de>
Tue, 17 Jan 2012 12:12:39 +0100
changeset 10100 23e01469104de36485c582bca1fd1e98694fc8ed
parent 10099 e00b8e4f29702c574185e034d0ab5a8a060bba5c
child 10101 17f718dfee5694dee68b9303a52427bc96805bc1
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs351870
Fix bug 351870 - unable to unselect single event from a group of selected events in main view. a=philipp
calendar/base/content/calendar-month-view.xml
calendar/base/content/calendar-multiday-view.xml
calendar/base/content/calendar-view-core.xml
--- a/calendar/base/content/calendar-month-view.xml
+++ b/calendar/base/content/calendar-month-view.xml
@@ -355,17 +355,19 @@
         if (this.mDate)
           this.calendarView.selectedDay = this.mDate;
       ]]></handler>
       <handler event="dblclick"><![CDATA[
         event.stopPropagation();
         this.calendarView.controller.createNewEvent();
       ]]></handler>
       <handler event="click" button="0"><![CDATA[
-        this.calendarView.setSelectedItems(0, []);
+        if (!(event.ctrlKey || event.metaKey)) {
+          this.calendarView.setSelectedItems(0, []);
+        }
       ]]></handler>
       <handler event="DOMMouseScroll"><![CDATA[
         if (getParentNodeOrThisByAttribute(event.originalTarget, "anonid", "day-label") == null) {
             if (this.dayitems.scrollHeight > this.dayitems.clientHeight) {
                 event.stopPropagation();
             }
         }
       ]]></handler>
--- a/calendar/base/content/calendar-multiday-view.xml
+++ b/calendar/base/content/calendar-multiday-view.xml
@@ -1945,18 +1945,20 @@
       <handler event="dblclick" button="0"><![CDATA[
         if (this.calendarView.controller) {
             let newStart = getClickedDateTime(event);
             this.calendarView.controller.createNewEvent(null, newStart, null);
         }
       ]]></handler>
 
       <handler event="click" button="0"><![CDATA[
-        this.calendarView.setSelectedItems(0, []);
-        this.focus();
+        if (!(event.ctrlKey || event.metaKey)) {
+          this.calendarView.setSelectedItems(0, []);
+          this.focus();
+        }
       ]]></handler>
 
       <handler event="click" button="2"><![CDATA[
         let newStart = getClickedDateTime(event);
         this.calendarView.selectedDateTime = newStart;
       ]]></handler>
 
       <!-- mouse down handler, in empty event column regions.  Starts sweeping out a new
@@ -2123,17 +2125,19 @@
     <handlers>
       <handler event="dblclick" button="0"><![CDATA[
         this.calendarView.controller.createNewEvent(null, this.mDate, null, true);
       ]]></handler>
       <handler event="mousedown"><![CDATA[
         this.calendarView.selectedDay = this.mDate;
       ]]></handler>
       <handler event="click" button="0"><![CDATA[
-        this.calendarView.setSelectedItems(0, []);
+        if (!(event.ctrlKey || event.metaKey)) {
+          this.calendarView.setSelectedItems(0, []);
+        }
       ]]></handler>
       <handler event="click" button="2"><![CDATA[
         let newStart = this.calendarView.selectedDay.clone();
         newStart.isDate = true;
         this.calendarView.selectedDateTime = newStart;
         event.stopPropagation();
       ]]></handler>
       <handler event="DOMMouseScroll"><![CDATA[
--- a/calendar/base/content/calendar-view-core.xml
+++ b/calendar/base/content/calendar-view-core.xml
@@ -279,24 +279,28 @@
         ]]></body>
       </method>
       <method name="select">
         <parameter name="event"/>
         <body><![CDATA[
             if (!this.calendarView) {
                 return;
             }
-            var items;
-            if (event.ctrlKey || event.metaKey) {
-                items = this.calendarView.mSelectedItems;
-                items.push(this.mOccurrence);
+            let items = this.calendarView.mSelectedItems.slice();
+            if (event.ctrlKey || event.metaKey) {    
+                if (this.selected) {
+                    let pos = items.indexOf(this.mOccurrence);
+                    items.splice(pos, 1);
+                } else {
+                    items.push(this.mOccurrence);
+                }
             } else {
                 items = [this.mOccurrence];
             }
-            this.calendarView.setSelectedItems(items.length, items);
+            this.calendarView.setSelectedItems(items.length, items, true);
         ]]></body>
       </method>
       <method name="stopEditing">
         <parameter name="saveChanges"/>
         <body><![CDATA[
           if (!this.mEditing)
             return;
 
@@ -327,21 +331,23 @@
          this.select(event);
        }
       ]]></handler>
       <handler event="click" button="0"><![CDATA[
         if (this.mEditing) {
             return;
         }
 
-        // If the left button was used and the item is already selected start
+        // If the left button was used and the item is already selected
+        // and there are no multiple items selected start
         // the 'single click edit' timeout. Otherwise select the item too.
         // Also, check if the calendar is readOnly or we are offline.
 
-        if (this.selected && isCalendarWritable(this.mOccurrence.calendar)) {
+        if (this.selected && !(event.ctrlKey || event.metaKey) &&
+              isCalendarWritable(this.mOccurrence.calendar)) {
             var self = this;
             if (this.editingTimer) {
                 clearTimeout(this.editingTimer);
             }
             this.editingTimer = setTimeout(function editingTimeout() { self.startEditing(); }, 350);
         } else {
             this.select(event);
             event.stopPropagation();