--- a/TabView.st Tue Jan 20 19:13:22 1998 +0100
+++ b/TabView.st Tue Jan 20 20:00:34 1998 +0100
@@ -14,7 +14,7 @@
View subclass:#TabView
instanceVariableNames:'list listHolder selection enabled action tabStyle useIndex
maxRawNr direction fitLastRow moveSelectedRow enableChannel
- oldExtent oneTabPerLine'
+ selectConditionBlock oldExtent oneTabPerLine'
classVariableNames:''
poolDictionaries:''
category:'Views-Interactors'
@@ -346,6 +346,22 @@
self enabled:aState
+!
+
+selectConditionBlock
+ "get the conditionBlock; this block is evaluated before a selection
+ change is performed; the change will not be done, if the evaluation
+ returns false. The argument to the block is the selection index
+ "
+ ^ selectConditionBlock
+!
+
+selectConditionBlock:aOneArgBlock
+ "get the conditionBlock; this block is evaluated before a selection
+ change is performed; the change will not be done, if the evaluation
+ returns false. The argument to the block is the selection index
+ "
+ selectConditionBlock := aOneArgBlock
! !
!TabView methodsFor:'accessing channels/holders'!
@@ -759,41 +775,61 @@
keyPress:aKey x:x y:y
"selection might change; look for corresponding list entry
"
- |size newSel index|
+ |size index n|
+
+ (self isEnabled and:[(size := list size) > 1]) ifFalse:[
+ ^ self
+ ].
- (self isEnabled and:[(size := list size) ~~ 0]) ifTrue:[
- (aKey == #CursorRight or:[aKey == #CursorDown]) ifTrue:[
- (selection isNil or:[selection == size]) ifTrue:[
- newSel := 1
- ] ifFalse:[
- newSel := (selection + 1)
+ (aKey == #CursorRight or:[aKey == #CursorDown]) ifTrue:[
+ n := selection ? 0.
+ (size - 1) timesRepeat:[
+ (n := n + 1) > size ifTrue:[n := 1].
+
+ (selectConditionBlock isNil or:[selectConditionBlock value:n]) ifTrue:[
+ ^ self selection:n
]
- ] ifFalse:[
- (aKey == #CursorLeft or:[aKey == #CursorUp]) ifTrue:[
- (selection isNil or:[selection == 1]) ifTrue:[
- newSel := size
- ] ifFalse:[
- newSel := (selection - 1)
+ ].
+ ^ self
+ ].
+
+ (aKey == #CursorLeft or:[aKey == #CursorUp]) ifTrue:[
+ n := selection ? size.
+ (size - 1) timesRepeat:[
+ (n := n - 1) < 1 ifTrue:[n := size].
+
+ (selectConditionBlock isNil or:[selectConditionBlock value:n]) ifTrue:[
+ ^ self selection:n
+ ]
+ ].
+ ^ self
+ ].
+
+ aKey isCharacter ifTrue:[
+ (selection isNil or:[selection == size]) ifTrue:[index := 1]
+ ifFalse:[index := selection + 1].
+
+ n := index - 1.
+ [
+ n := self findTabStartingWithKey:aKey startingAt:n + 1.
+
+ n ~~ 0 ifTrue:[
+ (selectConditionBlock isNil or:[selectConditionBlock value:n]) ifTrue:[
+ ^ self selection:n
]
- ] ifFalse:[
- aKey isCharacter ifTrue:[
- (selection isNil or:[selection == size]) ifTrue:[index := 1]
- ifFalse:[index := selection + 1].
- newSel := self findTabStartingWithKey:aKey startingAt:index.
+ ].
+ n ~~ 0
- (newSel == 0 and:[index ~~ 1]) ifTrue:[
- newSel := self findTabStartingWithKey:aKey startingAt:1
- ]
- ]
+ ] whileTrue.
+
+ index ~~ 1 ifTrue:[
+ (n := self findTabStartingWithKey:aKey startingAt:1) ~~ 0 ifTrue:[
+ ^ self selection:n
]
]
].
- (newSel isNil or:[newSel == 0]) ifTrue:[
- super keyPress:aKey x:x y:y
- ].
- self selection:newSel
-
+ super keyPress:aKey x:x y:y
! !
!TabView methodsFor:'initialization'!
@@ -1076,6 +1112,18 @@
!
+isTabSelectable:aTab
+ "returns true if tab is selectable
+ "
+ self isEnabled ifTrue:[
+ selectConditionBlock notNil ifTrue:[
+ ^ selectConditionBlock value:(list identityIndexOf:aTab)
+ ].
+ ^ true
+ ].
+ ^ false
+!
+
isVerticalDirection
"returns true in case of direction is #left or #right
"
@@ -1129,8 +1177,15 @@
list size == 0 ifTrue:[^ self].
newSel := self listIndexOf:something.
selection == newSel ifTrue:[^ self].
+
newSel notNil ifTrue:[
- (newSel between:1 and:list size) ifFalse:[newSel := nil].
+ (newSel between:1 and:list size) ifFalse:[
+ newSel := nil
+ ] ifTrue:[
+ selectConditionBlock notNil ifTrue:[
+ (selectConditionBlock value:newSel) ifFalse:[^ self]
+ ]
+ ]
].
self shown ifFalse:[
@@ -1200,5 +1255,5 @@
!TabView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/TabView.st,v 1.29 1997-11-02 18:28:49 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/TabView.st,v 1.30 1998-01-20 19:00:21 ca Exp $'
! !
--- a/TabWidget.st Tue Jan 20 19:13:22 1998 +0100
+++ b/TabWidget.st Tue Jan 20 20:00:34 1998 +0100
@@ -382,7 +382,7 @@
setLabelColor
"set the label color dependant on the enabled state of the tabView
"
- tabView isEnabled ifTrue:[
+ (tabView isTabSelectable:self) ifTrue:[
tabView paintColor:#labelColor.
] ifFalse:[
tabView paintColor:#shadowColorUnselected.
@@ -998,5 +998,5 @@
!TabWidget class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/TabWidget.st,v 1.12 1997-10-11 12:20:07 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/TabWidget.st,v 1.13 1998-01-20 19:00:34 ca Exp $'
! !