forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpMethodBrowser.class.st
131 lines (105 loc) · 2.58 KB
/
SpMethodBrowser.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
"
A MethodBrowser is a simple browser using Spec to display a list of methods and their source code
self example
"
Class {
#name : #SpMethodBrowser,
#superclass : #SpPresenter,
#instVars : [
'listModel',
'textModel',
'toolbarModel'
],
#category : #'Spec2-Morphic-Examples-Standalone'
}
{ #category : #specs }
SpMethodBrowser class >> defaultSpec [
^ SpPanedLayout newVertical
add: #listModel;
add:
(SpBoxLayout newVertical
add: #toolbarModel withConstraints: [ :constraints | constraints height: self toolbarHeight ];
add: #textModel;
yourself);
yourself
]
{ #category : #example }
SpMethodBrowser class >> example [
<sampleInstance>
| example |
example := SpMethodBrowser new.
example methods: Object methods;
openWithSpec.
^example
]
{ #category : #specs }
SpMethodBrowser class >> title [
^ 'Method Browser'
]
{ #category : #accessing }
SpMethodBrowser >> action [
^ textModel acceptBlock
]
{ #category : #initialization }
SpMethodBrowser >> connectPresenters [
listModel whenSelectionChangedDo: [ :selection |
selection isEmpty
ifTrue: [
textModel text: ''.
textModel beForMethod: nil.
toolbarModel method: nil ]
ifFalse: [ | m |
m := selection selectedItem.
textModel text: m sourceCode.
textModel beForMethod: m.
toolbarModel method: m ] ].
self whenSubmitDo: [ :text | self listModel selectedItem inspect ].
self wrapWith: [ :item | item methodClass name , '>>#' , item selector ]
]
{ #category : #api }
SpMethodBrowser >> displayBlock: aBlock [
listModel displayBlock: aBlock
]
{ #category : #initialization }
SpMethodBrowser >> initializePresenters [
listModel := self instantiate: SpListPresenter .
textModel := self newCode.
toolbarModel := self instantiate: SpMethodToolbar.
self focusOrder
add: listModel;
add: toolbarModel;
add: textModel
]
{ #category : #accessing }
SpMethodBrowser >> listModel [
^ listModel
]
{ #category : #api }
SpMethodBrowser >> methods: aList [
"Here I reroute my entry point to the list model's entry point"
self listModel items: aList
]
{ #category : #api }
SpMethodBrowser >> sortingBlock: aBlock [
listModel sortingBlock: aBlock
]
{ #category : #focus }
SpMethodBrowser >> takeKeyboardFocus [
^ self listModel takeKeyboardFocus
]
{ #category : #accessing }
SpMethodBrowser >> textModel [
^ textModel
]
{ #category : #accessing }
SpMethodBrowser >> toolbarModel [
^ toolbarModel
]
{ #category : #accessing }
SpMethodBrowser >> whenSubmitDo: aBlock [
textModel whenSubmitDo: aBlock
]
{ #category : #api }
SpMethodBrowser >> wrapWith: aBlock [
listModel display: aBlock
]