@@ -1302,64 +1302,36 @@ namespace IGFD
13021302 else
13031303 str = fileEntryString + str;
13041304 }
1305- bool selected = false ;
1306- if (m_SelectedFileNames.find (infos.fileName ) != m_SelectedFileNames.end ()) // found
1307- selected = true ;
1305+ bool selected = (m_SelectedFileNames.find (infos.fileName ) != m_SelectedFileNames.end ()); // found
13081306 ImGui::TableNextRow ();
1309- if (ImGui::TableSetColumnIndex (0 )) // first column
1310- {
1311- ImGuiSelectableFlags selectableFlags = ImGuiSelectableFlags_AllowDoubleClick;
1312- selectableFlags |=
1313- ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SpanAvailWidth;
13141307
1315- bool _selectablePressed = false ;
1316- #ifdef USE_EXPLORATION_BY_KEYS
1317- bool flashed = BeginFlashItem (i);
1318- _selectablePressed = FlashableSelectable (str.c_str (), selected, selectableFlags,
1319- flashed);
1320- if (flashed)
1321- EndFlashItem ();
1322- #else // USE_EXPLORATION_BY_KEYS
1323- _selectablePressed = ImGui::Selectable (str.c_str (), selected, selectableFlags);
1324- #endif // USE_EXPLORATION_BY_KEYS
1325- if (_selectablePressed)
1326- {
1327- if (infos.type == ' d' )
1328- {
1329- if (!dlg_filters.empty () || ImGui::IsMouseDoubleClicked (0 ))
1330- {
1331- m_PathClicked = SelectDirectory (infos);
1332- }
1333- else // directory chooser
1334- {
1335- SelectFileName (infos);
1336- }
1337-
1338- if (showColor)
1339- ImGui::PopStyleColor ();
1308+ bool needToBreakTheloop = false ;
13401309
1341- break ;
1342- }
1343- else
1344- {
1345- SelectFileName (infos);
1346- }
1347- }
1310+ if (ImGui::TableSetColumnIndex (0 )) // first column
1311+ {
1312+ needToBreakTheloop = SelectableItem (i, infos, selected, str.c_str ());
13481313 }
13491314 if (ImGui::TableSetColumnIndex (1 )) // second column
13501315 {
13511316 if (infos.type != ' d' )
13521317 {
1353- ImGui::Text (" %s " , infos.formatedFileSize .c_str ()); // -V111
1318+ needToBreakTheloop = SelectableItem (i, infos, selected, " %s " , infos.formatedFileSize .c_str ());
1319+ }
1320+ else
1321+ {
1322+ needToBreakTheloop = SelectableItem (i, infos, selected, " " );
13541323 }
13551324 }
13561325 if (ImGui::TableSetColumnIndex (2 )) // third column
13571326 {
1358- ImGui::Text ( " %s" , infos.fileModifDate .c_str ()); // -V111
1327+ needToBreakTheloop = SelectableItem (i, infos, selected, " %s" , infos.fileModifDate .c_str ());
13591328 }
1329+
13601330 if (showColor)
13611331 ImGui::PopStyleColor ();
13621332
1333+ if (needToBreakTheloop)
1334+ break ;
13631335 }
13641336 }
13651337 m_FileListClipper.End ();
@@ -1401,6 +1373,52 @@ namespace IGFD
14011373 ImGui::EndChild ();
14021374 }
14031375
1376+ bool IGFD::FileDialog::SelectableItem (int vidx, const FileInfoStruct& vInfos, bool vSelected, const char * vFmt, ...)
1377+ {
1378+ bool needToBreakTheloop = false ;
1379+ static ImGuiSelectableFlags selectableFlags = ImGuiSelectableFlags_AllowDoubleClick |
1380+ ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SpanAvailWidth;
1381+
1382+ va_list args;
1383+ va_start (args, vFmt);
1384+ int w = vsnprintf (VariadicBuffer, MAX_FILE_DIALOG_NAME_BUFFER - 1 , vFmt, args);
1385+ va_end (args);
1386+ if (w)
1387+ VariadicBuffer[w] = ' \0 ' ;
1388+
1389+ #ifdef USE_EXPLORATION_BY_KEYS
1390+ bool flashed = BeginFlashItem (vidx);
1391+ bool res = FlashableSelectable (VariadicBuffer, vSelected, selectableFlags,
1392+ flashed);
1393+ if (flashed)
1394+ EndFlashItem ();
1395+ #else // USE_EXPLORATION_BY_KEYS
1396+ res = ImGui::Selectable (VariadicBuffer, selected, selectableFlags);
1397+ #endif // USE_EXPLORATION_BY_KEYS
1398+ if (res)
1399+ {
1400+ if (vInfos.type == ' d' )
1401+ {
1402+ if (!dlg_filters.empty () || ImGui::IsMouseDoubleClicked (0 ))
1403+ {
1404+ m_PathClicked = SelectDirectory (vInfos);
1405+ }
1406+ else // directory chooser
1407+ {
1408+ SelectFileName (vInfos);
1409+ }
1410+
1411+ return true ; // needToBreakTheloop
1412+ }
1413+ else
1414+ {
1415+ SelectFileName (vInfos);
1416+ }
1417+ }
1418+
1419+ return false ;
1420+ }
1421+
14041422 void IGFD::FileDialog::DrawSidePane (float vHeight)
14051423 {
14061424 ImGui::SameLine ();
0 commit comments