-
Notifications
You must be signed in to change notification settings - Fork 11
/
Inspecting.ns
1004 lines (990 loc) · 27.9 KB
/
Inspecting.ns
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Newspeak3
'HopscotchIDE'
class Inspecting usingPlatform: platform ide: ide = (
(* Presenters for inspecting objects.
Copyright 2008, 2012 Cadence Design Systems, Inc.
Licensed under the Apache License, Version 2.0 (the ''License'');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an ''AS IS'' BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
||
private List = platform collections List.
private Color = platform graphics Color.
private ObjectMirror = platform mirrors ObjectMirror.
private Subject = platform hopscotch core Subject.
private BlankFragment = platform hopscotch fragments BlankFragment.
private TextEditorFragment = platform hopscotch fragments TextEditorFragment.
private ProgrammingPresenter = ide tools ProgrammingPresenter.
private OneLineDefinitionTemplate = ide tools OneLineDefinitionTemplate.
private workspaceManager = ide theWorkspaceManager.
private finalizer = ide finalizer.
private ToolSet = platform squeak ToolSet.
private PointerFinder = platform squeak PointerFinder.
private primitives = platform squeak VMMirror new. (* BOGUS. Should express reverse objects with mirrors somehow. *)
(* My slots *)
detailAreaRatio = 1.6.
captionColor = Color h: 240 s: 0.05 v: 0.9.
||
) (
class BrazilVisualTreePresenter onSubject: theSubject <BrazilVisualTreeSubject> = ProgrammingPresenter onSubject: theSubject () (
captionLine = (
| thumb |
thumb:: subject visual agent inspectorIconOfSize: 20.
^
row: {
thumb ifNil: [nothing] ifNotNil: [linkImage: thumb action: []].
mediumBlank.
label: subject title.
largeBlank.
(link: 'flash' action: [subject visual flash]) tinyFont.
mediumBlank.
(link: 'explore' action: [subject visual explore]) tinyFont.
filler.
elastic:: inspectorToggle.
}
)
captionLineWithToggleAction: aBlock = (
| thumb |
thumb:: subject visual agent inspectorIconOfSize: 20.
^
row: {
thumb ifNil: [nothing] ifNotNil: [linkImage: thumb action: aBlock].
mediumBlank.
link: subject title action: aBlock.
largeBlank.
(link: 'flash' action: [subject visual flash]) tinyFont.
mediumBlank.
(link: 'explore' action: [subject visual explore]) tinyFont.
filler.
elastic:: inspectorToggle.
}
)
childColumn = (
^
column:
(subject children collect:
[:each |
(BrazilVisualTreeSubject onModel: each) presenter])
)
definition = (
^
subject hasChildren
ifTrue: [expandableView]
ifFalse: [captionLine]
)
expandableView = (
| toggle |
toggle::
heading: (captionLineWithToggleAction: [toggle toggle])
details: [childColumn].
^toggle
)
inspectorToggle = (
^
collapsed: [label: 'Inspect']
expanded: [(ObjectSubject onModel: (ObjectMirror reflecting: subject visual)) presenter]
)
) : (
)
public class BrazilVisualTreeSubject onModel: theModel <Visual> = Subject onModel: theModel (
(* Part of the ''Meta'' window menu item implementation. The model is a Brazil visual. *)
) (
public children = (
^model children
)
public createPresenter = (
^BrazilVisualTreePresenter onSubject: self
)
public hasChildren = (
^model hasChildren
)
public title = (
^model printString
)
public visual = (
^model
)
) : (
)
public class EvaluatorPresenter onSubject: theSubject <ObjectSubject> = ProgrammingPresenter onSubject: theSubject (|
editor
results
|) (
addDiscardIfNeeded = (
results presenters isEmpty ifTrue:
[results add: discardResultsDefinition].
)
addExceptionalResultPresenterFor: exception <Exception> in: thread <NewspeakDebugging ThreadSubject> = (
addDiscardIfNeeded.
results addFirst: (
row: {
elastic::
collapsed: [ExceptionalResultPresenter on: exception in: thread]
expanded: [buildExceptionDetails: exception in: thread].
}
)
)
addResultPresenterOn: result <ObjectMirror> = (
addDiscardIfNeeded.
results addFirst: (resultFragmentOn: (ObjectSubject onModel: result))
)
buildExceptionDetails: exception <Exception> in: thread <NewspeakDebugging ThreadSubject> = (
^column: {
elastic:: row: {filler. (link: 'debug' action: [enterSubject: thread]) tinyFont}.
elastic:: (ObjectSubject onModel: (ObjectMirror reflecting: exception)) presenter.
}
)
clearResults = (
results presenters: {}
)
createEditor = (
editor:: TextEditorFragment new.
editor
changeResponse: [];
acceptResponse: [respondToEvaluate];
enterKeyResponse: [respondToEvaluate];
escapeKeyResponse: [sendUp deliveryOptional hideEvaluator].
^editor
)
definition = (
results:: list: {}.
^(column: {
smallBlank.
row: {
smallBlank.
elastic:: column: {filler. createEditor. filler}.
smallBlank.
button: 'Evaluate' action: [respondToEvaluate].
smallBlank.
}.
smallBlank.
row: {
elastic:: results
}
}) color: captionColor
)
discardResultsDefinition = (
^row: {
filler.
(link: 'discard results' action: [clearResults]) tinyFont.
}
)
respondToEvaluate = (
editor removeMessages.
addResultPresenterOn:: subject
evaluate: editor maybeSelectCurrentLine
ifCompilerError:
[:message |
^editor addMessage: message]
ifError:
[:thread :exception |
^addExceptionalResultPresenterFor: exception in: thread].
sendUp deliveryOptional noticeEvaluationBy: self
)
resultFragmentOn: result <ObjectSubject> ^ <Fragment> = (
| heading |
heading:: link: result title action: [enterSubject: result refreshmentSubject].
sendUp
deliveryOptional;
additionalResultFragment:
[:extra <Fragment> |
heading:: row: {
heading.
filler.
extra.
}] for: result objectMirror.
^collapsed: [heading]
expanded: [result presenter]
)
) : (
)
public class ExceptionalResultPresenter on: ex <Exception> in: theSubject <NewspeakDebugging ThreadSubject> = ProgrammingPresenter onSubject: theSubject (|
exception = ex.
|) (
buildInspectException = (
| message |
message:: exception messageText ifNotNil: [:it | it withBlanksTrimmed].
^message isEmptyOrNil
ifTrue: [(link: 'inspect' action: [inspect: exception]) tinyFont]
ifFalse: [link: message action: [inspect: exception]]
)
definition = (
^row: {
(link: (exception isNil
ifTrue: ['Error: ', subject title]
ifFalse: [exception description])
action: [respondToDebug]) color: Color red
}
)
respondToDebug = (
enterSubject: self subject
)
) : (
)
class ObjectIndexedSlotSubject on: mirror <ObjectMirror> slotIndex: i <Integer> = ObjectSlotSubject onModel: mirror (
(* Represents an indexed slot of an object, accessed using a vm mirror. For a subject to represent a value accessible by sending the public #at: message, see ObjectValueAtKeySubject. *)
|
public slotIdentifier = i.
|) (
public value = (
^objectMirror indexedSlotAt: slotIdentifier
)
public value: newValue = (
objectMirror indexedSlotAt: slotIdentifier put: newValue.
^newValue
)
) : (
)
class ObjectLiteralSubject on: theMirror key: theKey = ObjectValueAtKeySubject on: theMirror key: theKey (
) (
public value = (
^ObjectMirror reflecting: (model reflectee literalAt: key)
)
) : (
)
class ObjectNamedSlotSubject on: mirror <ObjectMirror> slotName: slotName <String> = ObjectSlotSubject onModel: mirror (
(* Represents a named slot of the model, to be accessed using a vm mirror. *)
|
public slotIdentifier = slotName.
|) (
public objectMirror = (
^model
)
public value = (
^objectMirror getSlot: slotIdentifier
)
public value: newValue <ObjectMirror> = (
objectMirror setSlot: slotIdentifier to: newValue reflectee.
^newValue
)
) : (
)
class ObjectPresenter onSubject: subj <ObjectSubject> = ProgrammingPresenter onSubject: subj (
(* The outer shell of an inspector: shows the caption bar with an evaluator opening link. Also contains and manages (switches) presenters for the different views onto the object contents. *)
|
public selfCaption ::= 'self'.
public objectDetailsHolder
|) (
actionsMenu = (
^menuWithLabelsAndActions: {
'Inspect in Squeak' -> [respondToInspectInSqueak].
#separator.
'References to this Object' -> [respondToIncomingReferences].
'Retaining path for this Object' -> [respondToRetainingPath].
#separator.
'Inspect Class' -> [inspect: subject modelClass].
'Inspect Presenter' -> [respondToInspectPresenter].
}
)
availableObjectViews ^<Collection[ObjectViewDescription]> = (
^Array streamContents:
[:s |
(subject reflecteePerform: #isForm) ifTrue:
[s nextPut:
(ObjectViewDescription
title: 'Form'
presenterCreator: [ObjectPresenterFormView onSubject: subject])].
((subject reflecteePerform: #isString) or: [subject reflecteePerform: #isText]) ifTrue:
[s nextPut:
(ObjectViewDescription
title: 'Text'
presenterCreator: [ObjectPresenterAsStringView onSubject: subject])].
(subject reflecteePerform: #isInteger) ifTrue:
[s nextPut:
(ObjectViewDescription
title: 'Radix'
presenterCreator: [ObjectPresenterAsIntegerView onSubject: subject])].
(subject reflecteePerform: #isCompiledMethod) ifTrue:
[s nextPut:
(ObjectViewDescription
title: 'Method'
presenterCreator: [ObjectPresenterMethodView onSubject: subject])].
(subject reflecteePerform: #isClosure) ifTrue:
[s nextPut:
(ObjectViewDescription
title: 'Block'
presenterCreator: [ObjectPresenterBlockView onSubject: subject])].
(subject reflecteePerform: #isDictionary) ifTrue:
[s nextPut:
(ObjectViewDescription
title: 'Dictionary'
presenterCreator: [ObjectPresenterDictionaryView onSubject: subject])].
(subject reflecteePerform: #isCollection) ifTrue: [
(subject reflecteePerform: #isSequenceable) ifTrue: [
s nextPut:
(ObjectViewDescription
title: 'Sequence'
presenterCreator: [ObjectPresenterSequenceView onSubject: subject])]].
s nextPut:
(ObjectViewDescription
title: 'Basic'
presenterCreator: [ObjectPresenterBasicView onSubject: subject]).
]
)
captionBar: body = (
^(column: {
smallBlank.
row: {
mediumBlank.
elastic: body.
smallBlank
}.
})
color: captionColor
)
classInfoLine = (
^row: {
(label: 'class') width: 0 elasticity: 1.
(row: {
link: subject className action: [browseClass: subject modelClass].
}) width: 0 elasticity: detailAreaRatio.
}
)
coloredBarWidth: pixels = (
^((row: {}) color: captionColor) width: pixels
)
definition = (
| views |
views:: availableObjectViews.
objectDetailsHolder:: holder: views first presenter.
^(column: {
headerDefinition.
evaluatorPresenter.
detailsSwitcherBarWith: views.
row: {
coloredBarWidth: 1.
blank: 3.
elastic:: objectDetailsHolder.
blank: 2.
coloredBarWidth: 1.
}.
coloredBarWidth: 1.
}) color: Color white
)
detailsSwitcherBarWith: details = (
^details size < 2
ifTrue: [nothing]
ifFalse:
[(row:
{ mediumBlank },
(switcherLinksWith: details)
) color: captionColor]
)
enclosingInfoLine = (
^row: {
(label: 'enclosingObject') width: 0 elasticity: 1.
(row: {
link: subject enclosingObjectName action: [inspect: subject classMirror enclosingObject reflectee].
}) width: 0 elasticity: detailAreaRatio.
}
)
evaluatorPresenter ^ <EvaluatorPresenter> = (
^EvaluatorPresenter onSubject: subject
)
goToSelf = (
enterSubject: (ObjectSubject onModel: subject objectMirror)
)
headerDefinition = (
^captionBar:
(column: {
selfInfoLine.
enclosingInfoLine.
classInfoLine.
}).
)
respondToIncomingReferences = (
enterSubject:: subject reverseSubject.
)
respondToInspectInSqueak = (
subject inspectInSqueak
)
respondToRetainingPath = (
inspect: subject retainingPath.
)
selfInfoLine = (
^row: {
(label: selfCaption asText allBold) width: 0 elasticity: 1.
(row: {
(link: subject title action: [goToSelf]) compressibility: 1.
filler compressibility: 0.
mediumBlank.
dropDownMenu: [actionsMenu]
}) width: 0 elasticity: detailAreaRatio.
}
)
switchDetailsTo: aPresenter = (
objectDetailsHolder content: aPresenter
)
switcherLinksWith: details = (
^
Array streamContents:
[:elements |
details
do:
[:each <ObjectDetailsView> |
elements nextPut:
(link: each title action: [switchDetailsTo: each presenter])]
separatedBy:
[elements nextPut: smallBlank]]
)
public title = (
^'Inspector on ', subject title
)
) : (
)
class ObjectPresenterAsIntegerView onSubject: subj <ObjectSubject> = ProgrammingPresenter onSubject: subj (
) (
definition = (
| radixList = list. |
{2. 8. 10. 16} with: {'binary'. 'octal'. 'decimal'. 'hex'} do:
[:radix :label | | radixString = printStringOf: subject objectMirror reflectee withRadix: radix. |
radixList add: (row: {(label: label) width: 80. label: radixString})].
^column: {
radixList
}
)
printStringOf: integer withRadix: radix = (
^String streamContents: [:stream | integer printOn: stream base: radix showRadix: false]
)
) : (
)
class ObjectPresenterAsStringView onSubject: subj <ObjectSubject> = ProgrammingPresenter onSubject: subj (
(* Presents an object that can be coerced to a String by sending #asString, by displaying the string it coerces to as a text block. *)
) (
copyText = (
copyToClipboard: subject objectMirror reflectee
)
definition = (
| editor |
editor:: TextEditorFragment new.
editor text: textToDisplay.
^column: {
row: {
filler.
(link: '[copy]' action: [copyText]) tinyFont.
}.
editor.
}
)
textToDisplay = (
^subject objectMirror reflectee
)
) : (
)
class ObjectPresenterBasicView onSubject: subj = ProgrammingPresenter onSubject: subj (
(* Presents an object (the model of its subject) as a collection of its named and indexed slots. *)
) (
definition = (
^list: slotPresenters
)
slotPresenters = (
^Array streamContents:
[:presenters |
subject namedSlotNames do:
[:each |
presenters nextPut:
(ObjectSlotPresenter onSubject:
(ObjectNamedSlotSubject on: subject objectMirror slotName: each))].
subject hasIndexedSlots ifTrue:
[subject indexedSlotRange do:
[:index |
presenters nextPut:
(ObjectSlotPresenter onSubject:
(ObjectIndexedSlotSubject on: subject objectMirror slotIndex: index))]].
subject transientSlotNames do:
[:each |
presenters nextPut:
(ObjectSlotPresenter onSubject:
(ObjectTransientSlotSubject on: subject objectMirror slotName: each))].
].
)
) : (
)
class ObjectPresenterBlockView onSubject: subj <ObjectSubject> = ProgrammingPresenter onSubject: subj () (
definition = (
^column: {
smallBlank.
minorHeadingBlock: (label: 'Source').
indentedBlock: (textDisplay: 'TODO: method presenter with closure highlighted and links to defining class').
minorHeadingBlock: (label: 'Free Variables').
indentedBlock: (textDisplay: 'TODO: list of names and values').
}
)
) : (
)
class ObjectPresenterDictionaryView onSubject: subj = ProgrammingPresenter onSubject: subj (
(* Presents an object that understands #keys and #at:, i.e. something dictionary-like, by going through the keys and displaying an entry for each of them, with the value obtained by sending #at:. *)
) (
definition = (
^list: entryPresenters
)
entryPresenters = (
| presenters |
presenters:: List new.
subject objectMirror reflectee keys do:
[:each |
presenters add: (newObjectValueAtKeySubjectForKey: each) presenter].
^presenters
)
newObjectValueAtKeySubjectForKey: key = (
^ObjectValueAtKeySubject on: subject objectMirror key: key
)
) : (
)
class ObjectPresenterFormView onSubject: s <ObjectSubect> = ProgrammingPresenter onSubject: s (
) (
definition = (
^padded: (image: subject objectMirror reflectee) with: {10. 10. 10. 10}
)
) : (
)
class ObjectPresenterMethodView onSubject: subj <ObjectSubject> = ProgrammingPresenter onSubject: subj (
(* Presents a compiled method by showing its decompiled source and a disassembly of its bytecodes. *)
) (
bytecodeString = (
^[method reflectee symbolic]
on: Error
do: [:ex | ex return: '<error retrieving the method''s bytecodes>']
)
decompiledString = (
^[method reflectee decompileString]
on: Error
do: [:ex | ex return: '<error decompiling the method>']
)
definition = (
^
column: {
smallBlank.
minorHeadingBlock: (label: 'Decompiled').
indentedBlock: (textDisplay: decompiledString).
minorHeadingBlock: (label: 'Header').
indentedBlock: (textDisplay: headerDescription withBlanksTrimmed).
minorHeadingBlock: (label: 'Literals').
indentedBlock: (literalPresenters).
minorHeadingBlock: (label: 'Bytecodes').
indentedBlock: (textDisplay: bytecodeString).
}
)
headerDescription = (
^[method reflectee headerDescription]
on: Error
do: [:ex | ex return: '<error retrieving the method''s headerDescription>']
)
literalPresenters = (
| presenters |
presenters:: List new.
1 to: (method reflectee numLiterals) do:
[:index |
presenters add:
(ObjectLiteralSubject on: subject objectMirror key: index) presenter].
^list: presenters
)
method = (
^subject objectMirror
)
) : (
)
class ObjectPresenterSequenceView onSubject: subj = ProgrammingPresenter onSubject: subj (
(* Presents objects that understand #size and #at:, most likely SequenceableCollections by stringing ObjectValueAtKeySubjects for indicex from 1 to <size>. *)
) (
definition = (
^list: elementPresenters
)
elementPresenters = (
^subject objectMirror reflectee size <= 200
ifTrue: [elementPresentersAll]
ifFalse: [elementPresentersSome]
)
elementPresentersAll = (
| presenters |
presenters:: List new.
1 to: subject objectMirror reflectee size do:
[:index |
presenters add: (newObjectValueAtKeySubjectForIndex: index) presenter].
^presenters
)
elementPresentersSome = (
| presenters collectionSize |
presenters:: List new.
collectionSize:: subject objectMirror reflectee size.
1 to: 100 do:
[:index |
presenters add: (newObjectValueAtKeySubjectForIndex: index) presenter].
presenters add:
(column: {
largeBlank.
row: {
blank: 40.
label: 'Skipping ', (collectionSize - 120 - 1) printString, ' elements...'.
}.
largeBlank.
}).
collectionSize - 20 to: collectionSize do:
[:index |
presenters add: (newObjectValueAtKeySubjectForIndex: index) presenter].
^presenters
)
newObjectValueAtKeySubjectForIndex: index <Number> ^<ObjectValueAtKeySubject> = (
^ObjectValueAtKeySubject on: subject objectMirror key: index
)
) : (
)
class ObjectSlotPresenter onSubject: subj = ProgrammingPresenter onSubject: subj (
(* This presenter is used for most of object detail views, such as the list of object slots, collection elements, or dictionary entries. Thus the actual interpretation of what ''slot'' means is a responsibility of the subject. The subject is something like ObjectIndexedSlotSubject, ObjectNamedSlotSubject, or ObjectValueAtKeySubject. This presenter displays the subject as a row with the caption of the subject, followed by the value string provided the subject. *)
| editorFragment inspectorHolder |) (
public caption = (
^row: {
(link: subject caption action: [expand])
width: 0 elasticity: 1;
color: actionLinkColor.
(link: [subject briefValuePrintString] (* updated on each #noticeImminentExposure *)
action: [respondToValueClick])
width: 0 elasticity: detailAreaRatio.
}
)
definition = (
^collapsed: caption expanded: [expandedDefinition]
)
editor = (
^editorFragment editor
)
public expand = (
substance expand
)
expandedDefinition = (
editorFragment:: OneLineDefinitionTemplate new
initialText: 'new value for ', subject slotIdentifier;
acceptResponse: [:t | setValue: t text asString];
cancelResponse: [:t | t editor defaultCancelResponse];
initiallyInEditState: false.
^column: {
editorFragment.
inspectorHolder:: holder: [subjectOnValue presenter].
}
)
public noticeImminentExposure = (
(* Refresh to update the slot value (the link label). *)
refresh.
)
respondToValueClick = (
enterSubject: subjectOnValue
)
setValue: expression <String> = (
subject
setValue: expression
ifCompilerError: [:msg | ^editor showMessage: msg]
ifError: [:msg | ^editor showMessage: msg].
editor leaveEditState.
refresh.
)
public setValue: expression <String> ifFail: failBlock = (
subject setValue: expression ifCompilerError: failBlock ifError: failBlock value.
refresh.
)
subjectOnValue = (
| valueSubject |
valueSubject:: ObjectSubject onModel: subject value.
valueSubject presenter selfCaption: subject caption.
^valueSubject
)
) : (
)
class ObjectSlotSubject onModel: mirror <ObjectMirror> = Subject onModel: mirror () (
public = another = (
^self class = another class and:
[self objectMirror = another objectMirror and:
[self slotIdentifier = another slotIdentifier]]
)
public briefValuePrintString = (
^value safePrintStringLimitedTo: 200
)
public caption ^<String> = (
(* The short string a presenter could use to identify the slot. *)
^slotIdentifier asString
)
public createPresenter = (
^ObjectSlotPresenter onSubject: self
)
public hash = (
^(self class hash bitXor: objectMirror hash) bitXor: slotIdentifier hash
)
public objectMirror = (
^self model
)
setValue: t = (
objectMirror setSlot: slotIdentifier to: t
)
public setValue: expression <String> ifCompilerError: compileFailBlock ifError: failBlock = (
| newValue |
newValue::
objectMirror evaluate: expression
with: workspaceManager workspaceScope
ifCompilerError: compileFailBlock
ifError: failBlock.
value: newValue
)
public setValue: expression <String> ifFail: failBlock = (
setValue: expression ifCompilerError: failBlock ifError: failBlock
)
public slotIdentifier = (
subclassResponsibility
)
) : (
)
public class ObjectSubject onModel: mirror <ObjectMirror> = Subject onModel: mirror (
(* Part of inspector functionality. The model is a mirror on the object being inspected. *)
) (
public = another <Object> ^<Boolean> = (
^self class = another class and:
[objectMirror = another objectMirror]
)
public classMirror ^<ClassMirror> = (
^model getClass
)
public className ^<String> = (
^classMirror simpleName
)
public createPresenter = (
^ObjectPresenter onSubject: self
)
public enclosingObjectName ^<String> = (
^classMirror enclosingObject safePrintStringLimitedTo: 200
)
public evaluate: expression <String>
ifCompilerError: onCompilerError <[:String]>
ifError: onError <[:NewspeakDebugging ThreadSubject :Exception]> ^<ObjectMirror> = (
| scope thread exception process |
scope:: workspaceManager workspaceScope.
[thread:: objectMirror evaluate: expression with: scope]
on: Error
do: [:ex | ^onCompilerError value: ex description].
thread isFulfilled ifTrue: [^thread result].
exception:: thread result reflectee.
process:: thread process.
^onError value: (finalizer subjectFor: exception in: process) value: exception
)
public hasIndexedSlots ^<Boolean> = (
^classMirror reflectee isVariable
)
public hash ^<Integer> = (
^self class hash bitXor: objectMirror hash
)
public incomingPointers = (
^objectMirror reflectee inboundPointersExcluding: {objectMirror}
)
public indexedSlotRange = (
^1 to: objectMirror indexedSlotSize
)
public inspectInSqueak = (
ToolSet inspect: objectMirror reflectee
)
public modelClass = (
^classMirror reflectee
)
public namedSlotNames ^<Collection[String]> = (
^objectMirror getClass slots collect: [:ea | ea name]
)
public objectMirror ^<ObjectMIrror> = (
^model
)
public printOn: s <WriteStream> = (
s
nextPutAll: self class simpleName;
nextPut: ":".
objectMirror reflecteePrintOn: s
)
public reflecteePerform: selector <Symbol> = (
^(objectMirror perform: selector with: {} ifFail: [halt]) reflectee.
)
public retainingPath = (
#BOGUS. (* Implement in Newspeak. Use the specialObjectsArray as the root. *)
^PointerFinder new goal: objectMirror reflectee; search; instVarNamed: #objectList
)
public reverseSubject = (
^ReverseObjectSubject onModel: model
)
public title = (
^objectMirror safePrintStringLimitedTo: 200
)
public transientSlotNames ^<Collection[String]> = (
^objectMirror getClass transientSlots collect: [:ea | ea name]
)
) : (
)
class ObjectTransientSlotSubject on: mirror <ObjectMirror> slotName: slotName <String> = ObjectSlotSubject onModel: mirror (
(* Represents a named slot of the model, to be accessed using a vm mirror. *)
|
public slotIdentifier = slotName.
|) (
public objectMirror = (
^model
)
public value = (
^objectMirror getTransientSlot: slotIdentifier.
)
public value: newValue <ObjectMirror> = (
objectMirror setTransientSlot: slotIdentifier to: newValue reflectee.
^newValue
)
) : (
)
class ObjectValueAtKeySubject on: theMirror key: theKey = Subject onModel: theMirror (|
public key = theKey.
|) (
public = another <Object> ^<Boolean> = (
^self class = another class and:
[self model == another objectMirror and:
[self key = another key]]
)
public briefValuePrintString = (
^[value safePrintStringLimitedTo: 200]
on: Error
do: [:ex | ex return: '<error printing the value>']
)
public caption = (
^[key printString]
on: Error
do: [:ex | ex return: '<error>']
)
public createPresenter = (
^ObjectSlotPresenter onSubject: self
)
public hash ^<Integer> = (
^model identityHash bitXor: key hash
)
public objectMirror = (
^model
)
public slotIdentifier = (
^'at: ', key printString
)
public value = (
^model perform: #at: with: {key} ifFail: [halt]
)
) : (
)
class ObjectViewDescription title: theTitle <String> presenterCreator: theCreator <Block> = (
(* A collection of these is held onto by ObjectPresenter as a list of views available for the object being presented. If more that one view is available, the object presenter typically displays some selection widgets to allow switching between the views. An instance of this is responsible for lazily instantiating its presenter when asked for the presenter. *)
|
public title = theTitle.
presenterCreator = theCreator.
private presenterX
|) (
public presenter = (
^presenterX ifNil:
[presenterX:: presenterCreator value.
presenterX]
)
) : (
)
class ReverseObjectPresenter onSubject: s = ProgrammingPresenter onSubject: s (|
public selfCaption ::= 'references to'.
|) (
captionBar: body = (
^(column: {
smallBlank.
row: {
mediumBlank.
elastic: body.
smallBlank
}.
})
color: captionColor
)
coloredBarWidth: pixels = (
^((row: {}) color: captionColor) width: pixels
)
definition = (
^(column: {
headerDefinition.
row: {
coloredBarWidth: 1.
blank: 3.
elastic:: detailsDefinition.
blank: 2.
coloredBarWidth: 1.
}.
coloredBarWidth: 1.
}) color: Color white
)
definitionForEdgeFrom: source named: slotname = (
|
sourceSubject = ObjectSubject onModel: (ObjectMirror reflecting: source).
sourceRSubject = ReverseObjectSubject onModel: (ObjectMirror reflecting: source).
toggle
|
toggle::
collapsed:
[row: {
(link: slotname action: [toggle expand])
width: 0 elasticity: 1;
color: actionLinkColor.
(link: [sourceSubject title] action: [enterSubject: sourceSubject])
width: 0 elasticity: detailAreaRatio.
}]
expanded:
[(ReverseObjectPresenter onSubject: sourceRSubject) selfCaption: slotname].
^toggle
)
detailsDefinition = (
^list: (subject incomingPointers collect:
[:ea | definitionForEdgeFrom: ea named: (subject nameForEdgeFrom: ea)])
)
goToSelf = (
enterSubject: subject forwardSubject
)
headerDefinition = (
^captionBar:
(column: {
selfInfoLine.
smallBlank.
}).
)
selfInfoLine = (
^row: {
(label: selfCaption asText allBold) width: 0 elasticity: 1.
(row: {
(link: subject title action: [goToSelf]) compressibility: 1.
}) width: 0 elasticity: detailAreaRatio.
}
)
public title = (
^'References to ', subject title
)
) : (
)
class ReverseObjectSubject onModel: mirror <ObjectMirror> = ObjectSubject onModel: mirror () (
public createPresenter = (
^ReverseObjectPresenter onSubject: self
)
public forwardSubject = (
^ObjectSubject onModel: model
)
public nameForEdgeFrom: source = (
(* BOGUS: Should not send any messages to source or sourceClass. *)
|
sourceClass = primitives classOf: source.
destination = model reflectee.
|
sourceClass == destination ifTrue: [^'<class>'].
1 to: sourceClass instSize do:
[:i | (source instVarAt: i) == destination
ifTrue: [^sourceClass allInstVarNames at: i]].
source isCompiledMethod ifTrue:
[1 to: source numLiterals do:
[:i | (source literalAt: i) == destination ifTrue: [^'literalAt: ', i printString]].
^'<unknown slot>'].
1 to: source basicSize do:
[:i | (source basicAt: i) == destination ifTrue: [^'at: ', i printString]].
^'<unknown slot>'
)