[Q][Connectors] real detach?

Ned Konz ned at bike-nomad.com
Sun Jun 29 19:25:23 UTC 2003


On Saturday 28 June 2003 09:04 pm, German Morales wrote:

> I have 2 morphs connected with a nice NCConnectorMorph, and I'd
> like to know when there is a REAL detach in order to remove the now
> disconnected Morph from my world.
>
> In other words, what I want to happen is:
>  before:
>    Morph1 -----> Morph2
>    (Morph1 and Morph2 are connected)
>
>  after case 1:
>    Morph1
>    (the connection was deleted (#delete), then M2 is not needed
>    and removed)
>
>  after case 2:
>    Morph1 ----->
>    (the connection is detached by means of dragging, then M2 is
>    not needed and removed)
>
>
> I first implemented #disconnectedFromBy: like this:
>    disconnectedFromBy: aConnector
>       (self incomingConnections) isEmpty ifTrue: [self delete]
>
> But I'm facing some problems with this approach:
> 1. When executing the #disconnectedFromBy: method, the query
> incomingConnections still returns the parameter aConnector as a
> result, which is at least unexpected for me, since i'm receiving a
> notification of disconnection.

I could change the ordering of this. But for now you can just do:

disconnectedFromBy: aConnector
(self incomingConnections copyWithout: aConnector)
  isEmpty ifTrue: self delete ].

> 2. in the case of disconnetion by means of dragging,
> #disconnectedFromBy: is called when I START dragging the connector
> end, not in the moment of the drop in another morph or the World. I
> understand that this is somehow correct since there is a
> disconnection, but there is the posibility that people were just
> dragging to better position the connector, and if in that moment I
> remove the target morph from the world the reconnection will be
> impossible. I want to know when a connection is confirmed to be
> disconnected (drop somewhere but not in the previous morph). Is
> that possible?

Sure. You can subclass NCConnectorMorph (you probably want to do this 
anyway if you have any special behavior in your connectors), and then 
signal events on connection and disconnection, or otherwise notify 
interested parties.

So on disconnection, your morph would wait around until it heard from 
the connector that it had been reconnected or deleted.

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE



More information about the Squeak-dev mailing list