copy and paste waves to another datafolder

Hi, can I copy and paste waves to another datafolder in the databrowser?

I konw I can duplicate the waves using Cmd+D but it makes copies of waves in the SAME datafolder.

 

As I could not find this feature in the Igor documentation, I am trying to make a function to implement this feature using the GetBrowserSelection.

However, GetBrowserSelection only allow me to select one wave. Is there a technique to select multiple waves from the databrowser?

Function CopyPasteWaves(mode)
    string mode
    
    NewDataFolder/O root:Packages
    NewDataFolder/O root:Packages:CopyPaste
    
    String targetpath
    
    strswitch(mode)    // string switch
        case "c":    // execute if case matches expression
            targetpath = GetBrowserSelection(0)
            Print targetpath
            string deswavepath = "root:Packages:CopyPaste:" + ParseFilePath(3,targetpath,":",0,0)
            Duplicate/O $targetpath, $deswavepath
            Print "waves copied"
            break
        case "x":    // execute if case matches expression
            Print "waves cutted"
            break
        case "p":    // execute if case matches expression
            Print "waves pasted"
            break

    endswitch
End

 

something like this?

menu "DataBrowserObjectsPopup", dynamic
    ValidBrowserSelection(0), /Q, CopyPasteWaves(0)
    ValidBrowserSelection(1), /Q, CopyPasteWaves(1)
end

function /S ValidBrowserSelection(int mode)
    if (strlen(GetBrowserSelection(-1)) == 0)
        return ""   // Data Browser is not open
    endif
    switch (mode)
        case 0:
            return SelectString(ItemsInList(getListOfBrowserWaves())-1, "", "Copy Wave", "Copy Waves")
            break
        case 1:
        case 2:
            // should check here that we have a sensible destination selected
            if (strlen(GetBrowserSelection(1)))
                return ""
            endif
            SVAR /Z copylist = getDFR():copylist
            if (SVAR_Exists(copylist))
                return SelectString(ItemsInList(copylist)-1, "", "Paste Wave", "Paste Waves")
            endif
            break
    endswitch
    return ""
end

function /DF getDFR()
    NewDataFolder/O root:Packages
    NewDataFolder/O root:Packages:CopyPaste
    DFREF dfr = root:Packages:CopyPaste
    return dfr
end
   
function /S getListOfBrowserWaves()
    string item = "", listofwaves = ""
    int i = 0
    do
        item = GetBrowserSelection(i)
        if (strlen(item) == 0)
            break
        endif
        wave /Z w = $item
        if (WaveExists(w))
            listofwaves = AddListItem(GetWavesDataFolder(w, 2), listofwaves)
        endif
        i ++
    while(1)
    return listofwaves
end

function CopyPasteWaves(int mode)    
   
    string targetpath, strWave
    int numwaves, i
   
    switch(mode)
    case 0:
        string /G getDFR():copylist = getListOfBrowserWaves()
        break
    case 1:
        SVAR copylist = getDFR():copylist
        targetpath =  GetBrowserSelection(0)
        DFREF dfr = $targetpath
        if (DataFolderRefStatus(dfr) == 0)
            targetpath = ParseFilePath(1, GetBrowserSelection(0), ":", 1, 0)
            DFREF dfr = $targetpath
        endif
        if (DataFolderRefStatus(dfr) == 0)
            return 0
        endif
        numwaves = ItemsInList(copylist)
        for (i=0;i<numwaves;i++)
            strWave = StringFromList(i, copylist)
            wave /Z sourcewave = $strWave
            if (!WaveExists(sourcewave))
                continue
            endif
            strWave = ParseFilePath(0, strWave, ":", 1, 0)
            wave /Z targetwave = dfr:$strWave
            if (WaveExists(targetwave))
                DoAlert 1, strWave + " exists. Overwrite?"
                if (v_flag == 2)
                    continue
                endif
            endif
            Duplicate /O sourcewave $targetpath + strWave
        endfor
        break
    endswitch
end

 

Note that drag and drop achieves the same as 'cut' and 'paste'.

Also, you will need Igor 9 to access the DataBrowserObjectsPopup menu

Note that you can also achieve something like copy & paste via drag and drop while holding the 'alt' or 'ctrl' key. A small + icon will appear next to the mouse cursor in this case. This works of course with multiple waves selected as well as with folders.

Thank you very much. Your code works perfectly. It is far beyond my expectation.

This copy and paste menu should be a native feature for future Igor.