protected void CommitChanges() { ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >(); TransactedToolUndoCommitHistoryMemento <TDerived, TChanges> memento = this.TryCommitChanges(); if (memento == null) { throw new InternalErrorException($"TryCommitChanges() returned null (Tool={base.GetType().Name})"); } base.HistoryStack.PushNewMemento(memento); }
private TransactedToolUndoCommitHistoryMemento <TDerived, TChanges> TryCommitChanges() { ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >(); this.VerifyState(TransactedToolState.Dirty); OperationCanceledException exception = null; TransactedToolUndoCommitHistoryMemento <TDerived, TChanges> memento = null; TChanges changes = this.Changes.Clone(); try { this.drawingSettingValuesBackup = null; HistoryMemento innerCommitHM = this.CommitChangesInner(changes); if (innerCommitHM == null) { throw new InternalErrorException($"CommitChangesInner() returned null (Tool={base.GetType().Name})"); } memento = new TransactedToolUndoCommitHistoryMemento <TDerived, TChanges>(base.DocumentWorkspace, changes, innerCommitHM); } catch (OperationCanceledException exception2) { exception = exception2; } if (exception != null) { this.VerifyState(TransactedToolState.Dirty); ExceptionDialog.ShowErrorDialog(base.DocumentWorkspace, exception.InnerException ?? exception); return(null); } this.VerifyState(TransactedToolState.Idle); if (this.changes != null) { throw new InternalErrorException($"this.Changes is not null (Tool={base.GetType().Name})"); } if (this.changesBeforeEditing != null) { throw new InternalErrorException($"this.changesBeforeEditing is not null (Tool={base.GetType().Name})"); } return(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); } } }