@@ -1975,11 +1975,13 @@ bool IGFD::FileManager::m_CompleteFileInfosWithUserFileAttirbutes(const FileDial
19751975void IGFD::FileManager::ClearFileLists () {
19761976 m_FilteredFileList.clear ();
19771977 m_FileList.clear ();
1978+ m_SelectedFileNames.clear ();
19781979}
19791980
19801981void IGFD::FileManager::ClearPathLists () {
19811982 m_FilteredPathList.clear ();
19821983 m_PathList.clear ();
1984+ m_SelectedFileNames.clear ();
19831985}
19841986
19851987void IGFD::FileManager::m_AddFile (const FileDialogInternal& vFileDialogInternal, const std::string& vPath, const std::string& vFileName, const FileType& vFileType) {
@@ -2711,16 +2713,23 @@ std::string IGFD::FileManager::GetResultingFilePathName(FileDialogInternal& vFil
27112713
27122714std::map<std::string, std::string> IGFD::FileManager::GetResultingSelection (FileDialogInternal& vFileDialogInternal, IGFD_ResultMode vFlag) {
27132715 std::map<std::string, std::string> res;
2714- for (const auto & selectedFileName : m_SelectedFileNames) {
2715- auto result = GetResultingPath ();
2716+ const auto & result_path = GetResultingPath ();
2717+ if (!m_SelectedFileNames.empty ()) {
2718+ for (const auto & selectedFileName : m_SelectedFileNames) {
2719+ auto result = result_path;
27162720#ifdef _IGFD_UNIX_
2717- if (fsRoot != result)
2721+ if (fsRoot != result)
27182722#endif // _IGFD_UNIX_
2719- {
2720- result += IGFD::Utils::GetPathSeparator ();
2723+ {
2724+ result += IGFD::Utils::GetPathSeparator ();
2725+ }
2726+ result += vFileDialogInternal.filterManager .ReplaceExtentionWithCurrentFilterIfNeeded (selectedFileName, vFlag);
2727+ res[selectedFileName] = result;
2728+ }
2729+ } else { // opened directory with no selection
2730+ if (vFileDialogInternal.fileManager .dLGDirectoryMode ) { // directory mode
2731+ res[" ." ] = result_path;
27212732 }
2722- result += vFileDialogInternal.filterManager .ReplaceExtentionWithCurrentFilterIfNeeded (selectedFileName, vFlag);
2723- res[selectedFileName] = result;
27242733 }
27252734 return res;
27262735}
@@ -3758,12 +3767,11 @@ bool IGFD::FileDialog::Display(const std::string& vKey, ImGuiWindowFlags vFlags,
37583767 }
37593768 m_FileDialogInternal.lastImGuiFrameCount = g.FrameCount ; // mark this instance as used this frame
37603769
3761- m_CurrentDisplayedFlags = ImGuiWindowFlags_None ;
3770+ m_CurrentDisplayedFlags = vFlags ;
37623771 std::string name = m_FileDialogInternal.dLGtitle + " ##" + m_FileDialogInternal.dLGkey ;
37633772 if (m_FileDialogInternal.name != name) {
37643773 fdFile.ClearComposer ();
37653774 fdFile.ClearFileLists ();
3766- m_CurrentDisplayedFlags = vFlags;
37673775 }
37683776
37693777 m_NewFrame ();
@@ -4018,7 +4026,8 @@ void IGFD::FileDialog::m_DisplayPathPopup(ImVec2 vSize) {
40184026
40194027bool IGFD::FileDialog::m_DrawOkButton () {
40204028 auto & fdFile = m_FileDialogInternal.fileManager ;
4021- if (m_FileDialogInternal.canWeContinue && strlen (fdFile.fileNameBuffer )) {
4029+ if (m_FileDialogInternal.canWeContinue && strlen (fdFile.fileNameBuffer ) || //
4030+ m_FileDialogInternal.getDialogConfig ().flags & ImGuiFileDialogFlags_OptionalFileName) { // optional
40224031 if (IMGUI_BUTTON (okButtonString " ##validationdialog" , ImVec2 (okButtonWidth, 0 .0f )) || m_FileDialogInternal.isOk ) {
40234032 m_FileDialogInternal.isOk = true ;
40244033 return true ;
@@ -4105,7 +4114,22 @@ bool IGFD::FileDialog::m_DrawFooter() {
41054114 return res;
41064115}
41074116
4108- void IGFD::FileDialog::m_SelectableItem (int vidx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char * vFmt, ...) {
4117+ bool IGFD::FileDialog::m_Selectable (int vRowIdx, const char * vLabel, bool vSelected, ImGuiSelectableFlags vFlags, const ImVec2& vSizeArg) {
4118+ bool res = false ;
4119+ #ifdef USE_EXPLORATION_BY_KEYS
4120+ bool flashed = m_BeginFlashItem ((size_t )vRowIdx);
4121+ res = m_FlashableSelectable (vLabel, vSelected, vFlags, flashed, vSizeArg);
4122+ if (flashed) {
4123+ m_EndFlashItem ();
4124+ }
4125+ #else // USE_EXPLORATION_BY_KEYS
4126+ (void )vRowIdx; // remove a warnings for unused var
4127+ res = ImGui::Selectable (vLabel, vSelected, vFlags, vSizeArg);
4128+ #endif // USE_EXPLORATION_BY_KEYS
4129+ return res;
4130+ }
4131+
4132+ void IGFD::FileDialog::m_SelectableItem (int vRowIdx, std::shared_ptr<FileInfos> vInfos, bool vSelected, const char * vFmt, ...) {
41094133 if (!vInfos.use_count ()) return ;
41104134
41114135 auto & fdi = m_FileDialogInternal.fileManager ;
@@ -4123,18 +4147,7 @@ void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr<FileInfos> vIn
41234147 h = DisplayMode_ThumbailsList_ImageHeight;
41244148 }
41254149#endif // USE_THUMBNAILS
4126- #ifdef USE_EXPLORATION_BY_KEYS
4127- bool flashed = m_BeginFlashItem ((size_t )vidx);
4128- bool res = m_FlashableSelectable (fdi.variadicBuffer , vSelected, selectableFlags, flashed, ImVec2 (-1 .0f , h));
4129- if (flashed) {
4130- m_EndFlashItem ();
4131- }
4132- #else // USE_EXPLORATION_BY_KEYS
4133- (void )vidx; // remove a warnings for unused var
4134-
4135- bool res = ImGui::Selectable (fdi.variadicBuffer , vSelected, selectableFlags, ImVec2 (-1 .0f , h));
4136- #endif // USE_EXPLORATION_BY_KEYS
4137- if (res) {
4150+ if (m_Selectable (vRowIdx, fdi.variadicBuffer , vSelected, selectableFlags, ImVec2 (-1 .0f , h))) {
41384151 if (vInfos->fileType .isDir ()) {
41394152 // nav system, selectable cause open directory or select directory
41404153 if (ImGui::GetIO ().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) {
@@ -4194,13 +4207,29 @@ void IGFD::FileDialog::m_BeginFileColorIconStyle(std::shared_ptr<FileInfos> vFil
41944207
41954208 vOutStr += " " + vFileInfos->fileNameExt ;
41964209
4197- if (vOutShowColor) ImGui::PushStyleColor (ImGuiCol_Text, vFileInfos->fileStyle ->color );
4198- if (*vOutFont) ImGui::PushFont (*vOutFont);
4210+ if (vOutShowColor) {
4211+ ImGui::PushStyleColor (ImGuiCol_Text, vFileInfos->fileStyle ->color );
4212+ }
4213+ if (*vOutFont) {
4214+ #if IMGUI_VERSION_NUM < 19201
4215+ ImGui::PushFont (*vOutFont);
4216+ #else
4217+ ImGui::PushFont (*vOutFont, 0 .0f );
4218+ #endif
4219+ }
41994220}
42004221
42014222void IGFD::FileDialog::m_EndFileColorIconStyle (const bool vShowColor, ImFont* vFont) {
4202- if (vFont) ImGui::PopFont ();
4203- if (vShowColor) ImGui::PopStyleColor ();
4223+ if (vFont) {
4224+ ImGui::PopFont ();
4225+ }
4226+ if (vShowColor) {
4227+ ImGui::PopStyleColor ();
4228+ }
4229+ }
4230+
4231+ void IGFD::FileDialog::m_drawColumnText (int /* vColIdx*/ , const char * vLabel, bool /* vSelected*/ , bool /* vHovered*/ ) {
4232+ ImGui::Text (" %s" , vLabel);
42044233}
42054234
42064235void IGFD::FileDialog::m_DrawFileListView (ImVec2 vSize) {
@@ -4310,6 +4339,7 @@ void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) {
43104339 bool _showColor = false ;
43114340
43124341 int column_id = 0 ;
4342+ bool _rowHovered = false ;
43134343 m_FileListClipper.Begin ((int )fdi.GetFilteredListSize (), ImGui::GetTextLineHeightWithSpacing ());
43144344 while (m_FileListClipper.Step ()) {
43154345 for (int i = m_FileListClipper.DisplayStart ; i < m_FileListClipper.DisplayEnd ; i++) {
@@ -4325,30 +4355,31 @@ void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) {
43254355 ImGui::TableNextRow ();
43264356
43274357 column_id = 0 ;
4358+ _rowHovered = false ;
43284359 if (ImGui::TableNextColumn ()) { // file name
43294360 if (!infos_ptr->deviceInfos .empty ()) {
43304361 _str += " " + infos_ptr->deviceInfos ;
43314362 }
43324363 m_SelectableItem (i, infos_ptr, selected, _str.c_str ());
4364+ _rowHovered = ImGui::IsItemHovered ();
43334365 m_DisplayFileInfosTooltip (i, column_id++, infos_ptr);
43344366 }
43354367 if (ImGui::TableNextColumn ()) { // file type
4336- ImGui::Text ( " %s " , infos_ptr->fileExtLevels [0 ].c_str ());
4368+ m_drawColumnText (column_id , infos_ptr->fileExtLevels [0 ].c_str (), selected, _rowHovered );
43374369 m_DisplayFileInfosTooltip (i, column_id++, infos_ptr);
43384370 }
43394371 if (ImGui::TableNextColumn ()) { // file size
43404372 if (!infos_ptr->fileType .isDir ()) {
4341- ImGui::Text ( " %s " , infos_ptr->formatedFileSize .c_str ());
4373+ m_drawColumnText (column_id , infos_ptr->formatedFileSize .c_str (), selected, _rowHovered );
43424374 } else {
43434375 ImGui::TextUnformatted (" " );
43444376 }
43454377 m_DisplayFileInfosTooltip (i, column_id++, infos_ptr);
43464378 }
43474379 if (ImGui::TableNextColumn ()) { // file date + time
4348- ImGui::Text ( " %s " , infos_ptr->fileModifDate .c_str ());
4380+ m_drawColumnText (column_id , infos_ptr->fileModifDate .c_str (), selected, _rowHovered );
43494381 m_DisplayFileInfosTooltip (i, column_id++, infos_ptr);
43504382 }
4351-
43524383 m_EndFileColorIconStyle (_showColor, _font);
43534384 }
43544385 }
0 commit comments