[haiku-development] Re: Query about BOutlineListView

  • From: "Máximo Castañeda" <dmarc-noreply@xxxxxxxxxxxxx> ("antiswen")
  • To: "haiku-development@xxxxxxxxxxxxx" <haiku-development@xxxxxxxxxxxxx>
  • Date: Sat, 6 Apr 2024 17:46:54 +0000 (UTC)

 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: