From 550261a31875756dc99c566362d0f46a874fba86 Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Tue, 12 Sep 2023 14:45:05 +0200 Subject: [PATCH] Adds apply permutation, adds regenerate --- .../SBExploriantsView.class.st | 10 ++-- .../Sandblocks-Core/SBResultsView.class.st | 47 ++++++++++++------- .../Sandblocks-Core/SBVariantsView.class.st | 2 + .../SBPermutation.class.st | 22 +++++++++ 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/packages/Sandblocks-Core/SBExploriantsView.class.st b/packages/Sandblocks-Core/SBExploriantsView.class.st index b437d021..2ca58a9e 100644 --- a/packages/Sandblocks-Core/SBExploriantsView.class.st +++ b/packages/Sandblocks-Core/SBExploriantsView.class.st @@ -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 @@ -60,7 +60,9 @@ SBExploriantsView >> containerRow [ cellPositioning: #topLeft; changeTableLayout; listDirection: #leftToRight; - layoutInset: 1; + layoutInset: 8; + cellGap: 8; + cellInset: 5; borderWidth: 0 ] @@ -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) ] diff --git a/packages/Sandblocks-Core/SBResultsView.class.st b/packages/Sandblocks-Core/SBResultsView.class.st index dfd8453e..4aa32e56 100644 --- a/packages/Sandblocks-Core/SBResultsView.class.st +++ b/packages/Sandblocks-Core/SBResultsView.class.st @@ -1,9 +1,6 @@ Class { #name : #SBResultsView, #superclass : #SBExploriantsView, - #instVars : [ - 'variants' - ], #category : #'Sandblocks-Core' } @@ -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. @@ -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) ] @@ -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 ] diff --git a/packages/Sandblocks-Core/SBVariantsView.class.st b/packages/Sandblocks-Core/SBVariantsView.class.st index 6e0ea858..1dfde0b6 100644 --- a/packages/Sandblocks-Core/SBVariantsView.class.st +++ b/packages/Sandblocks-Core/SBVariantsView.class.st @@ -26,5 +26,7 @@ SBVariantsView >> initialize [ { #category : #actions } SBVariantsView >> visualize [ + self clean. + self allMethodBlocksContainingVariants do: [:aSBStMethod | self buildMethodSectionFor: aSBStMethod] ] diff --git a/packages/Sandblocks-Smalltalk/SBPermutation.class.st b/packages/Sandblocks-Smalltalk/SBPermutation.class.st index 605212dc..9b1188a9 100644 --- a/packages/Sandblocks-Smalltalk/SBPermutation.class.st +++ b/packages/Sandblocks-Smalltalk/SBPermutation.class.st @@ -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 ]