private void CheckPopUnit(PopUnitReason reason)
 {
     if ((reason != PopUnitReason.Normal) || !this._host.InTransaction)
     {
         UndoUnit unit = (UndoUnit)this._unitStack.Pop();
         if (!unit.IsEmpty)
         {
             unit.Close();
             if (reason != PopUnitReason.TransactionCancel)
             {
                 if (this._unitStack.Count == 0)
                 {
                     this.AddUndoUnit(unit);
                 }
             }
             else
             {
                 unit.Undo();
                 if (this._unitStack.Count == 0)
                 {
                     this.DiscardUndoUnit(unit);
                 }
             }
         }
         else if (this._unitStack.Count == 0)
         {
             this.DiscardUndoUnit(unit);
         }
     }
 }
Exemple #2
0
        public void Redo()
        {
            if (disposed)
            {
                Debug.Assert(false);
                throw new InvalidOperationException();
            }

            if (OnBeforeUndoRedo != null)
            {
                OnBeforeUndoRedo.Invoke(this, EventArgs.Empty);
            }

            UndoUnit info = redo.Pop();

            try
            {
                SaveUndoInfo(false /*redo*/, false /*purgeRedo*/, info.Label);
                info.Inner.Do(client);
            }
            finally
            {
                IDisposable dispInfoInner = info.Inner as IDisposable;
                if (dispInfoInner != null)
                {
                    dispInfoInner.Dispose();
                }

                if (OnAfterUndoRedo != null)
                {
                    OnAfterUndoRedo.Invoke(this, EventArgs.Empty);
                }
            }
        }
Exemple #3
0
		// FIXME: there could be more transactions opened and closed (but not commited) after the first one!!!
		// This means that there should be multiple units. Only the top level transaction is commited though
		// 
		private void OnTransactionOpened (object sender, EventArgs args)
		{
			if (_currentUnit == null) {
				IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
				_currentUnit = CreateUndoUnit (host.TransactionDescription, true);
			}
		}
 private void OnComponentAdding(object sender, ComponentEventArgs args)
 {
     if (_currentUnit == null)
     {
         _currentUnit = CreateUndoUnit("Add " + args.Component.GetType().Name, true);
     }
     _currentUnit.ComponentAdding(args);
 }
 private void OnComponentRemoving(object sender, ComponentEventArgs args)
 {
     if (_currentUnit == null)
     {
         _currentUnit = CreateUndoUnit("Remove " + args.Component.Site.Name, true);
     }
     _currentUnit.ComponentRemoving(args);
 }
Exemple #6
0
		private void OnComponentChanging (object sender, ComponentChangingEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Modify " + ((IComponent)args.Component).Site.Name + 
							       (args.Member != null ? "." + args.Member.Name : ""), 
							       true);
			_currentUnit.ComponentChanging (args);
		}
Exemple #7
0
		protected virtual void Dispose (bool disposing)
		{
			if (disposing) {
				if (_currentUnit != null) {
					_currentUnit.Close ();
					_currentUnit = null;
				}
			}
		}
Exemple #8
0
		protected UndoEngine (IServiceProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException ("provider");

			_provider = provider;
			_currentUnit = null;
			Enable ();
		}
Exemple #9
0
		protected UndoEngine (IServiceProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException ("provider");

			_provider = provider;
			_currentUnit = null;
			Enable ();
		}
Exemple #10
0
 public void DoUndo()
 {
     if (this.currentPos > 0)
     {
         UndoUnit undoUnit = this.undoUnitList[this.currentPos - 1];
         undoUnit.Undo();
         this.currentPos--;
     }
     this.UpdateUndoRedoMenuCommandsStatus();
 }
Exemple #11
0
 public void DoRedo()
 {
     if (this.currentPos < this.undoUnitList.Count)
     {
         UndoUnit undoUnit = this.undoUnitList[this.currentPos];
         undoUnit.Undo();
         this.currentPos++;
     }
     this.UpdateUndoRedoMenuCommandsStatus();
 }
 public void AddUndo(UndoUnit unit)
 {
     if (this.PerformingAction)
     {
         this.actionsRecorded.Add(unit);
     }
     else if (!this.UndoingRedoing)
     {
         this.undoStack.Push(new UndoCollection(unit));
         this.redoStack.Clear();
     }
 }
Exemple #13
0
		private void OnComponentRename (object sender, ComponentRenameEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Rename " + ((IComponent)args.Component).Site.Name, true);
			_currentUnit.ComponentRename (args);

			IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
			if (!host.InTransaction) {
				_currentUnit.Close ();
				AddUndoUnit (_currentUnit);
				_currentUnit = null;
			}
		}
Exemple #14
0
 public void Undo(int actionsCount)
 {
     if (actionsCount <= 0 || actionsCount > _undoUnits.Count)
     {
         return;
     }
     for (; actionsCount != 0; actionsCount--)
     {
         UndoUnit unit = _undoUnits.Pop();
         // Console.WriteLine ("undo: " + unit.Name);
         unit.Undo();
         _redoUnits.Push(unit);
     }
 }
Exemple #15
0
		private void OnComponentChanged (object sender, ComponentChangedEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Modify " + ((IComponent)args.Component).Site.Name + "." + 
							       (args.Member != null ? "." + args.Member.Name : ""), 
							       true);
			_currentUnit.ComponentChanged (args);

			IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
			if (!host.InTransaction) {
				_currentUnit.Close ();
				AddUndoUnit (_currentUnit);
				_currentUnit = null;
			}
		}
Exemple #16
0
		private void OnTransactionClosed (object sender, DesignerTransactionCloseEventArgs args)
		{
			// Console.WriteLine ("TransactionClosed: Commited: " + args.TransactionCommitted.ToString ());
			IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
			if (!host.InTransaction) { // the "top-most"/last transaction was closed (currentUnit one)
				_currentUnit.Close ();
				if (args.TransactionCommitted) {
					AddUndoUnit (_currentUnit);
				} else {
					_currentUnit.Undo ();
					DiscardUndoUnit (_currentUnit);
				}
				_currentUnit = null;
			}
		}
Exemple #17
0
        private void OnComponentRemoved(object sender, ComponentEventArgs args)
        {
            if (_currentUnit == null)
            {
                _currentUnit = CreateUndoUnit("Remove " + args.Component.GetType().Name, true);
            }
            _currentUnit.ComponentRemoved(args);

            IDesignerHost host = GetRequiredService(typeof(IDesignerHost)) as IDesignerHost;

            if (!host.InTransaction)
            {
                _currentUnit.Close();
                AddUndoUnit(_currentUnit);
                _currentUnit = null;
            }
        }
 protected override void DiscardUndoUnit(UndoUnit unit)
 {
     this.undoUnitList.Remove(unit);
     base.DiscardUndoUnit(unit);
 }
 protected virtual void DiscardUndoUnit(UndoUnit unit)
 {
 }
Exemple #20
0
 protected override void DiscardUndoUnit(UndoUnit unit)
 {
     undoUnitList.Remove(unit);
     base.DiscardUndoUnit(unit);
 }
Exemple #21
0
		private void OnComponentRename (object sender, ComponentRenameEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Rename " + ((IComponent)args.Component).Site.Name, true);
			_currentUnit.ComponentRename (args);

			IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
			if (!host.InTransaction) {
				_currentUnit.Close ();
				AddUndoUnit (_currentUnit);
				_currentUnit = null;
			}
		}
Exemple #22
0
		private void OnComponentChanging (object sender, ComponentChangingEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Modify " + ((IComponent)args.Component).Site.Name + 
							       (args.Member != null ? "." + args.Member.Name : ""), 
							       true);
			_currentUnit.ComponentChanging (args);
		}
Exemple #23
0
		private void OnComponentAdding (object sender, ComponentEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Add " + args.Component.GetType ().Name, true);
			_currentUnit.ComponentAdding (args);
		}
Exemple #24
0
 private void AddUndo(int command, int startLine, int startIndex, int endLine, int endIndex, object data)
 {
     UndoUnit unit = new UndoUnit(command, startLine, startIndex, endLine, endIndex, data);
     if (this._batchUndoCount > 0)
     {
         ((BatchUndoUnit) this.UndoStack.Peek()).AddUndoUnit(unit);
     }
     else
     {
         this.UndoStack.Push(unit);
     }
 }
Exemple #25
0
        private void ProcessUndoUnit(UndoUnit unit, TextBufferLocation location)
        {
            TextBufferLocation location2 = this.CreateTextBufferLocation();
            location2.GotoLine(unit.StartLineNum);
            location2.ColumnIndex = unit.StartIndex;
            switch (unit.Command)
            {
                case 1:
                    this.DeleteChar(location2, false);
                    break;

                case 2:
                    this.InsertChar(location2, (char) unit.Data, false);
                    break;

                case 3:
                    this.InsertText(location2, (ArrayList) unit.Data, false);
                    break;

                case 4:
                {
                    TextBufferLocation end = this.CreateTextBufferLocation();
                    end.GotoLine(unit.EndLineNum);
                    end.ColumnIndex = unit.EndIndex;
                    this.DeleteText(new TextBufferSpan(location2, end), false);
                    end.Dispose();
                    break;
                }
            }
            if (location != null)
            {
                location.SetLine(location2.Line, location2.LineIndex);
                location.ColumnIndex = location2.ColumnIndex;
            }
            location2.Dispose();
        }
 protected override void AddUndoUnit(UndoUnit unit)
 {
     this.undoUnitList.RemoveRange(this.currentPos, this.undoUnitList.Count - this.currentPos);
     this.undoUnitList.Add(unit);
     this.currentPos = this.undoUnitList.Count;
 }
Exemple #27
0
 protected override void AddUndoUnit(UndoUnit unit)
 {
     this.undoUnitList.RemoveRange(this.currentPos, this.undoUnitList.Count - this.currentPos);
     this.undoUnitList.Add(unit);
     this.currentPos = this.undoUnitList.Count;
 }
 protected abstract void AddUndoUnit(UndoUnit unit);
Exemple #29
0
		private void OnTransactionClosed (object sender, DesignerTransactionCloseEventArgs args)
		{
			// Console.WriteLine ("TransactionClosed: Commited: " + args.TransactionCommitted.ToString ());
			IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
			if (!host.InTransaction) { // the "top-most"/last transaction was closed (currentUnit one)
				_currentUnit.Close ();
				if (args.TransactionCommitted) {
					AddUndoUnit (_currentUnit);
				} else {
					_currentUnit.Undo ();
					DiscardUndoUnit (_currentUnit);
				}
				_currentUnit = null;
			}
		}
 protected virtual void DiscardUndoUnit(UndoUnit unit)
 {
 }
Exemple #31
0
		private void OnComponentRemoving (object sender, ComponentEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Remove " + args.Component.Site.Name, true);
			_currentUnit.ComponentRemoving (args);
		}
 protected abstract void AddUndoUnit(UndoUnit unit);
Exemple #33
0
		private void OnComponentChanged (object sender, ComponentChangedEventArgs args)
		{
			if (_currentUnit == null)
				_currentUnit = CreateUndoUnit ("Modify " + ((IComponent)args.Component).Site.Name + "." + 
							       (args.Member != null ? "." + args.Member.Name : ""), 
							       true);
			_currentUnit.ComponentChanged (args);

			IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
			if (!host.InTransaction) {
				_currentUnit.Close ();
				AddUndoUnit (_currentUnit);
				_currentUnit = null;
			}
		}
Exemple #34
0
 protected virtual void DiscardUndoUnit(UndoUnit unit)
 {
     throw null;
 }
Exemple #35
0
		protected virtual void Dispose (bool disposing)
		{
			if (disposing) {
				if (_currentUnit != null) {
					_currentUnit.Close ();
					_currentUnit = null;
				}
			}
		}
Exemple #36
0
 protected override void AddUndoUnit(UndoUnit unit)
 {
     undoUnitList.RemoveRange(currentPos, undoUnitList.Count - currentPos);
     undoUnitList.Add(unit);
     currentPos = undoUnitList.Count;
 }
Exemple #37
0
		// FIXME: there could be more transactions opened and closed (but not commited) after the first one!!!
		// This means that there should be multiple units. Only the top level transaction is commited though
		// 
		private void OnTransactionOpened (object sender, EventArgs args)
		{
			if (_currentUnit == null) {
				IDesignerHost host = GetRequiredService (typeof (IDesignerHost)) as IDesignerHost;
				_currentUnit = CreateUndoUnit (host.TransactionDescription, true);
			}
		}
 protected override void AddUndoUnit(UndoUnit unit)
 {
 }