#include <ops.h>
Inheritance diagram for Action:
Public Member Functions | |
Action () | |
Action constructor. | |
virtual | ~Action () |
Action destructor. | |
virtual void | Slaughter () |
destructor which gets called when an operation is deleted | |
virtual ActionCode | Execute () |
This is a pure virtual method which should be redefined for all derived classes of Action. | |
virtual BOOL | IsADiscardableAction () |
Document * | GetWorkingDoc () |
View * | GetWorkingView () |
DocView * | GetWorkingDocView () |
UINT32 | GetSize () |
Find out which document this action is working on. Returns the View that is associated with this action. Note that the majority of actions don't care what view they work on - most of them are document-based, and cause all views attached to a document to be updated. Returns the DocView that is associated with this action. This will return NULL if the View the action is attached to is not actually a DocView (e.g. it may be a PrintView). Note that the majority of actions don't care what view they work on - most of them are document-based, and cause all views attached to a document to be updated. For finding the total size of the action. | |
virtual void | Dump () |
Shows debug information on the action. Override to display information specific to your action. | |
BOOL | TransferToOtherOp (Operation *pOtherOp, ActionList *pAddActions, ActionList *pOtherActions) |
Adds this action to the end of the specified action list. | |
Static Public Member Functions | |
static ActionCode | Init (Operation *pOp, ActionList *pActionList, UINT32 Size, CCRuntimeClass *ActionClass, Action **NewAction) |
To check that there is sufficient room for the action in the operation history, and if there is, then to add the action to the operations action list. | |
Protected Attributes | |
Operation * | pOperation |
ActionList * | pOppositeActLst |
UINT32 | Size |
Friends | |
class | OperationHistory |
Definition at line 559 of file ops.h.
|
Action constructor.
Definition at line 2322 of file ops.cpp. 02322 :ListItem() 02323 { 02324 }
|
|
Action destructor.
Definition at line 2341 of file ops.cpp.
|
|
Shows debug information on the action. Override to display information specific to your action.
Definition at line 2681 of file ops.cpp. 02682 { 02683 #if DEBUG_TREE 02684 TRACEALL( _T(" Action %s (Size = %d bytes)\n"), GetRuntimeClass()->GetClassName(), GetSize() ); 02685 #endif 02686 }
|
|
|
Find out which document this action is working on. Returns the View that is associated with this action. Note that the majority of actions don't care what view they work on - most of them are document-based, and cause all views attached to a document to be updated. Returns the DocView that is associated with this action. This will return NULL if the View the action is attached to is not actually a DocView (e.g. it may be a PrintView). Note that the majority of actions don't care what view they work on - most of them are document-based, and cause all views attached to a document to be updated. For finding the total size of the action.
Definition at line 2659 of file ops.cpp. 02660 { 02661 return (Size); 02662 }
|
|
Definition at line 582 of file ops.h. 00582 { return pOperation->GetWorkingDoc(); }
|
|
Definition at line 584 of file ops.h. 00584 { return pOperation->GetWorkingDocView(); }
|
|
Definition at line 583 of file ops.h. 00583 { return pOperation->GetWorkingView(); }
|
|
To check that there is sufficient room for the action in the operation history, and if there is, then to add the action to the operations action list.
Size: The size of the action in bytes. This should be the total size of the action (including any objects pointed to by the action).
Currently AC_RECORD is never returned, as we never fail an operation just because we exceed the max size of the operation history !. See code for a reason why AC_OK : The action was successfully initialised and added to the operation. OR we are unwinding. In this situation NewAction will be NULL.
Definition at line 2439 of file ops.cpp. 02445 { 02446 02447 ERROR3IF(!(pOp->IsKindOf(CC_RUNTIME_CLASS(UndoableOperation))), 02448 "Trying to create an action for a non-undoable operation"); 02449 02450 // Update the hour glass 02451 ContinueSlowJob(); 02452 02453 // OpDescriptor* pOpDesc = OpDescriptor::FindOpDescriptor(pOp->GetRuntimeClass()); 02454 02455 OperationHistory& OpHist = pOp->GetWorkingDoc()->GetOpHistory(); 02456 02457 //if (Action::LastDiscardableAction != NULL) 02458 //{ 02459 // delete (LastDiscardableAction); // LastDescardable action 02460 // Action::LastDiscardableAction = NULL; 02461 //} 02462 02463 02464 // If we are unwinding an operation during Undo or Redo then 02465 // we don't want to create an action as it will already exist on the oposite action 02466 // list. 02467 02468 // When unwinding a Do however things are a little different. Whilst we don't need 02469 // need to generatate Redo actions for redoing purposes, we do need them to tidy up 02470 // the dying Operation. eg. A ShowNodeAction may need to delete its hidden node, and its 02471 // Slaughter method must be called to acheive this. However if we fail to allocate an 02472 // action in this circumstance we don't want to return an AC_FAIL. Leaking memory is 02473 // preferable to having nowhere to go. 02474 02475 if (pOp->GetOpFlgs().UnwindingActions && (pOp->OpStatus!=DO || pOp->GetOpFlgs().KeepOnEnd)) 02476 { 02477 (*NewAction) = NULL; 02478 return (AC_OK); 02479 02480 } 02481 02482 02483 // TRACE( _T("Size of operation history = %ld\n"), OpHist.GetSize()); 02484 02485 02486 // Try to allocate memory for the action, deleting undo if we get desperate 02487 ALLOC_WITH_FAIL((*NewAction),(Action*)(ActionClass->CreateObject()),pOp); 02488 02489 // oh no it's all gone horribly wrong, I wouldn't like to be in your shoes 02490 if ((*NewAction) == NULL) 02491 { 02492 // If we are unwinding at this point then we don't fail the action (See note above) 02493 if ((pOp->GetOpFlgs().UnwindingActions)) 02494 { 02495 ERROR3IF(!(pOp->OpStatus == DO), "OpStatus should be Do"); 02496 return (AC_OK); 02497 } 02498 else 02499 { 02500 return (AC_FAIL); 02501 } 02502 } 02503 //if (IsUserName("Simon")) 02504 //{ 02505 // TRACE( _T("Adding action %s, NumBytes = %lu\n"),(*NewAction)->GetRuntimeClass()->m_lpszClassName, ActionSize); 02506 //} 02507 02508 02509 // If fail and discard then there is no need to prompt the user more than once 02510 if (!(pOp->GetOpFlgs().Failed)) 02511 { 02512 // Check that there is enough room in the operation history for the action 02513 if ((OpHist.GetSize() + ActionSize) > OpHist.GetMaxSize()) 02514 { 02515 //BOOL NoRoom = FALSE; 02516 // There is not enough room so first of all check if we can make room 02517 if (OpHist.GetMaxSize() > ActionSize) 02518 { 02519 // See if we can make room by deleting UNDO records 02520 //if (OpHist.ReduceSize((OpHist.GetMaxSize() - ActionSize),TRUE) == FALSE) 02521 // NoRoom = TRUE; 02522 // The outcome does not matter 02523 OpHist.ReduceSize((OpHist.GetMaxSize() - ActionSize),TRUE, TRUE); 02524 } 02525 else 02526 { 02527 // Very big action 02528 OpHist.ReduceSize(0,TRUE, TRUE); 02529 } 02530 // We used to give the user the option of either continuing and loosing all undo/redo 02531 // or have them abort their current operation. I didn't think this was a very good idea 02532 // so I have removed the code. Now we let the operation history grow to what 02533 // ever size it wants to, but keep the Maximum size the same. The operation history 02534 // will shrink towards the maximum size whenever there are undo operations which can be deleted. 02535 02536 // I found that in practice we were reaching this NoRoom situation when the user was undoing 02537 // almost back to the start. If the user redoes then this shrinks the OpHist 02538 // because there are undo ops to discard, if the user does then this also shrinks the OpHist because 02539 // all redo ops are discarded. 02540 02541 /* 02542 else 02543 NoRoom = TRUE; 02544 if (NoRoom) 02545 { 02546 02547 // We cannot make enough room in the operation history for the action 02548 UINT32 _R(IDS_MSG) = (pOp->OpStatus == UNDO) ? 02549 (UINT32)_R(IDS_CANNOT_REDO_WARNING): (UINT32)_R(IDS_CANNOT_UNDO_WARNING); 02550 02551 if (InformWarning(_R(IDS_MSG), 02552 _R(IDS_CONTINUE), 02553 _R(IDS_CANCEL)) == 2) 02554 { 02555 // The user does not want to continue, so inform the action's operation that 02556 // when the operation ends the actions previously added to its action list 02557 // will be executed to bring the document back to the state it was in before the 02558 // operation was* started. 02559 pOp->FailAndExecute(); 02560 LastDiscardableAction = *NewAction; 02561 return (AC_FAIL); 02562 } 02563 else 02564 // The user does want to continue, so inform the operation that when it ends 02565 // it should be deleted. 02566 pOp->FailAndDiscard(); 02567 02568 } 02569 */ 02570 } 02571 } 02572 // Add the action to the operation's action list. 02573 02574 // Note that actions are added to the operation's action list even after a fail and discard 02575 // error. The reason for this is that if memory runs out whilst trying to execute an operation 02576 // after such an error, we need to be able to unwind all actions which have been performed. If 02577 // we do not do this then all sorts of chaos will occur. 02578 02579 pActionList->AddTail(*NewAction); 02580 (*NewAction)->pOperation = pOp; // Record the operation to which the action is attached. 02581 02582 // Store a pointer to the opposite ActionList to that which the Action is atatched 02583 (*NewAction)->pOppositeActLst = (pOp->GetUndoActionList() == pActionList) ? 02584 (pOp->GetRedoActionList()) : (pOp->GetUndoActionList()); 02585 02586 (*NewAction)->Size = ActionSize; // Record the size of the action 02587 02588 // Even though the operation has not yet been added to the operation history and maybe 02589 // never will, we increase the current size of the operation history to accomodate the 02590 // action. If the operation fails then the Size of the operation history will be reduced 02591 // by the same ammount in the action list's execute methods. 02592 02593 OpHist.IncSize(ActionSize); 02594 02595 return (AC_OK); // success 02596 }
|
|
Definition at line 579 of file ops.h. 00579 { return FALSE; }
|
|
destructor which gets called when an operation is deleted
Reimplemented in ActionHideColours, FactorOutCommonChildAttrAct, LocaliseCommonAttrAct, ShowNodeAction, RestoreSelectionsAction, and TransformNodeAction. Definition at line 2362 of file ops.cpp.
|
|
Adds this action to the end of the specified action list.
Definition at line 2703 of file ops.cpp. 02704 { 02705 ERROR2IF((pOtherOp==NULL) || (pAddActions==NULL) || (pOtherActions==NULL), FALSE, "NULL parameter"); 02706 02707 pOperation = pOtherOp; 02708 pOppositeActLst = pOtherActions; 02709 02710 pAddActions->AddTail(this); 02711 02712 return TRUE; 02713 }
|
|
|
|
|
|
|
|
|