Add posibility to configure the select behaviour (select on button press
authorab
Tue, 25 Mar 2008 11:08:16 +0100
changeset 3370 5199f62a817d
parent 3369 9f8f7c5d328f
child 3371 c80f59a3a422
Add posibility to configure the select behaviour (select on button press or select on button release)
SelectionInListModelView.st
--- a/SelectionInListModelView.st	Sat Mar 15 18:15:46 2008 +0100
+++ b/SelectionInListModelView.st	Tue Mar 25 11:08:16 2008 +0100
@@ -19,7 +19,8 @@
 		hilightBgColorNoFocus hilightLevel hilightFrameColor hilightStyle
 		dropSource editorView openEditorAction closeEditorAction
 		highlightEnterItem enterItem cursorItem lineMask keyActionStyle
-		returnKeyActionStyle strikeOut modelChangedDuringButtonPress'
+		returnKeyActionStyle strikeOut modelChangedDuringButtonPress
+		selectOnButtonPress'
 	classVariableNames:'DefaultHilightStyle DefaultHilightBackgroundColor
 		DefaultHilightForegroundColor DefaultHilightLevel
 		DefaultHilightFrameColor'
@@ -513,6 +514,23 @@
     selectOnButtonMenu := aBoolean.
 !
 
+selectOnButtonPress
+    "get the selectOnButtonPress flag - see method #selectOnButtonPress: for more details
+    "
+    ^ selectOnButtonPress ? true
+!
+
+selectOnButtonPress:aBoolean
+    "set/clear the selectOnButtonPress flag - 
+     if set (default), the selection changed on button press. This was the
+     behaviour until now.
+     if cleared, the selection is changed on button release. This new behaviour allows to start
+     a drag without changing the real selection. The selection is changed during the
+     drag and restored after the drop.
+    "
+    selectOnButtonPress := aBoolean
+!
+
 toggleSelect
     "get the toggleSelect flag - see method #toggleSelect: for more details
     "
@@ -852,13 +870,14 @@
 
     dropSource notNil ifTrue:[
         dropSource startDragSelector notNil ifTrue:[
-            dropSource startDragIn:self at:aPoint
+            ^ dropSource startDragIn:self at:aPoint
         ] ifFalse:[
-            DragAndDropManager new startDragFrom:self
+            ^ DragAndDropManager new startDragFrom:self
                                       dropSource:dropSource
                                           offset:#center
         ]
-    ]
+    ].
+^ nil
 ! !
 
 !SelectionInListModelView methodsFor:'drawing'!
@@ -1292,8 +1311,33 @@
                     ]
                 ].
             buttonReleaseAction := [ self buttonPressOrReleaseAtLine:lineNr x:x y:y ].
+            ^ self.
+        ].
+
+        self selectOnButtonPress ifFalse: [
+            |oldSelection|
+            oldSelection := selection copy.
+            self selectAndUpdateModelWithoutChangeNotification: lineNr.
+            self windowGroup processExposeEvents.
+
+            buttonMotionAction := 
+                [:p|
+                    ((x@y) dist:p) > dragDistance ifTrue:[
+                        (self startDragAt:p) notifyEndOfDropAction:[
+                            self selectAndUpdateModelWithoutChangeNotification: oldSelection.
+                        ].
+                    ].
+                ].
+
+            buttonReleaseAction := [
+                self selectAndUpdateModelWithoutChangeNotification: oldSelection.
+
+                (self canSelectIndex:lineNr forAdd:false) ifTrue:[
+                    self buttonPressOrReleaseAtLine:lineNr x:x y:y
+                ].
+            ].
             ^ self
-        ].            
+        ].
     ].
 
     multipleSelectOk ifFalse:[
@@ -2376,6 +2420,16 @@
     ]
 !
 
+selectAndUpdateModelWithoutChangeNotification: aLineNo
+    |arg|
+
+    self selectWithoutScroll:aLineNo redraw:true.
+    modelChangedDuringButtonPress := false.
+    model isNil ifTrue:[ ^ self ].
+    arg := self argForChangeMessage.
+    self sendChangeMessage:#setValue: with:arg.
+!
+
 selectWithoutScroll:something redraw:doRedraw
     "change selection to something; returns true if selection changed
     "
@@ -2432,5 +2486,5 @@
 !SelectionInListModelView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.125 2008-03-13 16:40:15 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.126 2008-03-25 10:08:16 ab Exp $'
 ! !