diff --git a/ImGuiFileDialog.cpp b/ImGuiFileDialog.cpp index ae2ca83..e1f9e9f 100644 --- a/ImGuiFileDialog.cpp +++ b/ImGuiFileDialog.cpp @@ -4105,7 +4105,22 @@ bool IGFD::FileDialog::m_DrawFooter() { return res; } -void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr vInfos, bool vSelected, const char* vFmt, ...) { +bool IGFD::FileDialog::m_Selectable(int vRowIdx, const char* vLabel, bool vSelected, ImGuiSelectableFlags vFlags, const ImVec2& vSizeArg) { + bool res = false; +#ifdef USE_EXPLORATION_BY_KEYS + bool flashed = m_BeginFlashItem((size_t)vRowIdx); + res = m_FlashableSelectable(vLabel, vSelected, vFlags, flashed, vSizeArg); + if (flashed) { + m_EndFlashItem(); + } +#else // USE_EXPLORATION_BY_KEYS + (void)vRowIdx; // remove a warnings for unused var + res = ImGui::Selectable(vLabel, vSelected, vFlags, vSizeArg); +#endif // USE_EXPLORATION_BY_KEYS + return res; +} + +void IGFD::FileDialog::m_SelectableItem(int vRowIdx, std::shared_ptr vInfos, bool vSelected, const char* vFmt, ...) { if (!vInfos.use_count()) return; auto& fdi = m_FileDialogInternal.fileManager; @@ -4123,18 +4138,7 @@ void IGFD::FileDialog::m_SelectableItem(int vidx, std::shared_ptr vIn h = DisplayMode_ThumbailsList_ImageHeight; } #endif // USE_THUMBNAILS -#ifdef USE_EXPLORATION_BY_KEYS - bool flashed = m_BeginFlashItem((size_t)vidx); - bool res = m_FlashableSelectable(fdi.variadicBuffer, vSelected, selectableFlags, flashed, ImVec2(-1.0f, h)); - if (flashed) { - m_EndFlashItem(); - } -#else // USE_EXPLORATION_BY_KEYS - (void)vidx; // remove a warnings for unused var - - bool res = ImGui::Selectable(fdi.variadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h)); -#endif // USE_EXPLORATION_BY_KEYS - if (res) { + if (m_Selectable(vRowIdx, fdi.variadicBuffer, vSelected, selectableFlags, ImVec2(-1.0f, h))) { if (vInfos->fileType.isDir()) { // nav system, selectable cause open directory or select directory if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) { @@ -4203,6 +4207,10 @@ void IGFD::FileDialog::m_EndFileColorIconStyle(const bool vShowColor, ImFont* vF if (vShowColor) ImGui::PopStyleColor(); } +void IGFD::FileDialog::m_drawColumnText(int /*vColIdx*/, const char* vLabel, bool /*vSelected*/, bool /*vHovered*/) { + ImGui::Text("%s", vLabel); +} + void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) { auto& fdi = m_FileDialogInternal.fileManager; @@ -4310,6 +4318,7 @@ void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) { bool _showColor = false; int column_id = 0; + bool _rowHovered = false; m_FileListClipper.Begin((int)fdi.GetFilteredListSize(), ImGui::GetTextLineHeightWithSpacing()); while (m_FileListClipper.Step()) { for (int i = m_FileListClipper.DisplayStart; i < m_FileListClipper.DisplayEnd; i++) { @@ -4325,30 +4334,31 @@ void IGFD::FileDialog::m_DrawFileListView(ImVec2 vSize) { ImGui::TableNextRow(); column_id = 0; + _rowHovered = false; if (ImGui::TableNextColumn()) { // file name if (!infos_ptr->deviceInfos.empty()) { _str += " " + infos_ptr->deviceInfos; } m_SelectableItem(i, infos_ptr, selected, _str.c_str()); + _rowHovered = ImGui::IsItemHovered(); m_DisplayFileInfosTooltip(i, column_id++, infos_ptr); } if (ImGui::TableNextColumn()) { // file type - ImGui::Text("%s", infos_ptr->fileExtLevels[0].c_str()); + m_drawColumnText(column_id, infos_ptr->fileExtLevels[0].c_str(), selected, _rowHovered); m_DisplayFileInfosTooltip(i, column_id++, infos_ptr); } if (ImGui::TableNextColumn()) { // file size if (!infos_ptr->fileType.isDir()) { - ImGui::Text("%s ", infos_ptr->formatedFileSize.c_str()); + m_drawColumnText(column_id, infos_ptr->formatedFileSize.c_str(), selected, _rowHovered); } else { ImGui::TextUnformatted(""); } m_DisplayFileInfosTooltip(i, column_id++, infos_ptr); } if (ImGui::TableNextColumn()) { // file date + time - ImGui::Text("%s", infos_ptr->fileModifDate.c_str()); + m_drawColumnText(column_id, infos_ptr->fileModifDate.c_str(), selected, _rowHovered); m_DisplayFileInfosTooltip(i, column_id++, infos_ptr); } - m_EndFileColorIconStyle(_showColor, _font); } } diff --git a/ImGuiFileDialog.h b/ImGuiFileDialog.h index be63842..a8f4ca9 100644 --- a/ImGuiFileDialog.h +++ b/ImGuiFileDialog.h @@ -313,6 +313,7 @@ class IGFD_API FileInfos; class IGFD_API FileDialogInternal; class IGFD_API Utils { + friend class TestUtils; public: struct PathStruct { std::string path; @@ -339,11 +340,7 @@ class IGFD_API Utils { static std::string FormatFileSize(size_t vByteSize); // format file size field static bool NaturalCompare(const std::string& vA, const std::string& vB, bool vInsensitiveCase, bool vDescending); // natural sorting -#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS -public: -#else private: -#endif static bool M_IsAValidCharExt(const char& c); static bool M_IsAValidCharSuffix(const char& c); static bool M_ExtractNumFromStringAtPos(const std::string& str, size_t& pos, double& vOutNum); @@ -403,11 +400,8 @@ class IGFD_API FilterInfos { }; class IGFD_API FilterManager { -#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS -public: -#else + friend class TestFilterManager; private: -#endif std::vector m_ParsedFilters; std::unordered_map > > m_FilesStyle; // file infos for file // extention only @@ -535,6 +529,7 @@ class IFileSystem { }; class IGFD_API FileManager { + friend class TestFileManager; public: // types enum class SortingFieldEnum { // sorting for filetering of the file lsit FIELD_NONE = 0, // no sorting reference, result indetermined haha.. @@ -545,11 +540,7 @@ class IGFD_API FileManager { FIELD_THUMBNAILS, // sorted by thumbnails (comparaison by width then by height) }; -#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS -public: -#else private: -#endif std::string m_CurrentPath; // current path (to be decomposed in m_CurrentPathDecomposition std::vector m_CurrentPathDecomposition; // part words std::vector > m_FileList; // base container @@ -593,11 +584,7 @@ class IGFD_API FileManager { std::string fsRoot; -#ifdef NEED_TO_BE_PUBLIC_FOR_TESTS -public: -#else private: -#endif static void m_CompleteFileInfos(const std::shared_ptr& vInfos); // set time and date infos of a file (detail view mode) void m_RemoveFileNameInSelection(const std::string& vFileName); // selection : remove a file name void m_AddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName); // selection : add a file name @@ -993,8 +980,9 @@ class IGFD_API FileDialog : public PlacesFeature, public KeyExplorerFeature, pub virtual bool m_DrawOkButton(); // draw ok button virtual bool m_DrawCancelButton(); // draw cancel button virtual void m_DrawSidePane(float vHeight); // draw side pane - virtual void m_SelectableItem(int vidx, std::shared_ptr vInfos, bool vSelected, const char* vFmt, - ...); // draw a custom selectable behavior item + virtual bool m_Selectable(int vRowIdx, const char* vLabel, bool vSelected, ImGuiSelectableFlags vFlags, const ImVec2& vSizeArg); + virtual void m_SelectableItem(int vRowIdx, std::shared_ptr vInfos, bool vSelected, const char* vFmt, ...); // draw a custom selectable behavior item + virtual void m_drawColumnText(int vColIdx, const char* vLabel, bool vSelected, bool vHovered); virtual void m_DrawFileListView(ImVec2 vSize); // draw file list view (default mode) #ifdef USE_THUMBNAILS