Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ThumbTransactionalDragBehavior.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System.Linq;
4 using System.Windows;
5 using System.Windows.Controls.Primitives;
6 using System.Windows.Interactivity;
7 
8 using SiliconStudio.ActionStack;
9 
10 namespace SiliconStudio.Presentation.Behaviors
11 {
12  public class ThumbTransactionalDragBehavior : Behavior<Thumb>
13  {
14  public static DependencyProperty ActionStackProperty = DependencyProperty.Register("ActionStack", typeof(TransactionalActionStack), typeof(ThumbTransactionalDragBehavior));
15 
16  public TransactionalActionStack ActionStack { get { return (TransactionalActionStack)GetValue(ActionStackProperty); } set { SetValue(ActionStackProperty, value); } }
17 
18  protected override void OnAttached()
19  {
20  AssociatedObject.DragStarted += DragStarted;
21  AssociatedObject.DragCompleted += DragCompleted;
22  }
23 
24  protected override void OnDetaching()
25  {
26  AssociatedObject.DragStarted -= DragStarted;
27  AssociatedObject.DragCompleted -= DragCompleted;
28  }
29 
30  protected virtual void DragStarted(object sender, DragStartedEventArgs e)
31  {
32  if (ActionStack != null)
33  {
34  ActionStack.BeginTransaction();
35  }
36  }
37 
38  protected virtual void DragCompleted(object sender, DragCompletedEventArgs e)
39  {
40  if (ActionStack != null)
41  {
42  var items = ActionStack.GetCurrentTransactions();
43  if (items.Count > 0)
44  {
45  // We use the name of the first action (all actions in this list are
46  // supposed to be the same (ie. with the same name)
47  var name = items.First().Name;
48  ActionStack.EndTransaction(name);
49  }
50  else
51  {
52  // This is not supposed to happen
53  ActionStack.DiscardTransaction();
54  }
55  }
56  }
57  }
58 }
This class is an implementation of the ITransactionalActionStack interface.
virtual void DragCompleted(object sender, DragCompletedEventArgs e)
This class represents a thread-safe stack of action items that can be undone/redone.
Definition: ActionStack.cs:12