Skip to content

Commit

Permalink
Change permutation by clicking on label when original method and obje…
Browse files Browse the repository at this point in the history
…ct have been closed
  • Loading branch information
JoeAtHPI committed Apr 23, 2024
1 parent 99fc942 commit f30610e
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 15 deletions.
13 changes: 13 additions & 0 deletions packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ SBExploriants >> buttonClass [
SBExploriants >> cacheType: aClass for: aBlock [
]

{ #category : #actions }
SBExploriants >> changeIndexOf: aVariantId to: aNewIndex [

namedBlocks detect: #isVariantsView
ifFound: [:variantsView | variantsView changeIndexOf: aVariantId to: aNewIndex]
]

{ #category : #testing }
SBExploriants >> evaluationContext [

Expand Down Expand Up @@ -221,6 +228,12 @@ SBExploriants >> updateInBackgroundOnTimeoutRevertTo: theOldMultiverse [
] forkAt: Processor userBackgroundPriority.
]

{ #category : #actions }
SBExploriants >> variantsView [

^ namedBlocks detect: #isVariantsView
]

{ #category : #actions }
SBExploriants >> visualize [

Expand Down
6 changes: 6 additions & 0 deletions packages/Sandblocks-Babylonian/SBExploriantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ SBExploriantsView >> isOverview [
^false
]

{ #category : #accessing }
SBExploriantsView >> isVariantsView [

^ false
]

{ #category : #accessing }
SBExploriantsView >> multiverse [

Expand Down
24 changes: 19 additions & 5 deletions packages/Sandblocks-Babylonian/SBMultiverse.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,33 @@ SBMultiverse >> findExistingOrConvertToBlocksMaintainingWatches: aCollectionOfCo
{ #category : #'initialize-release' }
SBMultiverse >> gatherElements [

universes := OrderedCollection new.
activeExamples := self allActiveExamples.

self gatherVariants.

self gatherWatches

]

{ #category : #'initialize-release' }
SBMultiverse >> gatherVariants [

"We are looking for already opened methods so that we can assign the
variant there as the original in SBVariantProxy. That way, we immediately
have consistency between changes."
allMethodBlocksContainingVariants := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingVariants.

allMethodBlocksContainingWatches := self findExistingOrConvertToBlocksMaintainingWatches: self allCompiledMethodsContainingExampleWatches.

universes := OrderedCollection new.
activeExamples := self allActiveExamples.

variants := (allMethodBlocksContainingVariants collect: #containedVariants) flatten.
variants := variants select: #isActive.

]

{ #category : #'initialize-release' }
SBMultiverse >> gatherWatches [

allMethodBlocksContainingWatches := self findExistingOrConvertToBlocksMaintainingWatches: self allCompiledMethodsContainingExampleWatches.

watches := (allMethodBlocksContainingWatches collect: [:aMethodBlock | | copies |
copies := aMethodBlock containedExampleWatches.
"Because the watches share the id, values would be reported to original too. Stop that"
Expand Down
31 changes: 26 additions & 5 deletions packages/Sandblocks-Babylonian/SBVariantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@ Class {
{ #category : #building }
SBVariantsView >> buildMethodSectionFor: aSBStMethod [

| newProxy |
newProxy := aSBStMethod containedVariants collect: #asProxy.
contents addAllMorphsBack: {aSBStMethod methodDefinition.
self containerRow
addAllMorphsBack: (aSBStMethod containedVariants collect: #asProxy).
self containerRow addAllMorphsBack: newProxy.
LineMorph from: 0@0 to: 50@0 color: Color black width: 2}
]

{ #category : #building }
SBVariantsView >> buildNoVariantsText [

contents addMorphBack: (SBOwnTextMorph new contents: 'No variants exist.')
contents addMorphBack: (SBOwnTextMorph new contents: 'No variation points exist.')
]

{ #category : #actions }
SBVariantsView >> changeIndexOf: aVariantId to: aNewIndex [

self proxies
detect: [:aProxy | aProxy original id = aVariantId]
ifFound: [:theProxy | theProxy changeActiveIndexTo: aNewIndex ]
]

{ #category : #actions }
SBVariantsView >> clean [

super clean.

contents submorphs copy do: #delete
contents submorphs copy do: #delete.

]

Expand All @@ -38,7 +47,19 @@ SBVariantsView >> initialize [

contents := self containerRow listDirection: #topToBottom.

self name: 'Variants'.
self name: 'Variation Points'.
]

{ #category : #accessing }
SBVariantsView >> isVariantsView [

^ true
]

{ #category : #actions }
SBVariantsView >> proxies [

^ (contents allMorphs select: [:aMorph | aMorph isKindOf: SBVariantProxy])
]

{ #category : #copying }
Expand Down
2 changes: 2 additions & 0 deletions packages/Sandblocks-Core/SBTabView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ SBTabView >> asTabButton: aNamedBlock [
{ #category : #tabs }
SBTabView >> basicSetActive: aNamedBlock [

self sandblockEditor ifNil: [^ self activeIndex: (self namedBlocks indexOf: aNamedBlock ifAbsent: 1)].

self sandblockEditor do:
(self switchCommandFor: (self namedBlocks indexOf: aNamedBlock ifAbsent: 1)).

Expand Down
10 changes: 9 additions & 1 deletion packages/Sandblocks-Smalltalk/SBVariantProxy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ SBVariantProxy class >> for: aVariant [

{ #category : #callbacks }
SBVariantProxy >> artefactChanged: anArtefact [


anArtefact = self ifTrue: [self updateOriginalWithOwnValues ].

Expand All @@ -36,6 +35,15 @@ SBVariantProxy >> binding: aString for: block class: aClass ifPresent: aBlock [
^ original binding: aString for: block class: aClass ifPresent: aBlock
]

{ #category : #accessing }
SBVariantProxy >> changeActiveIndexTo: aNewIndex [

self firstSubmorph switchToAlternativeWithoutSaving: aNewIndex.
self updateOriginalWithOwnValues


]

{ #category : #accessing }
SBVariantProxy >> containedMethod [

Expand Down
32 changes: 28 additions & 4 deletions packages/Sandblocks-Utils/SBPermutation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,39 @@ SBPermutation >> activeScore [

{ #category : #actions }
SBPermutation >> apply [

self flag: #todo. "outdated references, jb"
(self referencedVariants anySatisfy: [:aVariant | aVariant sandblockEditor isNil])
ifTrue: [ self applyWithOutdatedReferences ]
ifFalse: [ self applyOnOriginals ].


]

{ #category : #private }
SBPermutation >> applyOnOriginals [

self referencedVariants do: [:aVariant | aVariant switchToAlternativeWithoutSaving: (self at: aVariant id)].
SBExploriants uniqueInstance ignoreUpdate: true.
((self referencedVariants collect: #containingArtefact) asSet) do: [:aMethod |
self referencedVariants first sandblockEditor save: aMethod tryFixing: false quick: false].
aMethod sandblockEditor save: aMethod tryFixing: false quick: false].
(self referencedVariants collect: #sandblockEditor) do: #sendNewPermutationNotification


]

{ #category : #private }
SBPermutation >> applyWithOutdatedReferences [

| newVariants |
self keys do: [:anId | SBExploriants uniqueInstance changeIndexOf: anId to: (self at: anId)].
newVariants := SBExploriants uniqueInstance variantsView proxies collect: #original.
self referencedVariants do: [:aVariant |
newVariants detect: [:new | new id = aVariant id]
ifFound: [:theVariant | aVariant becomeForward: theVariant]].
SBEditor current sendNewPermutationNotification


((Set newFrom: (referencedVariants collect: #sandblockEditor))
reject: #isNil)
do: #sendNewPermutationNotification
]

{ #category : #converting }
Expand Down

0 comments on commit f30610e

Please sign in to comment.