Skip to content

Commit

Permalink
Adds inactive variants
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Jan 16, 2024
1 parent 6840e96 commit 59db80c
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 14 deletions.
1 change: 0 additions & 1 deletion packages/Sandblocks-Babylonian/SBExample.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ SBExample >> runSynchronouslyIgnoreReturn [

| returned |
self sendStartNotification.

SBExecutionEnvironment value: self.
[returned := self evaluate] on: Error do: [:e | self scheduleLastError: e].
self scheduleLastError: nil.
Expand Down
4 changes: 3 additions & 1 deletion packages/Sandblocks-Babylonian/SBMultiverse.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ SBMultiverse >> createUniverseFomPermutation: aSBPermutation [
{ #category : #collecting }
SBMultiverse >> findExistingOrConvertToBlocks: aCollectionOfCompiledMethods [

^ aCollectionOfCompiledMethods
^ aCollectionOfCompiledMethods
collect: [:aCompiledMethod |
self sandblockEditor blockFor: aCompiledMethod withInterfaces: #(#isMethod)
ifOpen: [:existingMethodBlock | existingMethodBlock]
Expand All @@ -126,6 +126,8 @@ SBMultiverse >> gatherElements [
allMethodBlocksContainingWatches := self findExistingOrConvertToBlocks: self allCompiledMethodsContainingExampleWatches.

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

activeExamples := self allActiveExamples.


Expand Down
2 changes: 1 addition & 1 deletion packages/Sandblocks-Core/SBBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2586,7 +2586,7 @@ SBBlock >> sandblockForegroundColor [
{ #category : #'artefact protocol' }
SBBlock >> save [

(self saveTryFixing: false quick: false) ifFalse: [self error: 'failed to save block']
(self saveTryFixing: false quick: false)
]

{ #category : #saving }
Expand Down
112 changes: 101 additions & 11 deletions packages/Sandblocks-Smalltalk/SBVariant.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Class {
#instVars : [
'name',
'widget',
'id'
'id',
'isActive'
],
#category : #'Sandblocks-Smalltalk'
}
Expand Down Expand Up @@ -39,7 +40,7 @@ SBVariant class >> matches: aBlock [
{ #category : #constants }
SBVariant class >> matchingSelectors [

^ #(#named:associations:activeIndex:id:)
^ #(#named:associations:activeIndex:id:isActive:)
]

{ #category : #'instance creation' }
Expand All @@ -64,15 +65,29 @@ SBVariant class >> named: aString alternatives: aCollectionOfNamedBlocks activeI
]

{ #category : #'instance creation' }
SBVariant class >> named: aString associations: aCollectionOfAssociations activeIndex: aNumber id: uuid [
SBVariant class >> named: aString alternatives: aCollectionOfNamedBlocks activeIndex: aNumber id: uuid isActive: aBoolean [

^ self new
named: aString
alternatives: aCollectionOfNamedBlocks
activeIndex: aNumber
id: uuid
isActive: aBoolean

]

{ #category : #'instance creation' }
SBVariant class >> named: aString associations: aCollectionOfAssociations activeIndex: aNumber id: uuid isActive: aBoolean [

| defaultBehavior requestor requiredPermutation |
aNumber <= 0 ifTrue: [^ nil].
defaultBehavior := (aCollectionOfAssociations at: aNumber) value value.
"Inactive variants ignore any active or dynamic permutation shenanigans"
aBoolean ifFalse: [^ defaultBehavior].

"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"
Expand All @@ -97,6 +112,7 @@ SBVariant class >> newFor: aBlock [
alternatives: (aBlock arguments second childSandblocks collect: [:anAssociation | SBNamedBlock block: (anAssociation arguments first) named: (anAssociation receiver contents)])
activeIndex: aBlock arguments third parsedContents
id: aBlock arguments fourth contents
isActive: aBlock arguments fifth contents = 'true'
]

{ #category : #shortcuts }
Expand Down Expand Up @@ -130,6 +146,17 @@ SBVariant >> activeIndex [
^ self widget activeIndex
]

{ #category : #actions }
SBVariant >> activeMutateCommandWithNewValue: aBoolean [

^ SBMutatePropertyCommand new
target: self;
selector: #isActive;
mutateSelector: #isActive:;
value: aBoolean;
oldValue: self isActive
]

{ #category : #accessing }
SBVariant >> alternatives [

Expand Down Expand Up @@ -184,6 +211,34 @@ SBVariant >> asProxy [
^ SBVariantProxy for: self
]

{ #category : #actions }
SBVariant >> beActive [
<action>

| command |
command := self activeMutateCommandWithNewValue: true.

self sandblockEditor
ifNil: [command do]
ifNotNil:[:theEditor | theEditor do: command].

self saveArtefact.
]

{ #category : #actions }
SBVariant >> beInactive [
<action>

| command |
command := self activeMutateCommandWithNewValue: false.

self sandblockEditor
ifNil: [command do]
ifNotNil:[:theEditor | theEditor do: command].

self saveArtefact.
]

{ #category : #accessing }
SBVariant >> blockAt: anIndex [

Expand All @@ -196,12 +251,6 @@ SBVariant >> color [
^ Color transparent
]

{ #category : #accessing }
SBVariant >> drawnColor [

^ Color white
]

{ #category : #accessing }
SBVariant >> id [
^ id
Expand All @@ -226,6 +275,7 @@ SBVariant >> initialize [
namedBlocks: {SBNamedBlock block: (SBStBlockBody emptyWithDeclarations: {'a'. 'c'}) named: 'Code'}
activeIndex: 1).
id := UUID new asString.
isActive := true.

self
layoutInset: 0;
Expand All @@ -237,6 +287,23 @@ SBVariant >> initialize [
hResizing: #shrinkWrap
]

{ #category : #accessing }
SBVariant >> isActive [

^ isActive
]

{ #category : #accessing }
SBVariant >> isActive: aBoolean [

isActive := aBoolean.

isActive
ifTrue: [self localColorPolicy: SBEditor defaultColorPolicy new]
ifFalse: [self localColorPolicy: SBDisabledTheme new.
self activeBlock localColorPolicy: SBEditor defaultColorPolicy new.]
]

{ #category : #testing }
SBVariant >> isVariant [

Expand Down Expand Up @@ -269,6 +336,13 @@ SBVariant >> named: aString alternatives: aCollectionOfNamedBlocks activeIndex:
self named: aString alternatives: aCollectionOfNamedBlocks activeIndex: aNumber
]

{ #category : #initialization }
SBVariant >> named: aString alternatives: aCollectionOfNamedBlocks activeIndex: aNumber id: uuid isActive: aBoolean [

self isActive: aBoolean.
self named: aString alternatives: aCollectionOfNamedBlocks activeIndex: aNumber id: uuid
]

{ #category : #accessing }
SBVariant >> namedBlocks [

Expand Down Expand Up @@ -316,6 +390,14 @@ SBVariant >> replaceValuesFrom: anotherVariant [
self named: anotherVariant name alternatives: anotherVariant alternatives activeIndex: anotherVariant activeIndex
]

{ #category : #actions }
SBVariant >> saveArtefact [

self containingArtefact save.
self containingArtefact sandblockEditor ifNotNil: [:theEditor | theEditor markSaved: self containingArtefact]

]

{ #category : #accessing }
SBVariant >> statementsFor: aNamedBlock [

Expand All @@ -330,6 +412,12 @@ SBVariant >> switchToAlternative: anIndex [
self widget jumpToTab: anIndex
]

{ #category : #accessing }
SBVariant >> toggleActive [

isActive := isActive not
]

{ #category : #ui }
SBVariant >> updateResize [

Expand Down Expand Up @@ -371,5 +459,7 @@ SBVariant >> writeSourceOn: aStream [
self activeIndex storeOn: aStream.
aStream nextPutAll: ' id: '.
self id storeOn: aStream.
aStream nextPutAll: ' isActive: '.
self isActive storeOn: aStream.
aStream nextPutAll: ')'
]

0 comments on commit 59db80c

Please sign in to comment.