Added selectFirst/Next/Last/Prev to make it polymorph with SelectionInListView.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 22 Apr 2014 12:17:31 +0200
changeset 4574 4ccc6b5caf8c
parent 4573 bfa5f43b4d69
child 4575 abc45a4206e3
Added selectFirst/Next/Last/Prev to make it polymorph with SelectionInListView.
SelectionInListModelView.st
--- a/SelectionInListModelView.st	Mon Apr 14 22:01:33 2014 +0200
+++ b/SelectionInListModelView.st	Tue Apr 22 12:17:31 2014 +0200
@@ -2351,6 +2351,54 @@
     self makeLineVisible:(self firstInSelection).
 !
 
+nextAfterSelection
+    "return the index of the next selectable entry after the selection.
+     Wrap at end."
+
+    ^ self nextSelectableAfter:selection
+!
+
+nextSelectableAfter:indexOrIndexCollection
+    "return the index of the next selectable entry after the indexOrIndexCollection.
+     Wrap at end."
+
+    |next sz|
+
+    indexOrIndexCollection isNil ifTrue:[
+        next := 1
+    ] ifFalse:[
+        indexOrIndexCollection isCollection ifTrue:[
+            indexOrIndexCollection size == 0 ifTrue:[
+                next := 1
+            ] ifFalse:[
+                next := indexOrIndexCollection max + 1
+            ]
+        ] ifFalse:[
+            next := indexOrIndexCollection + 1
+        ].
+    ].
+
+    (self canSelectIndex:next) ifFalse:[
+        sz := self size.
+        next > sz ifTrue:[
+            next := 1.
+        ] ifFalse:[
+            [next <= sz
+             and:[(self canSelectIndex:next) not ]] whileTrue:[
+                next := next + 1
+            ].
+        ].
+    ].
+
+    (self canSelectIndex:next) ifFalse:[
+        next := nil
+    ].
+    ^ next
+
+    "Modified: / 08-08-1998 / 03:36:55 / cg"
+    "Modified: / 22-04-2014 / 12:15:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 numberOfSelections
     "return the number of selected items
     "
@@ -2359,6 +2407,51 @@
   ^ selection size
 !
 
+previousBeforeSelection
+    "return the index of the previous selectable entry before the selection.
+     Wrap at beginning."
+
+    ^ self previousSelectableBefore:selection
+
+!
+
+previousSelectableBefore:indexOrIndexCollection
+    "return the index of the previous selectable entry before the indexOrIndexCollection.
+     Wrap at beginning."
+
+    |prev|
+
+    indexOrIndexCollection isNil ifTrue:[
+        prev := list size 
+    ] ifFalse:[
+        indexOrIndexCollection isCollection ifTrue:[
+            indexOrIndexCollection size == 0 ifTrue:[
+                prev := list size
+            ] ifFalse:[
+                prev := indexOrIndexCollection min - 1
+            ]
+        ] ifFalse:[
+            prev := indexOrIndexCollection - 1
+        ].
+    ].
+    (self canSelectIndex:prev) ifFalse:[
+        prev < 1 ifTrue:[
+            prev := self size.
+        ] ifFalse:[
+            [prev >= 1
+             and:[(self canSelectIndex:prev) not]] whileTrue:[
+                prev := prev - 1
+            ].
+        ].
+    ].
+    (self canSelectIndex:prev) ifFalse:[
+        prev := nil
+    ].
+    ^ prev
+
+    "Modified: / 22-04-2014 / 12:16:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 removeFromSelection:lineNr
     "remove line from selection without scrolling but raise a change notification
     "
@@ -2413,6 +2506,13 @@
     "Created: / 06-10-2011 / 13:32:28 / cg"
 !
 
+selectFirst
+    "select the first selectable element.
+     Model and/or actionBlock notification IS done."
+
+    self selection:(self nextSelectableAfter:0)
+!
+
 selectFrom:aStart to:aStop
     "select lines between start and stop
     "
@@ -2448,6 +2548,34 @@
     ].
 !
 
+selectLast
+    "select the last selectable element.
+     Model and/or actionBlock notification IS done."
+
+    self selection:(self previousSelectableBefore:list size + 1)
+!
+
+selectNext
+    "select next line or first visible if there is currrently no selection.
+     Wrap at end. 
+     Model and/or actionBlock notification IS done."
+
+    self selection:(self nextAfterSelection)
+
+    "Modified: 15.11.1996 / 17:01:27 / cg"
+!
+
+selectPrevious
+    "select previous line or previous visible if there is currently no selection.
+     Wrap at beginning. 
+     Model and/or actionBlock notification IS done."
+
+    self selection:(self previousBeforeSelection).
+
+    "Modified: 26.9.1995 / 09:41:16 / stefan"
+    "Modified: 15.11.1996 / 17:01:34 / cg"
+!
+
 selectedElement
     "return the single selected item or nil
     "
@@ -2671,10 +2799,10 @@
 !SelectionInListModelView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.168 2014-04-13 21:00:15 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.169 2014-04-22 10:17:31 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.168 2014-04-13 21:00:15 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInListModelView.st,v 1.169 2014-04-22 10:17:31 vrany Exp $'
 ! !