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); } } }
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); } } }
// 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); }
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); }
protected virtual void Dispose (bool disposing) { if (disposing) { if (_currentUnit != null) { _currentUnit.Close (); _currentUnit = null; } } }
protected UndoEngine (IServiceProvider provider) { if (provider == null) throw new ArgumentNullException ("provider"); _provider = provider; _currentUnit = null; Enable (); }
public void DoUndo() { if (this.currentPos > 0) { UndoUnit undoUnit = this.undoUnitList[this.currentPos - 1]; undoUnit.Undo(); this.currentPos--; } this.UpdateUndoRedoMenuCommandsStatus(); }
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(); } }
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; } }
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); } }
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; } }
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; } }
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) { }
protected override void DiscardUndoUnit(UndoUnit unit) { undoUnitList.Remove(unit); base.DiscardUndoUnit(unit); }
private void OnComponentAdding (object sender, ComponentEventArgs args) { if (_currentUnit == null) _currentUnit = CreateUndoUnit ("Add " + args.Component.GetType ().Name, true); _currentUnit.ComponentAdding (args); }
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); } }
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; }
protected abstract void AddUndoUnit(UndoUnit unit);
private void OnComponentRemoving (object sender, ComponentEventArgs args) { if (_currentUnit == null) _currentUnit = CreateUndoUnit ("Remove " + args.Component.Site.Name, true); _currentUnit.ComponentRemoving (args); }
protected virtual void DiscardUndoUnit(UndoUnit unit) { throw null; }
protected override void AddUndoUnit(UndoUnit unit) { undoUnitList.RemoveRange(currentPos, undoUnitList.Count - currentPos); undoUnitList.Add(unit); currentPos = undoUnitList.Count; }
protected override void AddUndoUnit(UndoUnit unit) { }