forked from bonzini/gst-visualgst
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Extensions.st
774 lines (590 loc) · 17.6 KB
/
Extensions.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
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
Object extend [
gtkInspect [
"Open a GtkInspector on self"
<category: '*VisualGST'>
VisualGST.GtkInspector openOn: self
]
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkObjectInspectorView
]
hasLiterals [
<category: '*VisualGST'>
^ false
]
]
CompiledMethod class extend [
ExtensionIcon := nil.
OverrideIcon := nil.
OverriddenIcon := nil.
extensionIcon [
<category: '*VisualGST'>
^ ExtensionIcon ifNil: [ ExtensionIcon := GTK.GdkPixbuf newFromFile: (VisualGST.GtkLauncher / 'Icons/extension.png') file displayString error: nil ]
]
extensionsIcon: aGdkPixbuf [
<category: '*VisualGST'>
ExtensionIcon := aGdkPixbuf
]
overrideIcon [
<category: '*VisualGST'>
^ OverrideIcon ifNil: [ OverrideIcon := GTK.GdkPixbuf newFromFile: (VisualGST.GtkLauncher / 'Icons/override.png') file displayString error: nil ]
]
overrideIcon: aGdkPixbuf [
<category: '*VisualGST'>
OverrideIcon := aGdkPixbuf
]
overriddenIcon [
<category: '*VisualGST'>
^ OverriddenIcon ifNil: [ OverriddenIcon := GTK.GdkPixbuf newFromFile: (VisualGST.GtkLauncher / 'Icons/overridden.png') file displayString error: nil ]
]
overriddenIcon: aGdkPixbuf [
<category: '*VisualGST'>
OverriddenIcon := aGdkPixbuf
]
]
CompiledMethod extend [
override [
<category: '*VisualGST'>
self methodClass superclass ifNil: [ ^ false ].
^ (self methodClass superclass lookupSelector: self selector) isNil not
]
overridden [
<category: '*VisualGST'>
| set |
set := Set new.
set addAll: self methodClass subclasses.
set do: [ :each |
each methodDictionary ifNotNil: [ :dic | dic at: self selector ifPresent: [ :mth | ^ true ] ] ].
^ false
]
methodViewIcon [
<category: '*VisualGST'>
self methodCategory first = $* ifTrue: [ ^ self class extensionIcon ].
self overridden ifTrue: [ ^ self class overriddenIcon ].
self override ifTrue: [ ^ self class overrideIcon ].
^ nil
]
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkCompiledMethodInspectorView
]
]
CompiledBlock extend [
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkCompiledBlockInspectorView
]
methodRecompilationSourceString [
<category: '*VisualGST'>
^ self method methodRecompilationSourceString
]
]
SequenceableCollection extend [
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkSequenceableCollectionInspectorView
]
]
Set extend [
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkSetInspectorView
]
]
Dictionary extend [
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkDictionaryInspectorView
]
]
Character extend [
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkCharacterInspectorView
]
]
Integer extend [
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkIntegerInspectorView
]
]
Float extend [
inspectorView [
<category: '*VisualGST'>
^ VisualGST.GtkFloatInspectorView
]
]
Symbol extend [
hasLiterals [
<category: '*VisualGST'>
^ true
]
symbolFromliterals [
<category: '*VisualGST'>
^ {self}
]
]
Array extend [
hasLiterals [
<category: '*VisualGST'>
self do: [ :each |
each hasLiterals ifTrue: [ ^ true ] ].
^ false
]
symbolFromliterals [
<category: '*VisualGST'>
| result |
result := OrderedCollection new.
self do: [ :each |
each hasLiterals ifTrue: [ result add: each symbolFromliterals first ] ].
^ result
]
]
Class extend [
subclass: classNameString environment: aNamespace [
<category: '*VisualGST'>
"Define a subclass of the receiver with the given name. If the class
is already defined, don't modify its instance or class variables
but still, if necessary, recompile everything needed."
| meta |
KernelInitialized ifFalse: [^Smalltalk at: classNameString].
meta := self metaclassFor: classNameString.
^ meta
name: classNameString
environment: aNamespace
subclassOf: self
]
]
CompiledCode extend [
hasLiterals [
<category: '*VisualGST'>
^ self literals isEmpty not
]
isSendingWithSpecialSelector: aByteCode [
<category: '*VisualGST'>
^ aByteCode <= 31
]
specialSelectorSended: aByteCode and: anOperand [
<category: '*VisualGST'>
(self isSendingWithSpecialSelector: aByteCode) ifFalse: [ ^ self error: 'bad byte code' ].
aByteCode <= 26 ifTrue: [ ^ self class specialSelectors at: aByteCode + 1 ].
(aByteCode = 30 or: [ aByteCode = 31 ]) ifTrue: [ ^ self class specialSelectors at: anOperand + 1 ].
]
extractSpecialSelectors [
<category: '*VisualGST'>
| result |
result := Set new.
self allByteCodeIndicesDo: [ :i :bytecode :operand |
(self isSendingWithSpecialSelector: bytecode) ifTrue: [
result add: (self specialSelectorSended: bytecode and: operand) ] ].
^ result
]
literalsAndSpecialSelectors [
<category: '*VisualGST'>
"Answer whether the receiver refers to the given object"
| result |
result := Set new.
self literalsDo: [ :each |
each hasLiterals ifTrue: [ result addAll: each symbolFromliterals ] ].
^ result + self extractSpecialSelectors
]
literalsAndSpecialSelectorsDo: aOneArgBlock [
<category: '*VisualGST'>
self literalsAndSpecialSelectors do: aOneArgBlock
]
]
CompiledBlock extend [
symbolFromliterals [
<category: '*VisualGST'>
^ self extractSpecialSelectors
]
]
MethodContext extend [
variables [
<category: '*VisualGST'>
| variables method |
method := self method method parserClass parseMethod: self method method methodSourceString onError: [ :aString :position | ^ variables:= #() ].
(variables := method argumentNames asOrderedCollection) addAll: method body temporaryNames.
^ variables
]
]
BlockContext extend [
variables [
<category: '*VisualGST'>
| variables method |
method := self method method parserClass parseMethod: self method method methodSourceString.
variables := method argumentNames, method body temporaryNames.
^ variables
]
]
ContextPart extend [
parentContextAt: anInteger [
<category: '*VisualGST'>
| ctxt i |
anInteger <= 0 ifTrue: [ self error: 'Error indice <= 0' ].
self parentContext ifNil: [ self error: 'Error indice too high' ].
anInteger = 1 ifTrue: [ ^ self ].
i := 2.
ctxt := self parentContext.
[ i < anInteger and: [ ctxt parentContext isNil not ] ] whileTrue: [
ctxt := ctxt parentContext.
i := i + 1 ].
^ i = anInteger
ifTrue: [ ctxt ]
ifFalse: [ self error: 'Error indice too high' ]
]
variables [
<category: '*VisualGST'>
^ 1 to: self numArgs + self numTemps collect: [ :each |
each displayString ]
]
variablesDo: aBlock [
<category: '*VisualGST'>
^ self variables do: aBlock
]
stackInspectorView [
<category: '*VisualGST'>
^ GtkStackInspectorView
]
]
Debugger extend [
receiver [
<category: '*VisualGST'>
^ self suspendedContext receiver
]
myStepInto [
"Run to the end of the current line in the inferior process or to the
next message send."
"TODO: Stop when affectation (get the current bytecode)"
<category: '*VisualGST'>
| context |
context := self suspendedContext.
[ self stepBytecode.
self suspendedContext == context ]
whileTrue
]
myStep [
"Run to the end of the current line in the inferior process, skipping
over message sends."
"TODO: Stop when affectation (get the current bytecode)"
<category: '*VisualGST'>
| context |
context := self suspendedContext.
[ self stepBytecode.
(self suspendedContext notNil and: [ self suspendedContext parentContext == context ])
ifTrue: [ self finish: self suspendedContext. ^ self ].
self suspendedContext == context ]
whileTrue
]
]
Behavior extend [
debuggerClass [
<category: '*VisualGST'>
"^ nil"
^ VisualGST.GtkDebugger
]
]
VariableBinding extend [
hasLiterals [
<category: '*VisualGST'>
^ true
]
symbolFromliterals [
<category: '*VisualGST'>
^ {self key}
]
]
GTK.GtkButton class extend [
createButton: aStockId [
<category: 'instance creation'>
| image |
image := GTK.GtkImage newFromStock: aStockId size: GTK.Gtk gtkIconSizeMenu.
^ (GTK.GtkButton new)
setImage: image;
setRelief: GTK.Gtk gtkReliefNone;
yourself
]
closeButton [
<category: 'instance creation'>
^ self createButton: GTK.Gtk gtkStockClose
]
previousButton [
<category: 'instance creation'>
^ self createButton: GTK.Gtk gtkStockGoBack
]
nextButton [
<category: 'instance creation'>
^ self createButton: GTK.Gtk gtkStockGoForward
]
replaceButton [
<category: 'instance creation'>
^ self createButton: GTK.Gtk gtkStockFindAndReplace
]
]
Metaclass extend [
displaySymbol [
<category: '*VisualGST'>
^ self instanceClass name
]
]
AbstractNamespace extend [
displaySymbol [
<category: '*VisualGST'>
^ self displayString asSymbol
]
]
Symbol extend [
displaySymbol [
<category: '*VisualGST'>
^ self
]
]
CharacterArray extend [
deindexOf: aCharacterArray matchCase: aBoolean startingAt: anIndex [
"Answer an Interval of indices in the receiver which match the aCharacterArray
pattern. # in aCharacterArray means 'match any character', * in aCharacterArray means
'match any sequence of characters'. The first item of the returned interval
is >= anIndex. If aBoolean is false, the search is case-insensitive,
else it is case-sensitive. If no Interval matches the pattern, answer nil."
<category: '*VisualGST'>
| result |
aBoolean
ifFalse:
[ ^ self asLowercase
deindexOf: aCharacterArray asLowercase
matchCase: true
startingAt: anIndex ].
1 to: anIndex do:
[ :i |
result := aCharacterArray
matchSubstring: 1
in: self
at: anIndex - i + 1.
result notNil ifTrue: [ ^ anIndex - i + 1 to: result ] ].
^ nil
]
]
STInST.RBParser class extend [
selectedSymbol: aString [
<category: '*VisualGST'>
| stream parser node |
stream := aString readStream.
parser := STInST.RBBracketedMethodParser new.
parser errorBlock: [ :message :position | ^ nil ].
parser scanner: (parser scannerClass on: stream errorBlock: parser errorBlock).
node := parser parseExpression.
node := node bestNodeFor: (1 to: aString size).
[ node isNil ifTrue: [ ^ nil ].
node isMessage] whileFalse: [ node := node parent ].
^ node selector
]
]
GTK.GtkTreeModel class extend [
createModelWith: anArray [
<category: '*VisualGST'>
| model |
model := OrderedCollection new.
anArray do: [ :each | model addAll: (each collect: [ :elem | elem kind ]) ].
model addLast: VisualGST.GtkColumnOOPType kind.
^ self new: model size varargs: model asArray
]
]
GTK.GtkListStore class extend [
createModelWith: anArray [
<category: '*VisualGST'>
| model |
model := OrderedCollection new.
anArray do: [ :each | model addAll: (each collect: [ :elem | elem kind ]) ].
model addLast: VisualGST.GtkColumnOOPType kind.
^ self new: model size varargs: model asArray
]
]
GTK.GtkTreeStore class extend [
createModelWith: anArray [
<category: '*VisualGST'>
| model |
model := OrderedCollection new.
anArray do: [ :each | model addAll: (each collect: [ :elem | elem kind ]) ].
model addLast: VisualGST.GtkColumnOOPType kind.
^ self new: model size varargs: model asArray
]
]
GTK.GtkTreeView class extend [
createModel: aGtkStoreClass with: anArray [
<category: '*VisualGST'>
^ self newWithModel: (aGtkStoreClass createModelWith: anArray)
]
createTreeViewWith: anArray [
<category: '*VisualGST'>
^ self createModel: GtkTreeStore with: anArray
]
createListViewWith: anArray [
<category: '*VisualGST'>
^ self createModel: GtkListStore with: anArray
]
createColumnsOn: aGtkTreeView with: anArray [
<category: '*VisualGST'>
| colView i render |
i := 0.
anArray do: [ :each |
colView := GtkTreeViewColumn new.
each do: [ :column |
column isVisible ifTrue: [
colView
packStart: (render := column cellRenderer new) expand: false;
addAttribute: render attribute: column kindName column: i.
column hasTitle ifTrue: [ colView setTitle: column title ].
i := i + 1 ] ].
aGtkTreeView insertColumn: colView position: -1 ]
]
createListWithModel: anArray [
<category: '*VisualGST'>
| view |
view := self createListViewWith: anArray.
self createColumnsOn: view with: anArray.
^ view
]
createTreeWithModel: anArray [
<category: '*VisualGST'>
| view |
view := self createTreeViewWith: anArray.
self createColumnsOn: view with: anArray.
^ view
]
]
GTK.GtkTreeView extend [
| model |
model: aGtkModel [
<category: 'accessing'>
model := aGtkModel
]
model [
<category: 'accessing'>
^ model
]
selection [
<category: 'accessing'>
| iter string |
(iter := self selectedIter) ifNil: [ ^ self error: 'nothing is selected' ].
^ (self getModel at: iter) last
]
selections [
<category: 'accessing'>
| glist result |
result := OrderedCollection new.
(glist := self getSelection getSelectedRows: nil) ifNil: [ ^ result ].
glist do: [ :each | | iter path |
path := each castTo: GTK.GtkTreePath type.
iter := self getModel getIter: path.
result add: ((self getModel at: iter) last) ].
^ result
]
select: anObject [
<category: 'accessing'>
self getSelection unselectAll.
self getModel do: [ :elem :iter |
elem last = anObject ifTrue: [
self scrollToCell: (self getModel getPath: iter) column: nil useAlign: false rowAlign: 0.5 colAlign: 0.5.
^ self getSelection selectIter: iter ] ].
]
selectNth: anInteger [
<category: 'accessing'>
| path iter |
self getSelection unselectAll.
anInteger = 0 ifTrue: [^self].
path := GtkTreePath newFromIndices: {anInteger - 1. -1}.
(self getModel getIter: path) isNil ifTrue: [^self].
self scrollToCell: path column: nil useAlign: false rowAlign: 0.5 colAlign: 0.5.
self getSelection selectPath: path
]
selectFirstItem [
<category: 'accessing'>
| selection |
(selection := self getSelection) unselectAll.
selection unselectAll.
selection selectIter: self getModel getIterFirst
]
selectLastItem [
<category: 'accessing'>
| selection |
(selection := self getSelection) unselectAll.
selection unselectAll.
selection selectIter: self getModel getIterLast
]
]
GTK.GtkDialog extend [
showModal [
<category: '*VisualGST'>
self
setModal: true;
showAll
]
destroy: aGtkDialog [
<category: '*VisualGST'>
self destroy
]
showModalOnAnswer: aBlock [
<category: '*VisualGST'>
self
setModal: true;
connectSignal: 'response' to: aBlock selector: #cull:cull:;
showAll
]
showModalDestroy [
<category: '*VisualGST'>
self
setModal: true;
connectSignal: 'response' to: self selector: #destroy:;
showAll
]
showOnAnswer: aBlock [
<category: '*VisualGST'>
self
setModal: false;
connectSignal: 'response' to: aBlock selector: #cull:cull:;
showAll
]
]
GTK.GtkWidget extend [
getFocusChild [
<category: '*VisualGST'>
^nil
]
]
GTK.GtkPaned class extend [
addAll: anArray [
^ self addAll: anArray from: 1
]
addAll: anArray from: anInteger [
^ anArray size - anInteger = 0
ifTrue: [ self new
pack1: (anArray at: anInteger) resize: true shrink: true;
yourself ]
ifFalse: [
anArray size - anInteger > 1 ifTrue: [
self new
pack1: (anArray at: anInteger) resize: true shrink: true;
pack2: (self addAll: anArray from: anInteger + 1) resize: true shrink: false;
yourself ]
ifFalse: [ self new
pack1: (anArray at: anInteger) resize: true shrink: true;
pack2: (anArray at: anInteger + 1) resize: true shrink: false;
yourself ] ]
]
]
GTK.GtkScrolledWindow class extend [
withViewport: aGtkWidget [
<category: 'instance creation'>
^ (GTK.GtkScrolledWindow new: nil vadjustment: nil)
addWithViewport: aGtkWidget;
setPolicy: GTK.Gtk gtkPolicyAutomatic vscrollbarPolicy: GTK.Gtk gtkPolicyAutomatic;
yourself
]
]
Smalltalk.PackageLoader class extend [
root [
<category: 'accessing'>
^ root
]
]