Skip to content

Commit

Permalink
Adds ExamplesMorph and ExampleMorph UI
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeAtHPI committed Jul 6, 2023
1 parent 3e0a44d commit 4d46d19
Show file tree
Hide file tree
Showing 24 changed files with 211 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*Babylonian-ExampleMining-Core
addRecordAndMinimizeButtonMorph

| recordAndMinimizeButton |
recordAndMinimizeButton := IconicButton new.
recordAndMinimizeButton
labelGraphic: (BPIcons wrenchIcon scaledToSize: self iconSize * 0.7);
color: Color transparent;
borderWidth: 0;
extent: recordAndMinimizeButton extent * 0.7;
actionSelector: #recordAndMinimizeButtonClicked;
target: self;
balloonText: 'Record this example and open a tool with the full and minimized recording'.
self addMorphBack: recordAndMinimizeButton
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*Babylonian-ExampleMining-Core
recordAndMinimizeButtonClicked

BPMinimizePreview openFor: self example with: self containingBrowser
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*Babylonian-ExampleMining-Core-override
updateMorphs

self removeAllMorphs.

self
addActivationButtonMorph;
addCollapseButtonMorph;
addAssertResultButtonMorph;
addLoaderIconHolder;
addExampleNameMorph;
addMenuButtonMorph;
addExampleSpecificMorphs;
addRecordAndMinimizeButtonMorph;
addDeleteButtonMorph.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"class" : {
},
"instance" : {
"addRecordAndMinimizeButtonMorph" : "joabe 7/6/2023 22:32",
"recordAndMinimizeButtonClicked" : "joabe 7/6/2023 22:32",
"updateMorphs" : "joabe 7/6/2023 22:35" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "BPExampleMorph" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*Babylonian-ExampleMining-Core
addAsTestCaseExample

| class example method |
method := self containingBrowser compiledMethod.
class := method methodClass.
example := method bpNewExampleFrom: BPTestCaseExample.
example
testCaseClass: class;
methodSelector: method selector.
self containingBrowser saveMethodWithExamples
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*Babylonian-ExampleMining-Core
addRecordedExampleButtonClicked

self openRecordingTool
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*Babylonian-ExampleMining-Core
addTestCaseExampleButtonClicked

self containsTestMethod
ifTrue: [self addAsTestCaseExample]
ifFalse: [self openSearchTool]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*Babylonian-ExampleMining-Core
containsTestMethod

| method |
method := self containingBrowser compiledMethod.
^ (method selector asString includesSubstring: 'test')
and: (method methodClass inheritsFrom: TestCase)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
*Babylonian-ExampleMining-Core-override
initialize

super initialize.

self
color: Color transparent;
borderWidth: (PluggableButtonMorph basicNew userInterfaceTheme borderWidth);
borderColor: self class textColor.

self
changeTableLayout;
hResizing: #rigid;
listDirection: #topToBottom;
cellInset: 1.

self addCollapsedExamplesMorph.

self
addButtonBar;
addCreateExampleButtonLabeled: 'add example' selector: #addExampleButtonClicked;
addCreateExampleButtonLabeled: '| add script example' selector: #addScriptExampleButtonClicked;
addCreateExampleButtonLabeled: '| add referencing example' selector: #addReferencingExampleButtonClicked;
addCreateExampleButtonLabeled: '| add TestCaseExample' selector: #addTestCaseExampleButtonClicked;
addCreateExampleButtonLabeled: '| add recorded example' selector: #addRecordedExampleButtonClicked.

BPExamples value addDependent: self.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*Babylonian-ExampleMining-Core
openRecordingTool

BPExampleRecordingTool
openFor: self containingBrowser compiledMethod
with: self containingBrowser
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*Babylonian-ExampleMining-Core
openSearchTool

BPExampleSearchTool
openFor: self containingBrowser compiledMethod
with: self containingBrowser
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"class" : {
},
"instance" : {
"addAsTestCaseExample" : "joabe 7/6/2023 22:45",
"addRecordedExampleButtonClicked" : "joabe 7/6/2023 22:36",
"addTestCaseExampleButtonClicked" : "joabe 7/6/2023 22:45",
"containsTestMethod" : "joabe 7/6/2023 22:44",
"initialize" : "joabe 7/6/2023 22:43",
"openRecordingTool" : "joabe 7/6/2023 22:37",
"openSearchTool" : "joabe 7/6/2023 22:37" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "BPExamplesMorph" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
*Babylonian-ExampleMining-Core-override
addArgumentScriptMorphs

| editField container |
self example argumentNames withIndexDo: [:argumentName :index |
container := self newLabelContainerMorph: (argumentName , ': ').

editField := self
editFieldStyledInitialContent: (self example argumentScriptStringAt: index)
onChange: [:str |
self example argumentScripts at: index put: str.
self codeContentChanged]
onAccept: [:str |
self acceptChangesAtSource.
false "Do not continue handling this morphs edit"].
editField
balloonText: 'write code that instantiates the argument';
width: 240.
container addMorphBack: editField.

"Live specimen editing"
((self example argumentScripts at: index) isLiveSpecimenReference)
ifTrue: [container addMorphBack: (self newSpecimenEditingButtonFor: (self example argumentScripts at: index))].

"Live specimen selection"
container addMorphBack: (self newSpecimenSelectionButtonOnClick: [
self selectLiveSpecimen: (self example liveSpecimenAt: index) then: [:specimen |
self example argumentScripts at: index put: specimen.
self codeContentChanged.
editField setText: (self example argumentScriptStringAt: index)]]).

exampleSpecificMorphs addMorphBack: container].
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
*Babylonian-ExampleMining-Core-override
addReceiverConstructorMorph

| container editField |
container := self newLabelContainerMorph: 'self: '.

editField := (self
editFieldStyledInitialContent: self example receiverConstructorString
onChange: [:str |
self example receiverConstructor: str.
self codeContentChanged]
onAccept: [:str |
self acceptChangesAtSource]).
editField
balloonText: 'Write code that instantiates the receiver.
You can also provide a selector that will be called on the
class-side of this class to create a receiver object.';
width: 240.
container addMorphBack: editField.

"Live specimen editing"
(self example receiverConstructor isLiveSpecimenReference)
ifTrue: [container addMorphBack: (self newSpecimenEditingButtonFor: self example receiverConstructor)].

"Live specimen selection"
container addMorphBack: (self newSpecimenSelectionButtonOnClick: [
self selectLiveSpecimen: self example receiverConstructorLiveSpecimen then: [:specimen |.
self example receiverConstructor: specimen.
self codeContentChanged.
editField setText: self example receiverConstructorString]]).

exampleSpecificMorphs addMorphBack: container.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*Babylonian-ExampleMining-Core
newSpecimenEditingButtonFor: specimenConstructor

^ self newSpecimenSelectionButtonOnClick: [(self example resolveLiveSpecimen: specimenConstructor) inspect];
labelGraphic: (BPIcons wrenchIcon scaledToSize: self iconSize * 0.7);
balloonText: 'Click to open the specimen editing tool';
yourself
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"class" : {
},
"instance" : {
"addArgumentScriptMorphs" : "joabe 7/6/2023 22:59",
"addReceiverConstructorMorph" : "joabe 7/6/2023 22:51",
"newSpecimenEditingButtonFor:" : "joabe 7/6/2023 23:01" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "BPMethodExampleMorph" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ private-recording
recordFrom: aContext

#(bpExampleRecording) withoutLayersDo: [
recordedCalls add: {aContext receiver . aContext arguments}]
recordedCalls add: {aContext receiver copy. aContext arguments copy}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
recordedCalls

^ recordedCalls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"installMyselfInProcess" : "pre 12/16/2020 16:21",
"instrumentMethod:" : "pre 12/16/2020 17:06",
"instrumentedSourceFor:" : "pre 12/16/2020 17:00",
"recordFrom:" : "pre 12/16/2020 17:03",
"recordFrom:" : "joabe 7/6/2023 18:33",
"recordedCalls" : "joabe 7/6/2023 18:31",
"removeRecordingLayer" : "pre 12/16/2020 16:35",
"startRecording" : "pre 12/16/2020 16:19",
"stopRecording" : "pre 12/16/2020 17:04",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ updateMorphs
addExampleNameMorph;
addMenuButtonMorph;
addExampleSpecificMorphs;
addRecordAndMinimizeButtonMorph;
addDeleteButtonMorph.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
"textEmphasis" : "pre 9/30/2020 10:35",
"timeoutButtonClicked" : "joabe 9/27/2022 22:35",
"updateAssertResultIcon" : "jb 12/30/2021 22:33",
"updateMorphs" : "lu 2/15/2022 09:56",
"updateMorphs" : "joabe 7/6/2023 22:35",
"userWantsToDeleteAllAnnotations" : "lu 2/22/2022 01:10" } }

0 comments on commit 4d46d19

Please sign in to comment.