/
BISettingPreviewer.class.st
267 lines (236 loc) · 6.58 KB
/
BISettingPreviewer.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
"
Preview to see the effect of a setting on the behavior of the pretty printer.
self new openWithSpec
"
Class {
#name : #BISettingPreviewer,
#superclass : #ComposablePresenter,
#instVars : [
'settingsTree',
'classSearchField',
'methodSearchField',
'formattedCheckBox',
'sourceCodePane'
],
#category : #'BlueInk-Extras-Settings'
}
{ #category : #'build ui buttons' }
BISettingPreviewer class >> buildOpenBIInspectorButton [
^ PluggableButtonMorph
on: self
getState: #openBIInspectorButtonState
action: #openBIInspectorButtonAction
label: #openBIInspectorButtonLabel
]
{ #category : #specs }
BISettingPreviewer class >> defaultSpec [
<spec: #default>
^ SpecLayout composed
newColumn:
[ :col |
col
newRow: [ :rowUp | rowUp add: #settingsTree ];
newRow:
[ :rowMiddle |
rowMiddle
add: #classSearchField;
add: #methodSearchField;
add: #formattedCheckBox ]
height: 30;
newRow:
[ :rowDown | rowDown newColumn: [ :methodSourceCode | methodSourceCode add: #sourceCodePane ] ] ];
yourself
]
{ #category : #settings }
BISettingPreviewer class >> dialogOpenBIPreviewer [
^ self theme
newRowIn: self currentWorld
for:
{(self theme buttonLabelForText: 'Open Blue Ink Setting Previewer ').
self buildOpenBIInspectorButton}
]
{ #category : #'instance creation' }
BISettingPreviewer class >> open [
<script>
self new openWithSpec
]
{ #category : #'button behavior' }
BISettingPreviewer class >> openBIInspectorButtonAction [
<script>
BISettingPreviewer new openWithSpec
]
{ #category : #'button behavior' }
BISettingPreviewer class >> openBIInspectorButtonLabel [
^ 'Open'
]
{ #category : #'button behavior' }
BISettingPreviewer class >> openBIInspectorButtonState [
^ true
]
{ #category : #settings }
BISettingPreviewer class >> settingsOn: aBuilder [
<systemsettings>
(aBuilder group: #blueInkFormatterExtra)
target: self;
parent: #blueInkFormatter;
label: 'BlueInk Formatting Editor';
description: 'Open the BlueInk setting previewer to edit the formatting options';
dialog: [ self dialogOpenBIPreviewer ]
]
{ #category : #'item creation' }
BISettingPreviewer >> buildClassSearchField [
^ self newTextInput
ghostText: 'Enter the class name...';
autoAccept: true;
yourself
]
{ #category : #'item creation' }
BISettingPreviewer >> buildFormattedCheckBox [
^ self newCheckBox
label: 'Formatted';
state: true;
whenActivatedDo:
[
formattedCheckBox toggleState.
self selectorAndClassAreCorrect
ifTrue: [ self formatSourceCode ] ];
whenDeactivatedDo:
[
formattedCheckBox toggleState.
self selectorAndClassAreCorrect
ifTrue: [ sourceCodePane text: self compiledMethodFromSearchFields sourceCode ] ];
yourself
]
{ #category : #'item creation' }
BISettingPreviewer >> buildMethodSearchField [
^ self newTextInput
ghostText: 'Enter the method selector...';
whenTextIsAccepted: [ self whenSelectorAccepted ];
yourself
]
{ #category : #'item creation' }
BISettingPreviewer >> buildSettingsTreeModel [
| settingsTreeModel |
settingsTreeModel := self newTree.
settingsTreeModel
roots:
((SettingTree acceptableKeywords: #(#systemsettings)) nodeList
select: [ :node | node parentName = #blueInkFormatter ]).
settingsTreeModel displayBlock: [ :node | self displayNodeFor: node ].
^ settingsTreeModel
]
{ #category : #'item creation' }
BISettingPreviewer >> buildSourceCodePane [
^ self newText
aboutToStyle: true;
yourself
]
{ #category : #accessing }
BISettingPreviewer >> classSearchField [
^ classSearchField
]
{ #category : #accessing }
BISettingPreviewer >> compiledMethodFromSearchFields [
"precondition text represent class and selector"
^ (self class environment at: classSearchField text asSymbol)
>> methodSearchField text asSymbol
]
{ #category : #'item creation' }
BISettingPreviewer >> displayNodeFor: aNode [
| nodeMorphLeft nodeMorphRight |
nodeMorphLeft := StringMorph contents: aNode item label.
nodeMorphRight := (self theme newRowIn: self currentWorld for: {aNode settingDeclaration inputWidget})
clipSubmorphs: true;
cellInset: 0;
width: 570;
left: 400;
yourself.
^ PanelMorph new
addAllMorphs:
{nodeMorphLeft.
nodeMorphRight};
color: self theme lightBackgroundColor;
hResizing: #shrinkWrap;
yourself
]
{ #category : #api }
BISettingPreviewer >> formatSourceCode [
| source tree formatted |
source := self compiledMethodFromSearchFields sourceCode.
tree := RBParser parseMethod: source onError: [ :msg :pos | ^ self ].
formatted := tree formattedCode.
sourceCodePane text: formatted
]
{ #category : #accessing }
BISettingPreviewer >> formattedCheckBox [
^ formattedCheckBox
]
{ #category : #api }
BISettingPreviewer >> initialExtent [
^ 1000 @ 700
]
{ #category : #initialization }
BISettingPreviewer >> initializeWidgets [
sourceCodePane := self buildSourceCodePane.
classSearchField := self buildClassSearchField.
methodSearchField := self buildMethodSearchField.
settingsTree := self buildSettingsTreeModel.
formattedCheckBox := self buildFormattedCheckBox.
SystemAnnouncer uniqueInstance weak when: BISettingsChanged send: #whenASettingChanged to: self.
self focusOrder
add: settingsTree;
add: classSearchField;
add: methodSearchField;
add: formattedCheckBox;
add: sourceCodePane
]
{ #category : #accessing }
BISettingPreviewer >> methodSearchField [
^ methodSearchField
]
{ #category : #testing }
BISettingPreviewer >> selectorAndClassAreCorrect [
| class |
methodSearchField text
ifNotNil:
[ :method |
classSearchField text
ifNotNil:
[
class := self class environment at: classSearchField text asSymbol ifAbsent: [ ^ false].
(class includesSelector: method asSymbol)
ifTrue: [ ^ true ]]].
^ false
]
{ #category : #accessing }
BISettingPreviewer >> settingsTree [
^ settingsTree
]
{ #category : #accessing }
BISettingPreviewer >> sourceCodePane [
^ sourceCodePane
]
{ #category : #api }
BISettingPreviewer >> title [
^ 'Blue Ink Setting Previewer'
]
{ #category : #'event handling' }
BISettingPreviewer >> whenASettingChanged [
(self formattedCheckBox state and: [ self selectorAndClassAreCorrect ])
ifTrue: [ self formatSourceCode ]
]
{ #category : #'event handling' }
BISettingPreviewer >> whenSelectorAccepted [
| compiledMethod |
self selectorAndClassAreCorrect
ifTrue:
[
compiledMethod := self compiledMethodFromSearchFields.
sourceCodePane behavior: compiledMethod methodClass.
self formattedCheckBox state
ifTrue: [ self formatSourceCode ]
ifFalse: [ sourceCodePane text: compiledMethod sourceCode ]]
ifFalse: [
sourceCodePane behavior: nil.
sourceCodePane text: ' ' ]
]