@@ -269,6 +269,14 @@ SOFTWARE.
269
269
#define DateTimeFormat " %Y/%m/%d %H:%M"
270
270
#endif // DateTimeFormat
271
271
272
+ // /////////////////////////////
273
+ // // SHORTCUTS => ctrl + KEY
274
+ // /////////////////////////////
275
+
276
+ #ifndef SelectAllFilesKey
277
+ #define SelectAllFilesKey ImGuiKey_A
278
+ #endif // SelectAllFilesKey
279
+
272
280
// /////////////////////////////
273
281
// THUMBNAILS
274
282
// /////////////////////////////
@@ -1321,7 +1329,7 @@ void IGFD::FilterManager::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const
1321
1329
1322
1330
// will be called internally
1323
1331
// will not been exposed to IGFD API
1324
- bool IGFD::FilterManager::m_FillFileStyle (std::shared_ptr<FileInfos> vFileInfos) const {
1332
+ bool IGFD::FilterManager::FillFileStyle (std::shared_ptr<FileInfos> vFileInfos) const {
1325
1333
// todo : better system to found regarding what style to priorize regarding other
1326
1334
// maybe with a lambda fucntion for let the user use his style
1327
1335
// according to his use case
@@ -1919,7 +1927,7 @@ void IGFD::FileManager::m_AddFile(const FileDialogInternal& vFileDialogInternal,
1919
1927
}
1920
1928
}
1921
1929
1922
- vFileDialogInternal.filterManager .m_FillFileStyle (infos_ptr);
1930
+ vFileDialogInternal.filterManager .FillFileStyle (infos_ptr);
1923
1931
1924
1932
m_CompleteFileInfos (infos_ptr);
1925
1933
@@ -1948,7 +1956,7 @@ void IGFD::FileManager::m_AddPath(const FileDialogInternal& vFileDialogInternal,
1948
1956
}
1949
1957
}
1950
1958
1951
- vFileDialogInternal.filterManager .m_FillFileStyle (infos_ptr);
1959
+ vFileDialogInternal.filterManager .FillFileStyle (infos_ptr);
1952
1960
1953
1961
m_CompleteFileInfos (infos_ptr);
1954
1962
@@ -2180,7 +2188,10 @@ void IGFD::FileManager::m_RemoveFileNameInSelection(const std::string& vFileName
2180
2188
}
2181
2189
}
2182
2190
2183
- void IGFD::FileManager::m_m_AddFileNameInSelection (const std::string& vFileName, bool vSetLastSelectionFileName) {
2191
+ void IGFD::FileManager::m_AddFileNameInSelection (const std::string& vFileName, bool vSetLastSelectionFileName) {
2192
+ if (vFileName == " ." || vFileName == " .." ) {
2193
+ return ;
2194
+ }
2184
2195
m_SelectedFileNames.emplace (vFileName);
2185
2196
2186
2197
if (m_SelectedFileNames.size () == 1 ) {
@@ -2189,7 +2200,9 @@ void IGFD::FileManager::m_m_AddFileNameInSelection(const std::string& vFileName,
2189
2200
snprintf (fileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, " %zu files Selected" , m_SelectedFileNames.size ());
2190
2201
}
2191
2202
2192
- if (vSetLastSelectionFileName) m_LastSelectedFileName = vFileName;
2203
+ if (vSetLastSelectionFileName) {
2204
+ m_LastSelectedFileName = vFileName;
2205
+ }
2193
2206
}
2194
2207
2195
2208
void IGFD::FileManager::SetCurrentDir (const std::string& vPath) {
@@ -2337,24 +2350,38 @@ bool IGFD::FileManager::SelectDirectory(const std::shared_ptr<FileInfos>& vInfos
2337
2350
return pathClick;
2338
2351
}
2339
2352
2353
+ void IGFD::FileManager::SelectAllFileNames () {
2354
+ m_SelectedFileNames.clear ();
2355
+ for (const auto & infos_ptr : m_FilteredFileList) {
2356
+ if (infos_ptr != nullptr ) {
2357
+ m_AddFileNameInSelection (infos_ptr->fileNameExt , true );
2358
+ }
2359
+ }
2360
+ }
2361
+
2340
2362
void IGFD::FileManager::SelectFileName (const FileDialogInternal& vFileDialogInternal, const std::shared_ptr<FileInfos>& vInfos) {
2341
- if (!vInfos.use_count ()) return ;
2363
+ if (!vInfos.use_count ()) {
2364
+ return ;
2365
+ }
2366
+ m_AddFileNameInSelection (vInfos->fileNameExt , true );
2367
+ }
2368
+
2369
+ void IGFD::FileManager::SelectOrDeselectFileName (const FileDialogInternal& vFileDialogInternal, const std::shared_ptr<FileInfos>& vInfos) {
2370
+ if (!vInfos.use_count ()) {
2371
+ return ;
2372
+ }
2342
2373
2343
2374
if (ImGui::IsKeyDown (ImGuiMod_Ctrl)) {
2344
- if (dLGcountSelectionMax == 0 ) // infinite selection
2345
- {
2346
- if (m_SelectedFileNames.find (vInfos->fileNameExt ) == m_SelectedFileNames.end ()) // not found +> add
2347
- {
2348
- m_m_AddFileNameInSelection (vInfos->fileNameExt , true );
2375
+ if (dLGcountSelectionMax == 0 ) { // infinite selection
2376
+ if (m_SelectedFileNames.find (vInfos->fileNameExt ) == m_SelectedFileNames.end ()) { // not found +> add
2377
+ m_AddFileNameInSelection (vInfos->fileNameExt , true );
2349
2378
} else { // found +> remove
2350
2379
m_RemoveFileNameInSelection (vInfos->fileNameExt );
2351
2380
}
2352
- } else // selection limited by size
2353
- {
2381
+ } else { // selection limited by size
2354
2382
if (m_SelectedFileNames.size () < dLGcountSelectionMax) {
2355
- if (m_SelectedFileNames.find (vInfos->fileNameExt ) == m_SelectedFileNames.end ()) // not found +> add
2356
- {
2357
- m_m_AddFileNameInSelection (vInfos->fileNameExt , true );
2383
+ if (m_SelectedFileNames.find (vInfos->fileNameExt ) == m_SelectedFileNames.end ()) { // not found +> add
2384
+ m_AddFileNameInSelection (vInfos->fileNameExt , true );
2358
2385
} else { // found +> remove
2359
2386
m_RemoveFileNameInSelection (vInfos->fileNameExt );
2360
2387
}
@@ -2364,45 +2391,46 @@ void IGFD::FileManager::SelectFileName(const FileDialogInternal& vFileDialogInte
2364
2391
if (dLGcountSelectionMax != 1 ) {
2365
2392
m_SelectedFileNames.clear ();
2366
2393
// we will iterate filelist and get the last selection after the start selection
2367
- bool startMultiSelection = false ;
2394
+ bool startMultiSelection = false ;
2368
2395
std::string fileNameToSelect = vInfos->fileNameExt ;
2369
2396
std::string savedLastSelectedFileName; // for invert selection mode
2370
2397
for (const auto & file : m_FileList) {
2371
- if (!file.use_count ()) continue ;
2372
-
2398
+ if (!file.use_count ()) {
2399
+ continue ;
2400
+ }
2373
2401
bool canTake = true ;
2374
- if (!file->SearchForTag (vFileDialogInternal.searchManager .searchTag )) canTake = false ;
2375
- if (canTake) // if not filtered, we will take files who are filtered by the dialog
2376
- {
2402
+ if (!file->SearchForTag (vFileDialogInternal.searchManager .searchTag ))
2403
+ canTake = false ;
2404
+ if (canTake) { // if not filtered, we will take files who are filtered by the dialog
2377
2405
if (file->fileNameExt == m_LastSelectedFileName) {
2378
2406
startMultiSelection = true ;
2379
- m_m_AddFileNameInSelection (m_LastSelectedFileName, false );
2407
+ m_AddFileNameInSelection (m_LastSelectedFileName, false );
2380
2408
} else if (startMultiSelection) {
2381
- if (dLGcountSelectionMax == 0 ) // infinite selection
2382
- {
2383
- m_m_AddFileNameInSelection (file->fileNameExt , false );
2409
+ if (dLGcountSelectionMax == 0 ) { // infinite selection
2410
+ m_AddFileNameInSelection (file->fileNameExt , false );
2384
2411
} else { // selection limited by size
2385
2412
if (m_SelectedFileNames.size () < dLGcountSelectionMax) {
2386
- m_m_AddFileNameInSelection (file->fileNameExt , false );
2413
+ m_AddFileNameInSelection (file->fileNameExt , false );
2387
2414
} else {
2388
2415
startMultiSelection = false ;
2389
- if (!savedLastSelectedFileName.empty ()) m_LastSelectedFileName = savedLastSelectedFileName;
2416
+ if (!savedLastSelectedFileName.empty ())
2417
+ m_LastSelectedFileName = savedLastSelectedFileName;
2390
2418
break ;
2391
2419
}
2392
2420
}
2393
2421
}
2394
2422
2395
2423
if (file->fileNameExt == fileNameToSelect) {
2396
- if (!startMultiSelection) // we are before the last Selected FileName, so we must inverse
2397
- {
2424
+ if (!startMultiSelection) { // we are before the last Selected FileName, so we must inverse
2398
2425
savedLastSelectedFileName = m_LastSelectedFileName;
2399
- m_LastSelectedFileName = fileNameToSelect;
2400
- fileNameToSelect = savedLastSelectedFileName;
2401
- startMultiSelection = true ;
2402
- m_m_AddFileNameInSelection (m_LastSelectedFileName, false );
2426
+ m_LastSelectedFileName = fileNameToSelect;
2427
+ fileNameToSelect = savedLastSelectedFileName;
2428
+ startMultiSelection = true ;
2429
+ m_AddFileNameInSelection (m_LastSelectedFileName, false );
2403
2430
} else {
2404
2431
startMultiSelection = false ;
2405
- if (!savedLastSelectedFileName.empty ()) m_LastSelectedFileName = savedLastSelectedFileName;
2432
+ if (!savedLastSelectedFileName.empty ())
2433
+ m_LastSelectedFileName = savedLastSelectedFileName;
2406
2434
break ;
2407
2435
}
2408
2436
}
@@ -2412,7 +2440,7 @@ void IGFD::FileManager::SelectFileName(const FileDialogInternal& vFileDialogInte
2412
2440
} else {
2413
2441
m_SelectedFileNames.clear ();
2414
2442
IGFD::Utils::ResetBuffer (fileNameBuffer);
2415
- m_m_AddFileNameInSelection (vInfos->fileNameExt , true );
2443
+ m_AddFileNameInSelection (vInfos->fileNameExt , true );
2416
2444
}
2417
2445
}
2418
2446
@@ -2668,6 +2696,12 @@ void IGFD::FileDialogInternal::EndFrame() {
2668
2696
fileManager.inputPathActivated = false ;
2669
2697
}
2670
2698
}
2699
+
2700
+ if (ImGui::IsKeyDown (ImGuiMod_Ctrl)) {
2701
+ if (ImGui::IsKeyDown (SelectAllFilesKey)) {
2702
+ fileManager.SelectAllFileNames ();
2703
+ }
2704
+ }
2671
2705
}
2672
2706
2673
2707
void IGFD::FileDialogInternal::ResetForNewDialog () {
@@ -3971,7 +4005,8 @@ bool IGFD::FileDialog::m_DrawFooter() {
3971
4005
}
3972
4006
3973
4007
void IGFD::FileDialog::m_SelectableItem (int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char * vFmt, ...) {
3974
- if (!vInfos.use_count ()) return ;
4008
+ if (!vInfos.use_count ())
4009
+ return ;
3975
4010
3976
4011
auto & fdi = m_FileDialogInternal.fileManager ;
3977
4012
@@ -3990,8 +4025,9 @@ void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vIn
3990
4025
#endif // USE_THUMBNAILS
3991
4026
#ifdef USE_EXPLORATION_BY_KEYS
3992
4027
bool flashed = m_BeginFlashItem ((size_t )vidx);
3993
- bool res = m_FlashableSelectable (fdi.variadicBuffer , vSelected, selectableFlags, flashed, ImVec2 (-1 .0f , h));
3994
- if (flashed) m_EndFlashItem ();
4028
+ bool res = m_FlashableSelectable (fdi.variadicBuffer , vSelected, selectableFlags, flashed, ImVec2 (-1 .0f , h));
4029
+ if (flashed)
4030
+ m_EndFlashItem ();
3995
4031
#else // USE_EXPLORATION_BY_KEYS
3996
4032
(void )vidx; // remove a warnings ofr unused var
3997
4033
@@ -4002,28 +4038,22 @@ void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vIn
4002
4038
// nav system, selectable cause open directory or select directory
4003
4039
if (ImGui::GetIO ().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) {
4004
4040
// little fix for get back the mouse behavior in nav system
4005
- if (ImGui::IsMouseDoubleClicked (0 )) // 0 -> left mouse button double click
4006
- {
4041
+ if (ImGui::IsMouseDoubleClicked (0 )) { // 0 -> left mouse button double click
4007
4042
fdi.pathClicked = fdi.SelectDirectory (vInfos);
4008
- } else if (fdi.dLGDirectoryMode ) // directory chooser
4009
- {
4010
- fdi.SelectFileName (m_FileDialogInternal, vInfos);
4043
+ } else if (fdi.dLGDirectoryMode ) { // directory chooser
4044
+ fdi.SelectOrDeselectFileName (m_FileDialogInternal, vInfos);
4011
4045
} else {
4012
4046
fdi.pathClicked = fdi.SelectDirectory (vInfos);
4013
4047
}
4014
- } else // no nav system => classic behavior
4015
- {
4016
- if (ImGui::IsMouseDoubleClicked (0 )) // 0 -> left mouse button double click
4017
- {
4048
+ } else { // no nav system => classic behavior
4049
+ if (ImGui::IsMouseDoubleClicked (0 )) { // 0 -> left mouse button double click
4018
4050
fdi.pathClicked = fdi.SelectDirectory (vInfos);
4019
- } else if (fdi.dLGDirectoryMode ) // directory chooser
4020
- {
4021
- fdi.SelectFileName (m_FileDialogInternal, vInfos);
4051
+ } else if (fdi.dLGDirectoryMode ) { // directory chooser
4052
+ fdi.SelectOrDeselectFileName (m_FileDialogInternal, vInfos);
4022
4053
}
4023
4054
}
4024
4055
} else {
4025
- fdi.SelectFileName (m_FileDialogInternal, vInfos);
4026
-
4056
+ fdi.SelectOrDeselectFileName (m_FileDialogInternal, vInfos);
4027
4057
if (ImGui::IsMouseDoubleClicked (0 )) {
4028
4058
m_FileDialogInternal.isOk = true ;
4029
4059
}
0 commit comments