-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPyramidShowCodePlugin.class.st
More file actions
147 lines (124 loc) · 4.58 KB
/
PyramidShowCodePlugin.class.st
File metadata and controls
147 lines (124 loc) · 4.58 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
Class {
#name : #PyramidShowCodePlugin,
#superclass : #Object,
#traits : 'TPyramidPlugin',
#classTraits : 'TPyramidPlugin classTrait',
#instVars : [
'codePresenterForAll',
'codePresenterForSelection',
'projectModel'
],
#category : #'Pyramid-Bloc-plugin-showcode'
}
{ #category : #adding }
PyramidShowCodePlugin >> addPanelsOn: aPyramidSimpleWindow [
aPyramidSimpleWindow at: #tabLeft addItem: [ :builder |
builder
makeTab: self codePresenterForAll
label: 'Code for all'
icon: (Smalltalk ui icons iconNamed: #page)
order: 5 ].
aPyramidSimpleWindow at: #tabRight addItem: [ :builder |
builder
makeTab: self codePresenterForSelection
label: 'Code for selection'
icon: (Smalltalk ui icons iconNamed: #page)
order: 999 ]
]
{ #category : #accessing }
PyramidShowCodePlugin >> codePresenterForAll [
^ codePresenterForAll
]
{ #category : #accessing }
PyramidShowCodePlugin >> codePresenterForSelection [
^ codePresenterForSelection
]
{ #category : #connecting }
PyramidShowCodePlugin >> connectOn: aPyramidEditor [
projectModel := aPyramidEditor projectModel.
aPyramidEditor projectModel announcer
when: PyramidElementsChangedEvent
do: [ :evt | self elementsChanged: evt ]
for: self.
aPyramidEditor projectModel announcer
when: PyramidFirstLevelElementsChangedEvent
do: [ :evt | self firstLevelElementsChanged: evt ]
for: self.
aPyramidEditor projectModel announcer
when: PyramidSelectionChangedEvent
do: [ :evt | self selectionChanged: evt ]
for: self
]
{ #category : #'as yet unclassified' }
PyramidShowCodePlugin >> elementsChanged: aPyramidElementsChangedEvent [
self firstLevelElementsChanged: aPyramidElementsChangedEvent.
self selectionChanged: aPyramidElementsChangedEvent
]
{ #category : #'as yet unclassified' }
PyramidShowCodePlugin >> firstLevelElementsChanged: aPyramidFirstLevelElementsChangedEvent [
self codePresenterForAll text: (Stash new serialize:
aPyramidFirstLevelElementsChangedEvent firstLevelElements)
]
{ #category : #initialization }
PyramidShowCodePlugin >> initialize [
super initialize.
codePresenterForAll := SpCodePresenter new
beForScripting;
whenSubmitDo: [ :text |
self validateCodeForAll: text ];
yourself.
codePresenterForSelection := SpCodePresenter new
beForScripting;
whenSubmitDo: [ :text |
self validateCodeForSelection: text ];
yourself
]
{ #category : #accessing }
PyramidShowCodePlugin >> projectModel [
^ projectModel
]
{ #category : #'event handling' }
PyramidShowCodePlugin >> selectionChanged: aPyramidSelectionChangedEvent [
self codePresenterForSelection text: ''.
aPyramidSelectionChangedEvent selection ifEmpty: [
self codePresenterForSelection text: '"Select one element."'.
^ self ].
aPyramidSelectionChangedEvent selection size > 2 ifTrue: [
self codePresenterForSelection text: '"Select only one element."'.
^ self ].
self codePresenterForSelection text: (Stash new serialize:
aPyramidSelectionChangedEvent selection first)
]
{ #category : #'as yet unclassified' }
PyramidShowCodePlugin >> validateCodeForAll: aString [
| collection |
collection := Stash new materialize: aString.
collection isCollection ifFalse: [
^ self inform: 'Could not serialize: The code is not a collection.' ].
(collection allSatisfy: [ :each | each isKindOf: BlElement ])
ifFalse: [
^ self inform:
'Could not serialize: Not BlElement found in the code.' ].
self projectModel firstLevelElements replaceAll: collection.
self projectModel updateSelection
]
{ #category : #'as yet unclassified' }
PyramidShowCodePlugin >> validateCodeForSelection: aString [
| newElement currentSelection |
newElement := Stash new materialize: aString.
(newElement isKindOf: BlElement) ifFalse: [
^ self inform: 'Could not serialize: The code is not a BlElement.' ].
self projectModel selection size = 1 ifFalse: [
^ self inform:
'Could not serialize: The selection should only contains one element.' ].
currentSelection := self projectModel selection first.
(self projectModel firstLevelElements includes: currentSelection)
ifTrue: [
self projectModel firstLevelElements replaceAll:
(self projectModel firstLevelElements asArray
copyReplaceAll: { currentSelection }
with: { newElement }) ].
currentSelection parent ifNotNil: [ :p |
p replaceChild: currentSelection with: newElement ].
self projectModel selection replaceAll: { newElement }
]