示例#1
0
        public void PerformCommand(IUndoCommand command)
        {
            if (performingCommandSequence)
            {
                commandSequence.PerformCommand(command);
            }
            else
            {
                try
                {
                    command.Perform();

                    index++;

                    commands.Insert(index, command);

                    if (index < capacity && commands.Count > index + 1)
                    {
                        commands.RemoveRange(index + 1, commands.Count - (index + 1));
                    }

                    if (commands.Count > capacity)
                    {
                        commands.RemoveRange(0, commands.Count - capacity);
                    }

                    CommandPerformed?.Invoke(this, new EventArgs());
                }
                catch (Exception ex)
                {
                    HandleError(command, ex);
                }
            }
        }
示例#2
0
        public void BeginCommandSequence(string description)
        {
            performingCommandSequence = true;

            commandSequence = new UndoSequence(description, errorSink);
            commandSequence.CommandPerformed += (sender, e) => CommandPerformed?.Invoke(this, e);
        }
        public void PerformCommand()
        {
            if (!Enabled || Text.Length == 0)
            {
                return;
            }

            CommandPerformed?.Invoke(Text);
            Clear();
        }
示例#4
0
        public void Redo()
        {
            if (index + 1 == commands.Count)
            {
                return;
            }

            IUndoCommand command = commands.ElementAt(index + 1);

            try
            {
                command.Perform();

                index++;

                CommandPerformed?.Invoke(this, new EventArgs());
            }
            catch (Exception ex)
            {
                HandleError(command, ex);
            }
        }
示例#5
0
        public void Undo()
        {
            if (index < 0)
            {
                return;
            }

            IUndoCommand command = commands.ElementAt(index);

            try
            {
                command.Rollback();

                index--;

                CommandPerformed?.Invoke(this, new EventArgs());
            }
            catch (Exception ex)
            {
                HandleError(command, ex);
            }
        }
示例#6
0
        public void Do(CommandBase com)
        {
            MyGame.DebugAlert(DebugMode.Commands, "Doing " + com.ToString(MyGame));

            if (!(com is CommandGroup))
            {
                UndoStack.Push(com);
            }

            com.Do(MyGame);

            if (!SuspendViewUpdates)
            {
                com.UpdateViews(MyGame);
            }

            if (triggerOnCommandTypes.Contains(com.GetType()) && !IsLoading)
            {
                MyGame.MyTriggerHandler.GatherTriggers(com);
            }

            CommandPerformed?.Invoke(com);
        }
 internal void NotifyCommandPerformed(CommandReply repl)
 {
     CommandPerformed?.Invoke(this, repl);
     m_wasPerformed = true;
 }