diff --git a/Packages/MIES/MIES_AnalysisBrowser.ipf b/Packages/MIES/MIES_AnalysisBrowser.ipf index 90e80f27a8..3da7600853 100644 --- a/Packages/MIES/MIES_AnalysisBrowser.ipf +++ b/Packages/MIES/MIES_AnalysisBrowser.ipf @@ -88,7 +88,7 @@ End static Function AB_AddMapEntry(baseFolder, discLocation) string baseFolder, discLocation - variable index, fileID, nwbVersion, dim + variable nextFreeIndex, fileID, nwbVersion, dim, writeIndex string dataFolder, fileType, relativePath, extension WAVE/T map = GetAnalysisBrowserMap() @@ -99,21 +99,22 @@ static Function AB_AddMapEntry(baseFolder, discLocation) return -1 endif - index = GetNumberFromWaveNote(map, NOTE_INDEX) + nextFreeIndex = GetNumberFromWaveNote(map, NOTE_INDEX) dim = FindDimLabel(map, COLS, "DiscLocation") - FindValue/TEXT=""/TXOP=4/RMD=[][dim] map - if(V_row < index) - index = V_row + FindValue/TEXT=""/TXOP=4/RMD=[0, nextFreeIndex - 1][dim] map + if(V_row >= 0) + writeIndex = V_row else - EnsureLargeEnoughWave(map, indexShouldExist=index, dimension=ROWS) + writeIndex = nextFreeIndex + EnsureLargeEnoughWave(map, indexShouldExist=writeIndex, dimension=ROWS) endif // %DiscLocation = full path to file - map[index][%DiscLocation] = discLocation + map[writeIndex][%DiscLocation] = discLocation // %FileName = filename + extension relativePath = RemovePrefix(discLocation, start = baseFolder) - map[index][%FileName] = relativePath + map[writeIndex][%FileName] = relativePath extension = "." + GetFileSuffix(discLocation) @@ -141,19 +142,21 @@ static Function AB_AddMapEntry(baseFolder, discLocation) default: ASSERT(0, "invalid file type") endswitch - map[index][%FileType] = fileType + map[writeIndex][%FileType] = fileType DFREF dfrAB = GetAnalysisFolder() DFREF dfr = dfrAB:$AB_GetUserData(AB_UDATA_WORKINGDF) DFREF expFolder = UniqueDataFolder(dfr, RemoveEnding(relativePath, extension)) dataFolder = RemovePrefix(GetDataFolder(1, expFolder), start = GetDataFolder(1, dfrAB)) - map[index][%DataFolder] = RemoveEnding(dataFolder, ":") + map[writeIndex][%DataFolder] = RemoveEnding(dataFolder, ":") RefCounterDFIncrease(expFolder) - index += 1 - SetNumberInWaveNote(map, NOTE_INDEX, index) + if(writeIndex == nextFreeIndex) + nextFreeIndex += 1 + SetNumberInWaveNote(map, NOTE_INDEX, nextFreeIndex) + endif - return index - 1 + return writeIndex End static Function AB_RemoveMapEntry(variable index) @@ -2949,28 +2952,35 @@ Function AB_ButtonProc_AddFiles(ba) : ButtonControl break endif WAVE/T selFiles = ListToTextWave(fileList, "\r") - Duplicate/FREE/T selFiles, newFiles - - WAVE/T folderList = GetAnalysisBrowserGUIFolderList() - size = DimSize(selFiles, ROWS) - for(i = 0; i < size; i += 1) - FindValue/TEXT=selFiles[i]/TXOP=4 folderList - if(V_Value >= 0) - continue - endif - AB_AddElementToSourceList(selFiles[i]) - newFiles[index] = selFiles[i] - index += 1 - endfor - Redimension/N=(index) newFiles - - AB_AddExperimentEntries(ba.win, newFiles) + AB_AddFiles(ba.win, selFiles) break endswitch return 0 End +static Function AB_AddFiles(string win, WAVE/T selFiles) + + variable i, index, size + + Duplicate/FREE/T selFiles, newFiles + + WAVE/T folderList = GetAnalysisBrowserGUIFolderList() + size = DimSize(selFiles, ROWS) + for(i = 0; i < size; i += 1) + FindValue/TEXT=selFiles[i]/TXOP=4 folderList + if(V_Value >= 0) + continue + endif + AB_AddElementToSourceList(selFiles[i]) + newFiles[index] = selFiles[i] + index += 1 + endfor + Redimension/N=(index) newFiles + + AB_AddExperimentEntries(win, newFiles) +End + Function AB_AddElementToSourceList(string entry) variable size diff --git a/Packages/MIES/MIES_Downsample.ipf b/Packages/MIES/MIES_Downsample.ipf index b2458203f0..6547f8e239 100644 --- a/Packages/MIES/MIES_Downsample.ipf +++ b/Packages/MIES/MIES_Downsample.ipf @@ -455,11 +455,7 @@ Function DownsampleWindowHook(s) KillOrMoveToTrash(wv=GetDownsampleListWave()) KillOrMoveToTrash(wv=GetDownsampleDataRefWave()) KillOrMoveToTrash(wv=GetDownsampleRateWave()) - - RecursiveRemoveEmptyDataFolder($dataPath) - if(DataFolderExists(dataPath)) - printf "Could not remove all contents of %s\r", dataPath - endif + KillOrMoveToTrash(dfr=$dataPath) break endswitch diff --git a/Packages/MIES/MIES_GuiUtilities.ipf b/Packages/MIES/MIES_GuiUtilities.ipf index 4e26b95e88..774531b873 100644 --- a/Packages/MIES/MIES_GuiUtilities.ipf +++ b/Packages/MIES/MIES_GuiUtilities.ipf @@ -1695,6 +1695,36 @@ Function GetListBoxSelRow(win, ctrl) return V_Value End +/// @brief Set the listbox selection +/// +/// @param win panel +/// @param ctrl control +/// @param val One of @ref ListBoxSelectionWaveFlags +/// @param row row index +/// @param col [optional, defaults to all columns] column index +Function SetListBoxSelection(string win, string ctrl, variable val, variable row, [variable col]) + + variable colStart, colEnd + + if(ParamIsDefault(col)) + colStart = 0 + colEnd = inf + else + colStart = col + colEnd = col + endif + + ControlInfo/W=$win $ctrl + ASSERT(V_flag == 11, "Not a listbox control") + WAVE/Z selWave = $GetValueFromRecMacro("selWave", S_recreation) + ASSERT(WaveExists(selWave), "Missing selection wave") + + ASSERT(row < DimSize(selWave, ROWS), "Invalid row") + ASSERT(col < DimSize(selWave, COLS), "Invalid col") + + selWave[row][colStart, colEnd][0][0] = val +End + /// @brief Check if the location `loc` is inside the rectangle `r` Function IsInsideRect(loc, r) STRUCT Point& loc diff --git a/Packages/MIES/MIES_Utilities.ipf b/Packages/MIES/MIES_Utilities.ipf index 12e68e8c8b..62469f9683 100644 --- a/Packages/MIES/MIES_Utilities.ipf +++ b/Packages/MIES/MIES_Utilities.ipf @@ -978,7 +978,7 @@ Function IsDataFolderEmpty(DFREF dfr) ) == 0 End -/// @brief Removes all empty datafolders in the passed datafolder reference +/// @brief Remove all empty datafolders in the passed datafolder reference recursively including sourceDFR Function RemoveAllEmptyDataFolders(sourceDFR) DFREF sourceDFR @@ -991,39 +991,13 @@ Function RemoveAllEmptyDataFolders(sourceDFR) numFolder = CountObjectsDFR(sourceDFR, COUNTOBJECTS_DATAFOLDER) - if(!numFolder) - return NaN - endif - for(i = numFolder - 1; i >= 0; i -= 1) folder = GetDataFolder(1, sourceDFR) + GetIndexedObjNameDFR(sourceDFR, COUNTOBJECTS_DATAFOLDER, i) - RemoveEmptyDataFolder($folder) + RemoveAllEmptyDataFolders($folder) endfor -end -/// @brief Recursively remove all folders from the datafolder path, -/// if and only if all are empty. -Function RecursiveRemoveEmptyDataFolder(dfr) - dfref dfr - - variable numItems, i - string path, partialPath - - if(!DataFolderExistsDFR(dfr)) - return 0 - endif - - path = GetDataFolder(1, dfr) - path = RemoveEnding(path, ":") - numItems = ItemsInList(path, ":") - partialPath = path - for(i=numItems-1; i >= 1; i-=1) - if(!RemoveEmptyDataFolder($partialPath)) - break - endif - partialPath = RemoveEnding(partialPath, ":" + StringFromList(i, path, ":")) - endfor -End + RemoveEmptyDataFolder(sourceDFR) +end /// @name Debugger state constants for DisableDebugger and ResetDebuggerState /// @{ diff --git a/Packages/tests/Basic/UTF_Utils.ipf b/Packages/tests/Basic/UTF_Utils.ipf index 84c962e7ab..40e7e9c7b6 100644 --- a/Packages/tests/Basic/UTF_Utils.ipf +++ b/Packages/tests/Basic/UTF_Utils.ipf @@ -52,7 +52,8 @@ Function RemoveAllEmpty_init_IGNORE() NewDataFolder/O root:removeMe:X7 Make/O root:removeMe:X7:data NewDataFolder/O root:removeMe:X8 - NewDataFolder/O root:removeMe:x8 + NewDataFolder/O root:removeMe:X8:Y8 + NewDataFolder/O root:removeMe:X8:Y8:Z8 End Function RemoveAllEmpty_Works1() @@ -73,7 +74,7 @@ Function RemoveAllEmpty_Works3() NewDataFolder ttest string folder = GetDataFolder(1) + "ttest" RemoveAllEmptyDataFolders($folder) - CHECK(DataFolderExists(folder)) + CHECK(!DataFolderExists(folder)) End Function RemoveAllEmpty_Works4() @@ -82,7 +83,7 @@ Function RemoveAllEmpty_Works4() DFREF dfr = root:removeMe RemoveAllEmptyDataFolders(dfr) - CHECK_EQUAL_VAR(CountObjectsDFR(dfr, 4), 4) + CHECK_EQUAL_VAR(CountObjectsDFR(dfr, COUNTOBJECTS_DATAFOLDER), 3) End /// @} diff --git a/Packages/tests/HistoricData/UTF_HistoricDashboard.ipf b/Packages/tests/HistoricData/UTF_HistoricDashboard.ipf index 05640cbe36..b20c6255c0 100644 --- a/Packages/tests/HistoricData/UTF_HistoricDashboard.ipf +++ b/Packages/tests/HistoricData/UTF_HistoricDashboard.ipf @@ -53,3 +53,29 @@ Function TestDashboardWithHistoricData([string str]) bsPanel = BSP_GetPanel(sbWin) PGC_SetAndActivateControl(bsPanel, "check_BrowserSettings_DS", val = 1) End + +Function TestAnalysisBrowserAddingFiles() + + string abWin, sweepBrowsers, fileToReadd + variable holeIndex + + WAVE/T files = GetHistoricDataFiles() + files[] = "input:" + files[p] + + [abWin, sweepBrowsers] = OpenAnalysisBrowser(files) + + PGC_SetAndActivateControl(abWin, "button_collapse_all") + + WAVE/T map = GetAnalysisBrowserMap() + CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS)) + + holeIndex = 1 + fileToReadd = map[holeIndex] + + SetListBoxSelection(abWin, "listbox_AB_Folders", LISTBOX_SELECTED, holeIndex) + PGC_SetAndActivateControl(abWin, "button_AB_Remove") + CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS)) + + MIES_AB#AB_AddFiles(abWin, {fileToReadd}) + CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS)) +End diff --git a/Packages/tests/HistoricData/UTF_HistoricData.ipf b/Packages/tests/HistoricData/UTF_HistoricData.ipf index 80300153bb..a8015d4bb8 100644 --- a/Packages/tests/HistoricData/UTF_HistoricData.ipf +++ b/Packages/tests/HistoricData/UTF_HistoricData.ipf @@ -209,11 +209,11 @@ End Function/WAVE GetHistoricDataFiles() Make/FREE/T files = {"C57BL6J-629713.05.01.02.pxp", \ - "Chat-IRES-Cre-neo;Ai14-582723.15.10.01.pxp", \ - "Pvalb-IRES-Cre;Ai14-646904.13.03.02.pxp", \ - "Sst-IRES-Cre;Ai14-554002.08.06.02.pxp", \ - "Sst-IRES-Cre;Th-P2A-FlpO;Ai65-561491.09.09.02.pxp", \ - "epoch_clipping_2022_03_08_140256.pxp"} + "Chat-IRES-Cre-neo;Ai14-582723.15.10.01.pxp", \ + "Pvalb-IRES-Cre;Ai14-646904.13.03.02.pxp", \ + "Sst-IRES-Cre;Ai14-554002.08.06.02.pxp", \ + "Sst-IRES-Cre;Th-P2A-FlpO;Ai65-561491.09.09.02.pxp", \ + "epoch_clipping_2022_03_08_140256.pxp"} DownloadFilesIfRequired(files) SetLabelsForDGWave(files)