/// <summary> /// Adds a behavior to the <see cref="All"/> collection and the collection based on the <see cref="ParseCommandBase.CommandType"/> type. /// </summary> /// <param name="command"></param> public void AddSafe(ParseCommandBase command) { switch (command.CommandType) { case CommandTypes.Foreground: Foreground.Push(command); All.Push(command); break; case CommandTypes.Background: Background.Push(command); All.Push(command); break; case CommandTypes.Mirror: Mirror.Push(command); All.Push(command); break; case CommandTypes.Effect: Effect.Push(command); All.Push(command); break; case CommandTypes.Glyph: Glyph.Push(command); All.Push(command); break; default: break; } }
/// <summary> /// Adds a behavior to the <see cref="All"/> collection and the collection based on the <see cref="ParseCommandBase.CommandType"/> type. /// </summary> /// <param name="command"></param> public void AddSafe(ParseCommandBase command) { switch (command.CommandType) { case CommandTypes.Foreground: Foreground.Push(command); All.Push(command); break; case CommandTypes.Background: Background.Push(command); All.Push(command); break; case CommandTypes.SpriteEffect: SpriteEffect.Push(command); All.Push(command); break; case CommandTypes.Effect: Effect.Push(command); All.Push(command); break; case CommandTypes.Glyph: Glyph.Push(command); All.Push(command); break; default: break; } }
public ParseCommandUndo(string parameters, ParseCommandStacks stacks) { var badCommandException = new ArgumentException("command is invalid for Undo: " + parameters); string[] parts = parameters.Split(new char[] { ':' }, 3); int times = 1; bool isSpecificStack = false; CommandTypes stackType = CommandTypes.Invalid; if (parts.Length > 1) { isSpecificStack = true; switch (parts[1]) { case "f": stackType = CommandTypes.Foreground; break; case "b": stackType = CommandTypes.Background; break; case "g": stackType = CommandTypes.Glyph; break; case "e": stackType = CommandTypes.Effect; break; case "m": stackType = CommandTypes.Mirror; break; case "a": isSpecificStack = false; break; default: throw badCommandException; } } if (parts.Length >= 1 && parts[0] != "") { times = int.Parse(parts[0], CultureInfo.InvariantCulture); } for (int i = 0; i < times; i++) { ParseCommandBase behavior = null; if (!isSpecificStack) { if (stacks.All.Count != 0) { behavior = stacks.All.Pop(); switch (behavior.CommandType) { case CommandTypes.Foreground: stacks.Foreground.Pop(); break; case CommandTypes.Background: stacks.Background.Pop(); break; case CommandTypes.Glyph: stacks.Glyph.Pop(); break; case CommandTypes.Mirror: stacks.Mirror.Pop(); break; case CommandTypes.Effect: stacks.Effect.Pop(); break; default: break; } } else { break; } } else { switch (stackType) { case CommandTypes.Foreground: if (stacks.Foreground.Count != 0) { behavior = stacks.Foreground.Pop(); } break; case CommandTypes.Background: if (stacks.Background.Count != 0) { behavior = stacks.Background.Pop(); } break; case CommandTypes.Glyph: if (stacks.Glyph.Count != 0) { behavior = stacks.Glyph.Pop(); } break; case CommandTypes.Mirror: if (stacks.Mirror.Count != 0) { behavior = stacks.Mirror.Pop(); } break; case CommandTypes.Effect: if (stacks.Effect.Count != 0) { behavior = stacks.Effect.Pop(); } break; default: break; } if (behavior != null) { List <ParseCommandBase> all = new List <ParseCommandBase>(stacks.All); all.Remove(behavior); stacks.All = new Stack <ParseCommandBase>(all); } } } CommandType = CommandTypes.PureCommand; }
/// <summary> /// Removes a command from the appropriate command stack and from the <see cref="All"/> stack. /// </summary> /// <param name="command">The command to remove</param> public void RemoveSafe(ParseCommandBase command) { List <ParseCommandBase> commands = null; // Get the stack we need to remove from switch (command.CommandType) { case CommandTypes.Foreground: if (Foreground.Count != 0) { commands = new List <ParseCommandBase>(Foreground); } break; case CommandTypes.Background: if (Background.Count != 0) { commands = new List <ParseCommandBase>(Background); } break; case CommandTypes.Mirror: if (Mirror.Count != 0) { commands = new List <ParseCommandBase>(Mirror); } break; case CommandTypes.Effect: if (Effect.Count != 0) { commands = new List <ParseCommandBase>(Effect); } break; case CommandTypes.Glyph: if (Glyph.Count != 0) { commands = new List <ParseCommandBase>(Glyph); } break; default: return; } // If we have one, remove and restore stack if (commands != null && commands.Contains(command)) { commands.Remove(command); commands.Reverse(); switch (command.CommandType) { case CommandTypes.Foreground: Foreground = new Stack <ParseCommandBase>(commands); break; case CommandTypes.Background: Background = new Stack <ParseCommandBase>(commands); break; case CommandTypes.Mirror: Mirror = new Stack <ParseCommandBase>(commands); break; case CommandTypes.Effect: Effect = new Stack <ParseCommandBase>(commands); break; case CommandTypes.Glyph: Glyph = new Stack <ParseCommandBase>(commands); break; default: return; } } List <ParseCommandBase> all = new List <ParseCommandBase>(All); if (all.Contains(command)) { all.Remove(command); all.Reverse(); All = new Stack <ParseCommandBase>(all); } }
/// <summary> /// Removes a command from the appropriate command stack and from the <see cref="All"/> stack. /// </summary> /// <param name="command">The command to remove</param> public void RemoveSafe(ParseCommandBase command) { List<ParseCommandBase> commands = null; // Get the stack we need to remove from switch (command.CommandType) { case CommandTypes.Foreground: if (Foreground.Count != 0) commands = new List<ParseCommandBase>(Foreground); break; case CommandTypes.Background: if (Background.Count != 0) commands = new List<ParseCommandBase>(Background); break; case CommandTypes.SpriteEffect: if (SpriteEffect.Count != 0) commands = new List<ParseCommandBase>(SpriteEffect); break; case CommandTypes.Effect: if (Effect.Count != 0) commands = new List<ParseCommandBase>(Effect); break; case CommandTypes.Glyph: if (Glyph.Count != 0) commands = new List<ParseCommandBase>(Glyph); break; default: return; } // If we have one, remove and restore stack if (commands != null && commands.Contains(command)) { commands.Remove(command); commands.Reverse(); switch (command.CommandType) { case CommandTypes.Foreground: Foreground = new Stack<ParseCommandBase>(commands); break; case CommandTypes.Background: Background = new Stack<ParseCommandBase>(commands); break; case CommandTypes.SpriteEffect: SpriteEffect = new Stack<ParseCommandBase>(commands); break; case CommandTypes.Effect: Effect = new Stack<ParseCommandBase>(commands); break; case CommandTypes.Glyph: Glyph = new Stack<ParseCommandBase>(commands); break; default: return; } } List<ParseCommandBase> all = new List<ParseCommandBase>(All); if (all.Contains(command)) { all.Remove(command); all.Reverse(); All = new Stack<ParseCommandBase>(all); } }