3
- script: a script class instance
4
- parents: a collection of costume (BEWARE, and not math item)
7
#name : #DrGValueScriptItem,
8
#superclass : #DrGValueItem,
13
#category : #'DrGeoII-Core-Item'
16
{ #category : #comparing }
17
DrGValueScriptItem >> = aScriptItem [
18
^super = aScriptItem and: [self script class == aScriptItem script class]
21
{ #category : #private }
22
DrGValueScriptItem >> adaptiveDescriptiveName [
25
ifFalse: [string := 'This script "{1}"' translated]
28
ifTrue: [string := 'This script "{1}" with argument: %2' translated]
29
ifFalse: [string := 'This script "{1}" with arguments: %2' translated].
30
string := string copyReplaceAll: '%2' with: self argumentsName].
31
^string format: {script class scriptName}.
34
{ #category : #private }
35
DrGValueScriptItem >> argumentsName [
36
"collect parents name in a string as A, B, C"
38
parents size = 0 ifTrue: [ ^ '' ].
39
stream := ReadWriteStream on: String new.
40
parents allButLast do:
43
nextPutAll: (item safeName ifEmpty: [item printString]);
45
stream nextPutAll: (parents last safeName ifEmpty: [parents last printString]).
49
{ #category : #accessing }
50
DrGValueScriptItem >> compute [
51
"Do the script computation and return its result "
55
{ #category : #accessing }
56
DrGValueScriptItem >> costumeClass [
60
{ #category : #accessing }
61
DrGValueScriptItem >> costumes [
65
{ #category : #initialization }
66
DrGValueScriptItem >> initialize: theParentsCostume [
67
super initialize: theParentsCostume.
68
self script: (theParentsCostume at: theParentsCostume size - 1)
71
{ #category : #testing }
72
DrGValueScriptItem >> isPropertyEditable [
78
{ #category : #testing }
79
DrGValueScriptItem >> isScriptItem [
83
{ #category : #'xml writing' }
84
DrGValueScriptItem >> nodeType [
88
{ #category : #accessing }
89
DrGValueScriptItem >> parents: aCollection [
90
"last is the initial screen position of the value, and previous last is the script class"
91
aCollection isEmptyOrNil ifTrue:
92
[parents := aCollection.
93
parentsCostume := aCollection.
95
aCollection last isPoint
96
ifTrue: [ parents := aCollection allButLast: 2 ]
98
[ "play nicely with macro"
99
parents := aCollection ].
103
{ #category : #accessing }
104
DrGValueScriptItem >> parents: aCollection in: app [
105
"last is the initial screen position of the value, and previous last is the script class"
106
self parents: aCollection.
107
parents ifNotNil: [parentsCostume := app costumesOf: parents].
108
"reinject the argument in the script in cas it is already instanciated"
109
script ifNotNil: [script arguments: parentsCostume]
112
{ #category : #printing }
113
DrGValueScriptItem >> printNameOn: aStream [
114
aStream nextPutAll: 'Script ' translated.
118
{ #category : #printing }
119
DrGValueScriptItem >> printValueOn: aStream [
121
ifTrue: [^ self printDecimal: value on: aStream].
123
ifTrue: [^ self printCoordinates: value on: aStream].
127
{ #category : #comparing }
128
DrGValueScriptItem >> rehash [
129
^hash := super rehash bitXor: script class hash
132
{ #category : #accessing }
133
DrGValueScriptItem >> script [
137
{ #category : #accessing }
138
DrGValueScriptItem >> script: aScriptClass [
139
script := aScriptClass new arguments: self costumes.
143
{ #category : #updating }
144
DrGValueScriptItem >> update [
145
self doParentsExist ifTrue: [ value := script compute]
148
{ #category : #'xml writing' }
149
DrGValueScriptItem >> writeAsXmlTo: aNode [
151
node := super writeAsXmlTo: aNode.
152
node attributeAt: #class put: script class printString.
154
(XMLElement named: #code) addContent: (
155
XMLStringNode string: (String streamContents: [:out |script class fileOutOn: out]))).
156
^ self writeAsXmlPositionTo: node.