From d791ba800762df0d737891b231a177d38a630d5c Mon Sep 17 00:00:00 2001 From: Joana Bergsiek Date: Thu, 12 Oct 2023 16:22:40 +0200 Subject: [PATCH] Extracts inactive watches to their own class --- .../SBExampleValueDisplay.class.st | 4 +- .../SBExampleWatch.class.st | 31 ++---------- .../SBExampleWatch.extension.st | 2 +- .../SBInactiveExampleWatch.class.st | 50 +++++++++++++++++++ .../SBInactiveExampleWatch.extension.st | 7 +++ 5 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st create mode 100644 packages/Sandblocks-Babylonian/SBInactiveExampleWatch.extension.st diff --git a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st index d31c25f4..c16657ed 100644 --- a/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleValueDisplay.class.st @@ -27,7 +27,9 @@ SBExampleValueDisplay >> exampleFinished: anExample [ display exampleFinished: anExample. statusLabel - contents: (hadValue ifTrue: [''] ifFalse: ['- Not reached -']); + contents: (hadValue + ifTrue: [''] + ifFalse: ['- Not reached -']); visible: hadValue not ] diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st index e8628697..b505342d 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.class.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.class.st @@ -1,5 +1,5 @@ " -Observes (watches) an expression locally for added SBExamples. Whenever an example has finished running, it updates its belonging view. Only active watches update their views. Further, with a given modifyExpression, it transforms the watched expression values. Also known as a Probe in the context of Babylonian Smalltalk. +Observes (watches) an expression locally for added SBExamples. Whenever an example has finished running, it updates its belonging view. Further, with a given modifyExpression, it transforms the watched expression values. Also known as a Probe in the context of Babylonian Smalltalk. " Class { #name : #SBExampleWatch, @@ -8,7 +8,6 @@ Class { 'identifier', 'watchedExpression', 'modifyExpression', - 'isActive', 'exampleToDisplay', 'exampleToValues' ], @@ -112,31 +111,10 @@ SBExampleWatch >> applyModifyExpressionOnValues [ anExampleDisplayPair value updateDisplay] ] -{ #category : #callbacks } -SBExampleWatch >> artefactSaved: aBlock [ - - "As we are inactive, we have to manually apply our modifyExpression if it changes. - Otherwise, we would reset by examples starting" - (self isActive not and: [aBlock = self containingArtefact]) ifTrue: [self applyModifyExpressionOnValues] -] - { #category : #copying } SBExampleWatch >> asInactiveCopy [ - | copy | - copy := self veryDeepCopy beInactive. - - "Resolve bindings" - copy expression: (SBTextBubble new contents: copy expression sourceString). - copy setWatchedExpressionUneditable. - - ^ copy -] - -{ #category : #accessing } -SBExampleWatch >> beInactive [ - - isActive := false + ^ SBInactiveExampleWatch newFromWatch: self ] { #category : #'colors and color policies' } @@ -253,7 +231,6 @@ SBExampleWatch >> initialize [ exampleToValues := Dictionary new. watchedExpression := SBStMessageSend new. modifyExpression := SBStBlockBody identityNamed: 'result'. - isActive := true. self cellGap: 4; @@ -275,7 +252,7 @@ SBExampleWatch >> intoWorld: aWorld [ { #category : #accessing } SBExampleWatch >> isActive [ - ^ isActive + ^ true ] { #category : #'*Sandblocks-Babylonian' } @@ -314,7 +291,7 @@ SBExampleWatch >> layoutCommands [ { #category : #'*Sandblocks-Babylonian' } SBExampleWatch >> listensToExamples [ - ^ self isActive + ^ true ] { #category : #accessing } diff --git a/packages/Sandblocks-Babylonian/SBExampleWatch.extension.st b/packages/Sandblocks-Babylonian/SBExampleWatch.extension.st index 03cc8110..295787df 100644 --- a/packages/Sandblocks-Babylonian/SBExampleWatch.extension.st +++ b/packages/Sandblocks-Babylonian/SBExampleWatch.extension.st @@ -15,5 +15,5 @@ SBExampleWatch >> isGlobalWatch [ { #category : #'*Sandblocks-Babylonian' } SBExampleWatch >> listensToExamples [ - ^ self isActive + ^ true ] diff --git a/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st b/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st new file mode 100644 index 00000000..bb93a7ed --- /dev/null +++ b/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.class.st @@ -0,0 +1,50 @@ +" +Does not update its results anymore. Applying modification expressions is still possible. +" +Class { + #name : #SBInactiveExampleWatch, + #superclass : #SBExampleWatch, + #category : #'Sandblocks-Babylonian' +} + +{ #category : #'initialize-release' } +SBInactiveExampleWatch class >> newFromWatch: anActiveWatch [ + + ^ (anActiveWatch veryDeepCopy) + primitiveChangeClassTo: self basicNew; + expression: (SBTextBubble new contents: anActiveWatch expression sourceString); + yourself +] + +{ #category : #callbacks } +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] +] + +{ #category : #'event handling' } +SBInactiveExampleWatch >> doubleClick: evt [ + + "Nothing" +] + +{ #category : #'as yet unclassified' } +SBInactiveExampleWatch >> expression: aBlock [ + + super expression: aBlock. + watchedExpression selectable: false +] + +{ #category : #accessing } +SBInactiveExampleWatch >> isActive [ + + ^ false +] + +{ #category : #'*Sandblocks-Babylonian' } +SBInactiveExampleWatch >> listensToExamples [ + + ^ false +] diff --git a/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.extension.st b/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.extension.st new file mode 100644 index 00000000..76ada315 --- /dev/null +++ b/packages/Sandblocks-Babylonian/SBInactiveExampleWatch.extension.st @@ -0,0 +1,7 @@ +Extension { #name : #SBInactiveExampleWatch } + +{ #category : #'*Sandblocks-Babylonian' } +SBInactiveExampleWatch >> listensToExamples [ + + ^ false +]