/
PluggableListMorph.class.st
1767 lines (1412 loc) · 49.2 KB
/
PluggableListMorph.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
"
...
When a PluggableListMorph is in focus, type in a letter (or several
letters quickly) to go to the next item that begins with that letter.
Special keys (up, down, home, etc.) are also supported.
"
Class {
#name : #PluggableListMorph,
#superclass : #ScrollPane,
#instVars : [
'list',
'getListSelector',
'getListSizeSelector',
'getListElementSelector',
'getIndexSelector',
'setIndexSelector',
'keystrokeActionSelector',
'autoDeselect',
'lastKeystrokeTime',
'lastKeystrokes',
'doubleClickSelector',
'handlesBasicKeys',
'potentialDropRow',
'listMorph',
'hScrollRangeCache',
'dragItemSelector',
'dropItemSelector',
'wantsDropSelector',
'wrapSelector',
'searchedElement',
'multipleSelection',
'dragOnOrOff',
'setSelectionListSelector',
'getSelectionListSelector',
'resetListSelector',
'keystrokeSelector',
'backgroundColoringBlockOrSelector',
'separatorBlockOrSelector',
'separatorSize',
'separatorColor',
'lastNonZeroIndex',
'canMove',
'selectionColor',
'selectionColorToUse',
'enabled',
'getEnabledSelector'
],
#category : #'Morphic-Widgets-Pluggable-Lists'
}
{ #category : #'instance creation' }
PluggableListMorph class >> on: anObject list: listSel primarySelection: getSelectionSel changePrimarySelection: setSelectionSel listSelection: getListSel changeListSelection: setListSel menu: getMenuSel [
^ self new
on: anObject
list: listSel
primarySelection: getSelectionSel
changePrimarySelection: setSelectionSel
listSelection: getListSel
changeListSelection: setListSel
menu: getMenuSel
keystroke: #arrowKey:from: "default"
]
{ #category : #'instance creation' }
PluggableListMorph class >> on: anObject list: listSel primarySelection: getSelectionSel changePrimarySelection: setSelectionSel listSelection: getListSel changeListSelection: setListSel menu: getMenuSel keystroke: keyActionSel [
^ self new
on: anObject
list: listSel
primarySelection: getSelectionSel
changePrimarySelection: setSelectionSel
listSelection: getListSel
changeListSelection: setListSel
menu: getMenuSel
keystroke: keyActionSel
]
{ #category : #'instance creation' }
PluggableListMorph class >> on: anObject list: getListSel selected: getSelectionSel changeSelected: setSelectionSel [
"Create a 'pluggable' list view on the given model parameterized by the given message selectors."
^ self new
on: anObject
list: getListSel
selected: getSelectionSel
changeSelected: setSelectionSel
menu: nil
keystroke: #arrowKey:from: "default"
]
{ #category : #'instance creation' }
PluggableListMorph class >> on: anObject list: getListSel selected: getSelectionSel changeSelected: setSelectionSel menu: getMenuSel [
"Create a 'pluggable' list view on the given model parameterized by the given message selectors."
^ self new
on: anObject
list: getListSel
selected: getSelectionSel
changeSelected: setSelectionSel
menu: getMenuSel
keystroke: #arrowKey:from: "default"
]
{ #category : #'instance creation' }
PluggableListMorph class >> on: anObject list: getListSel selected: getSelectionSel changeSelected: setSelectionSel menu: getMenuSel keystroke: keyActionSel [
"Create a 'pluggable' list view on the given model parameterized by the given message selectors."
^ self new
on: anObject
list: getListSel
selected: getSelectionSel
changeSelected: setSelectionSel
menu: getMenuSel
keystroke: keyActionSel
]
{ #category : #'drag and drop' }
PluggableListMorph >> acceptDroppingMorph: aMorph event: evt [
"This message is sent when a morph is dropped onto a morph that has
agreed to accept the dropped morph by responding 'true' to the
wantsDroppedMorph:Event: message. The default implementation just
adds the given morph to the receiver."
"Here we let the model do its work."
dropItemSelector
ifNotNil: [| item |
dropItemSelector ifNil:[^self].
item := aMorph passenger.
model perform: dropItemSelector with: item with: potentialDropRow ]
ifNil: [
self model
acceptDroppingMorph: aMorph
event: evt
inMorph: self ].
self resetPotentialDropRow.
evt hand releaseMouseFocus: self.
Cursor normal show.
]
{ #category : #menus }
PluggableListMorph >> addCustomMenuItems: aMenu hand: aHandMorph [
"Add halo menu items to be handled by the invoking hand. The halo menu is invoked by clicking on the menu-handle of the receiver's halo."
super addCustomMenuItems: aMenu hand: aHandMorph.
aMenu addLine.
aMenu add: 'list font...' target: self selector: #setListFont.
aMenu add: 'copy list to clipboard' target: self selector: #copyListToClipboard.
aMenu add: 'copy selection to clipboard' target: self selector: #copySelectionToClipboard
]
{ #category : #drawing }
PluggableListMorph >> adoptPaneColor: paneColor [
"Pass on to the border too."
super adoptPaneColor: paneColor.
paneColor ifNil: [^self].
self selectionColor: self selectionColor.
self fillStyle: self fillStyleToUse.
self borderWidth > 0 ifTrue: [
self borderStyle: self borderStyleToUse]
]
{ #category : #'submorphs-accessing' }
PluggableListMorph >> allSubmorphNamesDo: nameBlock [
"Assume list morphs do not have named parts -- saves MUCH time"
^ self
]
{ #category : #accessing }
PluggableListMorph >> autoDeselect [
^ autoDeselect
ifNil: [ self resetListSelector notNil ]
ifNotNil: [ autoDeselect ]
]
{ #category : #initialization }
PluggableListMorph >> autoDeselect: trueOrFalse [
"Enable/disable autoDeselect (see class comment)"
autoDeselect := trueOrFalse.
]
{ #category : #'background coloring' }
PluggableListMorph >> backgroundColorFor: aRow [
| return |
aRow ifNil: [ ^ nil ].
self enabled
ifFalse: [ return := Color white darker darker ].
self backgroundColoringBlockOrSelector
ifNotNil: [:blockOrSelector || anItem |
anItem := getListElementSelector
ifNil: [ list at: aRow ifAbsent: [ ^ nil ]]
ifNotNil: [ model perform: getListElementSelector with: aRow ].
return := blockOrSelector isBlock
ifTrue: [ blockOrSelector cull: anItem cull: aRow ]
ifFalse: [
blockOrSelector isSymbol
ifTrue: [ blockOrSelector numArgs == 0
ifTrue: [ anItem perform: blockOrSelector ]
ifFalse: [ self model perform: blockOrSelector withEnoughArguments: { anItem. aRow} ]]
ifFalse: [ nil ]]].
^ return isColor
ifTrue: [ return ]
ifFalse: [ nil ]
]
{ #category : #'background coloring' }
PluggableListMorph >> backgroundColoringBlockOrSelector [
^ backgroundColoringBlockOrSelector
]
{ #category : #'background coloring' }
PluggableListMorph >> backgroundColoringBlockOrSelector: aSelector [
backgroundColoringBlockOrSelector := aSelector
]
{ #category : #initialization }
PluggableListMorph >> basicGetListElementSelector: aSymbol [
"specify a selector that can be used to obtain a single element in the underlying list"
getListElementSelector := aSymbol.
]
{ #category : #'event handling' }
PluggableListMorph >> basicKeyPressed: aChar [
"Return the index of the element matching the keystrokes.
Returns 0 if nothing found"
| nextSelection milliSeconds slowKeyStroke oldSelection |
nextSelection := oldSelection := self getCurrentSelectionIndex.
milliSeconds := Time millisecondClockValue.
slowKeyStroke := milliSeconds - lastKeystrokeTime > 500.
lastKeystrokeTime := milliSeconds.
self searchedElement: nil.
lastKeystrokes := slowKeyStroke
ifTrue: [ aChar asLowercase asString ]
ifFalse: [ lastKeystrokes , aChar asLowercase asString ]. "forget previous keystrokes and search in following elements" "append quick keystrokes but don't move selection if it still matches" "Get rid of blanks and style used in some lists"
nextSelection := self listForSearching findFirst: [ :a | a beginsWith: lastKeystrokes fromList: self ].
nextSelection isZero
ifTrue: [ ^ 0 ]. "No change if model is locked"
model okToChange
ifFalse: [ ^ 0 ]. "No change if model is locked" "The following line is a workaround around the behaviour of OBColumn>>selection:,
which deselects when called twice with the same argument."
oldSelection = nextSelection
ifTrue: [ ^ 0 ]. "change scrollbarvalue"
self searchedElement: nextSelection.
^ nextSelection
]
{ #category : #accessing }
PluggableListMorph >> basicWrapSelector: aSymbol [
wrapSelector := aSymbol.
]
{ #category : #'multi-selection' }
PluggableListMorph >> beMultipleSelection [
multipleSelection := true
]
{ #category : #'multi-selection' }
PluggableListMorph >> beSingleSelection [
multipleSelection := false
]
{ #category : #geometry }
PluggableListMorph >> borderStyleToUse [
"Answer the borderStyle that should be used for the receiver."
^self enabled
ifTrue: [self theme listNormalBorderStyleFor: self]
ifFalse: [self theme listDisabledBorderStyleFor: self]
]
{ #category : #'model access' }
PluggableListMorph >> changeModelSelection: anInteger [
"Change the model's selected item index to be anInteger."
setIndexSelector ifNotNil:
[model perform: setIndexSelector with: anInteger].
self isMultipleSelection
ifTrue: [
self listSelectionAt: self lastNonZeroIndex put: false.
self listSelectionAt: anInteger put: true ]
]
{ #category : #'model access' }
PluggableListMorph >> commandKeyTypedIntoMenu: evt [
"The user typed a command-key into a menu which has me as its command-key handler"
^ self modifierKeyPressed: evt
]
{ #category : #menus }
PluggableListMorph >> copyListToClipboard [
"Copy my items to the clipboard as a multi-line string"
| stream |
stream := (String new: self getList size * 40) writeStream.
list do: [:ea | stream nextPutAll: ea asString] separatedBy: [stream nextPut: Character cr].
Clipboard clipboardText: stream contents
]
{ #category : #menus }
PluggableListMorph >> copySelectionToClipboard [
"Copy my selected item to the clipboard as a string"
self selection ifNotNil: [ Clipboard clipboardText: self selection asString ] ifNil: [ self flash ]
]
{ #category : #'multi-selection' }
PluggableListMorph >> defaultMultipleSelectionValue [
^ false
]
{ #category : #'scroll cache' }
PluggableListMorph >> deriveHScrollRange [
| unadjustedRange totalRange |
(list isNil or: [list isEmpty])
ifTrue:[hScrollRangeCache := Array with: 0 with: 0 with: 0 with: 0 with: 0 ]
ifFalse:[
unadjustedRange := self listMorph hUnadjustedScrollRange.
totalRange := unadjustedRange + self hExtraScrollRange + self hMargin.
hScrollRangeCache := Array
with: totalRange
with: unadjustedRange
with: list size
with: list first
with: list last .
].
]
{ #category : #selection }
PluggableListMorph >> deselectAll [
self isMultipleSelection ifFalse: [ ^ self ].
self resetListSelection
]
{ #category : #configuration }
PluggableListMorph >> disable [
"Disable the receiver."
self enabled: false
]
{ #category : #events }
PluggableListMorph >> doubleClick: event [
| index |
doubleClickSelector ifNil: [^super doubleClick: event].
index := self rowAtLocation: event position.
index = 0 ifTrue: [^super doubleClick: event].
"selectedMorph ifNil: [self setSelectedMorph: aMorph]."
^ self model perform: doubleClickSelector
]
{ #category : #initialization }
PluggableListMorph >> doubleClickSelector: aSymbol [
doubleClickSelector := aSymbol
]
{ #category : #accessing }
PluggableListMorph >> dragItemSelector [
^dragItemSelector
]
{ #category : #accessing }
PluggableListMorph >> dragItemSelector: aSymbol [
dragItemSelector := aSymbol.
aSymbol ifNotNil:[self dragEnabled: true].
]
{ #category : #accessing }
PluggableListMorph >> dropItemSelector [
^dropItemSelector
]
{ #category : #accessing }
PluggableListMorph >> dropItemSelector: aSymbol [
dropItemSelector := aSymbol.
aSymbol ifNotNil:[self dropEnabled: true].
]
{ #category : #configuration }
PluggableListMorph >> enable [
"Enable the receiver."
self enabled: true
]
{ #category : #configuration }
PluggableListMorph >> enabled [
"Answer the enablement state of the receiver."
^enabled ifNil: [true]
]
{ #category : #configuration }
PluggableListMorph >> enabled: aBoolean [
"Set the enablement state of the receiver."
aBoolean = self enabled
ifFalse: [ enabled := aBoolean.
self adoptPaneColor: self paneColor;
changed]
]
{ #category : #geometry }
PluggableListMorph >> extent: newExtent [
super extent: newExtent.
"Change listMorph's bounds to the new width. It is either the size
of the widest list item, or the size of self, whatever is bigger"
self listMorph width: ((self width max: listMorph hUnadjustedScrollRange) + 20).
]
{ #category : #geometry }
PluggableListMorph >> fillStyleToUse [
"Answer the fillStyle that should be used for the receiver."
^self enabled
ifTrue: [self theme listNormalFillStyleFor: self]
ifFalse: [self theme listDisabledFillStyleFor: self]
]
{ #category : #geometry }
PluggableListMorph >> focusBounds [
"Answer the bounds for drawing the focus indication."
^self theme listFocusBoundsFor: self
]
{ #category : #initialization }
PluggableListMorph >> font [
^ self listMorph font
]
{ #category : #initialization }
PluggableListMorph >> font: aFontOrNil [
self listMorph font: aFontOrNil.
]
{ #category : #'model access' }
PluggableListMorph >> getCurrentSelectionIndex [
"Answer the index of the current selection."
getIndexSelector ifNil: [^0].
^model perform: getIndexSelector
]
{ #category : #accessing }
PluggableListMorph >> getEnabledSelector [
"Answer the value of getEnabledSelector"
^ getEnabledSelector ifNil: [ nil ]
]
{ #category : #accessing }
PluggableListMorph >> getEnabledSelector: aSymbol [
"Set the value of getEnabledSelector"
getEnabledSelector := aSymbol.
self updateEnabled
]
{ #category : #accessing }
PluggableListMorph >> getIndexSelector: aSelector [
getIndexSelector := aSelector
]
{ #category : #'model access' }
PluggableListMorph >> getList [
"Answer the list to be displayed. Caches the returned list in the 'list' ivar"
getListSelector == nil ifTrue: [^ #()].
list := model perform: getListSelector.
list == nil ifTrue: [^ #()].
list := list collectWithIndex: [ :item :index | self wrapItem: item index: index ].
^ list
]
{ #category : #accessing }
PluggableListMorph >> getListElementSelector [
^ getListElementSelector
]
{ #category : #initialization }
PluggableListMorph >> getListElementSelector: aSymbol [
"specify a selector that can be used to obtain a single element in the underlying list"
self basicGetListElementSelector: aSymbol.
list := nil. "this cache will not be updated if getListElementSelector has been specified, so go ahead and remove it"
self updateList.
]
{ #category : #'model access' }
PluggableListMorph >> getListItem: index [
"get the index-th item in the displayed list"
| element |
getListElementSelector ifNotNil: [ ^ self wrapItem: (model perform: getListElementSelector with: index) index: index ].
list ifNotNil: [ ^ list at: index ].
element := self getList at: index.
^ self wrapItem: element index: index
]
{ #category : #selection }
PluggableListMorph >> getListSelector [
^ getListSelector
]
{ #category : #initialization }
PluggableListMorph >> getListSelector: sel [
"Set the receiver's getListSelector as indicated, and trigger a recomputation of the list"
getListSelector := sel.
self changed.
self updateList.
]
{ #category : #'model access' }
PluggableListMorph >> getListSize [
"return the current number of items in the displayed list"
getListSizeSelector ifNotNil: [ ^model perform: getListSizeSelector ].
^self getList size
]
{ #category : #initialization }
PluggableListMorph >> getListSizeSelector: aSymbol [
"specify a selector that can be used to specify the list's size"
getListSizeSelector := aSymbol
]
{ #category : #menu }
PluggableListMorph >> getMenu: shiftKeyState [
"Answer the menu for this text view, supplying an empty menu to be filled in. If the menu selector takes an extra argument, pass in the current state of the shift key."
| aMenu |
aMenu := super getMenu: shiftKeyState.
aMenu ifNotNil: [aMenu commandKeyHandler: self].
^ aMenu
]
{ #category : #accessing }
PluggableListMorph >> getSelectionListSelector: getListSel [
getSelectionListSelector := getListSel
]
{ #category : #scrolling }
PluggableListMorph >> hExtraScrollRange [
"Return the amount of extra blank space to include to the right of the scroll content."
^5
]
{ #category : #scrolling }
PluggableListMorph >> hUnadjustedScrollRange [
"Return the entire scrolling range."
^self listMorph hUnadjustedScrollRange
]
{ #category : #events }
PluggableListMorph >> handleBasicKeys: aBoolean [
"set whether the list morph should handle basic keys like arrow keys, or whether everything should be passed to the model"
handlesBasicKeys := aBoolean
]
{ #category : #'event handling' }
PluggableListMorph >> handleFocusEvent: anEvent [
"Handle the given event. This message is sent if the receiver currently has the focus and is therefore receiving events directly from some hand."
self processEvent: anEvent. "give submorphs a chance"
(anEvent isMouse and: [anEvent isMouseDown and: [(self fullContainsPoint: anEvent position) not]])
ifFalse: [^super handleFocusEvent: anEvent].
"click outside - pass to event handler"
self eventHandler
ifNotNil: [self eventHandler mouseDown: anEvent fromMorph: self]
]
{ #category : #'event handling' }
PluggableListMorph >> handleMouseMove: anEvent [
"Reimplemented because we really want #mouseMove when a morph is dragged around"
anEvent wasHandled ifTrue:[^self]. "not interested"
(anEvent anyButtonPressed and:[anEvent hand mouseFocus == self]) ifFalse:[^self].
anEvent wasHandled: true.
self mouseMove: anEvent.
(self handlesMouseStillDown: anEvent) ifTrue:[
"Step at the new location"
self startStepping: #handleMouseStillDown:
at: Time millisecondClockValue
arguments: {anEvent copy resetHandlerFields}
stepTime: 1].
]
{ #category : #events }
PluggableListMorph >> handlesBasicKeys [
" if ya don't want the list to automatically handle non-modifier key
(excluding shift key) input, return false"
^ handlesBasicKeys ifNil: [ true ]
]
{ #category : #'event handling' }
PluggableListMorph >> handlesKeyboard: evt [
^true
]
{ #category : #'event handling' }
PluggableListMorph >> handlesMouseOverDragging: evt [
"Yes, for mouse down highlight."
^true
]
{ #category : #drawing }
PluggableListMorph >> highlightSelection [
]
{ #category : #initialization }
PluggableListMorph >> initForKeystrokes [
canMove := true.
lastKeystrokeTime := 0.
lastKeystrokes := ''
]
{ #category : #initialization }
PluggableListMorph >> initialize [
super initialize.
self initForKeystrokes.
]
{ #category : #keymapping }
PluggableListMorph >> initializeShortcuts: aKMDispatcher [
super initializeShortcuts: aKMDispatcher.
aKMDispatcher attachCategory: #MorphFocusNavigation
]
{ #category : #'multi-selection' }
PluggableListMorph >> isMultipleSelection [
^ self multipleSelection
]
{ #category : #'multi-selection' }
PluggableListMorph >> isSingleSelection [
^ self multipleSelection not
]
{ #category : #'model access' }
PluggableListMorph >> itemSelectedAmongMultiple: index [
"return whether the index-th row is selected. Always false in PluggableListMorph, but sometimes true in PluggableListMorphOfMany"
^ self isMultipleSelection
ifTrue: [ (self listSelectionAt: index) == true ]
ifFalse: [ false ]
]
{ #category : #'event handling' }
PluggableListMorph >> keyStroke: event [
"Process keys
specialKeys are things like up, down, etc. ALWAYS HANDLED
modifierKeys are regular characters either 1) accompanied with ctrl,
cmd or 2) any character if the list doesn't want to handle basic
keys (handlesBasicKeys returns false)
basicKeys are any characters"
| aChar |
(self scrollByKeyboard: event) ifTrue: [^self].
(self navigationKey: event) ifTrue: [^self].
aChar := event keyCharacter.
keystrokeSelector ifNotNil: [
(self keystrokeAction: event) ifTrue: [ ^ self ] ].
aChar asciiValue < 32 ifTrue: [^ self specialKeyPressed: event ].
(event anyModifierKeyPressed or: [self handlesBasicKeys not])
ifTrue: [^ self modifierKeyPressed: event].
^ self basicKeyPressed: aChar
]
{ #category : #'event handling' }
PluggableListMorph >> keyboardFocusChange: aBoolean [
"The message is sent to a morph when its keyboard focus changes.
Update for focus feedback."
super keyboardFocusChange: aBoolean.
self focusChanged
]
{ #category : #'model access' }
PluggableListMorph >> keystrokeAction: event [
| returnValue |
keystrokeSelector ifNil: [ ^ nil ].
returnValue := model
perform: keystrokeSelector
withEnoughArguments: { event. self }.
^ returnValue = true
]
{ #category : #initialization }
PluggableListMorph >> keystrokeActionSelector: keyActionSel [
"Set the keystroke action selector as specified"
keystrokeActionSelector := keyActionSel
]
{ #category : #'model access' }
PluggableListMorph >> keystrokeSelector: aSymbol [
keystrokeSelector := aSymbol
]
{ #category : #accessing }
PluggableListMorph >> lastNonZeroIndex [
^ lastNonZeroIndex ifNil: [ lastNonZeroIndex := 0 ]
]
{ #category : #searching }
PluggableListMorph >> listForSearching [
^ getListSelector
ifNotNil: [ self getList ]
ifNil: [ getListElementSelector
ifNil: [ #() ]
ifNotNil: [
(1 to: self getListSize) collect: [:index | self getListItem: index ]]]
]
{ #category : #initialization }
PluggableListMorph >> listItemHeight [
"This should be cleaned up. The list should get spaced by this parameter."
^ 12
]
{ #category : #accessing }
PluggableListMorph >> listMorph [
listMorph ifNil: [
"crate this lazily, in case the morph is legacy"
listMorph := self listMorphClass new.
listMorph listSource: self.
listMorph width: self scroller width.
listMorph color: self textColor ].
listMorph owner ~~ self scroller ifTrue: [
"list morph needs to be installed. Again, it's done this way to accomodate legacy PluggableListMorphs"
self scroller removeAllMorphs.
self scroller addMorph: listMorph ].
^listMorph
]
{ #category : #initialization }
PluggableListMorph >> listMorphClass [
^LazyListMorph
]
{ #category : #'multi-selection' }
PluggableListMorph >> listSelectionAt: index [
index isZero ifFalse:[ lastNonZeroIndex := index ].
getSelectionListSelector ifNil:[^false].
^model perform: getSelectionListSelector with: index
]
{ #category : #'multi-selection' }
PluggableListMorph >> listSelectionAt: index put: value [
self searchedElement: nil.
setSelectionListSelector ifNil:[^false].
^model perform: setSelectionListSelector with: index with: value
]
{ #category : #selection }
PluggableListMorph >> maximumSelection [
^ self getListSize
]
{ #category : #selection }
PluggableListMorph >> minimumSelection [
^ 1
]
{ #category : #'model access' }
PluggableListMorph >> modifierKeyPressed: event [
| args aChar |
aChar := event keyCharacter.
keystrokeActionSelector ifNil: [ ^ nil ].
args := keystrokeActionSelector numArgs.
args = 1 ifTrue: [^ model perform: keystrokeActionSelector with: aChar].
args = 2
ifTrue:
[^model
perform: keystrokeActionSelector
with: aChar
with: self].
^self error: 'keystrokeActionSelector must be a 1- or 2-keyword symbol'
]
{ #category : #'event handling' }
PluggableListMorph >> mouseDown: evt [
"Changed to only take focus if wanted."
| selectors row |
row := self rowAtLocation: evt position.
evt yellowButtonPressed
ifTrue: [
self isMultipleSelection
ifTrue: [
evt commandKeyPressed
ifFalse: [
"right click"
(self yellowButtonActivity: evt shiftPressed)
ifTrue: [ ^ super mouseDown: evt ] ] ]
ifFalse: [
(self yellowButtonActivity: evt shiftPressed)
ifTrue: [ ^ super mouseDown: evt ] ] ]. "First check for option (menu) click"
self enabled
ifFalse: [ ^ super mouseDown: evt ].
self wantsKeyboardFocus
ifTrue: [ self takeKeyboardFocus ].
row := self rowAtLocation: evt position.
row = 0
ifTrue: [ ^ super mouseDown: evt ].
self mouseDownRow: row.
self isMultipleSelection
ifTrue: [ self mouseDownOnMultiple: evt forRow: row ].
selectors := Array
with: #click:
with: (doubleClickSelector ifNotNil: [ #doubleClick: ])
with: nil
with:
(self dragEnabled
ifTrue: [ #startDrag: ]
ifFalse: [ nil ]).
evt hand
waitForClicksOrDrag: self
event: evt
selectors: selectors
threshold: 10. "pixels"
super mouseDown: evt
]
{ #category : #'multi-selection' }
PluggableListMorph >> mouseDownOnMultiple: event forRow: row [
| anInteger oldIndex oldVal valueKeeper |
"Set meaning for subsequent dragging of selection"
canMove ifFalse: [ ^ self ].
canMove := false.
model okToChange ifFalse: [
canMove := true.
^ self ].
canMove := true.
dragOnOrOff := (self listSelectionAt: row) not.
valueKeeper := dragOnOrOff.
" I store the value because #mouseUpOnMultiple: can reset dragOnOrOff before the end of this method (in case of halt by example)"
(event shiftPressed not and: [event yellowButtonPressed not and: [ self autoDeselect ]])
ifTrue: [ self resetListSelection ].
oldIndex := self getCurrentSelectionIndex.
oldIndex ~= 0 ifTrue: [oldVal := self listSelectionAt: oldIndex].
"Set or clear new primary selection (listIndex)"
anInteger := valueKeeper
ifTrue: [ row ]
ifFalse: [ 0 ].
setIndexSelector ifNotNil:
[ model perform: setIndexSelector with: anInteger ].
"Need to restore the old one, due to how model works, and set new one."
oldIndex ~= 0 ifTrue: [self listSelectionAt: oldIndex put: oldVal].
event shiftPressed
ifTrue: [((oldIndex max: 1) min: row) to: (oldIndex max: row) do: [:i |
self listSelectionAt: i put: valueKeeper].
self changed]
ifFalse: [self listSelectionAt: row put: valueKeeper].
]
{ #category : #accessing }
PluggableListMorph >> mouseDownRow [
"Answer the mouse down row or nil if none."
^self listMorph mouseDownRow
]
{ #category : #events }
PluggableListMorph >> mouseDownRow: anIntegerOrNil [
"Set the mouse down row or nil if none."
self listMorph mouseDownRow: anIntegerOrNil
]
{ #category : #'event handling' }
PluggableListMorph >> mouseEnter: event [
"Changed to take keyboardFocusOnMouseDown into account."
super mouseEnter: event.
self wantsKeyboardFocus ifFalse: [^self].
self keyboardFocusOnMouseDown
ifFalse: [self takeKeyboardFocus]
]
{ #category : #'event handling' }
PluggableListMorph >> mouseEnterDragging: evt [
"The mouse has entered with a button down.
Workaround for apparent flaw in MouseOverHandler constantly
sending this message when dragging.
Do nothing if disabled."
|row oldPDR|
self enabled ifFalse: [^self].
row := self rowAtLocation: evt position.
(self dragEnabled or: [evt hand hasSubmorphs]) ifFalse: [
row = 0 ifTrue: [ ^self ].
self listMorph mouseDownRow: row].
(evt hand hasSubmorphs and:[self dropEnabled]) ifFalse: ["no d&d"
^super mouseEnterDragging: evt].
potentialDropRow = row ifTrue: [^self].
oldPDR := potentialDropRow.
potentialDropRow := row.
evt hand newMouseFocus: self.
"above is ugly but necessary for now"
(self wantsDroppedMorph: evt hand firstSubmorph event: evt )
ifTrue: [self changed]
ifFalse: [(oldPDR ifNil: [0]) > 0
ifTrue: [self resetPotentialDropRow]
ifFalse: [potentialDropRow := 0]]
]
{ #category : #'event handling' }
PluggableListMorph >> mouseLeaveDragging: anEvent [
"The mouse has left with a button down."
(self dragEnabled or: [anEvent hand hasSubmorphs]) ifFalse: [
self listMorph mouseDownRow: nil].
(self dropEnabled and: [anEvent hand hasSubmorphs]) ifFalse: ["no d&d"
^super mouseLeaveDragging: anEvent].
self resetPotentialDropRow.
anEvent hand releaseMouseFocus: self.
"above is ugly but necessary for now"
]
{ #category : #'event handling' }
PluggableListMorph >> mouseMove: evt [
self isMultipleSelection
ifTrue: [ self mouseMoveOnMultiple: evt ]
ifFalse: [ self mouseMoveOnSingle:evt ]
]
{ #category : #'multi-selection' }
PluggableListMorph >> mouseMoveOnMultiple: event [
"The mouse has moved, as characterized by the event provided. Adjust the scrollbar, and alter the selection as appropriate"
| oldIndex oldVal row |
canMove ifFalse: [ ^ self ].
event position y < self top
ifTrue:
[ scrollBar scrollUp: 1.
row := self rowAtLocation: scroller topLeft + (1 @ 1)]
ifFalse:
[ row := event position y > self bottom
ifTrue:
[scrollBar scrollDown: 1.
self rowAtLocation: scroller bottomLeft + (1 @ -1)]
ifFalse: [ self rowAtLocation: event position ]].
row = 0 ifTrue: [ ^ super mouseDown: event ].
(self potentialDropItem notNil and: [ self dropEnabled ]) ifTrue: [ ^ self ].