|
'From Pharo6.0 of 13 May 2016 [Latest update: #60530] on 21 February 2018 at 9:43:37.179327 am'! |
|
ClyBrowserTool subclass: #MyClyGlmXmlEditorTool |
|
instanceVariableNames: 'editingMethod' |
|
classVariableNames: '' |
|
poolDictionaries: '' |
|
category: 'Cly-Editors'! |
|
!MyClyGlmXmlEditorTool commentStamp: 'PeterUhnak 2/21/2018 09:43' prior: 0! |
|
I am a Calypso tool for editing XML method containing <resource: 'xml'> pragma. |
|
|
|
Select #exampleXml method in me.! |
|
|
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'building' stamp: 'PeterUhnak 2/21/2018 09:34'! |
|
acceptChanges: aString |
|
| node newNode newContent | |
|
editingMethod ifNil: [ ^ false ]. |
|
newContent := aString parseXML removeAllFormattingNodes prettyPrinted. |
|
node := self editingNode. |
|
newNode := RBParser parseExpression: newContent printString. |
|
node replaceWith: newNode. |
|
editingMethod methodClass compile: node methodNode formattedCode. |
|
^ true! ! |
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'building' stamp: 'PeterUhnak 2/21/2018 09:34'! |
|
build |
|
| composite presentation morph currentTextStylerDecorator customPresentation | |
|
composite := GLMCompositePresentation new. |
|
customPresentation := GLMRubricHighlightedTextPresentation new |
|
editingMode: [ currentTextStylerDecorator := GLMXMLDocumentHighlighterTextStylerDecorator new. |
|
GLMHighlighterTextRubEditingMode withStylerDecorator: currentTextStylerDecorator ]; |
|
act: [ self acceptChanges: currentTextStylerDecorator text asString. |
|
customPresentation clearUserEdits ] |
|
icon: GLMUIThemeExtraIcons glamorousAccept |
|
on: $s |
|
entitled: 'Accept'. |
|
presentation := composite custom: customPresentation. |
|
presentation display: [ self editingText ]. |
|
morph := GLMMorphicRenderer new render: presentation. |
|
morph hResizing: #spaceFill. |
|
morph vResizing: #spaceFill. |
|
self addMorph: morph! ! |
|
|
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'initialization' stamp: 'PeterUhnak 2/21/2018 09:33'! |
|
setUpModelFromContext |
|
editingMethod := context lastSelectedMethod! ! |
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'initialization' stamp: 'PeterUhnak 2/20/2018 22:12'! |
|
defaultIconName |
|
^ #smallLeftFlush! ! |
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'initialization' stamp: 'PeterUhnak 2/21/2018 09:33'! |
|
editedMethod |
|
^ editingMethod! ! |
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'initialization' stamp: 'PeterUhnak 2/20/2018 22:26'! |
|
defaultTitle |
|
^ 'XML'! ! |
|
|
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'examples' stamp: 'PeterUhnak 2/21/2018 09:25'! |
|
exampleXml |
|
<resource: 'xml'> |
|
^ '<?xml version="1.0" encoding="UTF-8"?> |
|
<xmi:XMI xmlns:uml="http://www.omg.org/spec/UML/20110701" xmlns:xmi="http://www.omg.org/spec/XMI/20110701"> |
|
<uml:Package xmi:type="uml:Package" xmi:id="123" name="Package"> |
|
<packagedElement xmi:type="uml:Class" xmi:id="456" name="Class" /> |
|
</uml:Package> |
|
</xmi:XMI>'! ! |
|
|
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'accessing' stamp: 'PeterUhnak 2/21/2018 09:33'! |
|
editingNode |
|
^ editingMethod parseTree allChildren reversed detect: #isLiteralNode! ! |
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'accessing' stamp: 'PeterUhnak 2/20/2018 22:14'! |
|
editingText |
|
^ self editingNode sourceText trimBoth: [ :c | c = $' ]! ! |
|
|
|
|
|
!MyClyGlmXmlEditorTool methodsFor: 'testing' stamp: 'PeterUhnak 2/21/2018 09:33'! |
|
isSimilarTo: anotherBrowserTool |
|
(super isSimilarTo: anotherBrowserTool) |
|
ifFalse: [ ^ false ]. |
|
^ editingMethod methodClass == anotherBrowserTool editedMethod methodClass |
|
and: [ editingMethod selector == anotherBrowserTool editedMethod selector ]! ! |
|
|
|
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! |
|
|
|
MyClyGlmXmlEditorTool class |
|
slots: { }! |
|
|
|
!MyClyGlmXmlEditorTool class methodsFor: 'activation' stamp: 'PeterUhnak 2/21/2018 09:25'! |
|
shouldBeActivatedInContext: aBrowserContext |
|
^ aBrowserContext isMethodSelected |
|
and: [ aBrowserContext lastSelectedMethod pragmas |
|
anySatisfy: [ :each | each keyword = 'resource:' and: [ each arguments = #(xml) ] ] ]! ! |
|
|
|
!MyClyGlmXmlEditorTool class methodsFor: 'activation' stamp: 'PeterUhnak 2/20/2018 22:11'! |
|
methodTabActivation |
|
<classAnnotation> |
|
|
|
^ClyTabActivationStrategy for: ClyMethod asCalypsoItemContext! ! |
|
|
|
!MyClyGlmXmlEditorTool class methodsFor: 'activation' stamp: 'PeterUhnak 2/20/2018 22:11'! |
|
tabOrder |
|
^ 100! ! |