75 but derives from the ListModelView and thus the list is kept |
75 but derives from the ListModelView and thus the list is kept |
76 in the list. |
76 in the list. |
77 |
77 |
78 [Instance variables:] |
78 [Instance variables:] |
79 |
79 |
80 selection <misc> the current selection. nil, a number or collection of numbers |
80 selection <misc> the current selection. nil, a number or collection of numbers |
81 multipleSelectOk <Boolean> allow/disallow multiple selections( default:false ) |
81 multipleSelectOk <Boolean> allow/disallow multiple selections( default:false ) |
82 selectOnButtonMenu <Boolean> enable/disable selection will change on menu pressed |
82 selectOnButtonMenu <Boolean> enable/disable selection will change on menu pressed |
83 |
83 |
84 buttonReleaseAction <Action> called if the mouse button is released |
84 buttonReleaseAction <Action> called if the mouse button is released |
85 buttonMotionAction <Action> called during mouse motion with one argument the point |
85 buttonMotionAction <Action> called during mouse motion with one argument the point |
86 under the mouse. |
86 under the mouse. |
87 |
87 |
88 actionBlock <Block> action evaluated on single click (0/1/2 arguments) |
88 actionBlock <Block> action evaluated on single click (0/1/2 arguments) |
89 doubleClickActionBlock <Block> action evaluated on double click (0/1/2 arguments) |
89 doubleClickActionBlock <Block> action evaluated on double click (0/1/2 arguments) |
90 selectConditionBlock <Block> action evaluated before selection changed (0/1/2 arguments) |
90 selectConditionBlock <Block> action evaluated before selection changed (0/1/2 arguments) |
91 |
91 |
92 keyActionStyle <Symbol> controls how to respond to keyboard selects |
92 keyActionStyle <Symbol> controls how to respond to keyboard selects |
93 returnKeyActionStyle <Symbol> controls how to respond to return key |
93 returnKeyActionStyle <Symbol> controls how to respond to return key |
94 |
94 |
95 useIndex <Boolean> representation of the model selection |
95 useIndex <Boolean> representation of the model selection |
96 |
96 |
97 ignoreReselect <Boolean> if set, a click on an already selected entry is ignored |
97 ignoreReselect <Boolean> if set, a click on an already selected entry is ignored |
98 toggleSelect <Boolean> a click on an entry unselects it and vice versa |
98 toggleSelect <Boolean> a click on an entry unselects it and vice versa |
99 |
99 |
100 highlightMode <Symbol> how to draw the selection |
100 highlightMode <Symbol> how to draw the selection |
101 hilightFgColor <Color> foregroundColor of highlighted items |
101 hilightFgColor <Color> foregroundColor of highlighted items |
102 hilightBgColor <Color> backgroundColor of highlighted items |
102 hilightBgColor <Color> backgroundColor of highlighted items |
103 hilightLevel <Integer> level to draw selections (i.e. for 3D effect) |
103 hilightLevel <Integer> level to draw selections (i.e. for 3D effect) |
104 hilightFrameColor <Color> rectangle around highlighted items |
104 hilightFrameColor <Color> rectangle around highlighted items |
105 hilightStyle <Boolean> actions on widget are enabled/disabled |
105 hilightStyle <Boolean> actions on widget are enabled/disabled |
106 strikeOut <Boolean> turn on/off strikeOut mode |
106 strikeOut <Boolean> turn on/off strikeOut mode |
107 |
107 |
108 dropTarget <DropTarget> keeps information about the drop operation |
108 dropTarget <DropTarget> keeps information about the drop operation |
109 dropSource <DropSource> keeps information about the drag operation |
109 dropSource <DropSource> keeps information about the drag operation |
110 |
110 |
111 editorView <View> editor on current selected item |
111 editorView <View> editor on current selected item |
112 openEditorAction <Action> action to get an editor on the current selection from user |
112 openEditorAction <Action> action to get an editor on the current selection from user |
113 closeEditorAction <Action> action invoked before the editor is closed. |
113 closeEditorAction <Action> action invoked before the editor is closed. |
114 |
114 |
115 enterItem <Item/nil> item over which the mouse pointer is located |
115 enterItem <Item/nil> item over which the mouse pointer is located |
116 or nil |
116 or nil |
117 highlightEnterItem <Boolean> enable or disable highlight of enterItem |
117 highlightEnterItem <Boolean> enable or disable highlight of enterItem |
118 |
118 |
119 [author:] |
119 [author:] |
120 Claus Atzkern |
120 Claus Atzkern |
121 |
121 |
122 [see also:] |
122 [see also:] |
123 |
123 |
124 ListModelView |
124 ListModelView |
125 HierarchicalListView |
125 HierarchicalListView |
126 " |
126 " |
127 ! |
127 ! |
128 |
128 |
129 examples |
129 examples |
130 " |
130 " |
131 [exBegin] |
131 [exBegin] |
132 |top list view| |
132 |top list view| |
133 |
133 |
134 list := List new. |
134 list := List new. |
135 |
135 |
136 1 to:100 do:[:i| list add:('element: ', i printString) ]. |
136 1 to:100 do:[:i| list add:('element: ', i printString) ]. |
137 top := StandardSystemView new; extent:300@300. |
137 top := StandardSystemView new; extent:300@300. |
138 view := ScrollableView for:SelectionInListModelView miniScroller:true |
138 view := ScrollableView for:SelectionInListModelView miniScroller:true |
139 origin:0.0@0.0 corner:1.0@1.0 in:top. |
139 origin:0.0@0.0 corner:1.0@1.0 in:top. |
140 view list:list. |
140 view list:list. |
141 top open. |
141 top open. |
142 [exEnd] |
142 [exEnd] |
143 |
143 |
144 |
144 |
145 [exBegin] |
145 [exBegin] |
146 |top list view| |
146 |top list view| |
147 |
147 |
148 list := List new. |
148 list := List new. |
149 |
149 |
150 1 to:100 do:[:i| list add:('element: ', i printString) ]. |
150 1 to:100 do:[:i| list add:('element: ', i printString) ]. |
151 top := StandardSystemView new; extent:300@300. |
151 top := StandardSystemView new; extent:300@300. |
152 view := ScrollableView for:SelectionInListModelView miniScroller:true |
152 view := ScrollableView for:SelectionInListModelView miniScroller:true |
153 origin:0.0@0.0 corner:1.0@1.0 in:top. |
153 origin:0.0@0.0 corner:1.0@1.0 in:top. |
154 view list:list. |
154 view list:list. |
155 |
155 |
156 view openEditorAction:[:ln :aGC| |field| |
156 view openEditorAction:[:ln :aGC| |field| |
157 field := EditField new. |
157 field := EditField new. |
158 field level:0. |
158 field level:0. |
159 field acceptOnLostFocus:true. |
159 field acceptOnLostFocus:true. |
160 field acceptAction:[:x| list at:ln put:(field contents) ]. |
160 field acceptAction:[:x| list at:ln put:(field contents) ]. |
161 field font:(aGC font). |
161 field font:(aGC font). |
162 field contents:(list at:ln). |
162 field contents:(list at:ln). |
163 field |
163 field |
164 ]. |
164 ]. |
165 top open. |
165 top open. |
166 [exEnd] |
166 [exEnd] |
167 |
167 |
168 [exBegin] |
168 [exBegin] |
169 |top list view item| |
169 |top list view item| |
170 |
170 |
171 list := HierarchicalList new. |
171 list := HierarchicalList new. |
172 item := HierarchicalItem::Example labeled:'Test'. |
172 item := HierarchicalItem::Example labeled:'Test'. |
173 item expand. |
173 item expand. |
174 list showRoot:false. |
174 list showRoot:false. |
175 list root:item. |
175 list root:item. |
176 |
176 |
177 top := StandardSystemView new; extent:300@300. |
177 top := StandardSystemView new; extent:300@300. |
178 view := ScrollableView for:SelectionInListModelView miniScroller:true |
178 view := ScrollableView for:SelectionInListModelView miniScroller:true |
179 origin:0.0@0.0 corner:1.0@1.0 in:top. |
179 origin:0.0@0.0 corner:1.0@1.0 in:top. |
180 |
180 |
181 view list:list. |
181 view list:list. |
182 view doubleClickAction:[:i| (list at:i) toggleExpand ]. |
182 view doubleClickAction:[:i| (list at:i) toggleExpand ]. |
183 top open. |
183 top open. |
184 [exEnd] |
184 [exEnd] |
185 |
185 |
186 " |
186 " |
187 ! ! |
187 ! ! |
188 |
188 |
189 !SelectionInListModelView class methodsFor:'defaults'! |
189 !SelectionInListModelView class methodsFor:'defaults'! |
190 |
190 |
191 updateStyleCache |
191 updateStyleCache |
192 "extract values from the styleSheet and cache them in class variables" |
192 "extract values from the styleSheet and cache them in class variables" |
193 |
193 |
194 <resource: #style ( |
194 <resource: #style ( |
195 #'selection.hilightForegroundColor' #'selection.hilightBackgroundColor' |
195 #'selection.hilightForegroundColor' #'selection.hilightBackgroundColor' |
196 #'selection.hilightFrameColor' #'selection.hilightLevel' |
196 #'selection.hilightFrameColor' #'selection.hilightLevel' |
197 #'selection.foregroundColor' #'selection.backgroundColor' |
197 #'selection.foregroundColor' #'selection.backgroundColor' |
198 #'selection.shadowColor' #'selection.lightColor' |
198 #'selection.shadowColor' #'selection.lightColor' |
199 #'selection.font' #'selection.hilightStyle' |
199 #'selection.font' #'selection.hilightStyle' |
200 #'text.foregroundColor' |
200 #'text.foregroundColor' |
201 )> |
201 )> |
202 |
202 |
203 DefaultHilightForegroundColor := StyleSheet colorAt:'selection.hilightForegroundColor'. |
203 DefaultHilightForegroundColor := StyleSheet colorAt:'selection.hilightForegroundColor'. |
204 DefaultHilightBackgroundColor := StyleSheet colorAt:'selection.hilightBackgroundColor'. |
204 DefaultHilightBackgroundColor := StyleSheet colorAt:'selection.hilightBackgroundColor'. |
205 DefaultHilightFrameColor := StyleSheet colorAt:'selection.hilightFrameColor'. |
205 DefaultHilightFrameColor := StyleSheet colorAt:'selection.hilightFrameColor'. |
206 DefaultHilightLevel := StyleSheet at:'selection.hilightLevel' default:0. |
206 DefaultHilightLevel := StyleSheet at:'selection.hilightLevel' default:0. |
243 |
243 |
244 action |
244 action |
245 "get the action block to be performed on select |
245 "get the action block to be performed on select |
246 |
246 |
247 The arguments to the block are: |
247 The arguments to the block are: |
248 - no argument |
248 - no argument |
249 - 1 argument index or item |
249 - 1 argument index or item |
250 - 2 argument index or item, self |
250 - 2 argument index or item, self |
251 " |
251 " |
252 ^ actionBlock |
252 ^ actionBlock |
253 ! |
253 ! |
254 |
254 |
255 action:aOneArgAction |
255 action:aOneArgAction |
256 "set the action block to be performed on select |
256 "set the action block to be performed on select |
257 |
257 |
258 The arguments to the block are: |
258 The arguments to the block are: |
259 - no argument |
259 - no argument |
260 - 1 argument index or item |
260 - 1 argument index or item |
261 - 2 argument index or item, self |
261 - 2 argument index or item, self |
262 " |
262 " |
263 actionBlock := aOneArgAction |
263 actionBlock := aOneArgAction |
264 ! |
264 ! |
265 |
265 |
266 doubleClickAction |
266 doubleClickAction |
267 "get the action block to be performed on doubleclick. |
267 "get the action block to be performed on doubleclick. |
268 |
268 |
269 The arguments to the block are: |
269 The arguments to the block are: |
270 - no argument |
270 - no argument |
271 - 1 argument selectedIndex |
271 - 1 argument selectedIndex |
272 - 2 argument selectedIndex, self |
272 - 2 argument selectedIndex, self |
273 " |
273 " |
274 ^ doubleClickActionBlock |
274 ^ doubleClickActionBlock |
275 ! |
275 ! |
276 |
276 |
277 doubleClickAction:aOneArgAction |
277 doubleClickAction:aOneArgAction |
278 "set the action block to be performed on doubleclick. |
278 "set the action block to be performed on doubleclick. |
279 |
279 |
280 The arguments to the block are: |
280 The arguments to the block are: |
281 - no argument |
281 - no argument |
282 - 1 argument selectedIndex |
282 - 1 argument selectedIndex |
283 - 2 argument selectedIndex, self |
283 - 2 argument selectedIndex, self |
284 " |
284 " |
285 doubleClickActionBlock := aOneArgAction |
285 doubleClickActionBlock := aOneArgAction |
286 ! |
286 ! |
287 |
287 |
288 keyActionStyle |
288 keyActionStyle |
289 "defines how the view should respond to alpha-keys pressed. |
289 "defines how the view should respond to alpha-keys pressed. |
290 Possible values are: |
290 Possible values are: |
291 #select -> will select next entry starting with that |
291 #select -> will select next entry starting with that |
292 character and perform the click-action |
292 character and perform the click-action |
293 |
293 |
294 #selectAndDoubleclick -> will select next & perform double-click action |
294 #selectAndDoubleclick -> will select next & perform double-click action |
295 |
295 |
296 #pass -> will pass key to superclass (i.e. no special treatment) |
296 #pass -> will pass key to superclass (i.e. no special treatment) |
297 |
297 |
298 nil -> will ignore key |
298 nil -> will ignore key |
299 |
299 |
300 the default (set in #initialize) is #select |
300 the default (set in #initialize) is #select |
301 " |
301 " |
302 ^ keyActionStyle |
302 ^ keyActionStyle |
303 ! |
303 ! |
304 |
304 |
305 keyActionStyle:aSymbol |
305 keyActionStyle:aSymbol |
306 "defines how the view should respond to alpha-keys pressed. |
306 "defines how the view should respond to alpha-keys pressed. |
307 Possible values are: |
307 Possible values are: |
308 #select -> will select next entry starting with that |
308 #select -> will select next entry starting with that |
309 character and perform the click-action |
309 character and perform the click-action |
310 |
310 |
311 #selectAndDoubleclick -> will select next & perform double-click action |
311 #selectAndDoubleclick -> will select next & perform double-click action |
312 |
312 |
313 #pass -> will pass key to superclass (i.e. no special treatment) |
313 #pass -> will pass key to superclass (i.e. no special treatment) |
314 |
314 |
315 nil -> will ignore key |
315 nil -> will ignore key |
316 |
316 |
317 the default (set in #initialize) is #select |
317 the default (set in #initialize) is #select |
318 " |
318 " |
319 keyActionStyle := aSymbol |
319 keyActionStyle := aSymbol |
320 ! |
320 ! |
321 |
321 |
322 returnKeyActionStyle |
322 returnKeyActionStyle |
323 "defines how the view should respond to a return key pressed. |
323 "defines how the view should respond to a return key pressed. |
324 Possible values are: |
324 Possible values are: |
325 #doubleClick -> perform double-click action |
325 #doubleClick -> perform double-click action |
326 |
326 |
327 #pass -> will pass key to superclass (i.e. no special treatment) |
327 #pass -> will pass key to superclass (i.e. no special treatment) |
328 |
328 |
329 nil -> will ignore key |
329 nil -> will ignore key |
330 |
330 |
331 the default (set in #initialize) is #doubleClick |
331 the default (set in #initialize) is #doubleClick |
332 " |
332 " |
333 ^ returnKeyActionStyle |
333 ^ returnKeyActionStyle |
334 ! |
334 ! |
335 |
335 |
336 returnKeyActionStyle:aSymbol |
336 returnKeyActionStyle:aSymbol |
337 "defines how the view should respond to a return key pressed. |
337 "defines how the view should respond to a return key pressed. |
338 Possible values are: |
338 Possible values are: |
339 #doubleClick -> perform double-click action |
339 #doubleClick -> perform double-click action |
340 |
340 |
341 #pass -> will pass key to superclass (i.e. no special treatment) |
341 #pass -> will pass key to superclass (i.e. no special treatment) |
342 |
342 |
343 nil -> will ignore key |
343 nil -> will ignore key |
344 |
344 |
345 the default (set in #initialize) is #doubleClick |
345 the default (set in #initialize) is #doubleClick |
346 " |
346 " |
347 returnKeyActionStyle := aSymbol |
347 returnKeyActionStyle := aSymbol |
348 ! |
348 ! |
349 |
349 |
350 selectConditionBlock |
350 selectConditionBlock |
351 "set the conditionBlock; this block is evaluated before a selection |
351 "set the conditionBlock; this block is evaluated before a selection |
352 change is performed; the change will not be done, if the evaluation |
352 change is performed; the change will not be done, if the evaluation |
353 returns false |
353 returns false |
354 |
354 |
355 The arguments to the block are: |
355 The arguments to the block are: |
356 - no argument |
356 - no argument |
357 - 1 argument index |
357 - 1 argument index |
358 - 2 argument index, isForAdd |
358 - 2 argument index, isForAdd |
359 " |
359 " |
360 ^ selectConditionBlock |
360 ^ selectConditionBlock |
361 ! |
361 ! |
362 |
362 |
363 selectConditionBlock:aOneArgBlock |
363 selectConditionBlock:aOneArgBlock |
364 "set the conditionBlock; this block is evaluated before a selection |
364 "set the conditionBlock; this block is evaluated before a selection |
365 change is performed; the change will not be done, if the evaluation |
365 change is performed; the change will not be done, if the evaluation |
366 returns false. |
366 returns false. |
367 |
367 |
368 The arguments to the block are: |
368 The arguments to the block are: |
369 - no argument |
369 - no argument |
370 - 1 argument index |
370 - 1 argument index |
371 - 2 argument index, isForAdd |
371 - 2 argument index, isForAdd |
372 " |
372 " |
373 selectConditionBlock := aOneArgBlock. |
373 selectConditionBlock := aOneArgBlock. |
374 ! ! |
374 ! ! |
375 |
375 |
376 !SelectionInListModelView methodsFor:'accessing-attributes'! |
376 !SelectionInListModelView methodsFor:'accessing-attributes'! |
744 super listSizeChanged:aLnNr nLines:aDeltaLines. |
744 super listSizeChanged:aLnNr nLines:aDeltaLines. |
745 |
745 |
746 selection isNil ifTrue:[^ self]. |
746 selection isNil ifTrue:[^ self]. |
747 |
747 |
748 self size == 0 ifTrue:[ |
748 self size == 0 ifTrue:[ |
749 selection := nil. |
749 selection := nil. |
750 ^ self selectionChanged |
750 ^ self selectionChanged |
751 ]. |
751 ]. |
752 |
752 |
753 multipleSelectOk ifFalse:[ |
753 multipleSelectOk ifFalse:[ |
754 selection < aLnNr ifTrue:[^ self]. |
754 selection < aLnNr ifTrue:[^ self]. |
755 |
755 |
756 selection := selection + aDeltaLines. |
756 selection := selection + aDeltaLines. |
757 |
757 |
758 (aDeltaLines < 0 and:[selection < aLnNr]) ifTrue:[ |
758 (aDeltaLines < 0 and:[selection < aLnNr]) ifTrue:[ |
759 selection := nil. |
759 selection := nil. |
760 ^ self selectionChanged |
760 ^ self selectionChanged |
761 ] |
761 ] |
762 ] ifTrue:[ |
762 ] ifTrue:[ |
763 changed := false. |
763 changed := false. |
764 |
764 |
765 aDeltaLines < 0 ifFalse:[ |
765 aDeltaLines < 0 ifFalse:[ |
766 selection keysAndValuesDo:[:i :ln| |
766 selection keysAndValuesDo:[:i :ln| |
767 ln >= aLnNr ifTrue:[ |
767 ln >= aLnNr ifTrue:[ |
768 changed := true. |
768 changed := true. |
769 selection at:i put:(ln + aDeltaLines) |
769 selection at:i put:(ln + aDeltaLines) |
770 ] |
770 ] |
771 ] |
771 ] |
772 ] ifTrue:[ |
772 ] ifTrue:[ |
773 cnts := 0. |
773 cnts := 0. |
774 |
774 |
775 selection keysAndValuesDo:[:i :ln||new| |
775 selection keysAndValuesDo:[:i :ln||new| |
776 ln >= aLnNr ifTrue:[ |
776 ln >= aLnNr ifTrue:[ |
777 changed := true. |
777 changed := true. |
778 |
778 |
779 (new := ln + aDeltaLines) < aLnNr ifTrue:[ |
779 (new := ln + aDeltaLines) < aLnNr ifTrue:[ |
780 cnts := cnts + 1. |
780 cnts := cnts + 1. |
781 new := nil |
781 new := nil |
782 ]. |
782 ]. |
783 selection at:i put:new |
783 selection at:i put:new |
784 ] |
784 ] |
785 ]. |
785 ]. |
786 cnts ~~ 0 ifTrue:[ |
786 cnts ~~ 0 ifTrue:[ |
787 cnts == selection size ifTrue:[ |
787 cnts == selection size ifTrue:[ |
788 selection := nil |
788 selection := nil |
789 ] ifFalse:[ |
789 ] ifFalse:[ |
790 selection := selection select:[:ln| ln notNil] |
790 selection := selection select:[:ln| ln notNil] |
791 ]. |
791 ]. |
792 ^ self selectionChanged. |
792 ^ self selectionChanged. |
793 ]. |
793 ]. |
794 ]. |
794 ]. |
795 changed ifFalse:[^ self]. |
795 changed ifFalse:[^ self]. |
796 ]. |
796 ]. |
797 |
797 |
798 (useIndex and:[model notNil]) ifTrue:[ |
798 (useIndex and:[model notNil]) ifTrue:[ |
799 model setValue:(self argForChangeMessage) |
799 model setValue:(self argForChangeMessage) |
800 ]. |
800 ]. |
801 ! |
801 ! |
802 |
802 |
803 originChanged:delta |
803 originChanged:delta |
804 "setup the origin of the editing view |
804 "setup the origin of the editing view |
815 |arg| |
815 |arg| |
816 |
816 |
817 self closeEditor. |
817 self closeEditor. |
818 |
818 |
819 (model isNil and:[actionBlock isNil]) ifTrue:[ |
819 (model isNil and:[actionBlock isNil]) ifTrue:[ |
820 ^ self |
820 ^ self |
821 ]. |
821 ]. |
822 |
822 |
823 arg := self argForChangeMessage. |
823 arg := self argForChangeMessage. |
824 |
824 |
825 model notNil ifTrue:[ |
825 model notNil ifTrue:[ |
826 model removeDependent:self. |
826 model removeDependent:self. |
827 "/ change models value to force a change notification: reselect mode |
827 "/ change models value to force a change notification: reselect mode |
828 arg = model value ifTrue:[ |
828 arg = model value ifTrue:[ |
829 model setValue:(arg isNil ifTrue:[0] ifFalse:[nil]). |
829 model setValue:(arg isNil ifTrue:[0] ifFalse:[nil]). |
830 ]. |
830 ]. |
831 self sendChangeMessage:#value: with:arg. |
831 self sendChangeMessage:#value: with:arg. |
832 model notNil ifTrue:[ "/ argggh could be nilled |
832 model notNil ifTrue:[ "/ argggh could be nilled |
833 model addDependent:self. |
833 model addDependent:self. |
834 self updateFromModel. "/ care for possibly lost change notification, due to #removeDependent |
834 self updateFromModel. "/ care for possibly lost change notification, due to #removeDependent |
835 ] |
835 ] |
836 ]. |
836 ]. |
837 |
837 |
838 actionBlock notNil ifTrue:[ |
838 actionBlock notNil ifTrue:[ |
839 actionBlock valueWithOptionalArgument:arg and:self |
839 actionBlock valueWithOptionalArgument:arg and:self |
840 ]. |
840 ]. |
841 ! |
841 ! |
842 |
842 |
843 updateFromModel |
843 updateFromModel |
844 "update selection from the model |
844 "update selection from the model |
845 " |
845 " |
846 |value newSelection| |
846 |value newSelection| |
847 |
847 |
848 model isNil ifTrue:[ |
848 model isNil ifTrue:[ |
849 ^ self |
849 ^ self |
850 ]. |
850 ]. |
851 |
851 |
852 buttonMotionAction notNil ifTrue:[ |
852 buttonMotionAction notNil ifTrue:[ |
853 "running in button motion; discard change notification |
853 "running in button motion; discard change notification |
854 " |
854 " |
855 ^ self |
855 ^ self |
856 ]. |
856 ]. |
857 |
857 |
858 value := model value. |
858 value := model value. |
859 |
859 |
860 (useIndex or:[value isNil or:[value isNumber]]) ifFalse:[ |
860 (useIndex or:[value isNil or:[value isNumber]]) ifFalse:[ |
861 multipleSelectOk ifFalse:[ |
861 multipleSelectOk ifFalse:[ |
862 newSelection := self identityIndexOf:value |
862 newSelection := self identityIndexOf:value |
863 ] ifTrue:[ |
863 ] ifTrue:[ |
864 value size == 0 ifTrue:[ |
864 value size == 0 ifTrue:[ |
865 newSelection := nil |
865 newSelection := nil |
866 ] ifFalse:[ |
866 ] ifFalse:[ |
867 newSelection := OrderedCollection new. |
867 newSelection := OrderedCollection new. |
868 |
868 |
869 value do:[:e||index| |
869 value do:[:e||index| |
870 index := self identityIndexOf:e. |
870 index := self identityIndexOf:e. |
871 index ~~ 0 ifTrue:[ newSelection add:index ]. |
871 index ~~ 0 ifTrue:[ newSelection add:index ]. |
872 ]. |
872 ]. |
873 |
873 |
874 newSelection isEmpty ifTrue:[ |
874 newSelection isEmpty ifTrue:[ |
875 newSelection := nil |
875 newSelection := nil |
876 ]. |
876 ]. |
877 ] |
877 ] |
878 ]. |
878 ]. |
879 ] ifTrue:[ |
879 ] ifTrue:[ |
880 newSelection := value copy |
880 newSelection := value copy |
881 ]. |
881 ]. |
882 self setSelection:newSelection. |
882 self setSelection:newSelection. |
883 ! ! |
883 ! ! |
884 |
884 |
885 !SelectionInListModelView methodsFor:'drag & drop'! |
885 !SelectionInListModelView methodsFor:'drag & drop'! |
901 visibleY := aContext targetPoint y. |
901 visibleY := aContext targetPoint y. |
902 yOrigin := self yOriginOfContents. |
902 yOrigin := self yOriginOfContents. |
903 inset := 15 + margin. |
903 inset := 15 + margin. |
904 |
904 |
905 visibleY <= inset ifTrue:[ |
905 visibleY <= inset ifTrue:[ |
906 self yOriginOfContents == 0 ifTrue:[ ^ false ]. |
906 self yOriginOfContents == 0 ifTrue:[ ^ false ]. |
907 ] ifFalse:[ |
907 ] ifFalse:[ |
908 visibleY < (self height - inset) ifTrue:[ ^ false ]. |
908 visibleY < (self height - inset) ifTrue:[ ^ false ]. |
909 self yOriginOfContents < self maxViewOriginY ifFalse:[ ^ false ]. |
909 self yOriginOfContents < self maxViewOriginY ifFalse:[ ^ false ]. |
910 ]. |
910 ]. |
911 |
911 |
912 aContext contentsWillChange. |
912 aContext contentsWillChange. |
913 |
913 |
914 visibleY <= inset ifTrue:[ self scrollUp:inset ] |
914 visibleY <= inset ifTrue:[ self scrollUp:inset ] |
915 ifFalse:[ self scrollDown:inset ]. |
915 ifFalse:[ self scrollDown:inset ]. |
916 |
916 |
917 ^ true |
917 ^ true |
918 ! |
918 ! |
919 |
919 |
920 dropSource |
920 dropSource |
921 "returns the dropSource or nil" |
921 "returns the dropSource or nil" |
922 |
922 |
923 ^ dropSource |
923 ^ dropSource |
924 ! |
924 ! |
925 |
925 |
926 dropSource:aDropSourceOrNil |
926 dropSource:aDropSourceOrNil |
927 "set the dropSource or nil" |
927 "set the dropSource or nil" |
928 |
928 |
929 dropSource := aDropSourceOrNil. |
929 dropSource := aDropSourceOrNil. |
930 ! |
930 ! |
931 |
931 |
932 startDragAt:aPoint |
932 startDragAt:aPoint |
933 "start drag at a point |
933 "start drag at a point |
934 " |
934 " |
935 buttonMotionAction := buttonReleaseAction := nil. |
935 buttonMotionAction := buttonReleaseAction := nil. |
936 |
936 |
937 dropSource notNil ifTrue:[ |
937 dropSource notNil ifTrue:[ |
938 dropSource startDragSelector notNil ifTrue:[ |
938 dropSource startDragSelector notNil ifTrue:[ |
939 ^ dropSource startDragIn:self at:aPoint |
939 ^ dropSource startDragIn:self at:aPoint |
940 ] ifFalse:[ |
940 ] ifFalse:[ |
941 ^ DragAndDropManager new |
941 ^ DragAndDropManager new |
942 startDragFrom:self dropSource:dropSource offset:#center |
942 startDragFrom:self dropSource:dropSource offset:#center |
943 ] |
943 ] |
944 ]. |
944 ]. |
945 ^ nil |
945 ^ nil |
946 ! ! |
946 ! ! |
947 |
947 |
948 !SelectionInListModelView methodsFor:'drawing'! |
948 !SelectionInListModelView methodsFor:'drawing'! |
984 " |
984 " |
985 |item y0 x1 x w drawStrikeOut xOut0 xOut1| |
985 |item y0 x1 x w drawStrikeOut xOut0 xOut1| |
986 |
986 |
987 x := xI + 1. |
987 x := xI + 1. |
988 editorView notNil ifTrue:[ |
988 editorView notNil ifTrue:[ |
989 "/ there is an open editor for the line; thus no redraw for the label (hidden by editor) |
989 "/ there is an open editor for the line; thus no redraw for the label (hidden by editor) |
990 self selectedIndex == anIndex ifTrue:[^ self]. |
990 self selectedIndex == anIndex ifTrue:[^ self]. |
991 ]. |
991 ]. |
992 |
992 |
993 item := self at:anIndex ifAbsent:nil. |
993 item := self at:anIndex ifAbsent:nil. |
994 item isNil ifTrue:[^ self]. |
994 item isNil ifTrue:[^ self]. |
995 |
995 |
996 drawStrikeOut := false. |
996 drawStrikeOut := false. |
997 |
997 |
998 (highlightMode notNil and:[self isInSelection:anIndex]) ifTrue:[ |
998 (highlightMode notNil and:[self isInSelection:anIndex]) ifTrue:[ |
999 strikeOut ifTrue:[ |
999 strikeOut ifTrue:[ |
1000 drawStrikeOut := true. |
1000 drawStrikeOut := true. |
1001 self paint:fgColor on:bgColor |
1001 self paint:fgColor on:bgColor |
1002 ] ifFalse:[ |
1002 ] ifFalse:[ |
1003 (highlightMode == #dropMode or:[self hasFocus not]) ifTrue:[ |
1003 (highlightMode == #dropMode or:[self hasFocus not]) ifTrue:[ |
1004 self paint:hilightFgColorNoFocus on:hilightBgColorNoFocus. |
1004 self paint:hilightFgColorNoFocus on:hilightBgColorNoFocus. |
1005 ] ifFalse:[ |
1005 ] ifFalse:[ |
1006 self paint:hilightFgColor on:hilightBgColor |
1006 self paint:hilightFgColor on:hilightBgColor |
1007 ]. |
1007 ]. |
1008 ] |
1008 ] |
1009 ] ifFalse:[ |
1009 ] ifFalse:[ |
1010 enterItem == item ifTrue:[ |
1010 enterItem == item ifTrue:[ |
1011 self paint:hilightBgColor on:bgColor. |
1011 self paint:hilightBgColor on:bgColor. |
1012 ] ifFalse:[ |
1012 ] ifFalse:[ |
1013 self paint:fgColor on:bgColor. |
1013 self paint:fgColor on:bgColor. |
1014 ]. |
1014 ]. |
1015 ]. |
1015 ]. |
1016 renderer display:item atX:x y:y lineHeight:h. |
1016 listRenderer display:item atX:x y:y lineHeight:h. |
1017 |
1017 |
1018 drawStrikeOut ifTrue:[ |
1018 drawStrikeOut ifTrue:[ |
1019 xOut0 := self xVisibleOfItem:item. |
1019 xOut0 := self xVisibleOfItem:item. |
1020 highlightMode == #label ifTrue:[ |
1020 highlightMode == #label ifTrue:[ |
1021 xOut1 := xOut0 + (renderer widthFor:item). |
1021 xOut1 := xOut0 + (listRenderer widthFor:item). |
1022 ] ifFalse:[ |
1022 ] ifFalse:[ |
1023 xOut1 := width - margin. |
1023 xOut1 := width - margin. |
1024 ]. |
1024 ]. |
1025 y0 := y + (h // 2). |
1025 y0 := y + (h // 2). |
1026 self displayLineFromX:xOut0 y:y0 toX:xOut1 y:y0. |
1026 self displayLineFromX:xOut0 y:y0 toX:xOut1 y:y0. |
1027 y0 := y0 - 1. |
1027 y0 := y0 - 1. |
1028 self displayLineFromX:xOut0 y:y0 toX:xOut1 y:y0. |
1028 self displayLineFromX:xOut0 y:y0 toX:xOut1 y:y0. |
1029 ]. |
1029 ]. |
1030 |
1030 |
1031 cursorItem == item ifTrue:[ |
1031 cursorItem == item ifTrue:[ |
1032 "/ textStartLeft |
1032 "/ textStartLeft |
1033 self maskOrigin:((self viewOrigin + (0 @ 1)) \\ (lineMask extent)). |
1033 self maskOrigin:((self viewOrigin + (0 @ 1)) \\ (lineMask extent)). |
1034 self mask:lineMask. |
1034 self mask:lineMask. |
1035 w := renderer widthFor:item. |
1035 w := listRenderer widthFor:item. |
1036 self displayRectangleX:x -1 y:(y+2) width:w+2 height:(h - 4). |
1036 self displayRectangleX:x -1 y:(y+2) width:w+2 height:(h - 4). |
1037 self mask:nil. |
1037 self mask:nil. |
1038 ] ifFalse:[ |
1038 ] ifFalse:[ |
1039 enterItem == item ifTrue:[ |
1039 enterItem == item ifTrue:[ |
1040 self highlightWithUnderline ifTrue:[ |
1040 self highlightWithUnderline ifTrue:[ |
1041 "/ underline the hilite... |
1041 "/ underline the hilite... |
1042 y0 := y + h - 2. |
1042 y0 := y + h - 2. |
1043 x1 := x + (renderer widthFor:item). |
1043 x1 := x + (listRenderer widthFor:item). |
1044 |
1044 |
1045 self displayLineFromX:x y:y0 toX:x1 y:y0. |
1045 self displayLineFromX:x y:y0 toX:x1 y:y0. |
1046 ] |
1046 ] |
1047 ]. |
1047 ]. |
1048 ]. |
1048 ]. |
1049 ! |
1049 ! |
1050 |
1050 |
1051 drawSelectionFrameAt:lnNr x:x w:w |
1051 drawSelectionFrameAt:lnNr x:x w:w |
1052 "draw the background and foreground of the selection frame |
1052 "draw the background and foreground of the selection frame |
1053 at a lineNr. |
1053 at a lineNr. |
1054 " |
1054 " |
1055 |item xMax xLftDmg xRgtDmg x0 x1 y0 y1 hL wL| |
1055 |item xMax xLftDmg xRgtDmg x0 x1 y0 y1 hL wL| |
1056 |
1056 |
1057 (strikeOut or:[highlightMode isNil]) ifTrue:[ |
1057 (strikeOut or:[highlightMode isNil]) ifTrue:[ |
1058 ^ self |
1058 ^ self |
1059 ]. |
1059 ]. |
1060 editorView notNil ifTrue:[ |
1060 editorView notNil ifTrue:[ |
1061 "/ there is an open editor; do not redraw selected |
1061 "/ there is an open editor; do not redraw selected |
1062 ^ self |
1062 ^ self |
1063 ]. |
1063 ]. |
1064 |
1064 |
1065 ( highlightMode == #line |
1065 ( highlightMode == #line |
1066 or:[highlightMode == #label |
1066 or:[highlightMode == #label |
1067 or:[highlightMode == #dropMode]] |
1067 or:[highlightMode == #dropMode]] |
1068 ) ifFalse:[ |
1068 ) ifFalse:[ |
1069 "/ highlightMode not supported |
1069 "/ highlightMode not supported |
1070 ^ self |
1070 ^ self |
1071 ]. |
1071 ]. |
1072 (item := self at:lnNr ifAbsent:nil) isNil ifTrue:[ |
1072 (item := self at:lnNr ifAbsent:nil) isNil ifTrue:[ |
1073 "/ list might change during drawing; item no longer visible |
1073 "/ list might change during drawing; item no longer visible |
1074 ^ self |
1074 ^ self |
1075 ]. |
1075 ]. |
1076 xMax := x + w. |
1076 xMax := x + w. |
1077 |
1077 |
1078 "/ CLEAR THE BACKGROUND |
1078 "/ CLEAR THE BACKGROUND |
1079 |
1079 |
1080 y0 := self yVisibleOfLine:lnNr. |
1080 y0 := self yVisibleOfLine:lnNr. |
1081 y1 := self yVisibleOfLine:(lnNr + 1). |
1081 y1 := self yVisibleOfLine:(lnNr + 1). |
1082 hL := y1 - y0. |
1082 hL := y1 - y0. |
1083 |
1083 |
1084 highlightMode == #line ifTrue:[ |
1084 highlightMode == #line ifTrue:[ |
1085 x0 := x. |
1085 x0 := x. |
1086 x1 := xMax. |
1086 x1 := xMax. |
1087 ] ifFalse:[ "/ is #label or #rectangle |
1087 ] ifFalse:[ "/ is #label or #rectangle |
1088 x0 := (self xVisibleOfItem:item) - (textStartLeft // 2). |
1088 x0 := (self xVisibleOfItem:item) - (textStartLeft // 2). |
1089 x0 >= xMax ifTrue:[ ^ self ]. |
1089 x0 >= xMax ifTrue:[ ^ self ]. |
1090 |
1090 |
1091 x1 := x0 + (renderer widthFor:item) + textStartLeft + 1. |
1091 x1 := x0 + (listRenderer widthFor:item) + textStartLeft + 1. |
1092 x1 < x ifTrue:[ ^ self ]. |
1092 x1 < x ifTrue:[ ^ self ]. |
1093 ]. |
1093 ]. |
1094 xLftDmg := x0 max:x. |
1094 xLftDmg := x0 max:x. |
1095 xRgtDmg := x1 min:xMax. |
1095 xRgtDmg := x1 min:xMax. |
1096 xRgtDmg > xLftDmg ifFalse:[^ self]. |
1096 xRgtDmg > xLftDmg ifFalse:[^ self]. |
1097 |
1097 |
1098 (highlightMode == #dropMode or:[self hasFocus not]) ifTrue:[ |
1098 (highlightMode == #dropMode or:[self hasFocus not]) ifTrue:[ |
1099 self paint:hilightBgColorNoFocus. |
1099 self paint:hilightBgColorNoFocus. |
1100 ] ifFalse:[ |
1100 ] ifFalse:[ |
1101 self paint:hilightBgColor. |
1101 self paint:hilightBgColor. |
1102 ]. |
1102 ]. |
1103 self fillRectangleX:xLftDmg y:y0 width:(xRgtDmg - xLftDmg) height:hL. |
1103 self fillRectangleX:xLftDmg y:y0 width:(xRgtDmg - xLftDmg) height:hL. |
1104 wL := x1 - x0. |
1104 wL := x1 - x0. |
1105 |
1105 |
1106 "/ DRAW THE FRAME |
1106 "/ DRAW THE FRAME |
1107 |
1107 |
1108 hilightFrameColor notNil ifTrue:[ |
1108 hilightFrameColor notNil ifTrue:[ |
1109 hilightLevel == 0 ifTrue:[ |
1109 hilightLevel == 0 ifTrue:[ |
1110 self paint:hilightFrameColor. |
1110 self paint:hilightFrameColor. |
1111 |
1111 |
1112 highlightMode == #line ifTrue:[ |
1112 highlightMode == #line ifTrue:[ |
1113 self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
1113 self displayLineFromX:x0 y:y0 toX:x1 y:y0. |
1114 y1 := y0 + hL - 1. |
1114 y1 := y0 + hL - 1. |
1115 self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
1115 self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
1116 ] ifFalse:[ |
1116 ] ifFalse:[ |
1117 self displayRectangleX:x0 y:y0 width:wL height:hL |
1117 self displayRectangleX:x0 y:y0 width:wL height:hL |
1118 ]. |
1118 ]. |
1119 ^ self. |
1119 ^ self. |
1120 ] |
1120 ] |
1121 ] ifFalse:[ |
1121 ] ifFalse:[ |
1122 hilightStyle == #motif ifTrue:[ |
1122 hilightStyle == #motif ifTrue:[ |
1123 self paint:bgColor. |
1123 self paint:bgColor. |
1124 y1 := y0 + 1. |
1124 y1 := y0 + 1. |
1125 highlightMode == #line ifTrue:[ |
1125 highlightMode == #line ifTrue:[ |
1126 self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
1126 self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
1127 y1 := y0 + hL - 2. |
1127 y1 := y0 + hL - 2. |
1128 self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
1128 self displayLineFromX:x0 y:y1 toX:x1 y:y1. |
1129 ] ifFalse:[ |
1129 ] ifFalse:[ |
1130 self displayRectangleX:x0 + 1 y:y1 width:wL - 2 height:hL - 2 |
1130 self displayRectangleX:x0 + 1 y:y1 width:wL - 2 height:hL - 2 |
1131 ] |
1131 ] |
1132 ]. |
1132 ]. |
1133 hilightLevel == 0 ifTrue:[ ^ self ]. |
1133 hilightLevel == 0 ifTrue:[ ^ self ]. |
1134 ]. |
1134 ]. |
1135 |
1135 |
1136 "/ draw edge |
1136 "/ draw edge |
1137 highlightMode == #line ifTrue:[ |
1137 highlightMode == #line ifTrue:[ |
1138 x0 := margin. |
1138 x0 := margin. |
1139 wL := width - x0 - x0. |
1139 wL := width - x0 - x0. |
1140 ]. |
1140 ]. |
1141 self drawEdgesForX:x0 y:y0 width:wL height:hL level:hilightLevel. |
1141 self drawEdgesForX:x0 y:y0 width:wL height:hL level:hilightLevel. |
1142 ! |
1142 ! |
1143 |
1143 |
1144 invalidateSelection |
1144 invalidateSelection |
1145 "invalidate the current selection |
1145 "invalidate the current selection |
1146 " |
1146 " |
1147 shown ifTrue:[ |
1147 shown ifTrue:[ |
1148 self selectionDo:[:aLnNr| |
1148 self selectionDo:[:aLnNr| |
1149 self invalidateLineAt:aLnNr |
1149 self invalidateLineAt:aLnNr |
1150 ]. |
1150 ]. |
1151 ]. |
1151 ]. |
1152 ! |
1152 ! |
1153 |
1153 |
1154 invalidateSelectionAt:aLineNr |
1154 invalidateSelectionAt:aLineNr |
1155 "redraw a line which changed its selection status. |
1155 "redraw a line which changed its selection status. |
1156 optimized when drawing only the label. |
1156 optimized when drawing only the label. |
1157 " |
1157 " |
1158 |item x| |
1158 |item x| |
1159 |
1159 |
1160 editorView notNil ifTrue:[ |
1160 editorView notNil ifTrue:[ |
1161 "/ there is an open editor; do not redraw selected |
1161 "/ there is an open editor; do not redraw selected |
1162 ^ self |
1162 ^ self |
1163 ]. |
1163 ]. |
1164 |
1164 |
1165 (shown and:[aLineNr notNil and:[highlightMode notNil]]) ifFalse:[ |
1165 (shown and:[aLineNr notNil and:[highlightMode notNil]]) ifFalse:[ |
1166 ^ self |
1166 ^ self |
1167 ]. |
1167 ]. |
1168 |
1168 |
1169 highlightMode == #label ifTrue:[ |
1169 highlightMode == #label ifTrue:[ |
1170 item := self at:aLineNr ifAbsent:nil. |
1170 item := self at:aLineNr ifAbsent:nil. |
1171 |
1171 |
1172 item isNil ifTrue:[ |
1172 item isNil ifTrue:[ |
1173 ^ self |
1173 ^ self |
1174 ]. |
1174 ]. |
1175 x := (self xVisibleOfItem:item) - (textStartLeft // 2) |
1175 x := (self xVisibleOfItem:item) - (textStartLeft // 2) |
1176 ] ifFalse:[ |
1176 ] ifFalse:[ |
1177 x := 0. |
1177 x := 0. |
1178 ]. |
1178 ]. |
1179 self invalidateLineAt:aLineNr fromX:x |
1179 self invalidateLineAt:aLineNr fromX:x |
1180 ! ! |
1180 ! ! |
1181 |
1181 |
1182 !SelectionInListModelView methodsFor:'event handling'! |
1182 !SelectionInListModelView methodsFor:'event handling'! |
1187 |isInSelection prvLine chgSet doAdd| |
1187 |isInSelection prvLine chgSet doAdd| |
1188 |
1188 |
1189 isInSelection := self isInSelection:lineNr. |
1189 isInSelection := self isInSelection:lineNr. |
1190 |
1190 |
1191 multipleSelectOk ifFalse:[ |
1191 multipleSelectOk ifFalse:[ |
1192 isInSelection ifTrue:[ |
1192 isInSelection ifTrue:[ |
1193 self deselect |
1193 self deselect |
1194 ]ifFalse:[ |
1194 ]ifFalse:[ |
1195 (self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
1195 (self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
1196 self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
1196 self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
1197 ]. |
1197 ]. |
1198 ]. |
1198 ]. |
1199 ^ self |
1199 ^ self |
1200 ]. |
1200 ]. |
1201 isInSelection ifTrue:[ |
1201 isInSelection ifTrue:[ |
1202 self removeFromSelection:lineNr |
1202 self removeFromSelection:lineNr |
1203 ] ifFalse:[ |
1203 ] ifFalse:[ |
1204 self addToSelection:lineNr. |
1204 self addToSelection:lineNr. |
1205 |
1205 |
1206 (self isInSelection:lineNr) ifFalse:[ |
1206 (self isInSelection:lineNr) ifFalse:[ |
1207 "/ cannot add to selection |
1207 "/ cannot add to selection |
1208 ^ self |
1208 ^ self |
1209 ]. |
1209 ]. |
1210 ]. |
1210 ]. |
1211 |
1211 |
1212 prvLine := lineNr. |
1212 prvLine := lineNr. |
1213 chgSet := IdentitySet new. |
1213 chgSet := IdentitySet new. |
1214 doAdd := isInSelection not. |
1214 doAdd := isInSelection not. |
1215 |
1215 |
1216 buttonMotionAction := [:p| |rowNr mustRestore step f| |
1216 buttonMotionAction := [:p| |rowNr mustRestore step f| |
1217 rowNr := self yVisibleToLineNr:(p y). |
1217 rowNr := self yVisibleToLineNr:(p y). |
1218 |
1218 |
1219 (rowNr notNil and:[rowNr ~~ prvLine]) ifTrue:[ |
1219 (rowNr notNil and:[rowNr ~~ prvLine]) ifTrue:[ |
1220 rowNr == lineNr ifTrue:[ |
1220 rowNr == lineNr ifTrue:[ |
1221 mustRestore := true |
1221 mustRestore := true |
1222 ] ifFalse:[ |
1222 ] ifFalse:[ |
1223 rowNr > lineNr ifTrue:[ mustRestore := (rowNr < prvLine) ] |
1223 rowNr > lineNr ifTrue:[ mustRestore := (rowNr < prvLine) ] |
1224 ifFalse:[ mustRestore := (rowNr > prvLine) ]. |
1224 ifFalse:[ mustRestore := (rowNr > prvLine) ]. |
1225 ]. |
1225 ]. |
1226 prvLine > rowNr ifTrue:[ step := -1 ] |
1226 prvLine > rowNr ifTrue:[ step := -1 ] |
1227 ifFalse:[ step := 1 ]. |
1227 ifFalse:[ step := 1 ]. |
1228 mustRestore ifTrue:[ |
1228 mustRestore ifTrue:[ |
1229 [ prvLine ~~ rowNr ] whileTrue:[ |
1229 [ prvLine ~~ rowNr ] whileTrue:[ |
1230 (chgSet removeIdentical:prvLine ifAbsent:nil) notNil ifTrue:[ |
1230 (chgSet removeIdentical:prvLine ifAbsent:nil) notNil ifTrue:[ |
1231 doAdd ifFalse:[ self addToSelection:prvLine ] |
1231 doAdd ifFalse:[ self addToSelection:prvLine ] |
1232 ifTrue:[ self removeFromSelection:prvLine ]. |
1232 ifTrue:[ self removeFromSelection:prvLine ]. |
1233 ]. |
1233 ]. |
1234 prvLine := prvLine + step. |
1234 prvLine := prvLine + step. |
1235 ]. |
1235 ]. |
1236 ] ifFalse:[ |
1236 ] ifFalse:[ |
1237 [ prvLine ~~ rowNr ] whileTrue:[ |
1237 [ prvLine ~~ rowNr ] whileTrue:[ |
1238 prvLine := prvLine + step. |
1238 prvLine := prvLine + step. |
1239 |
1239 |
1240 doAdd ~~ (self isInSelection:rowNr) ifTrue:[ |
1240 doAdd ~~ (self isInSelection:rowNr) ifTrue:[ |
1241 chgSet add:prvLine. |
1241 chgSet add:prvLine. |
1242 |
1242 |
1243 doAdd ifTrue:[ self addToSelection:prvLine ] |
1243 doAdd ifTrue:[ self addToSelection:prvLine ] |
1244 ifFalse:[ self removeFromSelection:prvLine ]. |
1244 ifFalse:[ self removeFromSelection:prvLine ]. |
1245 ] |
1245 ] |
1246 ]. |
1246 ]. |
1247 ]. |
1247 ]. |
1248 ]. |
1248 ]. |
1249 ]. |
1249 ]. |
1250 ! |
1250 ! |
1251 |
1251 |
1252 buttonMotion:buttonMask x:x y:y |
1252 buttonMotion:buttonMask x:x y:y |
1253 "mouse-move while button was pressed - handle selection changes |
1253 "mouse-move while button was pressed - handle selection changes |
1311 |
1311 |
1312 modelChangedDuringButtonPress := buttonMotionAction := buttonReleaseAction := nil. |
1312 modelChangedDuringButtonPress := buttonMotionAction := buttonReleaseAction := nil. |
1313 |
1313 |
1314 self pointerEntersItem:nil. |
1314 self pointerEntersItem:nil. |
1315 self cursorEntersItem:nil. |
1315 self cursorEntersItem:nil. |
1316 self closeEditor. |
1316 self closeEditor. |
1317 |
1317 |
1318 enabled ifFalse:[^ self]. |
1318 enabled ifFalse:[^ self]. |
1319 |
1319 |
1320 sensor := self sensor. |
1320 sensor := self sensor. |
1321 lineNr := self yVisibleToLineNr:y. |
1321 lineNr := self yVisibleToLineNr:y. |
1322 |
1322 |
1323 ((button == 2) or:[button == #menu]) ifTrue:[ |
1323 ((button == 2) or:[button == #menu]) ifTrue:[ |
1324 (self selectOnMenuButton and:[self numberOfSelections <= 1]) ifTrue:[ |
1324 (self selectOnMenuButton and:[self numberOfSelections <= 1]) ifTrue:[ |
1325 ( lineNr notNil |
1325 ( lineNr notNil |
1326 and:[self canSelectIndex:lineNr forAdd:false ] |
1326 and:[self canSelectIndex:lineNr forAdd:false ] |
1327 ) ifTrue:[ |
1327 ) ifTrue:[ |
1328 (lineNr ~~ self selectedIndex) ifTrue: [ |
1328 (lineNr ~~ self selectedIndex) ifTrue: [ |
1329 (self selectWithoutScroll:lineNr redraw:true) ifTrue:[ |
1329 (self selectWithoutScroll:lineNr redraw:true) ifTrue:[ |
1330 self selectionChanged |
1330 self selectionChanged |
1331 ]. |
1331 ]. |
1332 ]. |
1332 ]. |
1333 item := self selectedElement. |
1333 item := self selectedElement. |
1334 ] ifFalse:[ |
1334 ] ifFalse:[ |
1335 item := nil. |
1335 item := nil. |
1336 item := self selectedElement. |
1336 item := self selectedElement. |
1337 "/ self deselect. |
1337 "/ self deselect. |
1338 ] |
1338 ] |
1339 ] ifFalse:[ |
1339 ] ifFalse:[ |
1340 item := self selectedElement. |
1340 item := self selectedElement. |
1341 ]. |
1341 ]. |
1342 |
1342 |
1343 item notNil ifTrue:[ |
1343 item notNil ifTrue:[ |
1344 self makeSelectionVisible. |
1344 self makeSelectionVisible. |
1345 |
1345 |
1346 menu := item perform:#middleButtonMenu ifNotUnderstood:nil. |
1346 menu := item perform:#middleButtonMenu ifNotUnderstood:nil. |
1347 menu notNil ifTrue:[ |
1347 menu notNil ifTrue:[ |
1348 menu isCollection ifTrue:[ |
1348 menu isCollection ifTrue:[ |
1349 menu := Menu decodeFromLiteralArray:menu. |
1349 menu := Menu decodeFromLiteralArray:menu. |
1350 appl := self application. |
1350 appl := self application. |
1351 |
1351 |
1352 appl notNil ifTrue:[ |
1352 appl notNil ifTrue:[ |
1353 menu findGuiResourcesIn:appl. |
1353 menu findGuiResourcesIn:appl. |
1354 "/ menu receiver:appl -- now done in findGuiResources ... |
1354 "/ menu receiver:appl -- now done in findGuiResources ... |
1355 ] ifFalse:[ |
1355 ] ifFalse:[ |
1356 menu receiver:item |
1356 menu receiver:item |
1357 ] |
1357 ] |
1358 ]. |
1358 ]. |
1359 self startUpMenu:menu. |
1359 self startUpMenu:menu. |
1360 ^ self |
1360 ^ self |
1361 ]. |
1361 ]. |
1362 ]. |
1362 ]. |
1363 super buttonPress:button x:x y:y. |
1363 super buttonPress:button x:x y:y. |
1364 ^ self |
1364 ^ self |
1365 ]. |
1365 ]. |
1366 lineNr isNil ifTrue:[ ^ self ]. |
1366 lineNr isNil ifTrue:[ ^ self ]. |
1367 modelChangedDuringButtonPress := false. |
1367 modelChangedDuringButtonPress := false. |
1368 |
1368 |
1369 sensor ctrlDown ifTrue:[ |
1369 sensor ctrlDown ifTrue:[ |
1370 self buttonControlPressAtLine:lineNr x:x y:y. |
1370 self buttonControlPressAtLine:lineNr x:x y:y. |
1371 ^ self |
1371 ^ self |
1372 ]. |
1372 ]. |
1373 |
1373 |
1374 isSelected := self isInSelection:lineNr. |
1374 isSelected := self isInSelection:lineNr. |
1375 |
1375 |
1376 (self canDrag and:[sensor shiftDown not]) ifTrue:[ |
1376 (self canDrag and:[sensor shiftDown not]) ifTrue:[ |
1377 dragDistance := UserPreferences current motionDistanceToStartDrag. |
1377 dragDistance := UserPreferences current motionDistanceToStartDrag. |
1378 |
1378 |
1379 isSelected ifTrue:[ |
1379 isSelected ifTrue:[ |
1380 buttonMotionAction := |
1380 buttonMotionAction := |
1381 [:p| |
1381 [:p| |
1382 ((x@y) dist:p) > dragDistance ifTrue:[ |
1382 ((x@y) dist:p) > dragDistance ifTrue:[ |
1383 self startDragAt:p. |
1383 self startDragAt:p. |
1384 ] |
1384 ] |
1385 ]. |
1385 ]. |
1386 buttonReleaseAction := [ self buttonPressOrReleaseAtLine:lineNr x:x y:y ]. |
1386 buttonReleaseAction := [ self buttonPressOrReleaseAtLine:lineNr x:x y:y ]. |
1387 ^ self. |
1387 ^ self. |
1388 ]. |
1388 ]. |
1389 |
1389 |
1390 self selectOnButtonPress ifFalse: [ |
1390 self selectOnButtonPress ifFalse: [ |
1391 |oldSelection| |
1391 |oldSelection| |
1392 |
1392 |
1393 "/ set selection to line; |
1393 "/ set selection to line; |
1394 "/ set the model without change notification (objects to drag) |
1394 "/ set the model without change notification (objects to drag) |
1395 |
1395 |
1396 oldSelection := selection copy. |
1396 oldSelection := selection copy. |
1397 self selectAndUpdateModelWithoutChangeNotification: lineNr. |
1397 self selectAndUpdateModelWithoutChangeNotification: lineNr. |
1398 self windowGroup processExposeEvents. |
1398 self windowGroup processExposeEvents. |
1399 |
1399 |
1400 buttonMotionAction := |
1400 buttonMotionAction := |
1401 [:p| |
1401 [:p| |
1402 ((x@y) dist:p) > dragDistance ifTrue:[ |
1402 ((x@y) dist:p) > dragDistance ifTrue:[ |
1403 |handler| |
1403 |handler| |
1404 |
1404 |
1405 handler := self startDragAt:p. |
1405 handler := self startDragAt:p. |
1406 handler contentsWillChange. |
1406 handler contentsWillChange. |
1407 "/ restore old selection |
1407 "/ restore old selection |
1408 self selectAndUpdateModelWithoutChangeNotification: oldSelection. |
1408 self selectAndUpdateModelWithoutChangeNotification: oldSelection. |
1409 self windowGroup processExposeEvents. |
1409 self windowGroup processExposeEvents. |
1410 ]. |
1410 ]. |
1411 ]. |
1411 ]. |
1412 |
1412 |
1413 buttonReleaseAction := [ |
1413 buttonReleaseAction := [ |
1414 (self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
1414 (self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
1415 "/ notify selection change |
1415 "/ notify selection change |
1416 self selectionChanged. |
1416 self selectionChanged. |
1417 ] ifFalse:[ |
1417 ] ifFalse:[ |
1418 "/ restore old selection |
1418 "/ restore old selection |
1419 self selectAndUpdateModelWithoutChangeNotification: oldSelection. |
1419 self selectAndUpdateModelWithoutChangeNotification: oldSelection. |
1420 ]. |
1420 ]. |
1421 ]. |
1421 ]. |
1422 ^ self |
1422 ^ self |
1423 ]. |
1423 ]. |
1424 ]. |
1424 ]. |
1425 |
1425 |
1426 multipleSelectOk ifFalse:[ |
1426 multipleSelectOk ifFalse:[ |
1427 (isSelected or:[self canSelectIndex:lineNr forAdd:false]) ifTrue:[ |
1427 (isSelected or:[self canSelectIndex:lineNr forAdd:false]) ifTrue:[ |
1428 self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
1428 self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
1429 |
1429 |
1430 (dragDistance notNil and:[self isInSelection:lineNr]) ifTrue:[ |
1430 (dragDistance notNil and:[self isInSelection:lineNr]) ifTrue:[ |
1431 buttonMotionAction := |
1431 buttonMotionAction := |
1432 [:p| |
1432 [:p| |
1433 ((x@y) dist:p) > dragDistance ifTrue:[ |
1433 ((x@y) dist:p) > dragDistance ifTrue:[ |
1434 self startDragAt:p. |
1434 self startDragAt:p. |
1435 ]. |
1435 ]. |
1436 ]. |
1436 ]. |
1437 ]. |
1437 ]. |
1438 ]. |
1438 ]. |
1439 ^ self |
1439 ^ self |
1440 ]. |
1440 ]. |
1441 startLine := lineNr. |
1441 startLine := lineNr. |
1442 |
1442 |
1443 sensor shiftDown ifTrue:[ |min max| |
1443 sensor shiftDown ifTrue:[ |min max| |
1444 (isSelected or:[self canSelectIndex:lineNr forAdd:true]) ifFalse:[ |
1444 (isSelected or:[self canSelectIndex:lineNr forAdd:true]) ifFalse:[ |
1445 ^ self |
1445 ^ self |
1446 ]. |
1446 ]. |
1447 |
1447 |
1448 multipleSelectOk ifTrue:[ |
1448 multipleSelectOk ifTrue:[ |
1449 startLine := self firstInSelection. |
1449 startLine := self firstInSelection. |
1450 startLine isNil ifTrue:[ startLine := lineNr ]. |
1450 startLine isNil ifTrue:[ startLine := lineNr ]. |
1451 |
1451 |
1452 startLine <= lineNr ifTrue:[ |
1452 startLine <= lineNr ifTrue:[ |
1453 self selectFrom:startLine to:lineNr. |
1453 self selectFrom:startLine to:lineNr. |
1454 ] ifFalse:[ |
1454 ] ifFalse:[ |
1455 startLine := self lastInSelection. |
1455 startLine := self lastInSelection. |
1456 self selectFrom:lineNr to:startLine. |
1456 self selectFrom:lineNr to:startLine. |
1457 ]. |
1457 ]. |
1458 ] |
1458 ] |
1459 ] ifFalse:[ |
1459 ] ifFalse:[ |
1460 (isSelected or:[self canSelectIndex:lineNr forAdd:false]) ifFalse:[ |
1460 (isSelected or:[self canSelectIndex:lineNr forAdd:false]) ifFalse:[ |
1461 ^ self |
1461 ^ self |
1462 ]. |
1462 ]. |
1463 self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
1463 self buttonPressOrReleaseAtLine:lineNr x:x y:y. |
1464 ]. |
1464 ]. |
1465 |
1465 |
1466 multipleSelectOk ifTrue:[ |
1466 multipleSelectOk ifTrue:[ |
1467 buttonMotionAction := |
1467 buttonMotionAction := |
1468 [:p| |ln| |
1468 [:p| |ln| |
1469 (p y between:0 and:height) ifTrue:[ |ln| |
1469 (p y between:0 and:height) ifTrue:[ |ln| |
1470 ln := self yVisibleToLineNr:p y. |
1470 ln := self yVisibleToLineNr:p y. |
1471 ln isNil ifTrue:[ln := self size]. |
1471 ln isNil ifTrue:[ln := self size]. |
1472 |
1472 |
1473 (ln ~~ self lastInSelection and:[ln ~~ self firstInSelection]) ifTrue:[ |
1473 (ln ~~ self lastInSelection and:[ln ~~ self firstInSelection]) ifTrue:[ |
1474 self selectFrom:startLine to:ln. |
1474 self selectFrom:startLine to:ln. |
1475 dragDistance := nil. "/ selection changed - no longer dragable |
1475 dragDistance := nil. "/ selection changed - no longer dragable |
1476 ] |
1476 ] |
1477 ]. |
1477 ]. |
1478 |
1478 |
1479 (dragDistance notNil and:[(x dist:p x) > dragDistance]) ifTrue:[ |
1479 (dragDistance notNil and:[(x dist:p x) > dragDistance]) ifTrue:[ |
1480 self startDragAt:p. |
1480 self startDragAt:p. |
1481 ]. |
1481 ]. |
1482 ]. |
1482 ]. |
1483 ]. |
1483 ]. |
1484 |
1484 |
1485 "Modified: / 27-03-2007 / 08:43:58 / cg" |
1485 "Modified: / 27-03-2007 / 08:43:58 / cg" |
1486 ! |
1486 ! |
1487 |
1487 |
1488 buttonPressOrReleaseAtLine:aLnNr x:x y:y |
1488 buttonPressOrReleaseAtLine:aLnNr x:x y:y |
1489 "handle a button press or release at a line |
1489 "handle a button press or release at a line |
1490 " |
1490 " |
1491 aLnNr == self selectedIndex ifTrue:[ |
1491 aLnNr == self selectedIndex ifTrue:[ |
1492 editorView notNil ifTrue:[^ self]. |
1492 editorView notNil ifTrue:[^ self]. |
1493 |
1493 |
1494 self openEditorAction notNil ifTrue:[ |
1494 self openEditorAction notNil ifTrue:[ |
1495 self openEditorAtX:x y:y. |
1495 self openEditorAtX:x y:y. |
1496 editorView notNil ifTrue:[^ self]. |
1496 editorView notNil ifTrue:[^ self]. |
1497 ]. |
1497 ]. |
1498 |
1498 |
1499 ignoreReselect ifFalse:[ |
1499 ignoreReselect ifFalse:[ |
1500 (toggleSelect and:[self sensor ctrlDown]) ifTrue:[ |
1500 (toggleSelect and:[self sensor ctrlDown]) ifTrue:[ |
1501 self selection:nil |
1501 self selection:nil |
1502 ] ifFalse:[ |
1502 ] ifFalse:[ |
1503 self selectionChanged |
1503 self selectionChanged |
1504 ]. |
1504 ]. |
1505 ]. |
1505 ]. |
1506 ] ifFalse:[ |
1506 ] ifFalse:[ |
1507 (self selectWithoutScroll:aLnNr redraw:true) ifTrue:[ |
1507 (self selectWithoutScroll:aLnNr redraw:true) ifTrue:[ |
1508 self selectionChanged |
1508 self selectionChanged |
1509 ] |
1509 ] |
1510 ]. |
1510 ]. |
1511 ! |
1511 ! |
1512 |
1512 |
1513 buttonRelease:button x:x y:y |
1513 buttonRelease:button x:x y:y |
1514 "a button was released |
1514 "a button was released |
1690 invalidateLineOfItem:anItem |
1690 invalidateLineOfItem:anItem |
1691 |lnNr x| |
1691 |lnNr x| |
1692 |
1692 |
1693 lnNr := self identityIndexOf:enterItem. |
1693 lnNr := self identityIndexOf:enterItem. |
1694 lnNr notNil ifTrue:[ |
1694 lnNr notNil ifTrue:[ |
1695 x := self xVisibleOfItem:enterItem. |
1695 x := self xVisibleOfItem:enterItem. |
1696 self invalidateLineAt:lnNr fromX:x |
1696 self invalidateLineAt:lnNr fromX:x |
1697 ]. |
1697 ]. |
1698 ! |
1698 ! |
1699 |
1699 |
1700 keyPress:aKey x:x y:y |
1700 keyPress:aKey x:x y:y |
1701 "a key was pressed - handle page-keys here |
1701 "a key was pressed - handle page-keys here |
1702 " |
1702 " |
1703 <resource: #keyboard( #CursorUp #CursorDown #EndOfText #EndOfLine |
1703 <resource: #keyboard( #CursorUp #CursorDown #EndOfText #EndOfLine |
1704 #BeginOfText #BeginOfLine #Return |
1704 #BeginOfText #BeginOfLine #Return |
1705 #CmdReturn #CmdCursorUp #CmdCursorDown #SelectAll)> |
1705 #CmdReturn #CmdCursorUp #CmdCursorDown #SelectAll)> |
1706 |
1706 |
1707 |lineNr listSize shifted newSel step start| |
1707 |lineNr listSize shifted newSel step start| |
1708 |
1708 |
1709 enabled ifFalse:[ ^ self ]. |
1709 enabled ifFalse:[ ^ self ]. |
1710 |
1710 |
1711 listSize := self size. |
1711 listSize := self size. |
1712 listSize == 0 ifTrue:[^ self]. |
1712 listSize == 0 ifTrue:[^ self]. |
1713 |
1713 |
1714 aKey isCharacter ifTrue:[ |
1714 aKey isCharacter ifTrue:[ |
1715 keyActionStyle notNil ifTrue:[ |
1715 keyActionStyle notNil ifTrue:[ |
1716 keyActionStyle == #pass ifTrue:[ |
1716 keyActionStyle == #pass ifTrue:[ |
1717 super keyPress:aKey x:x y:y |
1717 super keyPress:aKey x:x y:y |
1718 ] ifFalse:[ |
1718 ] ifFalse:[ |
1719 self characterPress:aKey x:x y:y. |
1719 self characterPress:aKey x:x y:y. |
1720 ]. |
1720 ]. |
1721 ]. |
1721 ]. |
1722 ^ self |
1722 ^ self |
1723 ]. |
1723 ]. |
1724 |
1724 |
1725 aKey == #Escape ifTrue:[ |
1725 aKey == #Escape ifTrue:[ |
1726 cursorItem notNil ifTrue:[ |
1726 cursorItem notNil ifTrue:[ |
1727 self cursorEntersItem:nil. |
1727 self cursorEntersItem:nil. |
1728 self makeSelectionVisible. |
1728 self makeSelectionVisible. |
1729 ]. |
1729 ]. |
1730 super keyPress:aKey x:x y:y. |
1730 super keyPress:aKey x:x y:y. |
1731 ^ self |
1731 ^ self |
1732 ]. |
1732 ]. |
1733 |
1733 |
1734 ((aKey == #BeginOfText) or:[aKey == #BeginOfLine]) ifTrue:[ |
1734 ((aKey == #BeginOfText) or:[aKey == #BeginOfLine]) ifTrue:[ |
1735 self cursorEntersItem:nil. |
1735 self cursorEntersItem:nil. |
1736 |
1736 |
1737 1 to:listSize do:[:i| |
1737 1 to:listSize do:[:i| |
1738 (self canSelectIndex:i forAdd:false) ifTrue:[ |
1738 (self canSelectIndex:i forAdd:false) ifTrue:[ |
1739 self selection:i. |
1739 self selection:i. |
1740 ^ self |
1740 ^ self |
1741 ]. |
1741 ]. |
1742 ]. |
1742 ]. |
1743 ^ self |
1743 ^ self |
1744 ]. |
1744 ]. |
1745 |
1745 |
1746 ((aKey == #EndOfText) or:[aKey == #EndOfLine]) ifTrue:[ |
1746 ((aKey == #EndOfText) or:[aKey == #EndOfLine]) ifTrue:[ |
1747 self cursorEntersItem:nil. |
1747 self cursorEntersItem:nil. |
1748 |
1748 |
1749 listSize to:1 by:-1 do:[:i| |
1749 listSize to:1 by:-1 do:[:i| |
1750 (self canSelectIndex:i forAdd:false) ifTrue:[ |
1750 (self canSelectIndex:i forAdd:false) ifTrue:[ |
1751 self selection:i. |
1751 self selection:i. |
1752 ^ self |
1752 ^ self |
1753 ]. |
1753 ]. |
1754 ]. |
1754 ]. |
1755 ^ self |
1755 ^ self |
1756 ]. |
1756 ]. |
1757 lineNr := self cursorLine. |
1757 lineNr := self cursorLine. |
1758 |
1758 |
1759 aKey == #Return ifTrue:[ |
1759 aKey == #Return ifTrue:[ |
1760 returnKeyActionStyle == #pass ifTrue:[ |
1760 returnKeyActionStyle == #pass ifTrue:[ |
1761 super keyPress:aKey x:x y:y |
1761 super keyPress:aKey x:x y:y |
1762 ] ifFalse:[ |
1762 ] ifFalse:[ |
1763 lineNr ~~ 0 ifTrue:[ |
1763 lineNr ~~ 0 ifTrue:[ |
1764 self cursorEntersItem:nil. |
1764 self cursorEntersItem:nil. |
1765 |
1765 |
1766 (self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
1766 (self canSelectIndex:lineNr forAdd:false) ifTrue:[ |
1767 self selection:lineNr |
1767 self selection:lineNr |
1768 ]. |
1768 ]. |
1769 ]. |
1769 ]. |
1770 |
1770 |
1771 returnKeyActionStyle == #doubleClick ifTrue:[ |
1771 returnKeyActionStyle == #doubleClick ifTrue:[ |
1772 self doubleClicked |
1772 self doubleClicked |
1773 ]. |
1773 ]. |
1774 ]. |
1774 ]. |
1775 ^ self |
1775 ^ self |
1776 ]. |
1776 ]. |
1777 |
1777 |
1778 aKey == #SelectAll ifTrue:[ |
1778 aKey == #SelectAll ifTrue:[ |
1779 self selectAll. |
1779 self selectAll. |
1780 ^ self |
1780 ^ self |
1781 ]. |
1781 ]. |
1782 |
1782 |
1783 (lineNr == 0 and:[selection notNil]) ifTrue:[ |
1783 (lineNr == 0 and:[selection notNil]) ifTrue:[ |
1784 multipleSelectOk ifFalse:[lineNr := selection] |
1784 multipleSelectOk ifFalse:[lineNr := selection] |
1785 ifTrue:[lineNr := selection last]. |
1785 ifTrue:[lineNr := selection last]. |
1786 ]. |
1786 ]. |
1787 |
1787 |
1788 aKey == #CmdReturn ifTrue:[ |
1788 aKey == #CmdReturn ifTrue:[ |
1789 "/ toggle selection of the item |
1789 "/ toggle selection of the item |
1790 lineNr ~~ 0 ifTrue:[ |
1790 lineNr ~~ 0 ifTrue:[ |
1791 (self isInSelection:lineNr) ifTrue:[ self removeFromSelection:lineNr ] |
1791 (self isInSelection:lineNr) ifTrue:[ self removeFromSelection:lineNr ] |
1792 ifFalse:[ self addToSelection:lineNr ]. |
1792 ifFalse:[ self addToSelection:lineNr ]. |
1793 |
1793 |
1794 self cursorEntersItem:(self at:lineNr). |
1794 self cursorEntersItem:(self at:lineNr). |
1795 ]. |
1795 ]. |
1796 ^ self |
1796 ^ self |
1797 ]. |
1797 ]. |
1798 |
1798 |
1799 (aKey == #CmdCursorDown or:[aKey == #CmdCursorUp]) ifTrue:[ |
1799 (aKey == #CmdCursorDown or:[aKey == #CmdCursorUp]) ifTrue:[ |
1800 aKey == #CmdCursorDown ifTrue:[ |
1800 aKey == #CmdCursorDown ifTrue:[ |
1801 lineNr := lineNr + 1. |
1801 lineNr := lineNr + 1. |
1802 lineNr > listSize ifTrue:[lineNr := 1]. |
1802 lineNr > listSize ifTrue:[lineNr := 1]. |
1803 ] ifFalse:[ |
1803 ] ifFalse:[ |
1804 lineNr := lineNr - 1. |
1804 lineNr := lineNr - 1. |
1805 lineNr < 1 ifTrue:[lineNr := listSize]. |
1805 lineNr < 1 ifTrue:[lineNr := listSize]. |
1806 ]. |
1806 ]. |
1807 self cursorEntersItem:(self at:lineNr). |
1807 self cursorEntersItem:(self at:lineNr). |
1808 ^ self |
1808 ^ self |
1809 ]. |
1809 ]. |
1810 |
1810 |
1811 (aKey == #CursorUp or:[aKey == #CursorDown]) ifFalse:[ |
1811 (aKey == #CursorUp or:[aKey == #CursorDown]) ifFalse:[ |
1812 super keyPress:aKey x:x y:y. |
1812 super keyPress:aKey x:x y:y. |
1813 ^ self |
1813 ^ self |
1814 ]. |
1814 ]. |
1815 shifted := (multipleSelectOk and:[self sensor shiftDown]). |
1815 shifted := (multipleSelectOk and:[self sensor shiftDown]). |
1816 self cursorEntersItem:nil. |
1816 self cursorEntersItem:nil. |
1817 |
1817 |
1818 aKey == #CursorDown ifTrue:[ step := 1.] |
1818 aKey == #CursorDown ifTrue:[ step := 1.] |
1819 ifFalse:[ step := -1.]. |
1819 ifFalse:[ step := -1.]. |
1820 |
1820 |
1821 shifted ifFalse:[ |compressed| |
1821 shifted ifFalse:[ |compressed| |
1822 compressed := self sensor compressKeyPressEventsWithKey:aKey. |
1822 compressed := self sensor compressKeyPressEventsWithKey:aKey. |
1823 |
1823 |
1824 compressed ~~ 0 ifTrue:[ |
1824 compressed ~~ 0 ifTrue:[ |
1825 aKey == #CursorDown ifTrue:[ |
1825 aKey == #CursorDown ifTrue:[ |
1826 lineNr := lineNr + compressed. |
1826 lineNr := lineNr + compressed. |
1827 lineNr > listSize ifTrue:[lineNr := 1]. |
1827 lineNr > listSize ifTrue:[lineNr := 1]. |
1828 ] ifFalse:[ |
1828 ] ifFalse:[ |
1829 lineNr := lineNr - compressed. |
1829 lineNr := lineNr - compressed. |
1830 lineNr < 1 ifTrue:[lineNr := listSize]. |
1830 lineNr < 1 ifTrue:[lineNr := listSize]. |
1831 ]. |
1831 ]. |
1832 ]. |
1832 ]. |
1833 ]. |
1833 ]. |
1834 start := lineNr. |
1834 start := lineNr. |
1835 lineNr := lineNr + step. |
1835 lineNr := lineNr + step. |
1836 |
1836 |
1837 [ lineNr ~~ start ] whileTrue:[ |
1837 [ lineNr ~~ start ] whileTrue:[ |
1838 (lineNr between:1 and:listSize) ifFalse:[ |
1838 (lineNr between:1 and:listSize) ifFalse:[ |
1839 lineNr < 1 ifTrue:[ lineNr := listSize ] |
1839 lineNr < 1 ifTrue:[ lineNr := listSize ] |
1840 ifFalse:[ lineNr := 1 ]. |
1840 ifFalse:[ lineNr := 1 ]. |
1841 ] ifTrue:[ |
1841 ] ifTrue:[ |
1842 (self canSelectIndex:lineNr forAdd:shifted) ifTrue:[ |
1842 (self canSelectIndex:lineNr forAdd:shifted) ifTrue:[ |
1843 shifted ifFalse:[ |
1843 shifted ifFalse:[ |
1844 self selection:lineNr. |
1844 self selection:lineNr. |
1845 ^ self |
1845 ^ self |
1846 ]. |
1846 ]. |
1847 (self isInSelection:lineNr) ifFalse:[ |
1847 (self isInSelection:lineNr) ifFalse:[ |
1848 selection isNil ifTrue:[ newSel := Array with:lineNr ] |
1848 selection isNil ifTrue:[ newSel := Array with:lineNr ] |
1849 ifFalse:[ newSel := selection copyWith:lineNr ]. |
1849 ifFalse:[ newSel := selection copyWith:lineNr ]. |
1850 ] ifTrue:[ |
1850 ] ifTrue:[ |
1851 (start ~~ 0 and:[selection size > 1]) ifFalse:[ |
1851 (start ~~ 0 and:[selection size > 1]) ifFalse:[ |
1852 ^ self |
1852 ^ self |
1853 ]. |
1853 ]. |
1854 newSel := selection copyWithout:start. |
1854 newSel := selection copyWithout:start. |
1855 ]. |
1855 ]. |
1856 self selectWithoutScroll:newSel redraw:true. |
1856 self selectWithoutScroll:newSel redraw:true. |
1857 self makeLineVisible:lineNr. |
1857 self makeLineVisible:lineNr. |
1858 self selectionChanged. |
1858 self selectionChanged. |
1859 ^ self |
1859 ^ self |
1860 ]. |
1860 ]. |
1861 lineNr := lineNr + step. |
1861 lineNr := lineNr + step. |
1862 ] |
1862 ] |
1863 ]. |
1863 ]. |
1864 ! |
1864 ! |
1865 |
1865 |
1866 pointerEntersItem:anItemOrNil |
1866 pointerEntersItem:anItemOrNil |
1867 "the pointer moves over an item or nil |
1867 "the pointer moves over an item or nil |
1868 " |
1868 " |
1869 |newItem| |
1869 |newItem| |
1870 |
1870 |
1871 (shown and:[self size ~~ 0]) ifFalse:[ |
1871 (shown and:[self size ~~ 0]) ifFalse:[ |
1872 enterItem := nil. |
1872 enterItem := nil. |
1873 ^ self. |
1873 ^ self. |
1874 ]. |
1874 ]. |
1875 |
1875 |
1876 highlightEnterItem ifTrue:[ newItem := anItemOrNil ] |
1876 highlightEnterItem ifTrue:[ newItem := anItemOrNil ] |
1877 ifFalse:[ newItem := nil ]. |
1877 ifFalse:[ newItem := nil ]. |
1878 |
1878 |
1879 anItemOrNil == enterItem ifTrue:[ ^ self ]. |
1879 anItemOrNil == enterItem ifTrue:[ ^ self ]. |
1880 |
1880 |
1881 enterItem notNil ifTrue:[ self invalidateLineOfItem:enterItem ]. |
1881 enterItem notNil ifTrue:[ self invalidateLineOfItem:enterItem ]. |
1882 enterItem := anItemOrNil. |
1882 enterItem := anItemOrNil. |
1963 ! |
1963 ! |
1964 |
1964 |
1965 initStyle |
1965 initStyle |
1966 "setup viewStyle specifics |
1966 "setup viewStyle specifics |
1967 " |
1967 " |
1968 <resource: #style (#'selection.selectOnMenuButton' |
1968 <resource: #style (#'selection.selectOnMenuButton' |
1969 #'selection.font')> |
1969 #'selection.font')> |
1970 super initStyle. |
1970 super initStyle. |
1971 |
1971 |
1972 lineMask isNil ifTrue:[ |
1972 lineMask isNil ifTrue:[ |
1973 lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
1973 lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55]. |
1974 ]. |
1974 ]. |
1975 |
1975 |
1976 hilightFrameColor := nil. |
1976 hilightFrameColor := nil. |
1977 hilightStyle := DefaultHilightStyle. |
1977 hilightStyle := DefaultHilightStyle. |
1978 highlightMode := #label. |
1978 highlightMode := #label. |
1979 textStartLeft := 4. |
1979 textStartLeft := 4. |
1980 selectOnMenuButton := styleSheet at:#'selection.selectOnMenuButton' default:nil. |
1980 selectOnMenuButton := styleSheet at:#'selection.selectOnMenuButton' default:nil. |
1981 selectOnMenuButton isNil ifTrue:[ |
1981 selectOnMenuButton isNil ifTrue:[ |
1982 selectOnMenuButton := UserPreferences current selectOnRightClick |
1982 selectOnMenuButton := UserPreferences current selectOnRightClick |
1983 ]. |
1983 ]. |
1984 |
1984 |
1985 super font:(styleSheet fontAt:#'selection.font'). |
1985 super font:(styleSheet fontAt:#'selection.font'). |
1986 |
1986 |
1987 device hasGrayscales ifTrue:[ |
1987 device hasGrayscales ifTrue:[ |
1988 " |
1988 " |
1989 must get rid of these hard codings |
1989 must get rid of these hard codings |
1990 " |
1990 " |
1991 (hilightStyle == #next) ifTrue:[ |
1991 (hilightStyle == #next) ifTrue:[ |
1992 hilightFgColor := fgColor. |
1992 hilightFgColor := fgColor. |
1993 hilightBgColor := White. |
1993 hilightBgColor := White. |
1994 hilightFrameColor := fgColor |
1994 hilightFrameColor := fgColor |
1995 ] ifFalse:[ |
1995 ] ifFalse:[ |
1996 (hilightStyle == #motif) ifTrue:[ |
1996 (hilightStyle == #motif) ifTrue:[ |
1997 fgColor := White. |
1997 fgColor := White. |
1998 bgColor := Grey. |
1998 bgColor := Grey. |
1999 viewBackground := bgColor. |
1999 viewBackground := bgColor. |
2000 hilightFgColor := bgColor. |
2000 hilightFgColor := bgColor. |
2001 hilightBgColor := fgColor. |
2001 hilightBgColor := fgColor. |
2002 ] ifFalse:[ |
2002 ] ifFalse:[ |
2003 (hilightStyle == #openwin) ifTrue:[ |
2003 (hilightStyle == #openwin) ifTrue:[ |
2004 hilightFgColor := fgColor. |
2004 hilightFgColor := fgColor. |
2005 hilightBgColor := Color grey. |
2005 hilightBgColor := Color grey. |
2006 ] |
2006 ] |
2007 ] |
2007 ] |
2008 ] |
2008 ] |
2009 ]. |
2009 ]. |
2010 |
2010 |
2011 hilightFgColor isNil ifTrue:[ |
2011 hilightFgColor isNil ifTrue:[ |
2012 hilightFgColor := bgColor. |
2012 hilightFgColor := bgColor. |
2013 ]. |
2013 ]. |
2014 hilightBgColor isNil ifTrue:[ |
2014 hilightBgColor isNil ifTrue:[ |
2015 hilightBgColor := fgColor. |
2015 hilightBgColor := fgColor. |
2016 ]. |
2016 ]. |
2017 DefaultForegroundColor notNil ifTrue:[ |
2017 DefaultForegroundColor notNil ifTrue:[ |
2018 fgColor := DefaultForegroundColor |
2018 fgColor := DefaultForegroundColor |
2019 ]. |
2019 ]. |
2020 DefaultBackgroundColor notNil ifTrue:[ |
2020 DefaultBackgroundColor notNil ifTrue:[ |
2021 bgColor := viewBackground := DefaultBackgroundColor |
2021 bgColor := viewBackground := DefaultBackgroundColor |
2022 ]. |
2022 ]. |
2023 |
2023 |
2024 DefaultHilightForegroundColor notNil ifTrue:[ |
2024 DefaultHilightForegroundColor notNil ifTrue:[ |
2025 hilightFgColor := DefaultHilightForegroundColor |
2025 hilightFgColor := DefaultHilightForegroundColor |
2026 ]. |
2026 ]. |
2027 DefaultHilightBackgroundColor notNil ifTrue:[ |
2027 DefaultHilightBackgroundColor notNil ifTrue:[ |
2028 hilightBgColor := DefaultHilightBackgroundColor |
2028 hilightBgColor := DefaultHilightBackgroundColor |
2029 ]. |
2029 ]. |
2030 DefaultHilightFrameColor notNil ifTrue:[ |
2030 DefaultHilightFrameColor notNil ifTrue:[ |
2031 hilightFrameColor := DefaultHilightFrameColor |
2031 hilightFrameColor := DefaultHilightFrameColor |
2032 ]. |
2032 ]. |
2033 |
2033 |
2034 hilightLevel := DefaultHilightLevel ? 0. |
2034 hilightLevel := DefaultHilightLevel ? 0. |
2035 lineSpacing := (hilightLevel abs > 0) ifTrue:[3] ifFalse:[2]. |
2035 lineSpacing := (hilightLevel abs > 0) ifTrue:[3] ifFalse:[2]. |
2036 |
2036 |
2037 hilightFgColor isNil ifTrue:[ |
2037 hilightFgColor isNil ifTrue:[ |
2038 hilightFgColor := bgColor. |
2038 hilightFgColor := bgColor. |
2039 hilightBgColor := fgColor. |
2039 hilightBgColor := fgColor. |
2040 ]. |
2040 ]. |
2041 |
2041 |
2042 hilightFgColorNoFocus isNil ifTrue:[ |
2042 hilightFgColorNoFocus isNil ifTrue:[ |
2043 hilightFgColorNoFocus := hilightFgColor. |
2043 hilightFgColorNoFocus := hilightFgColor. |
2044 ]. |
2044 ]. |
2045 hilightBgColorNoFocus isNil ifTrue:[ |
2045 hilightBgColorNoFocus isNil ifTrue:[ |
2046 hilightBgColorNoFocus := hilightBgColor lightened. |
2046 hilightBgColorNoFocus := hilightBgColor lightened. |
2047 ]. |
2047 ]. |
2048 ! |
2048 ! |
2049 |
2049 |
2050 initialize |
2050 initialize |
2051 "setup default attributes/behavior |
2051 "setup default attributes/behavior |
2371 |
2371 |
2372 start := aStart. |
2372 start := aStart. |
2373 stop := aStop. |
2373 stop := aStop. |
2374 |
2374 |
2375 aStart < aStop ifTrue:[ |
2375 aStart < aStop ifTrue:[ |
2376 start := aStart max:1. |
2376 start := aStart max:1. |
2377 stop := aStop min:(self size). |
2377 stop := aStop min:(self size). |
2378 step := 1. |
2378 step := 1. |
2379 start > stop ifTrue:[^ self]. |
2379 start > stop ifTrue:[^ self]. |
2380 |
2380 |
2381 ] ifFalse:[ |
2381 ] ifFalse:[ |
2382 start := aStart min:(self size). |
2382 start := aStart min:(self size). |
2383 stop := aStop max:1. |
2383 stop := aStop max:1. |
2384 step := -1. |
2384 step := -1. |
2385 start < stop ifTrue:[^ self]. |
2385 start < stop ifTrue:[^ self]. |
2386 ]. |
2386 ]. |
2387 nsel := OrderedCollection new. |
2387 nsel := OrderedCollection new. |
2388 |
2388 |
2389 start to:stop by:step do:[:i| |
2389 start to:stop by:step do:[:i| |
2390 (self canSelectIndex:i forAdd:true) ifTrue:[ |
2390 (self canSelectIndex:i forAdd:true) ifTrue:[ |
2391 nsel add:i. |
2391 nsel add:i. |
2392 ]. |
2392 ]. |
2393 ]. |
2393 ]. |
2394 |
2394 |
2395 (self selectWithoutScroll:nsel redraw:true) ifTrue:[ |
2395 (self selectWithoutScroll:nsel redraw:true) ifTrue:[ |
2396 self selectionChanged |
2396 self selectionChanged |
2397 ]. |
2397 ]. |
2398 ! |
2398 ! |
2399 |
2399 |
2400 selectedElement |
2400 selectedElement |
2401 "return the single selected item or nil |
2401 "return the single selected item or nil |
2402 " |
2402 " |
2403 |index| |
2403 |index| |
2404 |
2404 |
2405 (index := self selectedIndex) ~~ 0 ifTrue:[ |
2405 (index := self selectedIndex) ~~ 0 ifTrue:[ |
2406 ^ self at:index ifAbsent:nil |
2406 ^ self at:index ifAbsent:nil |
2407 ]. |
2407 ]. |
2408 ^ nil |
2408 ^ nil |
2409 ! |
2409 ! |
2410 |
2410 |
2411 selectedIndex |
2411 selectedIndex |
2412 "returns the index of the selected line or 0. If more |
2412 "returns the index of the selected line or 0. If more |
2413 lines are selected, 0 is returned |
2413 lines are selected, 0 is returned |
2414 " |
2414 " |
2415 selection notNil ifTrue:[ |
2415 selection notNil ifTrue:[ |
2416 multipleSelectOk ifFalse:[ ^ selection ]. |
2416 multipleSelectOk ifFalse:[ ^ selection ]. |
2417 |
2417 |
2418 selection size == 1 ifTrue:[ |
2418 selection size == 1 ifTrue:[ |
2419 ^ selection at:1 |
2419 ^ selection at:1 |
2420 ] |
2420 ] |
2421 ]. |
2421 ]. |
2422 ^ 0 |
2422 ^ 0 |
2423 ! |
2423 ! |
2424 |
2424 |
2425 selection |
2425 selection |
2426 "return the selection index or collection of indices |
2426 "return the selection index or collection of indices |
2427 in case of multiple selection enabled |
2427 in case of multiple selection enabled |
2428 " |
2428 " |
2429 ^ selection |
2429 ^ selection |
2430 |
2430 |
2431 ! |
2431 ! |
2562 selection = something ifTrue:[^ false]. |
2562 selection = something ifTrue:[^ false]. |
2563 |
2563 |
2564 oldSelect := selection. |
2564 oldSelect := selection. |
2565 |
2565 |
2566 (something isNil or:[something == 0]) ifTrue:[ |
2566 (something isNil or:[something == 0]) ifTrue:[ |
2567 selection := nil |
2567 selection := nil |
2568 ] ifFalse:[ |
2568 ] ifFalse:[ |
2569 something isNumber ifTrue:[ |
2569 something isNumber ifTrue:[ |
2570 selection := multipleSelectOk ifTrue:[Array with:something] |
2570 selection := multipleSelectOk ifTrue:[Array with:something] |
2571 ifFalse:[something] |
2571 ifFalse:[something] |
2572 ] ifFalse:[ |
2572 ] ifFalse:[ |
2573 something size == 0 ifTrue:[ |
2573 something size == 0 ifTrue:[ |
2574 selection := nil |
2574 selection := nil |
2575 ] ifFalse:[ |
2575 ] ifFalse:[ |
2576 selection := multipleSelectOk ifTrue:[something] |
2576 selection := multipleSelectOk ifTrue:[something] |
2577 ifFalse:[something at:1] |
2577 ifFalse:[something at:1] |
2578 ] |
2578 ] |
2579 ] |
2579 ] |
2580 ]. |
2580 ]. |
2581 selection = oldSelect ifTrue:[^ false]. |
2581 selection = oldSelect ifTrue:[^ false]. |
2582 |
2582 |
2583 modelChangedDuringButtonPress notNil ifTrue:[ |
2583 modelChangedDuringButtonPress notNil ifTrue:[ |
2584 modelChangedDuringButtonPress := true. |
2584 modelChangedDuringButtonPress := true. |
2585 ]. |
2585 ]. |
2586 |
2586 |
2587 self closeEditor. |
2587 self closeEditor. |
2588 self cursorEntersItem:nil. |
2588 self cursorEntersItem:nil. |
2589 |
2589 |
2590 |
2590 |
2591 (doRedraw and:[shown]) ifFalse:[ |
2591 (doRedraw and:[shown]) ifFalse:[ |
2592 ^ true |
2592 ^ true |
2593 ]. |
2593 ]. |
2594 |
2594 |
2595 multipleSelectOk ifFalse:[ |
2595 multipleSelectOk ifFalse:[ |
2596 oldSelect notNil ifTrue:[self invalidateSelectionAt:oldSelect]. |
2596 oldSelect notNil ifTrue:[self invalidateSelectionAt:oldSelect]. |
2597 selection notNil ifTrue:[self invalidateSelectionAt:selection]. |
2597 selection notNil ifTrue:[self invalidateSelectionAt:selection]. |
2598 ] ifTrue:[ |
2598 ] ifTrue:[ |
2599 (selection notNil and:[oldSelect notNil]) ifTrue:[ |
2599 (selection notNil and:[oldSelect notNil]) ifTrue:[ |
2600 selection do:[:i|(oldSelect includesIdentical:i) ifFalse:[self invalidateSelectionAt:i]]. |
2600 selection do:[:i|(oldSelect includesIdentical:i) ifFalse:[self invalidateSelectionAt:i]]. |
2601 oldSelect do:[:i|(selection includesIdentical:i) ifFalse:[self invalidateSelectionAt:i]]. |
2601 oldSelect do:[:i|(selection includesIdentical:i) ifFalse:[self invalidateSelectionAt:i]]. |
2602 ] ifFalse:[ |
2602 ] ifFalse:[ |
2603 oldSelect isNil ifTrue:[oldSelect := selection]. |
2603 oldSelect isNil ifTrue:[oldSelect := selection]. |
2604 oldSelect do:[:i|self invalidateSelectionAt:i] |
2604 oldSelect do:[:i|self invalidateSelectionAt:i] |
2605 ] |
2605 ] |
2606 ]. |
2606 ]. |
2607 ^ true |
2607 ^ true |
2608 ! ! |
2608 ! ! |
2609 |
2609 |
2610 !SelectionInListModelView class methodsFor:'documentation'! |
2610 !SelectionInListModelView class methodsFor:'documentation'! |
2611 |
2611 |
2612 version |
2612 version |
2613 ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.143 2009-05-27 06:05:59 ca Exp $' |
2613 ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.144 2009-08-07 10:50:41 sr Exp $' |
2614 ! ! |
2614 ! ! |