Folder Selector

This is my first code snippet, and is a little macro showing how to display a list of the first level folders. You can set as active any folder by double clicking on it. Future versions will work with different level folders. If you have suggestions please let me know.

#pragma rtGlobals=1     // Use modern global access method.

// Window Recreation
Window Folder_Selector() : Panel
    Makelist()
    PauseUpdate; Silent 1       // building window...
    NewPanel /W=(434,276,689,553) as "Folder Selector"
    SetDrawLayer UserBack
    DrawText 19,34,"Double click on the folder to set as active"
    ListBox list0,pos={19,52},size={75,132},proc=ListBox_G,frame=0
    ListBox list0,listWave=root:lista,mode= 2,selRow= 0
EndMacro

// List Box Control
Function ListBox_G(ctrlName,row,col,event) : ListBoxControl
    String ctrlName
    Variable row
    Variable col
    Variable event  //1=mouse down, 2=up, 3=dbl click, 4=cell select with mouse or keys
                    //5=cell select with shift key, 6=begin edit, 7=end
     
    WAVE lista=root:lista
   
if (event == 3)
    String/G nombre         //name of the current Folder
    string cmd
    sprintf cmd," nombre = root:lista[%g]", row
    execute cmd
    if (cmpstr (nombre,"root:") == 0)
        setdatafolder root:
    else
        nombre = "root:"+ nombre
        setdatafolder $nombre
    endif
    print nombre
    setdatafolder $nombre
endif
    return 0
End

// Folders List Function
Function Makelist()
string objName
variable n,i
i=0
n = CountObjects(":",4)
Make/O /T /N=(n+1) lista
lista[0] = "root:"
do
    objName = GetIndexedObjName(":", 4, i)
        if (strlen(objName) == 0)
        break
        endif
    lista[i+1]=objName
    i=i+1
    print i
while(1)
end
 
if (event == 3)
    String/G nombre         //name of the current Folder
    string cmd
    sprintf cmd," nombre = root:lista[%g]", row
    execute cmd
    if (cmpstr (nombre,"root:") == 0)
        setdatafolder root:
    else
        nombre = "root:"+ "'"+nombre+"'"
        setdatafolder $nombre
    endif
    setdatafolder $nombre
endif


works better whit liberal names.
    String/G nombre         //name of the current Folder
    string cmd
    sprintf cmd," nombre = root:lista[%g]", row
    execute cmd


Why do you need the global variable and execute? Can't you do it this way:

    String nombre           //name of the current Folder
    nombre = lista[row]


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More