[Bug][VW 7.5] Subscript out of bounds in TabControlBarView

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Bug][VW 7.5] Subscript out of bounds in TabControlBarView

Joachim Geidel
When the last tab in a TabControlBarView is the active one, and this tab
is removed programmatically, clicking on one of the remaining tabs
raises a SubscriptOutOfBoundsError in
TabControlBarView>>initializeVisuals. The error can be easily reproduced
in the RefactoringBrowser with RB_Tabs loaded by opening a few tabs,
activating the rightmost one, removing this view with the "Remove
current view" menu item and clicking on one of the other tabs.

Removing the tab does not update the view's instance variable
targetIndex. In SelectionView>>hasFocus: the old, invalid targetIndex is
used, which raises the exception. TabBarView>>hasFocus: seems to have
the same problem. I am not sure about TableView>>hasFocus:.

Although I am attaching a patch for SelectionView>>hasFocus: and
TabBarView>>hasFocus:, I think that the usage of the instance variable
should be given some consideration. There are 40 methods in my image
which directly access it. This might be changed to using an accessor
method which checks whether the value is still valid, e.g.

targetIndex
        targetIndex > self numberOfElements
                ifTrue: [targetIndex := self numberOfElements].
        ^targetIndex

Best regards,
Joachim Geidel

PS: T-shirt? No, thanks. Just buy me a beer next time we meet. :-)

<?xml version="1.0"?>

<st-source>
<time-stamp>From VisualWorks® NonCommercial, 7.5 of 16. April 2007 on 8. Juni 2007 at 14:23:07</time-stamp>


<methods>
<class-id>UI.SelectionView</class-id> <category>focus accessing</category>

<body package="VW75Patches" selector="hasFocus:">hasFocus: aBoolean
        state hasKeyboardFocus == aBoolean ifTrue: [^self].
        self triggerEvent: (aBoolean ifTrue: [#gettingFocus] ifFalse: [#losingFocus]).
        state hasKeyboardFocus: aBoolean.
        aBoolean
                ifTrue:
                        [self setValidTargetIndex: (targetIndex = self zeroIndex
                                                ifTrue: [1]
                                                ifFalse: [targetIndex])].
        self invalidateRectangle: (self boundsOfElementIndex: targetIndex inBounds: self bounds)</body>
</methods>

<methods>
<class-id>UI.TabBarView</class-id> <category>focus accessing</category>

<body package="VW75Patches" selector="hasFocus:">hasFocus: aBoolean

        hasFocus == aBoolean ifTrue: [^self].
        self upcastEvent: #triggerEvent with: (aBoolean ifTrue: [#gettingFocus] ifFalse: [#losingFocus]).
        hasFocus := aBoolean.
        aBoolean
                ifTrue:
                        [self setValidTargetIndex: (targetIndex = self zeroIndex
                                                ifTrue: [1]
                                                ifFalse: [targetIndex])].
</body>
</methods>

</st-source>