views:

97

answers:

2
  • The GoDiagram object model has a GoDocument.
  • GoViews have a reference to a GoDocument.
  • If the user does any modification on the diagramming surface, a GoDocument.Changed event is raised with the relevant information in the event arguments.

I would like to be notified when some user-actions happen, so that I can confer with my Controller (disallow/cancel it if need be) and then issue view-update orders from there that actually modify the Northwoods GoDiagram third party component.
The Changed event is a notification that something just happened (past tense) - Doing all of the above in the event handler results in a .... (wait for it)... StackOverflowException. (GoDocument.Changed handler > Updates GoDocument > Firing new Changed events.. )

So question, how do I get a BeforeEditing or BeforeResizing kind of notification model in GoDiagrams? Has anyone who's been there lived to tell a tale?

A: 

The event arguments (GoChangedEventArgs) for the change event has a property IsBeforeChanging which indicates whether the change event was raised from the "RaiseChanging" method (true), or the RaiseChanged (false). That should tell you whether the change has occurred yet, but I know of no way to cancel it.

The best I can suggest is instead of checking if the change is allowed and performing it, check if the change is not allowed, and if it isn't call the "Undo" method on the arguments in the change event. So essentially:

OnChanged(GoChangedEventArgs e)
{
  if(NotAllowed)
  {
    e.Undo();
  }
}
Brian B.
+2  A: 

JFYI... The component-vendor recommendation is to subclass and override appropriate methods for this. Override the bool CanXXX() method, raise a cancelable custom event. If the subscriber returns false, bail out (return false to abort the user action) of CanXXX. No built-in mechanism for this in GoDiagrams.

For example, you could define a CustomView.ObjectResizing cancelable event. In your override of GoToolResizing.CanStart, you can raise that event. If the CancelEventArgs.Cancel property becomes true, you would have CanStart() return false.

Source http://www.nwoods.com/forum/forum_posts.asp?TID=2745

Gishu