Skip to content

Commit

Permalink
Adds apply permutation, adds regenerate
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Sep 12, 2023
1 parent b181a73 commit 550261a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 20 deletions.
10 changes: 6 additions & 4 deletions packages/Sandblocks-Core/SBExploriantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SBExploriantsView >> allCompiledMethodsContainingVariants [
^ self allCompiledMethodsContainingClass: SBVariant
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
SBExploriantsView >> allMethodBlocksContainingVariants [

"We are looking for already opened methods so that we can assign the
Expand All @@ -60,7 +60,9 @@ SBExploriantsView >> containerRow [
cellPositioning: #topLeft;
changeTableLayout;
listDirection: #leftToRight;
layoutInset: 1;
layoutInset: 8;
cellGap: 8;
cellInset: 5;
borderWidth: 0
]

Expand All @@ -84,8 +86,8 @@ SBExploriantsView >> initialize [
color: Color white;
listDirection: #topToBottom;
layoutInset: 8;
cellGap: 16;
cellInset: 10;
cellGap: 8;
cellInset: 5;
hResizing: #shrinkWrap;
vResizing: #shrinkWrap)
]
Expand Down
47 changes: 31 additions & 16 deletions packages/Sandblocks-Core/SBResultsView.class.st
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Class {
#name : #SBResultsView,
#superclass : #SBExploriantsView,
#instVars : [
'variants'
],
#category : #'Sandblocks-Core'
}

Expand Down Expand Up @@ -45,10 +42,24 @@ SBResultsView >> allWatchesIn: aCollectionOfMethodBlocks [
aMethodBlock containedExampleWatches collect: #asInactiveCopy]) flatten
]

{ #category : #building }
SBResultsView >> applyButtonFor: aPermutation [

self flag: #todo. "should check if there were any changes to the variants before applying -jb"
^ SBButton new
icon: (SBIcon iconCheck
size: 6.0 sbScaled;
color: (Color r: 0.0 g: 1 b: 0.0))
label: 'Apply Permutation'
do: [aPermutation apply];
makeSmall;
cornerStyle: #squared
]

{ #category : #building }
SBResultsView >> buildAllPossibleResults [

| permutations activeExamples watchMethodBlocks |
| permutations activeExamples watchMethodBlocks variants |
self flag: #todo. "don't calculate all variants a second time (first time being the variants view) -jb"
variants := (self allMethodBlocksContainingVariants collect: #containedVariants) flatten.
watchMethodBlocks := self allMethodBlocksContainingWatches.
Expand All @@ -65,11 +76,13 @@ SBResultsView >> buildAllPossibleResults [
{ #category : #building }
SBResultsView >> buildPermutationFor: aPermutation collectingWatchesFrom: aCollectionOfMethodBlocks [

self block addMorphBack: (self titleMorphForPermutation: aPermutation).
self block addMorphBack: (SBOwnTextMorph new contents: aPermutation asString).
self block addMorphBack: (self applyButtonFor: aPermutation).

self block addMorphBack: (
self containerRow
addMorphBack: ((self containerRow listDirection: #leftToRight)
addAllMorphsBack: (self allWatchesIn: aCollectionOfMethodBlocks))).
(self containerRow listDirection: #leftToRight)
addAllMorphsBack: (self allWatchesIn: aCollectionOfMethodBlocks)).

self block addMorphBack: (LineMorph from: 0@0 to: 50@0 color: Color black width: 2)
]

Expand All @@ -84,18 +97,20 @@ SBResultsView >> initialize [
]

{ #category : #building }
SBResultsView >> titleMorphForPermutation: aPermutation [

"collecting instead of calling (a active name), ', ', (b active name) in fold
as one variant only will not return a string but a variant"
^ SBOwnTextMorph new contents: (
(aPermutation referencedVariants collect: [:aVariant |
(aVariant blockAt: (aPermutation at: aVariant id)) name])
fold: [:a :b | a, ', ', b ])
SBResultsView >> updateButton [

^ SBButton new
icon: SBIcon iconRotateLeft
label: 'Re-Generate'
do: [self visualize];
cornerStyle: #squared
]

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

self clean.

self block addMorphBack: self updateButton.
self buildAllPossibleResults
]
2 changes: 2 additions & 0 deletions packages/Sandblocks-Core/SBVariantsView.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ SBVariantsView >> initialize [
{ #category : #actions }
SBVariantsView >> visualize [

self clean.

self allMethodBlocksContainingVariants do: [:aSBStMethod | self buildMethodSectionFor: aSBStMethod]
]
22 changes: 22 additions & 0 deletions packages/Sandblocks-Smalltalk/SBPermutation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,34 @@ SBPermutation class >> allPermutationsOf: aCollectionOfVariants [

]

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

self referencedVariants do: [:aVariant | aVariant switchToAlternative: (self at: aVariant id)].
(Set newFrom: (referencedVariants collect: #containingArtefact thenSelect: #isMethod))
do: [:aMethodBlock | SBEditor current save: aMethodBlock tryFixing: true quick: true].
]

{ #category : #converting }
SBPermutation >> asString [

"collecting instead of calling (a active name), ', ', (b active name) in fold
as one variant only will not return a string but a variant"
^ (self referencedVariants collect: [:aVariant |
(aVariant blockAt: (self at: aVariant id)) name])
fold: [:a :b | a, ', ', b ]


]

{ #category : #accessing }
SBPermutation >> referencedVariants [

^ referencedVariants
]

{ #category : #accessing }
SBPermutation >> referencedVariants: anObject [

referencedVariants := anObject
]

0 comments on commit 550261a

Please sign in to comment.