Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AggregateActionItem.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;
4 using System.Collections.Generic;
5 using System.Linq;
6 
7 using SiliconStudio.Core.Extensions;
8 
9 namespace SiliconStudio.ActionStack
10 {
11  /// <summary>
12  /// An <see cref="ActionItem"/> that represents a set of multiple action items.
13  /// </summary>
15  {
16  private readonly IEnumerable<IActionItem> actionItems;
17 
18  /// <summary>
19  /// Initializes a new instance of the <see cref="AggregateActionItem"/> class with the given collection of action items.
20  /// </summary>
21  /// <param name="actionItems">The action items to add to this aggregation.</param>
23  : this(null, actionItems)
24  {
25  }
26 
27  /// <summary>
28  /// Initializes a new instance of the <see cref="AggregateActionItem"/> class with the given name and collection of action items.
29  /// </summary>
30  /// <param name="name">The name of this action item.</param>
31  /// <param name="actionItems">The action items to add to this aggregation.</param>
32  public AggregateActionItem(string name, IEnumerable<IActionItem> actionItems)
33  : base(name)
34  {
35  if (actionItems == null) throw new ArgumentNullException("actionItems");
36  this.actionItems = actionItems;
37  }
38 
39  /// <inheritdoc/>
40  public IEnumerable<IActionItem> ActionItems { get { return actionItems; } }
41 
42  /// <inheritdoc/>
43  public override bool IsSaved { get { return ActionItems.All(x => x.IsSaved); } set { ActionItems.ForEach(x => x.IsSaved = value); } }
44 
45  /// <inheritdoc/>
46  public bool ContainsAction(IActionItem actionItem)
47  {
48  return ActionItems.Any(x => x == actionItem || (x is IAggregateActionItem && ((IAggregateActionItem)x).ContainsAction(actionItem)));
49  }
50 
51  /// <inheritdoc/>
53  {
54  yield return this;
55  foreach (var actionItem in ActionItems)
56  {
57  var aggregateActionItem = actionItem as AggregateActionItem;
58  if (aggregateActionItem != null)
59  {
60  foreach (var subActionItem in aggregateActionItem.GetInnerActionItems())
61  {
62  yield return subActionItem;
63  }
64  }
65  else
66  {
67  yield return actionItem;
68  }
69  }
70  }
71 
72  /// <inheritdoc/>
73  protected override void FreezeMembers()
74  {
75  foreach (var actionItem in actionItems.Where(x => x != null))
76  actionItem.Freeze();
77  }
78 
79  /// <inheritdoc/>
80  protected override void UndoAction()
81  {
82  foreach (var actionItem in ActionItems.Reverse().Where(x => x != null))
83  actionItem.Undo();
84  }
85 
86  /// <inheritdoc/>
87  protected override void RedoAction()
88  {
89  foreach (var actionItem in ActionItems.Where(x => x != null))
90  actionItem.Redo();
91  }
92  }
93 }
override void FreezeMembers()
Invoked by Freeze before setting IsFrozen to true. This method will not be invoked if IsFrozen is alr...
override void UndoAction()
Invoked by Undo after setting IsDone to true.
Base class for action items.
Definition: ActionItem.cs:13
An ActionItem that represents a set of multiple action items.
AggregateActionItem(string name, IEnumerable< IActionItem > actionItems)
Initializes a new instance of the AggregateActionItem class with the given name and collection of act...
bool ContainsAction(IActionItem actionItem)
Gets whether the given action item is contained in this aggregate. The action item to look for...
Base interface for action items.
Definition: IActionItem.cs:10
Base interface of aggregate of action items.
IEnumerable< IActionItem > GetInnerActionItems()
Gets all action items contained in this aggregate that are not IAggregateActionItem themselves...
AggregateActionItem(IEnumerable< IActionItem > actionItems)
Initializes a new instance of the AggregateActionItem class with the given collection of action items...
override void RedoAction()
Invoked by Redo after setting IsDone to true.