Hi,

I am experimenting Spec to write a DrGeo user scripts browser (in DrGeo scripts are classes).

The layout and widgetery is so far ok (see screenshot).

Nevertheless I have issue to keep synchronized the compiled methods in the Spec list, a recompiled method when the user edit its code and save it, then the source code in the code widget.

Indeed when the user press save to keep the code it is compiled fine but the Spec list still hold what I guess is another instance of the compiled method.

My attempt to manage this situation makes my code to look like shit.

How will you manage this to keep up to date and synchronized the script information in the different Spec widgets?

Thanks

Hilaire

--
Dr. Geo
http://drgeo.eu

'From Pharo8.0.0 of 20 February 2020 [Build information: 
Pharo-8.0.0+build.1129.sha.278304fdce17a1b7cc3ede1006275ffbc7baf20a (64 Bit)] 
on 30 March 2020 at 4:07:31.728507 pm'!
SpPresenter subclass: #DrGScriptBrowser2
        instanceVariableNames: 'scripts methods source saveBtn'
        classVariableNames: ''
        package: 'DrGeoII-UI-Window'!
!DrGScriptBrowser2 commentStamp: 'HilaireFernandes 3/28/2020 12:59' prior: 0!
A DrGeo script browser written with Spec2.!


!DrGScriptBrowser2 methodsFor: 'action-button-actions' stamp: 'HilaireFernandes 
3/30/2020 15:54'!
saveCode
        | compiledMethod selectedMethodItem |
        selectedMethodItem := methods selectedPage activePresenter selection.
        compiledMethod  :=  selectedMethodItem selectedItem.
        methods selectedPage activePresenter inspect.
        (compiledMethod notNil and: [ source pendingText  ~= source text ]) 
ifTrue: [ 
                compiledMethod methodClass compile: source pendingText.
                methods selectedPage activePresenter selection selectedItem
                compiledMethod selector == #scriptName ifTrue: [ "Update the 
script name in Scripts list" 
"                       scripts selection inspect" scripts updateList
                        ].
                self inform: ('Method "{1}" saved' translated format: 
{compiledMethod selector}) ]! !


!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/30/2020 09:57'!
newButtons
        saveBtn := self newButton 
                label: 'Save' translated;
                icon: (self iconNamed: #smallSave);
                yourself! !

!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/30/2020 15:38'!
instanceMethodsTab
        ^ SpNotebookPage 
                title: 'Methods' translated 
                provider: [ self newList
                        display: [:aMethod | aMethod selector ];
                        whenSelectionChangedDo: [ :selection |  | method |
                                method := selection selectedItem.
                                source text:  method sourceCode; behavior: 
method methodClass];
                        yourself]! !

!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/28/2020 15:31'!
newScriptCode
        source := self instantiate: SpLabelledContainer.
        source
                label: 'Source' translated;
                content: SpCodePresenter! !

!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/30/2020 15:39'!
connectPresenters 
        scripts whenSelectedItemChanged: [ :class | 
                source clearContent; behavior: nil.
                class ifNotNil: [ 
                        (methods pageAt: 1) whenRetrievedDo: [ :list  |  list  
items:  class methods].
                        (methods pageAt: 2) whenRetrievedDo: [ :list  | list  
items:  class class methods].
                        methods resetAllPageContents.]].
        saveBtn action: [ self saveCode ].
        source acceptBlock: [ :text | text inspect ]! !

!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/29/2020 13:15'!
classMethodsTab
        ^ SpNotebookPage 
                title: 'Script data' translated 
                provider: [ self newList 
                        display: [:aMethod | aMethod selector ];
                        whenSelectionChangedDo: [ :selection | 
                                source text: selection selectedItem sourceCode.
                                source behavior: selection selectedItem 
methodClass];
                        yourself]! !

!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/28/2020 15:31'!
newScriptsList
        scripts := self instantiate: SpLabelledList.
        scripts  label: 'Scripts' translated;
                items: DrGeoUserScript allSubclasses;
                display: [ :aClass | aClass scriptName ]! !

!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/28/2020 15:10'!
newMethodsList
        methods := self newNotebook.
        methods
                addPage: self instanceMethodsTab;
                addPage: self classMethodsTab! !

!DrGScriptBrowser2 methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/30/2020 09:41'!
initializePresenters
        self newScriptsList.
        self newMethodsList.
        self newScriptCode.
        self newButtons! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

DrGScriptBrowser2 class
        instanceVariableNames: ''!

!DrGScriptBrowser2 class methodsFor: 'initialization' stamp: 'HilaireFernandes 
3/30/2020 14:54'!
defaultSpec
        ^ SpPanedLayout newVertical 
                add: (SpBoxLayout newHorizontal 
                        add: #scripts;
                        add: #methods;
                        yourself);
                add: (SpBoxLayout newVertical
                        add: #source;
                        add: #saveBtn withConstraints: [:c | c expand: false];
                        yourself);
                yourself! !

Reply via email to