Esempio n. 1
0
		private void ClearCommands()
		{
			while ((_currentCommand = commandsStack.Pop()) != null)
			{
				_currentCommand.Finished = true;
			}
			commandsStack.Push(null);
		}
Esempio n. 2
0
		private Command PopCommand()
		{
			if (_currentCommand != null)
			{
				Command command = commandsStack.Pop();
				_currentCommand = commandsStack.Peek();
				return command;
			}
			else
			{
				Debug.Fail("Commands stack is empty");
				return null;
			}
		}
Esempio n. 3
0
		internal void Merge(Command mergedCommand)
		{
			foreach (IUndoRedoMember member in mergedCommand.changes.Keys)
			{
				if (changes.ContainsKey(member))
				{
					changes[member].NewObject = mergedCommand.changes[member].NewObject;
				}
				else
				{
					changes[member] = mergedCommand.changes[member];
				}
			}
		}
Esempio n. 4
0
 private IDisposable Start(string commandCaption, bool visible)
 {
     AssertNoCommand();
     currentArea = this;
     currentCommand = new Command(commandCaption, this, visible);
     return currentCommand;
 }
Esempio n. 5
0
        /// <summary>Commits current command and saves changes into history</summary>
        public void Commit()
        {
            AssertCurrentCommand();
            if (currentCommand.HasChanges)
            {
                currentCommand.Commit();

                // remove all redo records
                int count = history.Count - currentPosition - 1;
                history.RemoveRange(currentPosition + 1, count);

                // add command to history
                if (currentCommand.Visible)
                {
                    history.Add(currentCommand);
                    currentPosition++;
                    TruncateHistory();
                }
                else
                {
                    // merge with previous command
                    if (currentPosition >= 0)
                        history[currentPosition].Merge(currentCommand);
                }

                currentCommand = null;
                OnCommandDone(CommandDoneType.Commit);
            }
            else
                currentCommand = null;
        }
Esempio n. 6
0
 /// <summary>
 /// Clears all history. It does not affect current data but history only. 
 /// It is usefull after any data initialization if you want forbid user to undo this initialization.
 /// </summary>
 public void ClearHistory()
 {
     currentCommand = null;
     currentPosition = -1;
     history.Clear();
 }
Esempio n. 7
0
 /// <summary>
 /// Rollback current command. It does not saves any changes done in current command.
 /// </summary>
 public void Cancel()
 {
     AssertCurrentCommand();
     currentCommand.Undo();
     currentCommand = null;
 }
Esempio n. 8
0
 private IDisposable Start(string commandCaption, bool visible)
 {
     _currentArea = this;
     Command command = new Command(commandCaption, this, visible);
     PushCommand(command);
     return command;
 }
Esempio n. 9
0
 private void PushCommand(Command command)
 {
     _commandsStack.Push(command);
     _currentCommand = command;
 }
Esempio n. 10
0
        private Command PopCommand()
        {
            if (_currentCommand == null)
            {
                throw new Exception("Commands stack is empty");
            }

            Command command = _commandsStack.Pop();
            _currentCommand = _commandsStack.Peek();
            return command;
        }
Esempio n. 11
0
 void OnCommandDone(Command command, CommandDoneType type)
 {
     command.NotifyOnChanges(type);
     if (CommandDone != null)
         CommandDone(null, new CommandDoneEventArgs(type));
 }
Esempio n. 12
0
		private IDisposable Start(bool visible)
		{
            
			currentArea = this;
			Command command = new Command(this, visible);
			PushCommand(command);
			return command;
		}
Esempio n. 13
0
 internal void Merge(Command mergedCommand)
 {
     if (merges == null)
         merges = new Dictionary<IUndoRedoMember, object>();
     foreach (IUndoRedoMember member in mergedCommand.changes.Keys)
         merges[member] = mergedCommand[member];
 }