Пример #1
0
        /// <summary>
        /// Executes a command and adds it to the command history if the command
        /// is undoable.
        /// </summary>
        /// <param name="command">The command to be executed.</param>
        public virtual void Insert(Command command)
        {
            DebugHelpers.CatchAndLog(() =>
            {
                command.Execute();

                if (command.HasUndo)
                {
                    var newNode       = new Node <Command>(command);
                    newNode.Previous  = FCurrentNode;
                    FCurrentNode.Next = newNode;
                    FCurrentNode      = newNode;
                }
                else
                {
                    FFirstNode.Next = null;
                    FCurrentNode    = FFirstNode;
                }

                Debug.WriteLine(string.Format("Command {0} executed.", command));
            },
                                     string.Format("Execution of command {0}", command));

            OnCommandInserted(command);
        }
Пример #2
0
 /// <summary>
 /// Executes a command and adds it to the command history if the command
 /// is undoable and sends the command to the remote server.
 /// </summary>
 /// <param name="command">The command to be executed.</param>
 public override void Insert(Command command)
 {
     DebugHelpers.CatchAndLog(
         () => FCommandSender.SendCommandAsync(command),
         string.Format("SendCommandAsync: {0}", command));
     base.Insert(command);
     Debug.WriteLine(string.Format("Executed on ClientCommandHistory for {0}", FIdItem.Name));
 }
Пример #3
0
        /// <summary>
        /// Redo last command.
        /// </summary>
        public virtual void Redo()
        {
            var command = NextCommand;

            if (command != null)
            {
                DebugHelpers.CatchAndLog(() =>
                {
                    command.Redo();
                    FCurrentNode = FCurrentNode.Next;
                    Debug.WriteLine(string.Format("Command {0} redone.", command));
                },
                                         string.Format("Redo of command {0}", command));
            }
        }
Пример #4
0
        /// <summary>
        /// Undo last command.
        /// </summary>
        public virtual void Undo()
        {
            var command = PreviousCommand;

            if (command != null)
            {
                DebugHelpers.CatchAndLog(() =>
                {
                    command.Undo();
                    FCurrentNode = FCurrentNode.Previous;
                    Debug.WriteLine(string.Format("Command {0} undone.", command));
                },
                                         string.Format("Undo of command {0}", command));
            }
        }
Пример #5
0
        private void InsertCommand(Command command, bool execute)
        {
            DebugHelpers.CatchAndLog(() =>
            {
                if (command is CompoundCommand)
                {
                    var comp = (command as CompoundCommand);
                    if (comp.IsEmptyRecursive())
                    {
                        Debug.WriteLine("History rejected empty compound command");
                        return;
                    }
                }

                if (execute)
                {
                    command.Execute();
                }

                if (command.HasUndo)
                {
                    var newNode       = new Node <Command>(command);
                    newNode.Previous  = FCurrentNode;
                    FCurrentNode.Next = newNode;
                    FCurrentNode      = newNode;
                }
                else
                {
                    FFirstNode.Next = null;
                    FCurrentNode    = FFirstNode;
                    Debug.WriteLine("undo history cleared");
                }

                Debug.WriteLine(string.Format("Command inserted: {0}", command));
            },
                                     string.Format("Execution of command {0}", command));

            OnCommandInserted(command);
        }