forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageBrowser.class.st
578 lines (480 loc) · 16.2 KB
/
MessageBrowser.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
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
"
A MessageBrowser is a UI to browse a list of method, regardless of what they could be.
example:
MessageBrowser new
openWithSpec;
messages: (SystemNavigation new allSendersOf: #at:)
yourself
"
Class {
#name : #MessageBrowser,
#superclass : #AbstractMessageCentricBrowser,
#instVars : [
'textModel',
'refreshingBlock'
],
#category : #'Spec2-Tools-Senders'
}
{ #category : #'instance creation' }
MessageBrowser class >> browse: aCollection [
"Special Version that sets the correct refreshing Block for Implentors Browser"
^ self new
messages: aCollection;
open
]
{ #category : #'instance creation' }
MessageBrowser class >> browse: aCollection asImplementorsOf: aSymbol [
"Special Version that sets the correct refreshing Block for Implentors Browser"
^ self new
setRefreshingBlockForImplementorsOf: aSymbol;
messages: aCollection;
title: 'Implementors of ', aSymbol printString;
open
]
{ #category : #'instance creation' }
MessageBrowser class >> browse: aCollection asSendersOf: aSymbol [
"Special Version that sets the correct refreshing Block for Senders Browser"
^ self new
setRefreshingBlockForSendersOf: aSymbol;
autoSelect: aSymbol;
messages: aCollection;
title: 'Senders of ', aSymbol printString;
open
]
{ #category : #'instance creation' }
MessageBrowser class >> browse: aCollection title: aString [
"Special Version that sets the correct refreshing Block for Implentors Browser"
^ self new
messages: aCollection;
title: aString;
open
]
{ #category : #'instance creation' }
MessageBrowser class >> browse: aCollection title: aString autoSelect: aSelectString [
"Special Version that sets the correct refreshing Block for Implentors Browser"
^ self new
messages: aCollection;
title: aString;
autoSelect: aSelectString;
open
]
{ #category : #'instance creation' }
MessageBrowser class >> browseImplementorsOf: aSymbol [
"Special Version that sets the correct refreshing Block for Implentors Browser"
^ self browse: aSymbol implementors asImplementorsOf: aSymbol
]
{ #category : #'instance creation' }
MessageBrowser class >> browseSendersOf: aSymbol [
"Special Version that sets the correct refreshing Block for Implentors Browser"
^ self browse: aSymbol senders asSendersOf: aSymbol
]
{ #category : #specs }
MessageBrowser class >> defaultSpec [
^ SpPanedLayout newVertical
add: #messageList;
add:
(SpBoxLayout newVertical
add: #toolbarPresenter withConstraints: [ :constraints | constraints height: self buttonHeight ];
add: #textModel;
yourself);
yourself
]
{ #category : #'instance creation - old' }
MessageBrowser class >> openMessageList: messageList name: aString autoSelect: aSelector refreshingBlockSelector: aRefreshingBlockSelector [
| browser |
browser := self new
messages: messageList;
title: aString;
autoSelect: aSelector;
yourself.
aRefreshingBlockSelector ifNotNil:[(browser perform: aRefreshingBlockSelector with: aSelector)].
^browser open
]
{ #category : #'tool registration' }
MessageBrowser class >> registerToolsOn: registry [
"Add ourselves to registry. See [Smalltalk tools]"
registry register: self as: #messageList
]
{ #category : #icons }
MessageBrowser class >> taskbarIconName [
"Answer the icon for an instance of the receiver in a task bar"
^#referencesIcon
]
{ #category : #specs }
MessageBrowser class >> title [
^ 'Message Browser'
]
{ #category : #private }
MessageBrowser >> accept: text notifying: notifyer [
^ self selectedMessage ifNotNil: [ :message |
message methodClass
compile: text
classified: message protocol
notifying: notifyer ]
]
{ #category : #'text selection' }
MessageBrowser >> autoSelect: aSelector [
textModel
readSelectionBlock:
[ :text |
self selectedMessage ifNotNil:
[ :msg | (self isMethodDefinition: msg)
ifFalse: [ self intervalOf: aSelector inCommentText: text ]
ifTrue: [ self intervalOf: aSelector inCode: text of: msg ] ] ]
]
{ #category : #initialization }
MessageBrowser >> buildUpdateTitle [
"Trying to have a clean subscription, this method is called in #initialize"
self updateTitle.
textModel text: textModel text
]
{ #category : #announcements }
MessageBrowser >> classRenamed: anAnnouncement [
"this method forces the announcement to be handled in the UI process"
UIManager default defer: [
self handleClassRenamed: anAnnouncement ]
]
{ #category : #private }
MessageBrowser >> codeFont [
^ StandardFonts codeFont
]
{ #category : #initialization }
MessageBrowser >> connectPresenters [
messageList
whenSelectionChangedDo: [ :selection | self selectItem: selection selectedItem ];
whenModelChangedDo: [ self updateTitle ].
textModel whenSubmitDo: [ :text | (self accept: text notifying: nil) notNil ]
]
{ #category : #'text selection' }
MessageBrowser >> findFirstOccurrenceOf: searchedString in: textToSearchIn [
"Return the first index of aString in textToSearchIn "
| firstIndex |
firstIndex := textToSearchIn findString: searchedString startingAt: 1.
[ (firstIndex > 1) and: [ (textToSearchIn at: (firstIndex - 1)) isAlphaNumeric ] ]
whileTrue: [
firstIndex := textToSearchIn findString: searchedString startingAt: firstIndex +1 ].
^ firstIndex
]
{ #category : #announcements }
MessageBrowser >> handleClassRenamed: anAnnouncement [
| items selectedIndex |
items := self messages
collect: [ :rgMethod |
| interestedClassName interestedClass |
interestedClassName := anAnnouncement oldName.
interestedClass := anAnnouncement classRenamed.
rgMethod isMetaSide
ifTrue: [ interestedClassName := interestedClassName , ' class'.
interestedClass := interestedClass classSide ].
rgMethod parentName = interestedClassName
ifTrue: [ (interestedClass >> rgMethod selector) asFullRingDefinition ]
ifFalse: [ rgMethod ] ].
selectedIndex := messageList selectedIndex.
self messages: items.
self setSelectedIndex: selectedIndex
]
{ #category : #announcements }
MessageBrowser >> handleMethodAdded: anAnnouncement [
| item sel text boolean |
self isDisplayed ifFalse: [ ^ self ].
refreshingBlock ifNil: [ ^ self ].
item := anAnnouncement method.
(self shouldRefreshItem: item fromAnnouncement: anAnnouncement) ifFalse: [ ^ self ].
((item methodClass notNil) and:[item methodClass isObsolete not]) ifFalse: [ ^ self ].
boolean := textModel hasUnacceptedEdits.
boolean ifTrue: [ text := textModel pendingText ].
sel := self selectedMessage.
self messages: (self messages add: item asFullRingDefinition; yourself).
self selectedMessage: sel.
boolean ifTrue: [ textModel pendingText: text ]
]
{ #category : #announcements }
MessageBrowser >> handleMethodModified: anAnnouncement [
| item oldItem sel index text list edits |
self isDisplayed
ifFalse: [ ^ self ].
refreshingBlock ifNil: [ ^ self ].
item := anAnnouncement newMethod.
oldItem := anAnnouncement oldMethod.
sel := self selectedMessage.
sel ifNil: [ ^ self ].
(sel methodClass = oldItem methodClass
and: [ sel selector = oldItem selector ])
ifFalse: [ ^ self ].
(self shouldRefreshItem: item fromAnnouncement: anAnnouncement)
ifFalse: [ ^ self ].
edits := textModel hasUnacceptedEdits.
edits
ifTrue: [ text := textModel pendingText ].
index := messageList selectedIndex.
list := self messages
remove: sel ifAbsent: [ ];
add: item asFullRingDefinition;
"to ensure it's still a RGMethod"
yourself.
self messages: list.
self setSelectedIndex: index.
edits
ifFalse: [ ^ self ].
textModel pendingText: text.
textModel hasEditingConflicts: true
]
{ #category : #announcements }
MessageBrowser >> handleMethodRemoved: anAnnouncement [
| item selection removeItem |
self isDisplayed
ifFalse: [ ^ self ].
refreshingBlock ifNil: [ ^ self ].
self okToChange
ifFalse: [ ^ self ].
"Item is a compiled methed, where the list is populated with RGMethod"
item := anAnnouncement method.
(item methodClass notNil and: [ item methodClass isObsolete not ])
ifFalse: [ ^ self ].
selection := messageList selectedIndex.
removeItem := self selectedMessage.
(removeItem notNil
and: [ removeItem methodClass = item methodClass
and: [ removeItem selector = item selector ] ])
ifTrue: [ textModel hasUnacceptedEdits: false ].
self
messages:
(self messages
remove: item asFullRingDefinition ifAbsent: [ nil ];
yourself).
self setSelectedIndex: selection
]
{ #category : #initialization }
MessageBrowser >> initialize [
super initialize.
self registerToAnnouncements.
self announcer when: SpWidgetBuilt send: #buildUpdateTitle to: self
]
{ #category : #initialization }
MessageBrowser >> initializeDropList [
toolbarPresenter
addItemLabeled: 'Source' do: [ self textConverter: SourceMethodConverter new ];
addItemLabeled: 'Time stamp' do: [ self textConverter: TimeStampMethodConverter new ]
]
{ #category : #initialization }
MessageBrowser >> initializePresenters [
super initializePresenters.
textModel := self newCode.
textModel whenBuiltDo: [ :ann | ann widget font: self codeFont ].
refreshingBlock := [ :item | true ].
self
initializeDropList;
setFocus
]
{ #category : #initialization }
MessageBrowser >> initializeWindow: aWindowPresenter [
super initializeWindow: aWindowPresenter.
aWindowPresenter
title: self title;
windowIcon: self taskbarIcon;
askOkToClose: true
]
{ #category : #private }
MessageBrowser >> installIconStylerFor: anItem [
"icons styler are only supported for method definitions (not nil / not for comment definitions
(those may occure for comment or general string searches))"
(self isMethodDefinition: anItem)
ifFalse: [ ^ self ].
IconStyler styleText: self textModel withAst: anItem ast.
]
{ #category : #private }
MessageBrowser >> intervalOf: aSelector inCode: aText of: aMethod [
aMethod compiledMethod ifNil: [ ^ 0 to: 0 ].
^ (self sourceIntervalOf: aSelector in: aMethod ast) ifEmpty: [ self searchedString: aSelector asString in: aText ]
]
{ #category : #private }
MessageBrowser >> intervalOf: aSelector inCommentText: aText [
^ self searchedString: aSelector asString in: aText
]
{ #category : #api }
MessageBrowser >> messages [
^ messageList messages
]
{ #category : #api }
MessageBrowser >> messages: aCollection [
messageList messages: aCollection
]
{ #category : #announcements }
MessageBrowser >> methodAdded: anAnnouncement [
"this method forces the announcement to be handled in the UI process"
UIManager default defer: [
self handleMethodAdded: anAnnouncement ]
]
{ #category : #private }
MessageBrowser >> methodClassNameForItem: anItem [
^ anItem methodClass ifNotNil: [ :class | class name ] ifNil: [ '' ]
]
{ #category : #announcements }
MessageBrowser >> methodModified: anAnnouncement [
"this method forces the announcement to be handled in the UI process"
UIManager default defer: [
self handleMethodModified: anAnnouncement ]
]
{ #category : #announcements }
MessageBrowser >> methodRecategorized: aMethod [
]
{ #category : #announcements }
MessageBrowser >> methodRemoved: anAnnouncement [
"this method forces the announcement to be handled in the UI process"
UIManager default defer: [
self handleMethodRemoved: anAnnouncement ]
]
{ #category : #'messageList interface' }
MessageBrowser >> open [
^self openWithSpec
]
{ #category : #private }
MessageBrowser >> packageNameForItem: anItem [
^ anItem package ifNil: [ '' ] ifNotNil: [ :package | package name ]
]
{ #category : #api }
MessageBrowser >> refreshingBlock: aBlock [
refreshingBlock := aBlock
]
{ #category : #'announcements-registration' }
MessageBrowser >> registerToAnnouncements [
SystemAnnouncer uniqueInstance weak
when: MethodAdded send: #methodAdded: to: self;
when: MethodModified send: #methodModified: to: self;
when: MethodRecategorized send: #methodRecategorized: to: self;
when: MethodRemoved send: #methodRemoved: to: self;
when: ClassRenamed send: #classRenamed: to: self
]
{ #category : #'text selection' }
MessageBrowser >> searchedString: searchedString in: aString [
"Return the interval that corresponds to the portion of aString "
"This method takes care of finding complete match to searchedString. "
| string interval firstIndex |
searchedString ifNil: [ ^ 0 to: 0 ].
aString isEmptyOrNil ifTrue: [ ^0 to: 0 ].
string := aString asString.
interval := 0 to: 0.
(searchedString includes: $:)
ifTrue: [ | list |
list := searchedString substrings: ':'.
list size = 1
ifTrue: [" binary selector "
firstIndex := self findFirstOccurrenceOf: searchedString in: string.
firstIndex isZero
ifFalse: [ interval := firstIndex to: (firstIndex+searchedString size-1) ] ]
ifFalse: [
| lastIndex |
firstIndex := self findFirstOccurrenceOf: list first, ':' in: string.
firstIndex >0 ifTrue: [
lastIndex := string findString: list last,':' startingAt: firstIndex+ (list first size -1).
interval := firstIndex to: (lastIndex + list last size) ] ] ]
ifFalse: [
" unary selector "
firstIndex := self findFirstOccurrenceOf: searchedString in: string.
firstIndex > 0
ifTrue: [ interval := firstIndex to: (firstIndex+searchedString size - 1) ] ].
^ interval
]
{ #category : #api }
MessageBrowser >> selectIndex: anIndex [
messageList selectIndex: anIndex
]
{ #category : #private }
MessageBrowser >> selectItem: item [
toolbarPresenter method: item.
textModel beForMethod: item.
textModel text: (self textConverter
method: item;
getText).
textModel clearUndoManager.
self installIconStylerFor: item
]
{ #category : #accessing }
MessageBrowser >> selectedClass [
^ self selectedMethod origin
]
{ #category : #api }
MessageBrowser >> selectedMessage: aMessage [
messageList selectMessage: aMessage
]
{ #category : #accessing }
MessageBrowser >> selectedMethod [
^ messageList selectedMethod
]
{ #category : #initialization }
MessageBrowser >> setFocus [
self focusOrder
add: messageList;
add: toolbarPresenter;
add: textModel
]
{ #category : #api }
MessageBrowser >> setRefreshingBlockForImplementorsOf: aSelector [
self refreshingBlock: [ :message | message selector = aSelector ]
]
{ #category : #api }
MessageBrowser >> setRefreshingBlockForSendersOf: aSelector [
| specialIndex |
specialIndex := Smalltalk specialSelectorIndexOrNil: aSelector.
self refreshingBlock: [:method |
method hasSelector: aSelector specialSelectorIndex: specialIndex ]
]
{ #category : #announcements }
MessageBrowser >> shouldRefreshItem: item fromAnnouncement: anAnnouncement [
"The refreshing block contains a block that accepts an item of the list, the received announcement and the message browser.
It will anwer a boolean indicating if the modified item should be refreshed.
Concretely, this is used to know if the contents of the selected message should be refreshed"
^ refreshingBlock cull: item cull: anAnnouncement cull: self
]
{ #category : #api }
MessageBrowser >> sortingBlock: aBlock [
messageList sortingBlock: aBlock
]
{ #category : #'text selection' }
MessageBrowser >> sourceIntervalOf: aSelector in: aMethodNode [
| senderNode |
senderNode := aMethodNode allChildren detect: [ :x | x isMessage and: [ x selector = aSelector ] ] ifNone: [ ^ #() ].
^ senderNode keywordsPositions first to: senderNode keywordsPositions last + senderNode keywords last size - 1
]
{ #category : #accessing }
MessageBrowser >> textConverter: aTextConverter [
super textConverter: aTextConverter.
textModel syntaxHighlight: self textConverter shouldShout .
textModel text: self textConverter getText.
]
{ #category : #accessing }
MessageBrowser >> textModel [
^ textModel
]
{ #category : #accessing }
MessageBrowser >> textModel: aModel [
textModel := aModel
]
{ #category : #private }
MessageBrowser >> title [
^ self class title , ' [' , messageList numberOfElements printString , ']'
]
{ #category : #accessing }
MessageBrowser >> toolbarPresenter [
^ toolbarPresenter
]
{ #category : #api }
MessageBrowser >> topologicSort [
^ messageList topologicSort
]
{ #category : #api }
MessageBrowser >> topologicSort: aBoolean [
^ messageList topologicSort: aBoolean
]
{ #category : #api }
MessageBrowser >> updateTitle [
self withWindowDo: [ :window | window title: self title ]
]
{ #category : #'api-events' }
MessageBrowser >> whenSelectedItemChanged: aBlock [
messageList whenSelectedItemChanged: aBlock
]
{ #category : #private }
MessageBrowser >> windowIsClosing [
SystemAnnouncer uniqueInstance unsubscribe: self
]