-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGtCoderElement.class.st
More file actions
326 lines (281 loc) · 10.1 KB
/
GtCoderElement.class.st
File metadata and controls
326 lines (281 loc) · 10.1 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
"
I am the entrance point into the coder as a tool. To instantiate me, use one of the following class-side methods:
- {{gtMethod:GtCoderElement class>>#forObject:|label=#selector}},
- {{gtMethod:GtCoderElement class>>#forClass:|label=#selector}},
- {{gtMethod:GtCoderElement class>>#forMethod:|label=#selector}},
- {{gtMethod:GtCoderElement class>>#forPackage:|label=#selector}},
- {{gtMethod:GtCoderElement class>>#new|label=#selector}}.
1. # Example
{{gtExample:GtCoderElementExamples>>#coderElementWithObject|previewExpanded|codeExpanded=false|previewHeight=700}}
"
Class {
#name : #GtCoderElement,
#superclass : #GtAbstractCoderElement,
#traits : 'TGtPagerPageInstantiator + TGtPhlowToolDetailAdjustable',
#classTraits : 'TGtPagerPageInstantiator classTrait + TGtPhlowToolDetailAdjustable classTrait',
#instVars : [
'sidebarElement',
'contentElement',
'titleNotifier'
],
#category : #'GToolkit-Coder-UI-! Core'
}
{ #category : #'instance creation' }
GtCoderElement class >> defaultSidebarWidth [
^ 1.0
]
{ #category : #'private - accessing' }
GtCoderElement >> contentElement [
<return: #GtCoderContentElement>
^ contentElement
]
{ #category : #'private - accessing' }
GtCoderElement >> contentElement: anElement [
<return: #GtCoderContentElement>
contentElement := anElement
]
{ #category : #'instance creation' }
GtCoderElement >> createPlaygroundElement [
^ GtCoderPlaygroundElement new
]
{ #category : #'instance creation' }
GtCoderElement >> createSidebarElement [
^ GtPhlowHorizontalSidebarElement new
beLeft;
resizerStrategy: (BrResizerElementLength weight: self class defaultSidebarWidth);
contentStencil: (GtCoderNavigationTabsStencil new navigationModel: self navigationModel);
addAptitude: (GtPhlowToolDetailAptitude new
left: [ :aStyle |
aStyle
do: [ :aWidget |
aWidget userData
at: #leftSidebarResizerStrategy
ifPresent: [ :aResizerStrategy | aWidget resizerStrategy: aResizerStrategy ]
ifAbsentPut: [ aWidget
resizerStrategy: (BrResizerElementLength weight: self class defaultSidebarWidth) ].
aWidget beLeft.
aWidget userData
at: #leftSidebarIsCollapsed
ifPresent: [ :aBoolean | aBoolean ifTrue: [ aWidget collapse ] ]
ifAbsent: [ ] ]
after: [ :aWidget |
aWidget userData at: #leftSidebarResizerStrategy put: aWidget resizerStrategy.
aWidget userData at: #leftSidebarIsCollapsed put: aWidget isCollapsed ] ];
top: [ :aStyle |
aStyle
do: [ :aWidget |
aWidget userData
at: #topSidebarResizerStrategy
ifPresent: [ :aResizerStrategy | aWidget resizerStrategy: aResizerStrategy ]
ifAbsentPut: [ aWidget
resizerStrategy: (BrResizerElementLength weight: 0.5) ].
aWidget beTop.
aWidget userData
at: #topSidebarIsCollapsed
ifPresent: [ :aBoolean | aBoolean ifTrue: [ aWidget collapse ] ]
ifAbsent: [ ] ]
after: [ :aWidget |
aWidget userData at: #topSidebarResizerStrategy put: aWidget resizerStrategy.
aWidget userData at: #topSidebarIsCollapsed put: aWidget isCollapsed ] ])
]
{ #category : #'instance creation' }
GtCoderElement >> createTitleNotifier [
^ GtPhlowTitleIconAndLabelNotifier new
shortLabel: [ self shortTitle ifEmpty: [ 'Coder' asRopedText ] ];
icon: BrGlamorousVectorIcons emphasizedBrowse
]
{ #category : #accessing }
GtCoderElement >> disablePlayPage [
contentElement disablePlayPage
]
{ #category : #'private - updating' }
GtCoderElement >> hideSidebar [
sidebarElement ifNil: [ ^ self ].
sidebarElement
hide;
removeFromParent
]
{ #category : #initialization }
GtCoderElement >> initialize [
super initialize.
contentElement := self createPlaygroundElement.
titleNotifier := self createTitleNotifier.
self
layout: BlLinearLayout horizontal;
addEventHandler: titleNotifier;
addAptitude: (GtPhlowToolDetailAptitude new
normal: [ :aStyle | aStyle do: [ :aWidget | aWidget hideSidebar ] ];
detailed: [ :aStyle | aStyle do: [ :aWidget | aWidget showSidebar ] ];
left: [ :aStyle |
aStyle do: [ :aWidget | aWidget layout: BlLinearLayout horizontal ].
aStyle
do: [ :aWidget |
aWidget sidebarElement
ifNotNil: [ :anElement | anElement states addState: GtPhlowToolDetailPositionState left ] ]
after: [ :aWidget |
aWidget sidebarElement
ifNotNil: [ :anElement | anElement states removeState: GtPhlowToolDetailPositionState left ] ] ];
top: [ :aStyle |
aStyle do: [ :aWidget | aWidget layout: BlLinearLayout vertical ].
aStyle
do: [ :aWidget |
aWidget sidebarElement
ifNotNil: [ :anElement | anElement states addState: GtPhlowToolDetailPositionState top ] ]
after: [ :aWidget |
aWidget sidebarElement
ifNotNil: [ :anElement | anElement states removeState: GtPhlowToolDetailPositionState top ] ] ]).
self addChild: contentElement as: #content.
self phlow beViewContent.
self phlow
accessTool: (GtPhlowToolClassType forClass: GtCoderElement)
viewModel: #navigationModel
object: #navigationModel.
GtCoderSettings defaultDetailState
ifNotNil: [ :aState | self states addState: aState ].
GtCoderSettings defaultDetailPositionState
ifNotNil: [ :aState | self states addState: aState ].
self
when: GtCoderSidebarVisibilityWish
do: [ :anEvent | self onGtCoderSidebarVisibilityWish: anEvent ].
self
when: GtCoderDisplayTopSidebarWish
do: [ :anEvent | self onGtCoderDisplayTopSidebarWish: anEvent ].
self
when: GtCoderHideSidebarWish
do: [ :anEvent | self onGtCoderHideSidebarWish: anEvent ].
self
when: GtNavigationMethodSelectionWish
do: [ :anEvent | self onGtNavigationMethodSelectionWish: anEvent ].
self
addAptitude: (BrLayoutResizerAptitude new
common: [ contentElement ];
common: [ sidebarElement ifNil: [ #() ] ])
]
{ #category : #'private - event handling' }
GtCoderElement >> onGtCoderDisplayTopSidebarWish: anEvent [
anEvent consumed: true.
self states addState: GtPhlowToolDetailPositionState top.
self states addState: GtPhlowToolDetailState detailed.
self requestStyle
]
{ #category : #'private - event handling' }
GtCoderElement >> onGtCoderHideSidebarWish: anEvent [
anEvent consumed: true.
self states removeState: GtPhlowToolDetailPositionState top.
self states removeState: GtPhlowToolDetailState normal.
self requestStyle
]
{ #category : #'private - event handling' }
GtCoderElement >> onGtCoderSidebarVisibilityWish: anEvent [
anEvent consumed: true.
self states
stateLike: GtPhlowToolDetailState detailed
ifFound: [ :aState |
anEvent isVisible: GtPhlowToolDetailState detailed = aState ]
ifNone: [ anEvent isVisible: false ]
]
{ #category : #initialization }
GtCoderElement >> onGtNavigationMethodSelectionWish: anEvent [
"Another method is selected in a methods coder,
let's select the same method in the navigation model."
| aCompiledMethod |
anEvent consumed: true.
anEvent source == self ifTrue: [ ^ self ].
aCompiledMethod := anEvent method.
self navigationModel ifNil: [ ^ self ].
self navigationModel
selectedMethod: aCompiledMethod
source: (anEvent source ifNil: [ self ])
]
{ #category : #'private - hooks' }
GtCoderElement >> onNavigationModelChanged [
super onNavigationModelChanged.
self contentElement navigationModel: self navigationModel.
self updateSidebarContent.
self updateTabLabel
]
{ #category : #'private - announcement handling' }
GtCoderElement >> onNavigationModelSubjectChange [
self enqueueTask: (BlTaskAction new action: [
self updateTabLabel ])
]
{ #category : #opening }
GtCoderElement >> pagerWindowTitle [
<return: #String>
^ self shortTitle
]
{ #category : #accessing }
GtCoderElement >> repository [
self navigationModel hasSelectedClass ifTrue: [
^ self navigationModel selectedClass repository ].
self navigationModel hasSelectedPackage ifTrue: [
^ self navigationModel selectedPackage repository ].
^ nil
]
{ #category : #filtering }
GtCoderElement >> selectMethodProtocolNamed: aMethodProtocolName [
"(GtCoder forClass: GtPhlowProtoView) selectMethodProtocolNamed: #decorating"
| classProtocols |
classProtocols := navigationModel selectedClass gtProtocols.
classProtocols
detect: [ :aProtocol | aProtocol name = aMethodProtocolName ]
ifFound: [ :aProtocol | self navigationModel selectProtocol: aProtocol source: self ]
ifNone: [ "ignore" ]
]
{ #category : #'private - accessing' }
GtCoderElement >> shortTitle [
^ (GtPhlowTitleLabelBuilder
longLabel: self subjectTitle)
build
]
{ #category : #'private - updating' }
GtCoderElement >> showSidebar [
sidebarElement ifNil: [ sidebarElement := self createSidebarElement ].
sidebarElement show.
(sidebarElement hasParent: self)
ifTrue: [
^ self ].
self addChildFirst: sidebarElement.
sidebarElement requestStyle
]
{ #category : #accessing }
GtCoderElement >> sidebarElement [
<return: #GtPhlowHorizontalSidebarElement or: nil>
^ sidebarElement
]
{ #category : #'private - accessing' }
GtCoderElement >> subjectTitle [
<return: #String or: nil>
self navigationModel selectedClassDo: [ :aClass | ^ aClass name ].
self navigationModel selectedTagDo: [ :aPackageTag | ^ aPackageTag packageName, '-', aPackageTag name ].
self navigationModel selectedPackageDo: [ :aPackage | ^ aPackage name ].
^ nil
]
{ #category : #'private - subscriptions' }
GtCoderElement >> subscribeToNavigationModel [
super subscribeToNavigationModel.
self navigationModel weak
when: GtCoderNavigationPackagesSelected,
GtCoderNavigationPackageSelected,
GtCoderNavigationPackageRenamed,
GtCoderNavigationPackageTagSelected,
GtCoderNavigationPackageTagRenamed,
GtCoderNavigationClassSelected,
GtCoderNavigationClassRenamed,
GtCoderNavigationClassModified
send: #onNavigationModelSubjectChange to: self
]
{ #category : #'private - accessing' }
GtCoderElement >> titleNotifier [
<return: #GtPhlowTitleNotifier>
^ titleNotifier
]
{ #category : #'private - updating' }
GtCoderElement >> updateSidebarContent [
sidebarElement ifNil: [ ^ self ].
sidebarElement contentStencil: (GtCoderNavigationTabsStencil new navigationModel: self navigationModel)
]
{ #category : #'private - updating' }
GtCoderElement >> updateTabLabel [
self titleNotifier notifyIfFocused
]