I found and fixed a little bug in TreeView

in findItemFromIdentifierString, 2.0.21 version of modules code, Backslashes are not treated correctly.

The original juce method:

[code]
TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
{
const String thisId (getUniqueName());

if (thisId == identifierString)
    return this;

if (identifierString.startsWith (thisId + "/"))
{
    const String remainingPath (identifierString.substring (thisId.length() + 1));

    const bool wasOpen = isOpen();
    setOpen (true);

    for (int i = subItems.size(); --i >= 0;)
    {
        TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);

        if (item != nullptr)
            return item;
    }

    setOpen (wasOpen);
}

return nullptr;

}[/code]

The above doesn´t work unless you change two lines, as per the version below:

[code]TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
{
const String thisId (getUniqueName());

// Onar3d was here
if ("/" + thisId == identifierString)
return this;

// and here
if (identifierString.startsWith ("/" + thisId))
{
const String remainingPath (identifierString.substring (thisId.length() + 1));

    const bool wasOpen = isOpen();
    setOpen (true);

    for (int i = subItems.size(); --i >= 0;)
    {
        TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);

        if (item != nullptr)
            return item;
    }

    setOpen (wasOpen);
}

return nullptr;

}[/code]

The string I call the function with is straight from getItemIdentifierString(), not edited by myself in any way.

Thanks! I’ll take a look at that right away…

heh, I just independently came upon the exact issue too.

Did this actually get a fix checked in?
[I’m using the modules acquired from the introjucer, as i’m working on one project on 3 separate computers at the moment, and don’t have git on all of them so haven’t got the bleeding edge version…]

I had a browse on sourceforge and it didn’t look like it’d been fixed. [TreeView selection restoring is broken without it, though the above fix works fine]

Yeah, I did this last week. I’m pretty sure my fix worked because I’ve been doing a lot of stuff with the introjucer’s treeview, which was suffering from the same problem, but that restores its state correctly now.

Splendid!