/
FTExampleMethodTableDataSource.class.st
122 lines (103 loc) · 3.61 KB
/
FTExampleMethodTableDataSource.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
"
I'm an example of fast table, who will use a list of methods as data source elements.
self example1.
self example2.
"
Class {
#name : #FTExampleMethodTableDataSource,
#superclass : #FTSimpleDataSource,
#category : #'Morphic-Widgets-FastTable-Examples'
}
{ #category : #'instance creation' }
FTExampleMethodTableDataSource class >> for: aClass [
^ self basicNew
initializeClass: aClass;
yourself
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> cellColumn: column row: rowIndex [
column id = '#' ifTrue: [ ^ FTCellMorph new addMorph: rowIndex asMorph ].
column id = 'Name' ifTrue: [ ^ self nameColumn: column row: rowIndex ].
column id = 'Protocol' ifTrue: [ ^ self protocolColumn: column row: rowIndex ].
column id = 'Origin' ifTrue: [ ^ self originColumn: column row: rowIndex ].
self error: 'Invalid column'
]
{ #category : #private }
FTExampleMethodTableDataSource >> colorFor: index [
"index odd ifTrue: [ ^ Smalltalk ui theme lightBackgroundColor ]."
^Color transparent "Smalltalk ui theme backgroundColor"
]
{ #category : #private }
FTExampleMethodTableDataSource >> iconFor: rowIndex [
^ (self elementAt: rowIndex) actionOn: self
]
{ #category : #initialization }
FTExampleMethodTableDataSource >> initializeClass: aClass [
self initialize.
self elements: ((aClass allSelectors sorted: [ :a :b | a < b ]) collect: [ :each | FTExampleMethodModel method: (aClass lookupSelector: each) ])
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> menuColumn: column row: rowIndex [
rowIndex = 0 ifTrue: [
"I could answer a menu without selection, but in this case I will just answer nil,
which means 'no menu'"
^ nil ].
"protocols do not have associated menu"
column id = 'Name' ifTrue: [ ^ self nameMenuColumn: column row: rowIndex ].
column id = 'Origin' ifTrue: [ ^ self originMenuColumn: column row: rowIndex ].
^ nil
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> nameColumn: column row: rowIndex [
^ FTCellMorph new
color: (self colorFor: rowIndex);
cellInset: 5;
addMorphBack: (self iconFor: rowIndex) asMorph;
addMorphBack: (self elementAt: rowIndex) name asStringMorph;
yourself
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> nameMenuColumn: column row: rowIndex [
| method menu |
method := (self elementAt: rowIndex) method.
menu := UIManager default newMenuIn: self table for: self.
menu add: ('Browse ', (method methodClass name), '>>#', method selector)
target: method
selector: #browse.
menu add: ('Inspect #', (method methodClass name), '>>#', method selector)
target: method
selector: #inspect.
^ menu
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> originColumn: column row: rowIndex [
^ FTCellMorph new
color: (self colorFor: rowIndex);
addMorph: (self elementAt: rowIndex) origin name asMorph;
yourself
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> originMenuColumn: column row: rowIndex [
| method menu |
method := (self elementAt: rowIndex) method.
menu := UIManager default newMenuIn: self table for: self.
menu add: ('Browse ', (method methodClass name))
target: method methodClass
selector: #browse.
^ menu
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> protocolColumn: column row: rowIndex [
^ FTCellMorph new
color: (self colorFor: rowIndex);
addMorph: (self elementAt: rowIndex) protocol asStringMorph;
yourself
]
{ #category : #accessing }
FTExampleMethodTableDataSource >> searchText: aString [
aString isEmptyOrNil ifTrue: [ ^ #() ].
self elements withIndexDo: [ :each :index |
( each name beginsWith: aString)
ifTrue: [ ^ { index } ] ].
^ #()
]