Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for variants in dynamic ui methods #128

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ SBExampleValueDisplay >> clear [
hadValue := false
]

{ #category : #accessing }
SBExampleValueDisplay >> displayedWatchValueBlocks [

^ display displayedMorphs
]

{ #category : #accessing }
SBExampleValueDisplay >> exampleFinished: anExample [

Expand Down
2 changes: 1 addition & 1 deletion packages/Sandblocks-Babylonian/SBExampleWatch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ SBExampleWatch >> initialize [
prefix: 'Dimensions: ';
labels: (options collect: #label);
values: options;
object: options first;
object: options third;
when: #selectionChanged send: #applyResizerOnValues to: self.
modifyExpression := SBStBlockBody identityNamed: 'each'.

Expand Down
20 changes: 20 additions & 0 deletions packages/Sandblocks-Babylonian/SBExploriants.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"
objectToPermutation is a WeakKeyDictionary to enable permutation execution for dynamic objects. E.G. UI is run in a shared process which does not know the SBActiveVariantPermutation of the example processes, resulting in all morphs running the same step method.
"
Class {
#name : #SBExploriants,
#superclass : #SBTabView,
#instVars : [
'objectToPermutation'
],
#classInstVars : [
'uniqueInstance'
],
Expand All @@ -19,6 +25,12 @@ SBExploriants class >> new [
^ self error: 'Singleton. Use #uniqueInstance'
]

{ #category : #accessing }
SBExploriants class >> objectToPermutation [

^ self uniqueInstance objectToPermutation
]

{ #category : #accessing }
SBExploriants class >> uniqueInstance [

Expand All @@ -36,6 +48,8 @@ SBExploriants >> initialize [

super initialize.

objectToPermutation := WeakKeyDictionary new.

self
attachDecorator: SBMoveDecorator new;
changeTableLayout;
Expand All @@ -49,6 +63,12 @@ SBExploriants >> isArtefact [
^ true
]

{ #category : #accessing }
SBExploriants >> objectToPermutation [

^ objectToPermutation
]

{ #category : #'artefact protocol' }
SBExploriants >> saveTryFixing: aFixBoolean quick: aQuickBoolean [

Expand Down
15 changes: 14 additions & 1 deletion packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SBInactiveExampleWatch class >> newFromWatch: anActiveWatch [
^ (anActiveWatch veryDeepCopy)
primitiveChangeClassTo: self basicNew;
expression: (SBTextBubble new contents: anActiveWatch expression sourceString);
saveObjectsActivePermutations;
yourself
]

Expand All @@ -21,7 +22,8 @@ SBInactiveExampleWatch >> artefactSaved: aBlock [

"As we are inactive, we have to manually apply our modifyExpression if it changes.
Otherwise, we would reset by examples starting"
(aBlock = self containingArtefact) ifTrue: [self applyModifyExpressionOnValues]
(aBlock = self containingArtefact)
ifTrue: [self applyModifyExpressionOnValues. self saveObjectsActivePermutations.]
]

{ #category : #'event handling' }
Expand All @@ -48,3 +50,14 @@ SBInactiveExampleWatch >> listensToExamples [

^ false
]

{ #category : #'*Sandblocks-Babylonian' }
SBInactiveExampleWatch >> saveObjectsActivePermutations [

"Force morphs to persist their permutation even when on the UI process"
exampleToDisplay associationsDo: [:anExampleDisplayPair |
anExampleDisplayPair value displayedWatchValueBlocks do: [:aValueMorph |
SBExploriants objectToPermutation
at: aValueMorph lastSubmorph
put: SBActiveVariantPermutation value]].
]
11 changes: 11 additions & 0 deletions packages/Sandblocks-Babylonian/SBInactiveExampleWatch.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,14 @@ SBInactiveExampleWatch >> listensToExamples [

^ false
]

{ #category : #'*Sandblocks-Babylonian' }
SBInactiveExampleWatch >> saveObjectsActivePermutations [

"Force morphs to persist their permutation even when on the UI process"
exampleToDisplay associationsDo: [:anExampleDisplayPair |
anExampleDisplayPair value displayedWatchValueBlocks do: [:aValueMorph |
SBExploriants objectToPermutation
at: aValueMorph lastSubmorph
put: SBActiveVariantPermutation value]].
]
18 changes: 14 additions & 4 deletions packages/Sandblocks-Smalltalk/SBVariant.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,21 @@ SBVariant class >> named: aString alternatives: aCollectionOfNamedBlocks activeI
{ #category : #'instance creation' }
SBVariant class >> named: aString associations: aCollectionOfAssociations activeIndex: aNumber id: uuid [

| defaultBehavior requestor requiredPermutation |
aNumber <= 0 ifTrue: [^ nil].
^ SBActiveVariantPermutation value
ifNil: [(aCollectionOfAssociations at: aNumber) value value]
ifNotNil: [(aCollectionOfAssociations at: (SBActiveVariantPermutation value at: uuid)) value value].

"Always prioritize the permutation which is marked as active"
SBActiveVariantPermutation value ifNotNil: [^ (aCollectionOfAssociations at: (SBActiveVariantPermutation value at: uuid)) value value].

defaultBehavior := (aCollectionOfAssociations at: aNumber) value value.

"The requesting object does not require dynamic update behavior in which it needs to know a certain alternative"
SBExploriants objectToPermutation at: (requestor := thisContext sender receiver) ifAbsent: [^ defaultBehavior].
"The permutation is outdated and does not know this variant"
(requiredPermutation := SBExploriants objectToPermutation at: requestor) at: uuid ifAbsent: [^ defaultBehavior].
"An outdated permutation in which an alternative with a higher index than current has been deleted"
aCollectionOfAssociations at: (requiredPermutation at: uuid) ifAbsent: [^ defaultBehavior].

^ (aCollectionOfAssociations at: (requiredPermutation at: uuid)) value value
]

{ #category : #'instance creation' }
Expand Down
2 changes: 1 addition & 1 deletion packages/Sandblocks-Watch/SBMorphResizer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SBMorphResizer class >> newThumbmail [
{ #category : #'initialize-release' }
SBMorphResizer class >> newTiny [

^ self newLabeled: 'small' transforming: [:aMorph | aMorph extent: 15@15]
^ self newLabeled: 'tiny' transforming: [:aMorph | aMorph extent: 15@15]
]

{ #category : #'initialize-release' }
Expand Down
6 changes: 6 additions & 0 deletions packages/Sandblocks-Watch/SBWatchView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ SBWatchView >> displayWatchValues [
self displayOnScrollPane: valuesMorph.
]

{ #category : #accessing }
SBWatchView >> displayedMorphs [

^ self scroller submorphs first "container for scrolling" submorphs
]

{ #category : #'event handling' }
SBWatchView >> doubleClick: evt [

Expand Down
Loading