[haiku-development] Re: Query about BOutlineListView

  • From: Zenja Solaja <solaja@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sun, 7 Apr 2024 17:37:35 +0200

Yes, this worked.
The “trick” was to use fOutlineListView->IndexOf(tree_item); to get the
subindex, then use the subindex in the call to list_view->Select(subindex).
Not exactly intuitive, since its a 2 step process.

Ideally, a FullListSelect(index) can be added to the class API to prevent
other devs from encountering the same problem.

Thx again, now onto my next problem with BTranslationUtils when called from
many threads simultaneously (single thread access is fine) …. A topic for
another day.



On Sat, 6 Apr 2024 at 19:52, Zenja Solaja <solaja@xxxxxxxxx> wrote:

Thank you Maximo, I will try that tomorrow and report back.
Haiku community is awesome.



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

 En sábado, 6 de abril de 2024, 19:25:09 CEST, Zenja Solaja <
solaja@xxxxxxxxx> escribió:

The tree select will work for first branch (trunk) since the list view
index corresponds. Try a 2nd/Nth branch while the upper branches are
collapsed.  In that scenario, it no longer matches.

In my directory structure, I’ve only expanded the selected path.  All
higher branches are collapsed. All lower branches are collapsed. Only the
branches leading to a user file are expanded.



Still works for me, and I don't even know what can go wrong, except maybe
the index calculation.

Here is a tested full implementation, in case you still have problems:

bool
FullListSelectItem(BOutlineListView* listview, int32 index, bool
expandIfNecessary)
{
    BListItem* item = listview->FullListItemAt(index);
    if (item == NULL)
        return false;
    if (expandIfNecessary) {
        BListItem* parent = listview->Superitem(item);
        while (parent) {
            listview->Expand(parent);
            parent = listview->Superitem(parent);
        }
    }
    index = listview->IndexOf(item);
    if (index < 0)
        return false;
    listview->Select(index);
    return true;
}


But from what you are saying now, you already know the BListItem you want
to select and you have all the "path" expanded, so you don't need the "full
tree" index and this should be enough for you:
listview->Select(listview->IndexOf(item));



Other related posts: