Exemplo n.º 1
0
        public void BeginDrawing(TransactedToolDrawingAgent <TChanges> agent, TChanges initialChanges, HistoryMemento beforeDrawingMemento)
        {
            Validate.Begin().IsNotNull <TransactedToolDrawingAgent <TChanges> >(agent, "agent").IsNotNull <TChanges>(initialChanges, "changes").IsNotNull <HistoryMemento>(beforeDrawingMemento, "beforeDrawingMemento").Check();
            ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >();
            agent.VerifyIsNotActive();
            if (this.State != TransactedToolState.Idle)
            {
                throw new InvalidOperationException($"Can only BeginDrawing when State is Idle (State={this.State}, Tool={base.GetType().Name})");
            }
            if (this.beforeDrawingMemento != null)
            {
                throw new InternalErrorException($"this.beforeDrawingMemento != null (Tool={base.GetType().Name})");
            }
            this.beforeDrawingMemento = beforeDrawingMemento;
            TransactedToolDrawingTransactionTokenPrivate <TDerived, TChanges> @private = new TransactedToolDrawingTransactionTokenPrivate <TDerived, TChanges>((TDerived)this);

            agent.TransactionToken = @private;
            this.drawingAgent      = agent;
            this.SetState(TransactedToolState.Drawing);
            this.Changes = initialChanges.Clone();
        }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
 private void CancelDrawing()
 {
     ((TransactedTool <TDerived, TChanges>) this).VerifyAccess <TransactedTool <TDerived, TChanges> >();
     if (this.State != TransactedToolState.Drawing)
     {
         throw new InvalidOperationException($"Can only CancelDrawing when State is Drawing (State={this.State}, Tool={base.GetType().Name})");
     }
     if (!this.drawingAgent.TransactionToken.IsCanceling)
     {
         this.drawingAgent.TransactionToken.Cancel();
     }
     else
     {
         this.OnCancelingDrawing();
         this.drawingAgent.TransactionToken = null;
         this.drawingAgent = null;
         this.SetState(TransactedToolState.Idle);
         this.Changes = default(TChanges);
         HistoryMemento beforeDrawingMemento = this.beforeDrawingMemento;
         this.beforeDrawingMemento = null;
         beforeDrawingMemento.PerformUndo(null);
     }
 }
Exemplo n.º 5
0
 public void BeginDrawing(TransactedToolDrawingAgent <TChanges> agent, TChanges initialChanges, string mementoName, ImageResource mementoImage)
 {
     this.BeginDrawing(agent, initialChanges, new EmptyHistoryMemento(mementoName, mementoImage));
 }
Exemplo n.º 6
0
 public void BeginDrawing(TransactedToolDrawingAgent <TChanges> agent, TChanges initialChanges)
 {
     this.BeginDrawing(agent, initialChanges, base.Name, base.Image);
 }