Skip to content

Commit 9b7a093

Browse files
committed
[feenkcom/gtoolkit#4133] extract slots and methods list to separate classes
1 parent 8dfcc69 commit 9b7a093

5 files changed

+627
-469
lines changed
Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
Class {
2+
#name : #GtCoderMethodsGroupedListElement,
3+
#superclass : #BrGroupedList,
4+
#traits : 'TGtCoderNavigationWithContextMenu',
5+
#classTraits : 'TGtCoderNavigationWithContextMenu classTrait',
6+
#instVars : [
7+
'navigationModel',
8+
'methodGroups'
9+
],
10+
#category : #'GToolkit-Coder-UI-Navigation - Helpers'
11+
}
12+
13+
{ #category : #'private - actions' }
14+
GtCoderMethodsGroupedListElement >> browseHierarchyImplementorsOf: aSymbol [
15+
self phlow
16+
spawnObject: (GtSearchMethodsInClassFilter forClass: self selectedClass) withSuperclasses
17+
withSubclasses & aSymbol gtImplementors
18+
]
19+
20+
{ #category : #'private - actions' }
21+
GtCoderMethodsGroupedListElement >> browseHierarchyReferencesOf: aSymbol [
22+
self phlow
23+
spawnObject: (GtSearchMethodsInClassFilter forClass: self selectedClass) withSuperclasses
24+
withSubclasses & aSymbol gtSenders
25+
]
26+
27+
{ #category : #'private - actions' }
28+
GtCoderMethodsGroupedListElement >> browseImplementorsOf: aSymbol [
29+
self phlow spawnObject: (GtSearchImplementorsFilter selector: aSymbol)
30+
]
31+
32+
{ #category : #'private - actions' }
33+
GtCoderMethodsGroupedListElement >> browseReferencesOf: aSymbol [
34+
self phlow spawnObject: (GtSearchReferencesFilter literal: aSymbol)
35+
]
36+
37+
{ #category : #'private - insance creation' }
38+
GtCoderMethodsGroupedListElement >> buildMethodItem [
39+
<return: #BlElement>
40+
| aLabel |
41+
aLabel := BrLabel new.
42+
aLabel
43+
hMatchParent;
44+
vFitContent;
45+
beSmallSize;
46+
aptitude: BrGlamorousLabelAptitude + BrGlamorousListItemAptitude
47+
+ (BrGlamorousWithContextMenuAptitude
48+
content: [ GtCoderNavigationContextMenuContent new
49+
items: (self methodListContextMenuItemsFor: (aLabel userData at: #method)) ]).
50+
51+
aLabel addEventHandler: self createMethodDragHandler.
52+
53+
^ aLabel
54+
]
55+
56+
{ #category : #'private - insance creation' }
57+
GtCoderMethodsGroupedListElement >> createDraggedMethodItem: aDragItem [
58+
59+
^ BrLabel new
60+
aptitude: (BrGlamorousLabelAptitude new padding: (BlInsets all: 5)) + BrShadowAptitude;
61+
beSmallSize;
62+
opacity: 0.85;
63+
margin: (BlInsets all: 5);
64+
background: Color white;
65+
beFocusable;
66+
requestFocus;
67+
geometry: (BlRoundedRectangleGeometry cornerRadius: 5);
68+
fitContent;
69+
text: aDragItem domainObject printString
70+
]
71+
72+
{ #category : #'private - insance creation' }
73+
GtCoderMethodsGroupedListElement >> createMethodDragHandler [
74+
^ BlDragHandler new
75+
enableCopy;
76+
liftItem: [ :aLabelElement |
77+
BlDragItem new
78+
sourceElement: aLabelElement;
79+
domainObject: (aLabelElement userData at: #method);
80+
stencil: [ :aDragItem | self createDraggedMethodItem: aDragItem ] ]
81+
]
82+
83+
{ #category : #'private - insance creation' }
84+
GtCoderMethodsGroupedListElement >> createMethodGroups [
85+
| classGroup instanceGroup |
86+
instanceGroup := BrGroup new
87+
domainObject: 'instance side';
88+
stream: #() asAsyncStream;
89+
itemStencil: [ self buildMethodItem ];
90+
itemDataBinder: [ :element :eachCompiledMethod |
91+
| aSelector |
92+
element userData at: #method put: eachCompiledMethod.
93+
94+
aSelector := eachCompiledMethod selector asRopedText.
95+
eachCompiledMethod isDeprecated
96+
ifTrue: [ aSelector lineThrough ].
97+
98+
element text: aSelector ];
99+
shouldShowWithoutItems: false.
100+
classGroup := instanceGroup copy domainObject: 'class side'.
101+
^ {instanceGroup.
102+
classGroup}
103+
]
104+
105+
{ #category : #initialization }
106+
GtCoderMethodsGroupedListElement >> initialize [
107+
super initialize.
108+
109+
self
110+
padding: (BlInsets left: 5 right: 10);
111+
matchParent;
112+
headerElementStencil: [ BrLabel new
113+
beSmallSize;
114+
aptitude: (BrGlamorousLabelAptitude new foreground: Color gray) ];
115+
headerDataBinder: [ :label :each | label text: each domainObject asRopedText ].
116+
117+
methodGroups := self createMethodGroups.
118+
self groups: methodGroups.
119+
120+
self
121+
when: BrSelectionChanged
122+
do: [ :anEvent | self onMethodsListSelectionChanged ]
123+
]
124+
125+
{ #category : #accessing }
126+
GtCoderMethodsGroupedListElement >> methodList [
127+
^ methodGroups flatCollect: [ :grp | grp itemsProvider currentItems ]
128+
]
129+
130+
{ #category : #'private - context menu' }
131+
GtCoderMethodsGroupedListElement >> methodListContextMenuItemsFor: item [
132+
^ {(self createLabel: 'Browse implementors' description: item selector)
133+
-> [ :elem | self browseImplementorsOf: item selector ].
134+
(self createLabel: 'Browse hierarachy implementors' description: item selector)
135+
-> [ :elem | self browseHierarchyImplementorsOf: item selector ].
136+
(self createLabel: 'Browse references' description: item selector)
137+
-> [ :elem | self browseReferencesOf: item selector ].
138+
(self createLabel: 'Browse hierarchy references' description: item selector)
139+
-> [ :elem | self browseHierarchyReferencesOf: item selector ].
140+
(self createLabel: 'Push up method' description: item selector)
141+
-> [ :elem | self pushUpMethod: item selector inElement: elem ].
142+
(self createLabel: 'Push down method' description: item selector)
143+
-> [ :elem | self pushDownMethod: item selector inElement: elem ].
144+
(self createLabel: 'Rename message' description: item selector)
145+
-> [ :elem | self renameMethod: item selector inElement: elem ].
146+
(self createLabel: 'Remove method' description: item selector)
147+
-> [ :elem | self removeMethod: item selector inElement: elem ]}
148+
]
149+
150+
{ #category : #accessing }
151+
GtCoderMethodsGroupedListElement >> navigationModel [
152+
^ navigationModel
153+
]
154+
155+
{ #category : #accessing }
156+
GtCoderMethodsGroupedListElement >> navigationModel: anObject [
157+
navigationModel == anObject
158+
ifTrue: [ ^ self ].
159+
160+
self unsubscribeFromNavigationModel.
161+
navigationModel := anObject.
162+
self subscribeToNavigationModel.
163+
164+
self updateMethodList
165+
]
166+
167+
{ #category : #'event handling - selection' }
168+
GtCoderMethodsGroupedListElement >> onMethodSelected: anAnnouncement [
169+
170+
]
171+
172+
{ #category : #'event handling - selection' }
173+
GtCoderMethodsGroupedListElement >> onMethodsListSelectionChanged [
174+
| theIndices anIndex aSelectedItem |
175+
176+
theIndices := self selectedIndices ifEmpty: [ ^ self ].
177+
anIndex := theIndices first.
178+
(anIndex between: 1 and: self viewModel entityCount)
179+
ifFalse: [ ^ self ].
180+
aSelectedItem := (self viewModel entityAt: anIndex) value object.
181+
self navigationModel selectMethod: aSelectedItem
182+
]
183+
184+
{ #category : #'event handling' }
185+
GtCoderMethodsGroupedListElement >> onMethodsToShowChanged: anAnnouncement [
186+
self updateMethodList
187+
]
188+
189+
{ #category : #'private - actions' }
190+
GtCoderMethodsGroupedListElement >> pushDownMethod: aSelector inElement: elem [
191+
| refactoring |
192+
refactoring := RBPushDownMethodRefactoring
193+
pushDown: {aSelector}
194+
from: self selectedClass.
195+
^ self
196+
addPreviewButtonFor: refactoring
197+
to: elem
198+
cancelSelector: #updateProtocolList
199+
]
200+
201+
{ #category : #'private - actions' }
202+
GtCoderMethodsGroupedListElement >> pushUpMethod: aSelector inElement: elem [
203+
| refactoring |
204+
refactoring := RBPullUpMethodRefactoring
205+
pullUp: {aSelector}
206+
from: self selectedClass.
207+
^ self
208+
addPreviewButtonFor: refactoring
209+
to: elem
210+
cancelSelector: #updateProtocolList
211+
]
212+
213+
{ #category : #'private - actions' }
214+
GtCoderMethodsGroupedListElement >> removeMethod: aSelector inElement: elem [
215+
| change button |
216+
change := RBRemoveMethodChange remove: aSelector from: self selectedClass.
217+
button := GtPreviewChangeButton new
218+
icon: BrGlamorousVectorIcons remove;
219+
label: 'Remove';
220+
changeAction: [ change gtExecuteWithUndo ];
221+
changeStencil: [ GtPharoRemoveMethodPreviewStencil new
222+
selectorToRemove: aSelector;
223+
isEmptyMethod: false;
224+
anElement: self;
225+
create ].
226+
button
227+
when: GtRefactoringsAppliedEvent
228+
do: [ :anEvent | elem removeChild: anEvent currentTarget ].
229+
^ elem addChild: button as: #preview
230+
]
231+
232+
{ #category : #'private - actions' }
233+
GtCoderMethodsGroupedListElement >> renameMethod: aSelector inElement: elem [
234+
| refactoring edit |
235+
edit := BrEditableLabel new.
236+
edit
237+
aptitude: (BrGlamorousEditableLabelAptitude new
238+
fontSize: 11.9; "Force the font to match the label font"
239+
background: Color transparent);
240+
text: aSelector;
241+
when: BrEditorAcceptWish
242+
do: [ :aWish |
243+
refactoring := GtRBRenameMethodRefactoring
244+
renameMethod: aSelector
245+
in: self selectedClass
246+
to: aWish text asString
247+
permutation: (1 to: aSelector numArgs).
248+
edit switchToLabel.
249+
self
250+
addPreviewButtonFor: refactoring
251+
to: elem
252+
cancelSelector: #updateProtocolList ];
253+
switchToEditor.
254+
edit requestFocus.
255+
elem removeChildren.
256+
elem addChild: edit
257+
]
258+
259+
{ #category : #accessing }
260+
GtCoderMethodsGroupedListElement >> selectedClass [
261+
^ navigationModel selectedClass
262+
]
263+
264+
{ #category : #'private - subscriptions' }
265+
GtCoderMethodsGroupedListElement >> subscribeToNavigationModel [
266+
| subscriptions |
267+
268+
subscriptions := {
269+
GtCoderNavigationMethodsToShowChanged -> #onMethodsToShowChanged:.
270+
GtCoderNavigationMethodSelected -> #onMethodSelected:.
271+
}.
272+
273+
subscriptions
274+
do: [ :sub |
275+
navigationModel weak
276+
when: sub key
277+
send: sub value
278+
to: self ]
279+
]
280+
281+
{ #category : #'private - subscriptions' }
282+
GtCoderMethodsGroupedListElement >> unsubscribeFromNavigationModel [
283+
navigationModel ifNotNil: [ :aModel | aModel unsubscribe: self ]
284+
]
285+
286+
{ #category : #'updating lists' }
287+
GtCoderMethodsGroupedListElement >> updateMethodList [
288+
self navigationModel ifNil: [ ^ self ].
289+
self updateMethodListWith: self navigationModel methodsToShow
290+
]
291+
292+
{ #category : #'updating lists' }
293+
GtCoderMethodsGroupedListElement >> updateMethodListWith: aCollectionOfCompiledMethods [
294+
| instMethStream classMethStream instanceMethods classMethods |
295+
self deselectAll.
296+
297+
instanceMethods := aCollectionOfCompiledMethods
298+
select: [ :each | each methodClass isInstanceSide ].
299+
300+
classMethods := aCollectionOfCompiledMethods
301+
select: [ :each | each methodClass isClassSide ].
302+
303+
instMethStream := instanceMethods asSortedCollection: GtMethodsSortFunction new.
304+
305+
classMethStream := classMethods asSortedCollection: GtMethodsSortFunction new.
306+
307+
methodGroups
308+
with: {instMethStream.
309+
classMethStream}
310+
do: [ :grp :str | grp items: str ].
311+
312+
self groups: methodGroups
313+
]

0 commit comments

Comments
 (0)