From 8f48fc25c3876867efc3ad9d97339429ebf06bb8 Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Sun, 17 Apr 2022 21:39:50 +0200 Subject: [PATCH] Add half of a coder --- src/Carp/CarpExpression.class.st | 5 ++ src/Carp/CarpModule.class.st | 15 ++-- src/Carp/CarpModuleCoderElement.class.st | 72 +++++++++---------- .../CarpStreamingMethodsCoderElement.class.st | 40 +++++++---- 4 files changed, 77 insertions(+), 55 deletions(-) diff --git a/src/Carp/CarpExpression.class.st b/src/Carp/CarpExpression.class.st index b891d62..0ff67ac 100644 --- a/src/Carp/CarpExpression.class.st +++ b/src/Carp/CarpExpression.class.st @@ -7,6 +7,11 @@ Class { #category : #'Carp-IDE' } +{ #category : #accessing } +CarpExpression >> asElement [ + ^ (GtCarpCoderModel new sourceCode: (GtCoderExplicitStringSource new source: self toCarp)) asElement +] + { #category : #accessing } CarpExpression >> documentation [ ^ documentation ifNil: [''] diff --git a/src/Carp/CarpModule.class.st b/src/Carp/CarpModule.class.st index fdfd5b9..978860f 100644 --- a/src/Carp/CarpModule.class.st +++ b/src/Carp/CarpModule.class.st @@ -52,16 +52,16 @@ CarpModule >> carpCoderCommentsFor: aView [ action: [ :aToggle :aTab | self documentation: aTab viewContentElement children first text asString ]; - actionUpdateButtonTooltip: 'Update documentation' + actionButtonIcon: BrGlamorousVectorIcons cancel + tooltip: 'Discard documentation' + action: [ :aToggle :aTab | + aTab viewContentElement children first text: self documentation ] ] { #category : #accessing } CarpModule >> carpCoderStreamingMethodsFor: aView context: aPhlowContext [ | aMethodsCoder aMethodsCoderViewModel aNewMethodCoderHolder | - - aMethodsCoder := GtStreamingCodersModel new. - aMethodsCoderViewModel := GtStreamingCodersViewModel new streamingCodersModel: aMethodsCoder. aNewMethodCoderHolder := ValueHolder new. @@ -109,7 +109,12 @@ CarpModule >> carpCoderStreamingMethodsFor: aView context: aPhlowContext [ padding: (BlInsets all: 5); addAptitude: BrGlamorousFocusableShadowAptitude new ]; name: #'button--add-new-expression']; - stencil: [ CarpStreamingMethodsCoderElement new streamingCodersViewModel: aMethodsCoderViewModel ] + stencil: [ CarpStreamingMethodsCoderElement forModule: self ] +] + +{ #category : #accessing } +CarpModule >> expressions [ + ^ expressions ] { #category : #initialization } diff --git a/src/Carp/CarpModuleCoderElement.class.st b/src/Carp/CarpModuleCoderElement.class.st index baac0ff..9161043 100644 --- a/src/Carp/CarpModuleCoderElement.class.st +++ b/src/Carp/CarpModuleCoderElement.class.st @@ -46,49 +46,47 @@ CarpModuleCoderElement >> buildDefinitionElement [ { #category : #accessing } CarpModuleCoderElement >> buildModuleLabel [ + | classCoder aModuleNameEditor aContainer aPreviewButton removeClassButton | - aContainer := BrHorizontalPane new - hMatchParent; - alignCenterLeft; - vFitContent. - + hMatchParent; + alignCenterLeft; + vFitContent. + aModuleNameEditor := BrEditableLabel new - aptitude: (BrGlamorousEditableLabelAptitude new - defaultBackground: Color transparent; - glamorousCodeFont; - bold; - fontSize: 18); - inputFilter: BrTextEditorClassNameInputFilter new; - text: self module name; - margin: (BlInsets all: 0); - id: GtBehaviorCoderBehaviorNameId; - whenKey: BlKeyCombination primaryG - labelDo: [ :aShortcutEvent | self phlow spawnObject: self module ]; - whenKey: BlKeyCombination primaryR - labelDo: [ :aShortcutEvent | aShortcutEvent currentTarget switchToEditor ]; - whenKey: BlKeyCombination primaryC - labelDo: [ :aShortcutEvent | Clipboard clipboardText: self module name asString ]. - - aPreviewButton := BrButton new - id: CarpCoderBehaviorNameApplyPreviewId; - margin: (BlInsets left: 5); - addAptitude: BrGlamorousButtonWithIconAptitude; - icon: BrGlamorousVectorIcons accept; - action: [self module name: aModuleNameEditor text]. - - aModuleNameEditor editor - when: BrTextEditorModifiedEvent - do: [ :anEvent | - anEvent text asString trimBoth asSymbol = self module name - ifTrue: [ aContainer removeChild: aPreviewButton ] - ifFalse: [ - "show preview button when name is modified" - (aContainer hasChild: aPreviewButton) - ifFalse: [ aContainer addChild: aPreviewButton after: aModuleNameEditor ] ] ]. + aptitude: + (BrGlamorousEditableLabelAptitude new + defaultBackground: Color transparent; + glamorousCodeFont; + bold; + fontSize: 18); + text: self module name; + margin: (BlInsets all: 0); + id: GtBehaviorCoderBehaviorNameId; + whenKey: BlKeyCombination primaryG + labelDo: [ :aShortcutEvent | + self phlow spawnObject: self module ]; + whenKey: BlKeyCombination primaryR + labelDo: [ :aShortcutEvent | + aShortcutEvent currentTarget switchToEditor ]; + whenKey: BlKeyCombination primaryC + labelDo: [ :aShortcutEvent | + Clipboard clipboardText: + self module name asString ]; + when: BrEditorAcceptWish + do: [ :aWish | + self module name: aWish text asString ]. aContainer addChild: aModuleNameEditor. + aContainer addChild: (BrButton new + aptitude: BrGlamorousButtonWithIconAptitude; + icon: BrGlamorousVectorIcons play; + beSmallSize; + label: 'Generate source'; + action: [ :aButton | + aButton phlow spawnObject: self module toCarp ]). + ^ aContainer ] diff --git a/src/Carp/CarpStreamingMethodsCoderElement.class.st b/src/Carp/CarpStreamingMethodsCoderElement.class.st index caa131c..0d0b308 100644 --- a/src/Carp/CarpStreamingMethodsCoderElement.class.st +++ b/src/Carp/CarpStreamingMethodsCoderElement.class.st @@ -4,28 +4,42 @@ Class { #traits : 'TBrLayoutResizable + TGtWithStreamingCodersViewModel', #classTraits : 'TBrLayoutResizable classTrait + TGtWithStreamingCodersViewModel classTrait', #instVars : [ - 'listItemsProvider', - 'list' + 'list', + 'module' ], #category : #'Carp-Coder' } +{ #category : #accessing } +CarpStreamingMethodsCoderElement class >> forModule: aModule [ + ^ self new module: aModule +] + { #category : #accessing } CarpStreamingMethodsCoderElement >> initialize [ + super initialize. - + self matchParent. - - listItemsProvider := BrListStreamItemsProvider new stream: AsyncEmptyStream new. list := BrSimpleList new - itemType: [ :anItemTypeFactory :anItemObject | anItemObject elementClass ]; - itemStencil: [ :anElementClass | anElementClass new id: GtSourceCoderId ]; - itemDataBinder: [ :aCoderElement :aCoderViewModel | - BlFrameTelemetry - time: [ 'Set {1} as a view model of {2}' format: { aCoderViewModel class name . aCoderElement class name } ] - during: [ aCoderElement textualCoderViewModel: aCoderViewModel ] ]; - itemsProvider: listItemsProvider. - + itemType: [ :anItemTypeFactory :anItemObject | + anItemObject ]; + itemStencil: [ :anItem | + anItem asElement id: GtSourceCoderId ]; + itemsProvider: + (BrListStreamItemsProvider new stream: AsyncEmptyStream new). + self addChild: list ] + +{ #category : #accessing } +CarpStreamingMethodsCoderElement >> initializeForModule [ + list itemsProvider: module expressions asBrItemsProvider +] + +{ #category : #accessing } +CarpStreamingMethodsCoderElement >> module: aModule [ + module := aModule. + self initializeForModule +]