Skip to content

Commit

Permalink
adding completion strategy to transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
j-brant committed Aug 27, 2024
1 parent 772643e commit 20cf573
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,44 +46,41 @@ GtSmaCCAbstractRewriteElement >> build [
self addCommentElement
]

{ #category : #private }
GtSmaCCAbstractRewriteElement >> connectModel [
rewrite ifNil: [ ^ self ].
rewrite announcer weak
when: #comment
send: #updateComment
to: self
]

{ #category : #private }
GtSmaCCAbstractRewriteElement >> disconnectModel [
rewrite ifNil: [ ^ self ].
rewrite announcer unsubscribe: self
]

{ #category : #'initialize-release' }
GtSmaCCAbstractRewriteElement >> initialize [
super initialize.
self matchParent.
self padding: (BlInsets all: 5)
]

{ #category : #'hooks - children' }
GtSmaCCAbstractRewriteElement >> onAddedToParent [
super onAddedToParent.
rewrite notNil ifTrue: [ rewrite addDependent: self ]
]

{ #category : #'hooks - children' }
GtSmaCCAbstractRewriteElement >> onRemovedFromParent: aParentElement [
super onRemovedFromParent: aParentElement.
rewrite notNil ifTrue: [ rewrite removeDependent: self ]
]

{ #category : #accessing }
GtSmaCCAbstractRewriteElement >> rewrite [
^ rewrite
]

{ #category : #accessing }
GtSmaCCAbstractRewriteElement >> rewrite: aRewrite [
rewrite notNil ifTrue: [ rewrite removeDependent: self ].
self disconnectModel.
rewrite := aRewrite.
(rewrite notNil and: [ parent notNil ]) ifTrue: [ self addDependent: self ].
self connectModel.
self updateContent
]

{ #category : #updating }
GtSmaCCAbstractRewriteElement >> update: aSymbol [
aSymbol = #comment ifTrue: [ self updateComment ].
^ super update: aSymbol
]

{ #category : #updating }
GtSmaCCAbstractRewriteElement >> updateComment [
self childNamed: #commentEditor ifFound: [ :editor | editor text: rewrite comment asRopedText ]
Expand Down
9 changes: 8 additions & 1 deletion src/GT4SmaCC-Rewrite-Engine-UI/GtSmaCCCodeElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ GtSmaCCCodeElement >> format: aString [

{ #category : #initialization }
GtSmaCCCodeElement >> initialize [
| editor |
| editor completionStrategy completionController |
super initialize.
editor := BrEditor new.
editor
Expand All @@ -56,6 +56,13 @@ GtSmaCCCodeElement >> initialize [
source := self format: editor editor text asString.
model code: source.
editor editor text: source asRopedText ]).
completionStrategy := GtPharoCompletionStrategy new.
completionStrategy classOrMetaClass: SmaCCRewriteMatchContext.
completionStrategy isMethod: false.
completionController := GtCompletionController
on: editor
strategy: completionStrategy.
completionController install.
self padding: (BlInsets all: 5).
self matchParent.
self addChild: editor as: #code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Class {

{ #category : #'initialize-release' }
GtSmaCCMethodDefinitionElement >> build [
| completionStrategy completionController |
super build.
editor := BrEditor new.
editor
Expand All @@ -17,24 +18,41 @@ GtSmaCCMethodDefinitionElement >> build [
vFitContent;
aptitude: BrGlamorousCodeEditorAptitude new;
beEditable;
padding:
(BlInsets
top: 5
left: 10
bottom: 5
right: 10);
padding: (BlInsets
top: 5
left: 10
bottom: 5
right: 10);
matchParent.
editor
addShortcut:
((BlShortcutWithAction new)
addShortcut: (BlShortcutWithAction new
combination: BlKeyCombination primaryShiftF;
action: [ self format ]).
editor editor styler: self styler.
editor editor when: BrTextEditorModifiedEvent do: [ :event | self sourceChanged ].
editor editor
when: BrTextEditorModifiedEvent
do: [ :event | self sourceChanged ].
completionStrategy := GtPharoCompletionStrategy new.
completionStrategy classOrMetaClass: SmaCCRewriteMatchContext.
completionStrategy isMethod: true.
completionController := GtCompletionController
on: editor
strategy: completionStrategy.
completionController install.
self updateSource.
self addChild: editor
]

{ #category : #private }
GtSmaCCMethodDefinitionElement >> connectModel [
super connectModel.
rewrite ifNil: [ ^ self ].
rewrite announcer weak
when: #source
send: #updateSource
to: self
]

{ #category : #actions }
GtSmaCCMethodDefinitionElement >> format [
| ast |
Expand Down
4 changes: 2 additions & 2 deletions src/GT4SmaCC-Rewrite-Engine-UI/GtSmaCCPreviewElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ GtSmaCCPreviewElement >> updateEditorsForAnnotation: annotation [
childNamed: #inputSource
ifFound: [ :element |
element editor text
clearAttributes: [ :each | each isKindOf: GtSmaCCTransformedAttribute ].
clearAttributes: [ :each | each class = GtSmaCCTransformedAttribute ].
annotation
ifNotNil: [ element editor text
attributes: {GtSmaCCTransformedAttribute new}
Expand All @@ -412,7 +412,7 @@ GtSmaCCPreviewElement >> updateEditorsForAnnotation: annotation [
childNamed: #outputSource
ifFound: [ :element |
element editor text
clearAttributes: [ :each | each isKindOf: GtSmaCCTransformedAttribute ].
clearAttributes: [ :each | each class = GtSmaCCTransformedAttribute ].
annotation
ifNotNil: [ | firstIndex |
firstIndex := SmallInteger maxVal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ GtSmaCCPropertyDefinitionElement >> build [
self updateGlobals
]

{ #category : #private }
GtSmaCCPropertyDefinitionElement >> connectModel [
super connectModel.
rewrite ifNil: [ ^ self ].
rewrite announcer weak
when: #locals
send: #updateLocals
to: self;
when: #globals
send: #updateGlobals
to: self
]

{ #category : #building }
GtSmaCCPropertyDefinitionElement >> removeButton: aString list: list [
^ BrButton new
Expand All @@ -84,13 +97,6 @@ GtSmaCCPropertyDefinitionElement >> removeButton: aString list: list [
with: (list items at: i ifAbsent: [ ]) ] ]
]

{ #category : #updating }
GtSmaCCPropertyDefinitionElement >> update: aSymbol [
aSymbol = #locals ifTrue: [ self updateLocals ].
aSymbol = #globals ifTrue: [ self updateGlobals ].
^ super update: aSymbol
]

{ #category : #private }
GtSmaCCPropertyDefinitionElement >> updateGlobals [
self childNamed: #GlobalVariables ifFound: [ :list | list items: rewrite globalVariableNames ].
Expand Down
20 changes: 13 additions & 7 deletions src/GT4SmaCC-Rewrite-Engine-UI/GtSmaCCRewriteElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ GtSmaCCRewriteElement >> build [
transformationTabGroup when: BrTabSelectedEvent do: [ :event | self transformationTabSwitched ]
]

{ #category : #private }
GtSmaCCRewriteElement >> connectModel [
super connectModel.
rewrite ifNil: [ ^ self ].
rewrite announcer weak
when: #match
send: #updateMatch
to: self;
when: #transformation
send: #updateTransformation
to: self
]

{ #category : #initialization }
GtSmaCCRewriteElement >> initialize [
super initialize.
Expand Down Expand Up @@ -151,13 +164,6 @@ GtSmaCCRewriteElement >> transformationTabSwitched [
rewrite transformation: transformationPattern ] ] ]
]

{ #category : #updating }
GtSmaCCRewriteElement >> update: aSymbol [
aSymbol = #match ifTrue: [ self updateMatch ].
aSymbol = #transformation ifTrue: [ self updateTransformation ].
^ super update: aSymbol
]

{ #category : #updating }
GtSmaCCRewriteElement >> updateMatch [
self
Expand Down
16 changes: 10 additions & 6 deletions src/GT4SmaCC-Rewrite-Engine-UI/GtSmaCCRewriteFileElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ GtSmaCCRewriteFileElement >> build [
self updateParserClass
]

{ #category : #private }
GtSmaCCRewriteFileElement >> connectModel [
super connectModel.
rewrite ifNil: [ ^ self ].
rewrite announcer weak
when: #parserClass
send: #updateParserClass
to: self
]

{ #category : #building }
GtSmaCCRewriteFileElement >> parserElement [
| element |
Expand All @@ -33,12 +43,6 @@ GtSmaCCRewriteFileElement >> parserElement [
^ element
]

{ #category : #updating }
GtSmaCCRewriteFileElement >> update: aSymbol [
aSymbol = #parserClass ifTrue: [ self updateParserClass ].
^ super update: aSymbol
]

{ #category : #updating }
GtSmaCCRewriteFileElement >> updateParserClass [
self childNamed: #parserClass ifFound: [ :list | list selectedItem: rewrite parserClass ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ GtSmaCCTransformationToolkit >> buildUI [

{ #category : #accessing }
GtSmaCCTransformationToolkit >> connectToModel [
| announcer |
results := Dictionary new.
model addDependent: self.
announcer := model announcer weak.
announcer
model announcer weak
when: #files
send: #updateFiles
to: self;
Expand Down Expand Up @@ -310,15 +308,15 @@ GtSmaCCTransformationToolkit >> initialize [
self model: SmaCCTransformationToolkitModel new.
self
addShortcut: (BlShortcutWithAction new
combination: (BlKeyCombination builder
combination: ((BlKeyCombination builder
key: BlKeyboardKey F5;
build);
build) or: BlKeyCombination primaryG);
action: [ :anEvent :aShortcut | self preview ]).
self
addShortcut: (BlShortcutWithAction new
combination: (BlKeyCombination builder shift
combination: ((BlKeyCombination builder shift
key: BlKeyboardKey F5;
build);
build) or: BlKeyCombination primaryD);
action: [ :anEvent :aShortcut | self run ])
]

Expand Down

0 comments on commit 20cf573

Please sign in to comment.