/
SpCodeSelectionCommand.class.st
64 lines (52 loc) · 1.69 KB
/
SpCodeSelectionCommand.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"
I'm a code presenter command who's actions depends on the selected text.
In case no text is selected, the commands will take the text from cursor position to begining of line as an ""ad hoc"" selection.
""context"" needs to conform a certain api to be used here:
- selectedText
- selectedTextOrLine
- doItReceiver
- doItContext
"
Class {
#name : #SpCodeSelectionCommand,
#superclass : #SpToolCommand,
#category : #'Spec2-Code-Commands'
}
{ #category : #private }
SpCodeSelectionCommand >> evaluate: aString andDo: aBlock [
"Treat the current selection as an expression; evaluate it and invoke
aBlock with the result."
| stream result model receiver evaluationContext |
stream := aString readStream.
self flag: 'I replaced requestor here: model -> evaluationContext. We need to see if it is stable. -Steven'.
model := self context interactionModel.
receiver := model doItReceiver.
evaluationContext := model doItContext.
result := receiver class compiler
source: stream;
context: evaluationContext;
receiver: receiver;
requestor: evaluationContext;
failBlock: [ ^ nil ];
evaluate.
^ aBlock value: result
]
{ #category : #private }
SpCodeSelectionCommand >> evaluateSelectionAndDo: aBlock [
"Treat the current selection as an expression; evaluate it and invoke aBlock with the result.
If no selection is present select the current line."
| selection |
selection := self selectedTextOrLine.
selection ifEmpty: [ ^ '' ].
^ self
evaluate: selection
andDo: aBlock
]
{ #category : #accessing }
SpCodeSelectionCommand >> selectedText [
^ self context selectedText
]
{ #category : #accessing }
SpCodeSelectionCommand >> selectedTextOrLine [
^ self context selectedTextOrLine
]