Benjamin wrote:
Hi Ben,

I've gave that a go and had some success, but it raised an architectural question I ask near the end.  I've documented my investigation here in case it is of use to others new to Spec or the Spec documentation being developed. 
    
Spec documentation is actually under heavy construction :)
May I keep this content for further quotation?
  
Sure thing. That was part of my original intention.

  
So the question this leads up to is... 
    Should child ComposableModels all reference the same WindowModel as their owner?
    
The thing is, the isn’t var window doesn’t point to the same, but the method `window` does :)
Could you try something like:

 PhLTitledTreeModel>>repository: aRepository
repositoryHolder value: aRepository.
        self repository whenChangedSend: #refresh to: self.  "<--subscription-of-concern"
        self refresh.
	self whenBuiltDo: [ self window whenClosed: [ self repository unsubscribe: self ] ]


Thanks for your investigation :)
Ben

  
When I try...
    self whenBuiltDo: [ self halt. self window whenClosedDo: [ self halt. self repository unsubscribe: self ] ].
none of the halts occur.

However I got what I needed with the following...
----------
   ComposableModel>>topWindowHolder
         ^ owner
                ifNil: [ window ]
                ifNotNil: [ :o | o topWindowHolder ].
----------
  ComposableModel>>whenWindowClosed: aBlock
        self topWindowHolder value
            ifNotNil: [ :w | w whenClosedDo: aBlock ]
            ifNil: [  self topWindowHolder whenChangedDo: [  :w  | w whenClosedDo: aBlock ] ].
----------
    PhLTitledTreeModel>>repository: aRepository
       self assert: self repository isNil description: 'Changing the repository is not allowed because we would have to change the context as well'.
        repositoryHolder value: aRepository.
        self repository whenChangedSend: #refresh to: self.
        self whenWindowClosed: [ self repository unsubscribe: self.   self inform: 'Works for composed sub-items'. ] .
        self refresh
----------
    PharoLauncher>>initialize
        super initialize.
        self whenWindowClosed: [ self inform: 'Works for top level owner' ].
----------
And optionally you could now have...
    ComposableModel>>window
        ^ self topWindowHolder value
----------

If those ComposableModel additions are okay, I'll submit a slice on Case 12677 (renamed to "ComposableModel subcomponents need to act on window close")
https://pharo.fogbugz.com/f/cases/12677/

cheers -ben

Reply via email to