diff --git a/src/Carp/AbstractFileReference.extension.st b/src/Carp/AbstractFileReference.extension.st new file mode 100644 index 0000000..ec67f69 --- /dev/null +++ b/src/Carp/AbstractFileReference.extension.st @@ -0,0 +1,31 @@ +Extension { #name : #AbstractFileReference } + +{ #category : #'*Carp' } +AbstractFileReference >> gtCarpFor: aView [ + + + self isFile ifFalse: [ ^ aView empty ]. + self path extension = 'carp' ifFalse: [ ^ aView empty ]. + [ self readStreamDo: [ :s | s next: 1000 ] ] + on: ZnInvalidUTF8 + do: [ ^ aView empty ]. + ^ aView explicit + title: 'Carp' translated; + priority: 50; + stencil: [ + (GtCarpCoderModel code: self contents) asElement matchParent ]; + actionStencil: [ :tab | + BrButton new + aptitude: BrGlamorousButtonWithIconAptitude; + label: 'Save'; + icon: BrGlamorousVectorIcons accept; + action: [ + | newContents | + newContents := tab viewContentElement children first children + second children first children first editor text asString. + (self fullName , '.backup') asFileReference ensureDelete. + self copyTo: (self fullName , '.backup') asFileReference. + self + ensureDelete; + writeStreamDo: [ :s | s nextPutAll: newContents ] ] ] +] diff --git a/src/Carp/CarpExpression.class.st b/src/Carp/CarpExpression.class.st index 0ff67ac..38f62d8 100644 --- a/src/Carp/CarpExpression.class.st +++ b/src/Carp/CarpExpression.class.st @@ -9,7 +9,7 @@ Class { { #category : #accessing } CarpExpression >> asElement [ - ^ (GtCarpCoderModel new sourceCode: (GtCoderExplicitStringSource new source: self toCarp)) asElement + ^ (GtCarpCoderModel code: self toCarp) asElement ] { #category : #accessing } diff --git a/src/Carp/GtCarpCoderModel.class.st b/src/Carp/GtCarpCoderModel.class.st index 52d77c1..2c8ce6d 100644 --- a/src/Carp/GtCarpCoderModel.class.st +++ b/src/Carp/GtCarpCoderModel.class.st @@ -8,6 +8,13 @@ Class { #category : #'Carp-Coder' } +{ #category : #'instance creation' } +GtCarpCoderModel class >> code: aString [ + + ^ self new sourceCode: + (GtCoderExplicitStringSource new source: aString) +] + { #category : #converting } GtCarpCoderModel >> asCoderViewModel [