Redraw a list without changing the selection

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

Redraw a list without changing the selection

Kjell Fredrik Pettersen
First of all: Why is a symbol for the death used for the DeafObject's icon?
A friend of mine is deaf, but as far as I know very well alive. :-)

To my real problem today: Is there a way I can redraw each line in a list
(Enhanged view) and still keep the selection highlighted? If I send
#refreshContents to the listpresenters view, it redraws the contents, but
also looses the selection. The same problem aplies to my treeview.

The background is a case where the presentation of some elements in the list
(icon, font etc) is changed. I need to update this immediately, but I also
want to keep the selection (as well as the expanded state for the tree).

Kjell Fredrik Pettersen


Reply | Threaded
Open this post in threaded view
|

Re: Redraw a list without changing the selection

Kjell Fredrik Pettersen
[ Kjell Fredrik Pettersen ]:
> First of all: Why is a symbol for the death used for the DeafObject's
icon?
> A friend of mine is deaf, but as far as I know very well alive. :-)
>
> To my real problem today: Is there a way I can redraw each line in a list
> (Enhanged view) and still keep the selection highlighted? If I send
> #refreshContents to the listpresenters view, it redraws the contents, but
> also looses the selection. The same problem aplies to my treeview.
>
> The background is a case where the presentation of some elements in the
list
> (icon, font etc) is changed. I need to update this immediately, but I also
> want to keep the selection (as well as the expanded state for the tree).
>
> Kjell Fredrik Pettersen

I partly solved it myself. The answer was to use ListModel>>#updateItem: for
each item that needs a redraw (I'm able to determine which ones). I have not
looked at the tree model yet, as this is more complex in my case.

About the DeafObject, however, I'm still wondering  ... :-)

Kjell Fredik Pettersen


Reply | Threaded
Open this post in threaded view
|

Re: Redraw a list without changing the selection

Louis Sumberg-2
In reply to this post by Kjell Fredrik Pettersen
Kjell,

> want to keep the selection (as well as the expanded state for the tree).

One way to do it is to save the current selection and its expansion state,
then refresh the treeview, and then restore the selection and state.
Something like so:

    | sel expanded |
    sel := treeview selection.
    expanded := treeview isExpanded: sel.
    treeview refreshContents.
    treeview selection: sel.
    expanded ifTrue: [treeview expand: sel].

You can filein the following for TreeView>>isExpanded:.

!TreeView methodsFor!

isExpanded: anObject
 "Answer whether or not the <Object> argument is an expanded item in the
tree."

 | tvItem |
 tvItem := TVITEM new.
 tvItem
  mask: TVIF_STATE;
  hItem: (self handleFromObject: anObject);
  stateMask: TVIS_EXPANDED.
 self tvmGetItem: tvItem.
 ^(tvItem dwState bitAnd: TVIS_EXPANDED) = TVIS_EXPANDED! !
!TreeView categoriesFor: #isExpanded:!public!testing! !

If you find or have found a better way to refresh the treeview "in place",
please let us know.

-- Louis