Benjamin wrote:
On 20 Jan 2014, at 13:51, b...@openinworld.com wrote:
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…

did you try to register in the initialize method ?
Because if you register once the application is already open, it may not work :)
I don't want to unsubscribe #refresh in PhLTitledTreeModel>>initialize.
I _really_ want to unsubscribe #refresh immediately after the subscribe #refresh is set up.

----------
   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
—————

topWindowHolder sounds a bit hackish :)
I tried to avoid calling in #windowHolder but would that preferred?
Do you have another suggestion? 

btw, the 'window' i-var of ComposableModel seems like it should be 'windowHolder'

I think this can be achieved with the whenBuiltDo:, I should investigate :)


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/

You can also submitted here: https://github.com/SpecForPharo/spec if you want :)
(and become a Spec contributor :P)

Ben

Reply via email to