From 6107a8b65d7728bdafee57c6fafe7c753274c481 Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Mon, 18 Sep 2023 15:09:40 +0200 Subject: [PATCH] Exploriants as tab view --- .../SBExampleWatch.class.st | 12 -------- .../Sandblocks-Core/SBExploriants.class.st | 6 ++-- .../SBExploriantsView.class.st | 8 ++++- packages/Sandblocks-Core/SBTabView.class.st | 2 +- .../SBPermutation.class.st | 2 +- .../Sandblocks-Smalltalk/SBVariant.class.st | 30 +++++++++++++++---- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st index dda80798..a984e2ab 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st @@ -132,20 +132,8 @@ SBExampleWatch >> asInactiveCopy [ ^ (self veryDeepCopy) beInactive. ] -{ #category : #accessing } -SBExampleWatch >> beActive [ - - - self flag: #todo. "action for debugging, remove later. bc when applying modification and - then turning inactive, the already modified values are seen as the ground truth. - is aber allgemein ein problemchen....eig sollten die watchviews die wahren values haben und nur - die modifizierten anzeigen." - isActive := true -] - { #category : #accessing } SBExampleWatch >> beInactive [ - isActive := false ] diff --git a/packages/Sandblocks-Core/SBExploriants.class.st b/packages/Sandblocks-Core/SBExploriants.class.st index 9926653f..6b491ddf 100644 --- a/packages/Sandblocks-Core/SBExploriants.class.st +++ b/packages/Sandblocks-Core/SBExploriants.class.st @@ -1,6 +1,6 @@ Class { #name : #SBExploriants, - #superclass : #SBBlock, + #superclass : #SBTabView, #instVars : [ 'watchMethodBlocks', 'variants', @@ -63,7 +63,5 @@ SBExploriants >> saveTryFixing: aFixBoolean quick: aQuickBoolean [ { #category : #actions } SBExploriants >> visualize [ - self submorphs copy do: #delete. - - self addMorphBack: SBExploriantsView asTabView. + self namedBlocks: SBExploriantsView getTabs activeIndex: 1 ] diff --git a/packages/Sandblocks-Core/SBExploriantsView.class.st b/packages/Sandblocks-Core/SBExploriantsView.class.st index bdfc7e66..ca655991 100644 --- a/packages/Sandblocks-Core/SBExploriantsView.class.st +++ b/packages/Sandblocks-Core/SBExploriantsView.class.st @@ -7,7 +7,7 @@ Class { { #category : #'instance creation' } SBExploriantsView class >> asTabView [ - ^ SBTabView + ^ SBExploriants namedBlocks: (self subclasses collect: #new) activeIndex: 1 ] @@ -19,6 +19,12 @@ SBExploriantsView class >> block: aSBBlock named: aString [ self shouldNotImplement ] +{ #category : #'instance creation' } +SBExploriantsView class >> getTabs [ + + ^ self subclasses collect: #new +] + { #category : #accessing } SBExploriantsView >> allCompiledMethodsContainingClass: aClass [ diff --git a/packages/Sandblocks-Core/SBTabView.class.st b/packages/Sandblocks-Core/SBTabView.class.st index 11b2d5ff..d94f08cd 100644 --- a/packages/Sandblocks-Core/SBTabView.class.st +++ b/packages/Sandblocks-Core/SBTabView.class.st @@ -377,7 +377,7 @@ SBTabView >> removeCurrentTab [ { #category : #tabs } SBTabView >> setActive: aNamedBlock [ - self sandblockEditor do: + SBEditor current do: (self switchCommandFor: (self namedBlocks indexOf: aNamedBlock ifAbsent: 1)) ] diff --git a/packages/Sandblocks-Smalltalk/SBPermutation.class.st b/packages/Sandblocks-Smalltalk/SBPermutation.class.st index 9b1188a9..c410de51 100644 --- a/packages/Sandblocks-Smalltalk/SBPermutation.class.st +++ b/packages/Sandblocks-Smalltalk/SBPermutation.class.st @@ -49,7 +49,7 @@ 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]) + aVariant name, ': ', (aVariant blockAt: (self at: aVariant id)) name]) fold: [:a :b | a, ', ', b ] diff --git a/packages/Sandblocks-Smalltalk/SBVariant.class.st b/packages/Sandblocks-Smalltalk/SBVariant.class.st index 1c56c817..1b270ee9 100644 --- a/packages/Sandblocks-Smalltalk/SBVariant.class.st +++ b/packages/Sandblocks-Smalltalk/SBVariant.class.st @@ -156,6 +156,14 @@ SBVariant >> blockAt: anIndex [ ^ self widget blockAt: anIndex ] +{ #category : #accessing } +SBVariant >> codeFor: aNamedBlock [ + + ^ (aNamedBlock block submorphs size > 1) + ifTrue: [aNamedBlock block lastSubmorph] + ifFalse: [nil] +] + { #category : #accessing } SBVariant >> color [ @@ -242,22 +250,32 @@ SBVariant >> namedBlocks [ { #category : #actions } SBVariant >> replaceSelfWithBlock: aNamedBlock [ + | command | "As deleting the last tab also deletes the tab view, we gotta recreate it" self widget: (SBTabView namedBlocks: {aNamedBlock} activeIndex: 1). self addMorphBack: widget. - self sandblockEditor do: (SBUnwrapConsecutiveCommand new + command := (self codeFor: widget active) + ifNil: [SBDeleteCommand new target: self] + ifNotNil: [SBUnwrapConsecutiveCommand new target: self; - unwrapped: {widget activeBlock lastSubmorph}) + unwrapped: {(self codeFor: widget active)}]. + + self sandblockEditor do: command ] { #category : #actions } SBVariant >> replaceSelfWithChosen [ - self sandblockEditor do: (SBUnwrapConsecutiveCommand new + | command | + command := (self codeFor: widget active) + ifNil: [SBDeleteCommand new target: self] + ifNotNil: [SBUnwrapConsecutiveCommand new target: self; - unwrapped: {self activeBlock lastSubmorph}) + unwrapped: {(self codeFor: widget active)}]. + + self sandblockEditor do: command ] { #category : #initialization } @@ -306,7 +324,9 @@ SBVariant >> writeSourceOn: aStream [ do: [:aNamedBlock | aNamedBlock name storeOn: aStream. aStream nextPutAll: ' -> ['. - aNamedBlock block lastSubmorph writeSourceOn: aStream. + (self codeFor: aNamedBlock) + ifNotNil: [(self codeFor: aNamedBlock) writeSourceOn: aStream] + ifNil: [aStream nextPutAll: ' ']. aStream nextPut: $]. ] separatedBy: [aStream nextPut: $.].