[bug] Initial ChoicePrompter selections

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

[bug] Initial ChoicePrompter selections

Bill Dargel
Found a bug in keeping the initial selections in a ChoicePrompter. Or at
least I'm pretty sure that it's a bug. I'm open to there being a better
way to do what I'm trying to accomplish.

As illustrated in the attached script, a problem arises when setting the
#getTextBlock: for a ChoicePrompter. The #refreshContents called in
#getTextBlock: ends up killing the selection which causes the second
assert to fail.

The fix I came up with was to have ListView>>getTextBlock: save and
restore the selections. There's probably a better way to deal with the
problem, but I'll leave that to OA. Looks like #getImageBlock: would
have the same issue.

-Bill

------------------
prompter := ChoicePrompter
        createOn: #(one three)
        multipleChoices: #(one two three four)
        caption: nil.
self assert: [(prompter view viewNamed: 'choices') selectionsByIndex =
#(1 3)].
prompter getTextBlock: [:each | each asUppercase].
self assert: [(prompter view viewNamed: 'choices') selectionsByIndex =
#(1 3)].
prompter showModal.
-------------------
!ListView methodsFor!
getTextBlock: aOneArgBlock
        | savedSelections |
        savedSelections := lastSelIndices.
        super getTextBlock: aOneArgBlock.
        self basicSelectionsByIndex: savedSelections! !

-------------------------------------------
Bill Dargel            [hidden email]
Shoshana Technologies
100 West Joy Road, Ann Arbor, MI 48105  USA


Reply | Threaded
Open this post in threaded view
|

Re: [bug] Initial ChoicePrompter selections

Bill Dargel
I wrote:
> The fix I came up with was to have ListView>>getTextBlock: save and
> restore the selections.

Which didn't work very well. If one merely accepted without making any
changes to the selections, then what got returned was an empty array,
not the selections. Using #selectionsByIndex: instead of
#basicSelectionsByIndex: seems to be working better.

Makes me think that there must be a better way.

-Bill

-------------------
!ListView methodsFor!
getTextBlock: aOneArgBlock
        | savedSelections |
        savedSelections := lastSelIndices.
        super getTextBlock: aOneArgBlock.
        self selectionsByIndex: savedSelections! !

-------------------------------------------
Bill Dargel            [hidden email]
Shoshana Technologies
100 West Joy Road, Ann Arbor, MI 48105  USA


Reply | Threaded
Open this post in threaded view
|

Re: [bug] Initial ChoicePrompter selections

Blair McGlashan
"Bill Dargel" <[hidden email]> wrote in message
news:[hidden email]...

> I wrote:
> > The fix I came up with was to have ListView>>getTextBlock: save and
> > restore the selections.
>
> Which didn't work very well. If one merely accepted without making any
> changes to the selections, then what got returned was an empty array,
> not the selections. Using #selectionsByIndex: instead of
> #basicSelectionsByIndex: seems to be working better.
>
> Makes me think that there must be a better way.

#getTextBlock: and #getImageBlock: should be using #updateAll instead of
#refreshContents. For a virtual list this simply repaints. For a non-virtual
list (e.g. a ListBox, or a ListView or TreeView in non-virtual modes) it is
equivalent to refreshContents (and implemented in terms of that) but
maintains the selection. This change has been made in D6, but the hierarchy
has been refactored significantly in that version so it doesn't easily
translate into a patch for D5.1. I've recorded it in our issue tracking
database, however, as #1533.

Regards

Blair