/
RubSmalltalkEditor.class.st
1355 lines (1082 loc) · 39.3 KB
/
RubSmalltalkEditor.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
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
"
I am the editor for smalltalk code, I allow to browse, execute etc
"
Class {
#name : #RubSmalltalkEditor,
#superclass : #RubTextEditor,
#instVars : [
'selectorChooser',
'notificationStrategy',
'completionEngine'
],
#classVars : [
'CompletionEngine'
],
#category : #'Rubric-Editing-Code'
}
{ #category : #keymapping }
RubSmalltalkEditor class >> buildPatchShortcutsForDoItInWindowsOn: aBuilder [
"this is because for some reason Ctrl+d means Ctrl+end on Windows"
<keymap>
(aBuilder shortcut: #doItPatchForWindows)
category: RubSmalltalkEditor name
default: Character end ctrl win
do: [ :target | target editor doIt: nil ]
description: 'Do it'.
(aBuilder shortcut: #debugItPatchForWindows)
category: RubSmalltalkEditor name
default: Character end shift ctrl win
do: [ :target | target editor debugIt: nil ]
description: 'Debug it'
]
{ #category : #keymapping }
RubSmalltalkEditor class >> buildShortcutsOn: aBuilder [
"We are defining the bindings twice because we want to support
both Cmd and meta for Windows and Linux. This should happen at least as long as in the development environment
both of these are supported.
We list both variations explicitly because we want to be able to see the action code when inspecting the morph.
"
<keymap>
(aBuilder shortcut: #querySymbol)
category: RubSmalltalkEditor name
default: $q meta
do: [ :target | target editor querySymbol: nil ]
description: 'Query symbol'.
(aBuilder shortcut: #browseIt)
category: RubSmalltalkEditor name
default: $b meta
do: [ :target | target editor browseIt: nil ]
description: 'Browse'.
(aBuilder shortcut: #doIt)
category: RubSmalltalkEditor name
default: $d meta
do: [ :target | target editor doIt: nil ]
description: 'Do it'.
(aBuilder shortcut: #inspectIt)
category: RubSmalltalkEditor name
default: $i meta
do: [ :target | target editor inspectIt: nil ]
description: 'Inspect it'.
(aBuilder shortcut: #basicInspectIt)
category: RubSmalltalkEditor name
default: $i meta shift
do: [ :target | target editor basicInspectIt ]
description: 'Basic Inspect it'.
(aBuilder shortcut: #implementorsOfIt)
category: RubSmalltalkEditor name
default: $m meta
do: [ :target | target editor implementorsOfIt: nil ]
description: 'Implementors of it'.
(aBuilder shortcut: #senderOfIt)
category: RubSmalltalkEditor name
default: $n meta
do: [ :target | target editor sendersOfIt: nil ]
description: 'Senders of it'.
(aBuilder shortcut: #printIt)
category: RubSmalltalkEditor name
default: $p meta
do: [ :target | target editor printIt ]
description: 'Print it'.
(aBuilder shortcut: #debugIt)
category: RubSmalltalkEditor name
default: $d meta shift
do: [ :target | target editor debugIt: nil ]
description: 'Debug it'.
(aBuilder shortcut: #referencesToIt)
category: RubSmalltalkEditor name
default: $n meta shift
do: [ :target | target editor referencesToIt: nil ]
description: 'References to it'.
(aBuilder shortcut: #methodStringsContainingIt)
category: RubSmalltalkEditor name
default: $e meta shift
do: [ :target | target editor methodStringsContainingIt: nil ]
description: 'Method strings containing it'.
(aBuilder shortcut: #format)
category: RubSmalltalkEditor name
default: PharoShortcuts current formatCodeShortcut
do: [ :target | target formatMethodCode ].
(aBuilder shortcut: #jumpToNextKeywordOfIt)
category: RubSmalltalkEditor name
default: $j meta
do: [ :target | target editor jumpToNextKeywordOfIt: true ]
description: 'Jump to next keyword'.
(aBuilder shortcut: #jumpToNextKeywordOfIt)
category: RubSmalltalkEditor name
default: $j shift meta
do: [ :target | target editor jumpToNextKeywordOfIt: false ]
description: 'Jump to previous keyword'.
(aBuilder shortcut: #widenSelectionOfIt)
category: RubSmalltalkEditor name
default: $2 meta
do: [ :target | target editor widenSelectionOfIt ]
description: 'Widen selection'.
]
{ #category : #'completion engine' }
RubSmalltalkEditor class >> completionEngine [
^ CompletionEngine
]
{ #category : #'completion engine' }
RubSmalltalkEditor class >> completionEngine: anEngine [
CompletionEngine := anEngine
]
{ #category : #'completion engine' }
RubSmalltalkEditor class >> noCompletion [
CompletionEngine := nil
]
{ #category : #'completion engine' }
RubSmalltalkEditor >> atCompletionPosition [
"Return true if the cursor is at a possible completion position"
| cursorPosition |
cursorPosition := self startIndex.
cursorPosition < 2 ifTrue: [ ^ false ].
^ (self text at: cursorPosition - 1) isCompletionCharacter
]
{ #category : #'do-its' }
RubSmalltalkEditor >> basicInspectIt [
self evaluateSelectionAndDo: [:result | result basicInspect]
]
{ #category : #'source navigation' }
RubSmalltalkEditor >> bestNodeInString: source at: selectionInterval edittingMode: aRubEdittingMode shouldFavourExpressions: isFavouringExpressions onError: aBlock [
"Find the best node in the source text in the identified selection area"
| ast node start stop |
source ifEmpty: aBlock.
start := selectionInterval first min: source size.
stop := selectionInterval last min: source size.
ast := aRubEdittingMode parseSource: source.
ast ifNotNil: [
"If there is no text selection"
(selectionInterval isEmpty and: [ isFavouringExpressions and: [
(source at: (stop + 1 min: source size)) isAlphaNumeric not ]]) ifTrue: [
"If there is white space or statement terminator, try to backup to find a better node"
[stop > 0 and: [('.;' includes: (source at: stop)) or: [(source at: stop) isSeparator ]]]
whileTrue: [ start := stop := stop - 1 ].
start := stop].
node := ast bestNodeFor: (start to: stop).
node ifNil: [
node := RBParseErrorNodeVisitor
visit: ast
detect: [ :n | n intersectsInterval: (start to: start)]
ifNone: [ ^aBlock value ]].
node isFaulty ifTrue: [
node allChildren size = 1 ifTrue: [
(aRubEdittingMode parseExpression: (node value padLeftTo: source size))
ifNil: [ ^node ]
ifNotNil: [ :newNode |
ast replaceNode: node withNode: newNode.
node := newNode ].
].
node := RBGenericNodeVisitor
visit: node
detect: [ :n | n intersectsInterval: (start to: start) ]
ifNone: [ node ] ] ].
^node
]
{ #category : #'source navigation' }
RubSmalltalkEditor >> bestNodeInTextArea [
"Find the best node in the editor text area at the current pointer location"
| node start stop |
start := self textArea startIndex.
stop := self textArea stopIndex.
[node := RBParser parseMethod: self textArea string onError: [
RBParser parseFaultyExpression: self textArea string]
] on: Error do: [^nil].
^node bestNodeFor: (start to: stop).
]
{ #category : #'source navigation' }
RubSmalltalkEditor >> bestNodeInTextAreaOnError: aBlock [
"Find the best node in the editor text area at the current pointer location"
| start stop source |
start := self textArea startIndex.
stop := self textArea stopIndex.
source := self textArea string.
^ self
bestNodeInString: source
at: (start to: stop)
edittingMode: self editingMode
shouldFavourExpressions: true
onError: aBlock
]
{ #category : #binding }
RubSmalltalkEditor >> bindingOf: aString [
^ self textArea bindingOf: aString
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> browseClassFrom: aClassString [
"Launch a hierarchy browser for the class indicated by the current selection. If multiple classes matching the selection exist, let the user choose among them."
| selectedClass |
"self lineSelectAndEmptyCheck: [ ^ self ]."
(aClassString isNil or: [ aClassString isEmpty]) ifTrue: [
textArea flash.
^self ].
selectedClass := self model systemNavigation
classFromPattern: aClassString
withCaption: 'choose a class to browse...'.
selectedClass isNil
ifTrue: [ ^ self internalCallToImplementorsOf: aClassString ].
Smalltalk tools browser openOnClass: selectedClass
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> browseClassFromIt [
"Launch a hierarchy browser for the class indicated by the current selection. If multiple classes matching the selection exist, let the user choose among them."
"self lineSelectAndEmptyCheck: [^ self]."
self browseClassFrom: self findClassFromAST
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> browseIt [
"Launch a browser for the current selection, if appropriate"
^ self browseClassFromIt
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> browseIt: t1 [
self browseIt.
^ true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> classCommentsContainingIt [
"Open a browser class comments which contain the current selection somewhere in them."
self lineSelectAndEmptyCheck: [^ self].
self model systemNavigation browseClassCommentsWithString: self selection string matchCase: false.
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> classNamesContainingIt [
"Open a browser on classes whose names contain the selected string"
self lineSelectAndEmptyCheck: [^self].
self model systemNavigation
browseClassesWithNamesContaining: self selection string
caseSensitive: Sensor shiftPressed
]
{ #category : #events }
RubSmalltalkEditor >> click: anEvent [
self selectorChooserClose.
^ super click: anEvent
]
{ #category : #'do-its' }
RubSmalltalkEditor >> compile: aStream for: anObject in: evalContext [
| methodClass |
methodClass := evalContext
ifNil: [ anObject class ]
ifNotNil: [ evalContext methodClass ].
^self class compiler
source: aStream;
class: methodClass;
context: evalContext;
requestor: self morph;
noPattern: true;
failBlock: [ ^ nil ];
compile
]
{ #category : #'do-its' }
RubSmalltalkEditor >> compileSelectionFor: anObject in: evalContext [
^ self compile: self selectionAsStream for: anObject in: evalContext
]
{ #category : #'completion engine' }
RubSmalltalkEditor >> completionAround: aBlock keyStroke: anEvent [
"I'm a editor for Smalltalk, so, ok do completion around"
self isCompletionEnabled
ifTrue: [ self completionEngine
codeCompletionAround: aBlock
textMorph: textArea
keyStroke: anEvent
]
]
{ #category : #'completion engine' }
RubSmalltalkEditor >> completionEngine [
^ completionEngine
]
{ #category : #'completion engine' }
RubSmalltalkEditor >> completionEngine: aCompletionEngine [
completionEngine := aCompletionEngine.
self textArea setCompletionEngine: aCompletionEngine.
]
{ #category : #'new selection' }
RubSmalltalkEditor >> computeSelectionIntervalForCurrentLine [
| i left right s quoteCounter|
s := self string.
i := s encompassParagraph: self selectionInterval.
left := i first.
right := i last.
"we need to skip all text that is inside of quote pairs"
quoteCounter := 0.
[ left <= right and: [ (s at: left) = $"
or: [ quoteCounter % 2 = 1
or: [(s at: left) isSeparator] ] ] ]
whileTrue: [
(s at: left) = $" ifTrue: [ quoteCounter := quoteCounter + 1 ].
left := left + 1 ].
quoteCounter := 0.
[ left <= right and: [ ((s at: right) = $"
"we need to stop if quote is defined as character"
and: [ right - 1 < 1 or: [ (s at: right - 1) ~= $$ ] ])
or: [ quoteCounter % 2 = 1 or: [(s at: right) isSeparator] ] ] ]
whileTrue: [
(s at: right) = $" ifTrue: [ quoteCounter := quoteCounter + 1 ].
right := right - 1 ].
^ left to: right
]
{ #category : #private }
RubSmalltalkEditor >> computeSelectionIntervalFromCodeIn: aString at: anInterval [
^ (RBParser parseExpression: (aString copyFrom: anInterval first to: anInterval last)) sourceInterval
]
{ #category : #private }
RubSmalltalkEditor >> computeSelectionIntervalFromCommentIn: aString at: anInterval [
| comment commentInterval |
comment := (RBScanner on: (aString copyFrom: anInterval first to: anInterval last) readStream) getComments.
comment ifNil: [ ^ 0 to: -1 ].
commentInterval := comment first.
^ commentInterval first + 1 to: commentInterval last - 1
]
{ #category : #'do-its' }
RubSmalltalkEditor >> debug: aStream [
| method receiver context |
(self model respondsTo: #doItReceiver)
ifTrue:
[receiver := self model doItReceiver.
context := self model doItContext]
ifFalse:
[receiver := context := nil].
method := self compile: aStream for: receiver in: context.
method isReturnSpecial ifTrue:[ self inform:'Nothing to debug, the expression is optimized'. ^self.].
method notNil ifTrue: [
self debug: method receiver: receiver in: context ].
]
{ #category : #'do-its' }
RubSmalltalkEditor >> debug: aCompiledMethod receiver: anObject in: evalContext [
| guineaPig context debugSession |
guineaPig := [ aCompiledMethod
valueWithReceiver: anObject
arguments: (evalContext ifNil: [ #() ] ifNotNil: [ {evalContext} ]) ]
newProcess.
context := guineaPig suspendedContext.
debugSession := guineaPig newDebugSessionNamed: 'debug it' startedAt: context.
debugSession stepIntoUntil: [:currentContext |
currentContext method == aCompiledMethod ].
Smalltalk tools debugger openOn: debugSession withFullView: true.
]
{ #category : #'do-its' }
RubSmalltalkEditor >> debugHighlight [
"Treat the current highlight as an expression; evaluate and debugg it in a new debugger."
self highlightAndEmptyCheck: [ ^ self ].
self debug: self highlightedTextAsStream
]
{ #category : #'do-its' }
RubSmalltalkEditor >> debugIt [
^ self debugSelection
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> debugIt: aKeyboardEvent [
"Evaluate the current selection in the Debugger."
self debugIt.
^ true
]
{ #category : #'do-its' }
RubSmalltalkEditor >> debugSelection [
"Treat the current selection as an expression; evaluate and debugg it in a new debugger."
self lineSelectAndEmptyCheck: [^self].
self debug: self selectionAsStream
]
{ #category : #'typing/selecting keys' }
RubSmalltalkEditor >> displayIfFalse: aKeyboardEvent [
"Replace the current text selection with the text 'ifFalse:'--initiated by
ctrl-f."
self addString: 'ifFalse:'.
^false
]
{ #category : #'typing/selecting keys' }
RubSmalltalkEditor >> displayIfTrue: aKeyboardEvent [
"Replace the current text selection with the text 'ifTrue:'--initiated by
ctrl-t."
self addString: 'ifTrue:'.
^false
]
{ #category : #'do-its' }
RubSmalltalkEditor >> doIt [
"Set the context to include pool vars of the model. Then evaluate."
^ self evaluateSelection
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> doIt: aKeyboardEvent [
"Called when user hits cmd-d. Select the current line, if relevant, then evaluate and execute. 2/1/96 sw.
2/29/96 sw: don't call selectLine; it's done by doIt now"
self doIt.
^ true
]
{ #category : #private }
RubSmalltalkEditor >> editingMode [
^self textArea editingMode
]
{ #category : #'do-its' }
RubSmalltalkEditor >> evaluate: aStream andDo: aBlock [
"Treat the current selection as an expression; evaluate it and invoke aBlock with the result."
| result rcvr ctxt |
(self model respondsTo: #doItReceiver)
ifTrue: [ rcvr := self model doItReceiver.
ctxt := self model doItContext]
ifFalse: [ rcvr := ctxt := nil].
result := rcvr class compiler
source: aStream;
context: ctxt;
receiver: rcvr;
requestor: self morph "don't set it to self.. The receiver can be destroyed as a result of evaluateSelection";
failBlock: [self morph flash. ^ nil];
evaluate.
^ aBlock value: result
]
{ #category : #'do-its' }
RubSmalltalkEditor >> evaluateSelection [
"Treat the current selection as an expression; evaluate it and return the result"
^self evaluateSelectionAndDo: [:result | result]
]
{ #category : #'do-its' }
RubSmalltalkEditor >> evaluateSelectionAndDo: aBlock [
"Treat the current selection as an expression; evaluate it and invoke aBlock with the result.
If no selection is present select the current line."
self lineSelectAndEmptyCheck: [^ ''].
^ self
evaluate: self selectionForDoitAsStream
andDo: aBlock
]
{ #category : #'do-its' }
RubSmalltalkEditor >> exploreIt [
self evaluateSelectionAndDo: [:result | result inspect]
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> exploreIt: aKeyboardEvent [
"Explore the selection -- invoked via cmd-shift-I. If there is no current selection, use the current line."
self exploreIt.
^ true
]
{ #category : #'source navigation' }
RubSmalltalkEditor >> findClassFromAST [
"Try to make a class name out of the current text selection"
| node fallbackBlock className |
"Preserve original behavior - although could consider building AST from selection"
self hasSelection ifTrue: [
^(self selection string copyWithoutAll: CharacterSet crlf) trimBoth ].
fallbackBlock := [^nil].
node := self bestNodeInTextAreaOnError: fallbackBlock.
[node isVariable] whileFalse: [
(node := node parent) ifNil: fallbackBlock ].
className := node name.
[ className first isUppercase ] whileFalse: [
(className := className allButFirst) ifEmpty: fallbackBlock ].
^className
]
{ #category : #'source navigation' }
RubSmalltalkEditor >> findNextKeywordIn: sourceCode selection: selectionInterval searchingForward: isFwd ifFound: textSelectionBlock [
"Find the next keyword/useful source location to then apply a @textSelectionBlock to.
Anser the result of the @textSelectionBlock"
| checkBlock ranges potentialLocation selectionEnd|
"match on typical locations you jump to in source to complete typing. We use regex to more
easily cope with broken source code (where its very handy to jump while fixing code) -
and get initial location hints which can then use an ast to infer on. It might be possible
to do this completely with the AST, but this was an easier starting point"
ranges := sourceCode allRangesOfRegexMatches:
'\S+\:\s|', "ifTrue1: I...."
'\:=\s*|', "x := Iself ..."
'\|\s*|', "[ :var | Iself...]"
'\:\S+|', "[ :varI :var2I | ..."
'\;\s+|', " self msg1; Imsg2...."
'\,\s*|', " 'string1', I'string 2'...."
'\)|', " 4 + 5)I ifTrue..."
'\]|', " true and: [ true ]I )..."
'\^\s*|', " ^ Iself"
'self\s+|', "self Imsg"
"Note sure if these ones cause over-jumping, so currently excluded"
"'\[\s*|'," "[ Iself msg1... ]"
"'\(\s*|'," "( I5 + 2..."
"Should insist on whitespace after a $. or do we want to jump between {1.2.3}?"
'\.\s+'. "self msg1. Iself msg2..."
selectionEnd := selectionInterval
ifEmpty: [selectionInterval first]
ifNotEmpty: [selectionInterval last].
isFwd
ifTrue: [ checkBlock := [ :match | match last > selectionEnd ] ]
ifFalse: [ ranges := ranges reversed.
checkBlock := [ :match | match last < (selectionEnd - 1) ] ].
ranges
do: [ :match |
(checkBlock value: match)
ifTrue: [
potentialLocation := match last.
self
findValidKeywordIn: sourceCode
at: potentialLocation
ifFound: [
^textSelectionBlock value: potentialLocation] ] ].
"If nothing found, then jump to end of any current selection"
selectionInterval isEmpty
ifTrue: [ textSelectionBlock value:
(isFwd ifTrue: [sourceCode size] ifFalse: [ 0 ]) ]
ifFalse: [ textSelectionBlock value: selectionEnd ]
]
{ #category : #'source navigation' }
RubSmalltalkEditor >> findSelectorFromAST [
"Try to make a selector out of the current text selection"
| node fallbackBlock |
fallbackBlock := [ ^ nil ].
node := self bestNodeInTextAreaOnError: fallbackBlock.
node isMethod ifFalse: [
(node isValue and: [ node value isSymbol ]) ifTrue: [ ^node value ].
[ node isMessage ] whileFalse: [
(node := node parent) ifNil: fallbackBlock ]].
^node selector
]
{ #category : #'source navigation' }
RubSmalltalkEditor >> findValidKeywordIn: sourceCode at: locationIndex ifFound: aBlock [
"find a valid keyword in the source, starting at @locationIndex. If a suitable node is found,
evaluate the Block"
| node validLocation locationInterval |
validLocation := true.
locationInterval := locationIndex to: locationIndex.
node := self
bestNodeInString: sourceCode
at: locationInterval
edittingMode: self editingMode
shouldFavourExpressions: false
onError: [ nil ].
node
ifNotNil: [
node isLiteralNode
ifTrue: [ validLocation := false ].
node nodesDo: [ :subNode |
subNode comments
detect: [ :c | c intersectsInterval: locationInterval ]
ifFound: [ validLocation := false ] ] ].
validLocation ifTrue: aBlock
]
{ #category : #private }
RubSmalltalkEditor >> focusChanged [
super focusChanged.
self selectorChooserFocusChange
]
{ #category : #'do-its' }
RubSmalltalkEditor >> format [
self model formatSourceCodeInView
]
{ #category : #'do-its' }
RubSmalltalkEditor >> highlightEvaluateAndDo: aBlock [
"Treat the current selection as an expression; evaluate it and invoke aBlock with the result."
self highlightAndEmptyCheck: [ ^ '' ].
^ self
evaluate: self highlightedTextAsStream
andDo: [:result | aBlock value: result]
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> implementorsOf: aSelector [
"Open an implementors browser on the given selector"
(self model systemNavigation allImplementorsOf: aSelector) isEmpty
ifTrue: [ self internalCallToBrowse: aSelector ]
ifFalse: [ self model interactionModel systemNavigation browseAllImplementorsOf: aSelector ]
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> implementorsOfIt [
"Open an implementors browser on the selected selector"
| aSelector |
"self lineSelectAndEmptyCheck: [^ self]."
(aSelector := self selectedSelector) ifNil: [^ textArea flash].
self implementorsOf: aSelector
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> implementorsOfIt: aKeyboardEvent [
"Triggered by Cmd-m; browse implementors of the selector represented by the current selection, if plausible. 2/1/96 sw"
self implementorsOfIt.
^ true
]
{ #category : #initialization }
RubSmalltalkEditor >> initialize [
super initialize.
notificationStrategy := RubTextInsertionStrategy new editor: self.
completionEngine := CompletionEngine.
"this way we can instance-based and shared completion between all the instances
of editor instances."
]
{ #category : #keymapping }
RubSmalltalkEditor >> initializeShortcuts: aKMDispatcher [
super initializeShortcuts: aKMDispatcher.
aKMDispatcher attachCategory: RubSmalltalkEditor name
]
{ #category : #'do-its' }
RubSmalltalkEditor >> inspectIt [
self evaluateSelectionAndDo: [:result | result inspect]
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> inspectIt: aKeyboardEvent [
"Inspect the selection -- invoked via cmd-i. If there is no current selection, use the current line. 1/17/96 sw
2/29/96 sw: don't call selectLine; it's done by inspectIt now"
self inspectIt.
^ true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> internalCallToBrowse: aSelector [
"Launch a browser for the class indicated by the given selector.
If multiple classes matching the selection exist, let the user choose among them."
| aClass |
aClass := self model systemNavigation
classFromPattern: aSelector
withCaption: 'choose a class to browse...'.
aClass ifNil: [^ self].
Smalltalk tools browser openOnClass: aClass
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> internalCallToImplementorsOf: aSelector [
"Open an implementors browser on the given selector"
(self model systemNavigation allImplementorsOf: aSelector) isEmpty
ifFalse: [ self model systemNavigation browseAllImplementorsOf: aSelector]
]
{ #category : #'completion engine' }
RubSmalltalkEditor >> isCompletionEnabled [
^ completionEngine isNotNil and: [ self editingMode isCompletionEnabled ]
]
{ #category : #testing }
RubSmalltalkEditor >> isSmalltalkEditor [
^ true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> jumpToNextKeywordOfIt [
"Jump to the next keyword after the cursor - this is for legacy support"
self jumpToNextKeywordOfIt: true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> jumpToNextKeywordOfIt: isForwardJump [
"Jump to the next/previous keyword after the cursor"
self
findNextKeywordIn: self textArea string
selection: self textArea selectionInterval
searchingForward: isForwardJump
ifFound: [ :foundIndex | self selectFrom: foundIndex + 1 to: foundIndex ]
]
{ #category : #'typing support' }
RubSmalltalkEditor >> keystroke: aKeyboardEvent [
self isCompletionEnabled
ifFalse: [ ^ super keystroke: aKeyboardEvent ].
self
completionAround: [
(self selectorChooserHandlesKeyboard: aKeyboardEvent)
ifFalse: [ super keystroke: aKeyboardEvent ].
self selectorChooserKeystroke: aKeyboardEvent ]
keyStroke: aKeyboardEvent
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> methodCaseSensitiveStringsContainingit [
"Open a browser on methods which contain the current selection as part of a string constant."
self lineSelectAndEmptyCheck: [^ self].
self model systemNavigation browseMethodsWithString: self selection string matchCase: true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> methodNamesContainingIt [
"Open a browser on methods names containing the selected string"
self lineSelectAndEmptyCheck: [ ^ self ].
Cursor wait
showWhile: [ self model interactionModel systemNavigation
browseMethodsWhoseNamesContain: self selection string trimBoth ]
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> methodNamesContainingIt: aKeyboardEvent [
"Browse methods whose selectors containing the selection in their names"
self methodNamesContainingIt.
^ true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> methodSourceContainingIt [
"Open a browser on methods which contain the current selection in their source (case-sensitive full-text search of source)."
self lineSelectAndEmptyCheck: [ ^ self ].
self model interactionModel systemNavigation
browseMethodsWithSourceString: self selection string
matchCase: false
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> methodStringsContainingIt: aKeyboardEvent [
"Invoked from cmd-E -- open a browser on all methods holding string constants containing it."
self methodStringsContainingit.
^ true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> methodStringsContainingit [
"Open a browser on methods which contain the current selection as part of a string constant."
self lineSelectAndEmptyCheck: [ ^ self ].
self model interactionModel systemNavigation
browseMethodsWithString: self selection string
matchCase: false
]
{ #category : #private }
RubSmalltalkEditor >> modelCurrentSelectedClass [
" ugly dispatch, but current Browser protocol names aren't really cool "
" for Nautilus ( and other tools), selectedClass sounds better, but I think it shouldn't be hardcoded "
" IT'S A TEMP SOLUTION -- BenjaminVanRyseghem 14/04/11"
" From now, all tools should use #selectedBehavior, waiting for a better solution - Thx Nice "
(self model interactionModel respondsTo: #selectedBehavior)
ifTrue: [^ self model interactionModel selectedBehavior ].
" old selectors in order of uses "
(self model respondsTo: #selectedClass)
ifTrue: [^ self model selectedClass ].
(self model respondsTo: #selectedClassOrMetaClass)
ifTrue: [ ^ self model selectedClassOrMetaClass ].
^ nil
]
{ #category : #'new selection' }
RubSmalltalkEditor >> nextTokenFrom: start direction: dir [
"simple token-finder for compiler automated corrections"
| loc str |
loc := start + dir.
str := self string.
[(loc between: 1 and: str size) and: [(str at: loc) isSeparator]]
whileTrue: [loc := loc + dir].
^ loc
]
{ #category : #accessing }
RubSmalltalkEditor >> notificationStrategy [
^ notificationStrategy
]
{ #category : #accessing }
RubSmalltalkEditor >> notificationStrategy: aStrategy [
notificationStrategy := aStrategy.
aStrategy editor: self
]
{ #category : #'new selection' }
RubSmalltalkEditor >> notify: aString at: anInteger in: aStream [
^ self notificationStrategy
notify: aString
at: anInteger
in: aStream
]
{ #category : #'editing keys' }
RubSmalltalkEditor >> pasteInitials: aKeyboardEvent [
"Replace the current text selection by an authorship name/date stamp; invoked by cmd-shift-v, easy way to put an authorship stamp in the comments of an editor."
self closeTypeIn.
self replace: self selectionInterval with: (Text fromString: Author changeStamp) and: [self selectAt: self stopIndex].
^ true
]
{ #category : #'do-its' }
RubSmalltalkEditor >> printIt [
"Treat the current text selection as an expression; evaluate it. Insert the
description of the result of evaluation after the selection and then make
this description the new text selection."
| printString |
self
evaluateSelectionAndDo: [ :result |
printString := [ result printString ]
on: Error
do: [ '<error in printString: try ''Inspect it'' to debug>' ].
self afterSelectionInsertAndSelect: printString ]
]
{ #category : #'basic-completion' }
RubSmalltalkEditor >> querySymbol [
self selectorChooseQuerySymbol
]
{ #category : #'typing/selecting keys' }
RubSmalltalkEditor >> querySymbol: aKeyboardEvent [
"Invoked by Ctrl-q to query the Symbol table and display alternate symbols.
See comment in completeSymbol:lastOffering: for details."
self closeTypeIn.
self selectorChooserClose.
self querySymbol.
^true
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> referencesTo: aVariableOrClassName [
"Open a references browser on the given symbol"
| env ref |
" ugly dispatch, but current Browser protocol names aren't really cool "
env := self modelCurrentSelectedClass ifNil: [ Smalltalk globals ].
env isBehavior ifTrue: [
(env hasSlotNamed: aVariableOrClassName) ifTrue: [
^ self systemNavigation browseAllAccessesTo: aVariableOrClassName from: env]].
ref:= (env bindingOf: aVariableOrClassName) ifNil: [ ^ self ].
self systemNavigation browseAllSendersOf: ref
]
{ #category : #'menu messages' }
RubSmalltalkEditor >> referencesToIt [