Fix #10: Add Carp highlighter for AbstractFileReference

This commit is contained in:
2022-04-18 21:38:36 +02:00
parent a416447f14
commit 63bb2c8e02
3 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
Extension { #name : #AbstractFileReference }
{ #category : #'*Carp' }
AbstractFileReference >> gtCarpFor: aView [
<gtView>
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 ] ] ]
]

View File

@@ -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 }

View File

@@ -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 [