private void EndDrawing() { ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >(); if (this.State != TransactedToolState.Drawing) { throw new InvalidOperationException($"Can only EndDrawing when State is Drawing (State={this.State}, Tool={base.GetType().Name})"); } if (this.beforeDrawingMemento == null) { throw new InternalErrorException($"this.beforeDrawingMemento == null (Tool={base.GetType().Name})"); } if (!this.drawingAgent.TransactionToken.IsEnding) { this.drawingAgent.TransactionToken.End(); } else { string historyMementoNameForChanges; ImageResource historyMementoImageForChanges; this.OnEndingDrawing(); this.drawingAgent.TransactionToken = null; this.drawingAgent = null; this.SetState(TransactedToolState.Dirty); this.CoerceChangesAfterEndDrawing(); if ((this.beforeDrawingMemento == null) && !(this.beforeDrawingMemento is EmptyHistoryMemento)) { TChanges oldChanges = default(TChanges); historyMementoNameForChanges = this.GetHistoryMementoNameForChanges(oldChanges, this.Changes); historyMementoImageForChanges = this.GetHistoryMementoImageForChanges(default(TChanges), this.Changes); } else { historyMementoNameForChanges = this.beforeDrawingMemento.Name; historyMementoImageForChanges = this.beforeDrawingMemento.Image; } TransactedToolUndoDrawHistoryMemento <TDerived, TChanges> memento = new TransactedToolUndoDrawHistoryMemento <TDerived, TChanges>(base.DocumentWorkspace, historyMementoNameForChanges, historyMementoImageForChanges, this.beforeDrawingMemento); this.beforeDrawingMemento = null; base.HistoryStack.PushNewMemento(memento); } }
private void CommitDrawing() { ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >(); if (this.State != TransactedToolState.Drawing) { throw new InvalidOperationException($"Can only CommitDrawing when State is Drawing (State={this.State}, Tool={base.GetType().Name})"); } if (this.beforeDrawingMemento == null) { throw new InternalErrorException($"this.beforeDrawingMemento == null (Tool={base.GetType().Name})"); } if (!this.drawingAgent.TransactionToken.IsCommitting) { this.drawingAgent.TransactionToken.Commit(); } else { this.OnEndingDrawing(); this.drawingAgent.TransactionToken = null; this.drawingAgent = null; this.SetState(TransactedToolState.Dirty); this.CoerceChangesAfterEndDrawing(); TChanges newChanges = this.Changes.Clone(); HistoryMemento beforeDrawingMemento = this.beforeDrawingMemento; this.beforeDrawingMemento = null; TChanges oldChanges = default(TChanges); string historyMementoNameForChanges = this.GetHistoryMementoNameForChanges(oldChanges, newChanges); ImageResource historyMementoImageForChanges = this.GetHistoryMementoImageForChanges(default(TChanges), newChanges); TransactedToolUndoDrawHistoryMemento <TDerived, TChanges> memento2 = new TransactedToolUndoDrawHistoryMemento <TDerived, TChanges>(base.DocumentWorkspace, historyMementoNameForChanges, historyMementoImageForChanges, beforeDrawingMemento); TransactedToolUndoCommitHistoryMemento <TDerived, TChanges> memento3 = this.TryCommitChanges(); if (!(beforeDrawingMemento is EmptyHistoryMemento) || !(memento3.InnerMemento is EmptyHistoryMemento)) { HistoryMemento[] actions = new HistoryMemento[] { memento2, memento3 }; CompoundHistoryMemento memento4 = new CompoundHistoryMemento(memento3.Name, memento3.Image, actions); base.HistoryStack.PushNewMemento(memento4); } } }