[haiku-development] Re: Query about BOutlineListView

  • From: Zenja Solaja <solaja@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sat, 6 Apr 2024 17:58:05 +0200

I
I’ll have the full code on Github eventually.

Code is very simple:
fTreeOutlineView->FullListItemAt(idx)->Select();  // correct item is
highlighted, but fLastSelected is not set in code path.
//fTreeOutlineView->Select(idx);  //incorrect item is highlighted, but with
fLastSelected naturally pointing to highlighted item

The BoutlineListView is a directory tree, and I’m highlighting a specific
file on app start (last session restore). I calculate the full list idx.


On Sat, 6 Apr 2024 at 16:55, Máximo Castañeda <dmarc-noreply@xxxxxxxxxxxxx>
wrote:

 En sábado, 6 de abril de 2024, 16:05:50 CEST, Zenja Solaja <
solaja@xxxxxxxxx> escribió:

This wont work since BOutlineListView is a tree, so the full list index
(eg. 22) doesnt map to a branch BListView subindex with a smaller number of
elements. This was the first thing I tried and immediate got an out of
bounds access error.

BListView Select(idx) wont work for trees. I’m only limited to
BOutlineListView::FullListItemAt(idx) pointers, but that wont allow me to
set the private fLastSelected which is used to remove highlight when the
mouse selects another item.

On Sat, 6 Apr 2024 at 13:23, Máximo Castañeda <
dmarc-noreply@xxxxxxxxxxxxx> wrote:

BListItem* itemToSelect = list.FullListItemAt(fullIndex);
int32 showIndex = list.IndexOf(itemToSelect);
list.Select(showIndex);

You may want to check return values, and maybe call list.Expand(item)
before getting its index.



BOutlineListView is a BListView, so its methods should work. In fact, it
keeps its data as a list with its items having the "depth" information, not
as a tree with items containing a list of children.

Select() checks the index and just returns false if out of bounds, so if
you got an out of bounds error there must be a bug somewhere. Can you share
your code?

Notice in the sample code the index with which you call Select() is not
the same one you started with. If you start with a "full tree" index: you
first get the item with FullListItemAt, the you find the "visible list"
index with IndexOf (a method from BListView) and then you Select using that
index. And you will have to make sure its path is expanded, of course, or
its "visible list" will be -1.


Other related posts: