src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 140 fc7c12f9da30
parent 136 8b513df1b446
child 146 dd8ed4d3beb6
--- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Sun Oct 11 20:38:22 2009 +0200
+++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Tue Oct 13 10:43:39 2009 +0200
@@ -10,13 +10,14 @@
 using System.Windows.Media.Animation;
 using System.Windows.Navigation;
 using System.Windows.Controls.Primitives;
+using Microsoft.Surface.Presentation;
 using Microsoft.Surface.Presentation.Controls;
-using Microsoft.Surface.Presentation;
 using System.Windows.Threading;
 
 using FingersDance.Data;
 using FingersDance.ViewModels;
 using FingersDance.Views;
+using FingersDance.Control.Close;
 
 namespace FingersDance.Control.TimeLine
 {
@@ -28,7 +29,7 @@
         private bool isDragging = false;
         private bool finishedDragging = false;
         #endregion
-
+        
         public event EventHandler DragStarted;
         public event EventHandler DragCompleted;
         public event EventHandler TimerTick;
@@ -41,6 +42,8 @@
         private Boolean AnnotWaiting = false;
         private float AnnotTcBegin;
 
+        private AnnotationViewModel canceledAnnotationVM;
+
         #region Properties
 
         public SurfaceSlider Slider
@@ -98,7 +101,7 @@
 		public UserControlTimeLine()
 		{
 			this.InitializeComponent();
-
+            
 			// Insert code required on object creation below this point.
             
 		}
@@ -361,7 +364,7 @@
                     DataContext = findSource.DataContext
                 }
             };
-
+            
             // We apply the current scale to the dragged annotation
             ((TimelineAnnotationView)cursorVisual.Content).RenderTransform = this.RenderTransform;
 
@@ -401,28 +404,42 @@
 
         private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e)
         {
-            Console.WriteLine("onDragCanceled = " + sender + ", ((ContentControl)e.Cursor.Visual).Content = " + ((ContentControl)e.Cursor.Visual).Content);
-            // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
-            AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
+            //Console.WriteLine("onDragCanceled = " + sender + ", ((ContentControl)e.Cursor.Visual).Content = " + ((ContentControl)e.Cursor.Visual).Content);
             // We check if the annotation is well one of the current annotations
             if (CuttingVM != null)
             {
+                // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
+                canceledAnnotationVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
+                confirmCancelPopup.Visibility = Visibility.Visible;
+            }
+        }
+
+        private void confirmCancelPopup_ConfirmYesOrNo(object sender, ConfirmEventArgs e)
+        {
+            //Console.WriteLine("Confirm = " + e.Confirmed);
+            // We check if the annotation is well one of the current annotations
+            if (CuttingVM != null && canceledAnnotationVM != null && e.Confirmed == true)
+            {
                 foreach (Annotation a in AnnotList)
                 {
-                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
-                    // Check begin TC
-                    if (a.TcBegin == annotationDataVM.TcBegin && a.Dur == annotationDataVM.Dur && a.GestureType==annotationDataVM.GestureType)
+                    // Check begin TcBegin, duration and gesture type
+                    if (a.TcBegin == canceledAnnotationVM.TcBegin && a.Dur == canceledAnnotationVM.Dur && a.GestureType == canceledAnnotationVM.GestureType)
                     {
-                        // We found the good annotation so we can delete it
+                        // We found the good annotation so we can remove it
                         AnnotList.Remove(a);
                         // We redisplay the timeline
                         CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
                         tv.DataContext = null;
                         tv.DataContext = CuttingVM;
+                        // We close the popup and return as soon as we removed the annotation to avoid an error on AnnotList, which is just modified
+                        confirmCancelPopup.Visibility = Visibility.Hidden;
+                        canceledAnnotationVM = null;
                         return;
                     }
                 }
             }
+            confirmCancelPopup.Visibility = Visibility.Hidden;
+            canceledAnnotationVM = null;
         }