Hierarchical list widget error?

I'm having good fun with the hierarchical lists, but I do get a surprising error (version 6.32A mac OS X 10.7). It happens when all items have been removed from a list, and I add a new one:

To make the listbox:
Function ErrorHierarchicalList()
    String Swinname="WindowDataHierarchy"  
    String Slistboxname="HierarchicalListbox"  

    Dowindow/K $(Swinname) 
    NewPanel /N=$(Swinname) /W=(1000,100,1250,460) as "Data gestructureerd"

    Make /O/T WhierarchyItems
    Make/O WhierarchySel
   
    ListBox $(Slistboxname),ListWave=WhierarchyItems,size={235,315},pos={5,30},widths={30,185}
    ListBox $(Slistboxname),fsize=15,mode=4,SelWave=WhierarchySel

    MakeListIntoHierarchicalList(Swinname,Slistboxname,"ContainerOpenFamOrFolder")
end


To get the error, execute:
ErrorHierarchicalList()
WMHL_AddObject("WindowDataHierarchy","HierarchicalListbox","","item 1",1)
WMHL_DeleteRowAndChildren("WindowDataHierarchy","HierarchicalListbox",0)
WMHL_AddObject("WindowDataHierarchy","HierarchicalListbox","","item 1",1)


Am I making a basic mistake?

(ps, edit: the error is: "While executing a wave write, the following error occured: Index out of range for wave "Selwave".)
Update!
I started digging in the procedure file of the hierarchical listwidget, and I think I have the root of the trouble: if the LB is initialized, but all rows are killed, then the number of columns and layers of SelWave and ListWave are also reduced to zero. Changing the function WMHL_AddObjectToList solved the error, but I don't know if I introduced other errors as well. (When extra columns are used e.g.) Some advice please!

Change to WMHL_AddObjectToList:
if (strlen(ParentPath) == 0)
        if ( (nRows == 1) && (CmpStr(ListWave[0][1][1], "<uninitialized>") == 0) )
            nRows = 0
        else
            InsertPoints nRows, 1, SelWave, ListWave
            redimension /N=(-1,2) Selwave       //  added as a "fix"
            redimension /N=(-1,2,2) Listwave            //  added as a "fix"
        endif
...



You have, indeed, found a bug in HierarchicalListWidget. I'm reviewing it now to see what the best solution might be.

Just as a side note- ErrorHierarchicalLis() makes a listwave and selwave for the listbox, but that's not needed. MakeListIntoHierarchicalList() creates waves private to HierarchicalListWidget, abandoning the waves you created. The only things you need to do with the listbox are to create it and give it a size and position.

I'll let you know what I figure out.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Your solution to the problem works only for a HierarchicalListWidget that has not had columns added using WMHL_AddColumns(). The problem is, as you found, that removing the last row from ListWave and SelWave causes the waves to forget that they were multidimensional waves. My solution is to change WMHL_DeleteRowAndChildren() such that if you remove the last row, it returns the waves to the state of an uninitialized listbox, so that the next call to WMHL_AddObject() will Do the Right Thing. Here's my revised version of that function:
Function WMHL_DeleteRowAndChildren(windowname, listcontrolname, theRow)
    String windowname
    String listcontrolname
    Variable theRow

    STRUCT HierarchicalListListInfo ListInfo
    if (WMHL_GetListInfo(windowname, listcontrolname, ListInfo))
        Wave SelWave = $("root:Packages:WM_HierarchicalList:"+ListInfo.FolderName+":"+ListInfo.SelWaveName)
        Wave/T ListWave = $("root:Packages:WM_HierarchicalList:"+ListInfo.FolderName+":"+ListInfo.ListWaveName)
        Variable lastRow = theRow
        if ( WMHL_RowIsContainer(windowname, listcontrolname, theRow) && WMHL_RowIsOpen(windowname, listcontrolname, theRow) )
            lastRow = WMHL_FindLastChild(ListInfo, theRow)
        endif
        Variable numRowsToDelete = lastRow-theRow+1
        if (numRowsToDelete == DimSize(SelWave, 0))
            // JW 131022 We are deleting all rows in the list. If we remove all the rows in the waves, they will forget that they are
            // multicolumn waves. So here we just return the list to the same state as it was in when it was new, except that if WMHL_AddColumns()
            // has been used, it will have more columns than a new list.
            Redimension/N=(1, -1) SelWave
            Redimension/N=(1, -1, -1) ListWave
            ListWave = ""
            ListWave[0][1][1] = "<uninitialized>"
            SelWave = 0
        else
            DeletePoints/M=0 theRow, lastRow-theRow+1, SelWave, ListWave
        endif
    endif
end

This fix will be included in the next minor release of Igor, but I don't know when that might be. I don't want to post the revised procedure file here because then it will have an indefinite life. I would be happy to send you a copy if you send an e-mail to support@wavemetrics.com.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thanks for your quick reply John. Good to know I don't need to initialize those waves, and I'll see what the fix will be. I'm building a browser for our hierarchical data, so the widget comes in really nice.

edit: as I typed this reply, you posted the fix. I replaced "WMHL_DeleteRowAndChildren" by your function, and it works! Thank you so much for the fantastic service.
Glad I could help. We try to fix bugs as quickly as possible. Let me know if you find any other problems with HierarchicalListWidget. It doesn't get much use, so it probably has more bugs.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Roger that!
The current fix of reinitialization seems to kill color support as well, I have to add it after removing the last item.