Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
NumericTextBoxTransactionalRepeatButtonsBehavior.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 
6 using SiliconStudio.ActionStack;
7 using SiliconStudio.Presentation.Controls;
8 
9 namespace SiliconStudio.Presentation.Behaviors
10 {
11  /// <summary>
12  /// This behavior allows more convenient editing of the value of a char using a TextBox.
13  /// </summary>
14  public class NumericTextBoxTransactionalRepeatButtonsBehavior : DeferredBehaviorBase<NumericTextBox>
15  {
16  public static DependencyProperty ActionStackProperty = DependencyProperty.Register("ActionStack", typeof(TransactionalActionStack), typeof(NumericTextBoxTransactionalRepeatButtonsBehavior));
17 
18  public TransactionalActionStack ActionStack { get { return (TransactionalActionStack)GetValue(ActionStackProperty); } set { SetValue(ActionStackProperty, value); } }
19 
20  protected override void OnAttachedOverride()
21  {
22  AssociatedObject.RepeatButtonPressed += RepeatButtonPressed;
23  AssociatedObject.RepeatButtonReleased += RepeatButtonReleased;
24  }
25 
26  protected override void OnDetachingOverride()
27  {
28  AssociatedObject.RepeatButtonPressed -= RepeatButtonPressed;
29  AssociatedObject.RepeatButtonReleased -= RepeatButtonReleased;
30  }
31 
32  private void RepeatButtonPressed(object sender, RepeatButtonPressedRoutedEventArgs e)
33  {
34  if (ActionStack != null)
35  {
36  ActionStack.BeginTransaction();
37  }
38  }
39 
40  private void RepeatButtonReleased(object sender, RepeatButtonPressedRoutedEventArgs e)
41  {
42  if (ActionStack != null)
43  {
44  var items = ActionStack.GetCurrentTransactions();
45  if (items.Count > 0)
46  {
47  // We use the name of the first action (all actions in this list are
48  // supposed to be the same (ie. with the same name)
49  var name = items.First().Name;
50  ActionStack.EndTransaction(name);
51  }
52  else
53  {
54  // This is not supposed to happen
55  ActionStack.DiscardTransaction();
56  }
57  }
58  }
59  }
60 }
This class is an implementation of the ITransactionalActionStack interface.
This behavior allows more convenient editing of the value of a char using a TextBox.
This class represents a thread-safe stack of action items that can be undone/redone.
Definition: ActionStack.cs:12