GUI: fix IGFD glitch when opening empty dir

This commit is contained in:
tildearrow 2023-03-24 00:52:11 -05:00
parent caa2a71d39
commit 6f8cfa42ea
2 changed files with 35 additions and 7 deletions

View File

@ -26,6 +26,7 @@ SOFTWARE.
*/
#include "ImGuiFileDialog.h"
#include "../../src/ta-log.h"
#ifdef __cplusplus
@ -1202,11 +1203,13 @@ namespace IGFD
SetDefaultFileName(".");
else
SetDefaultFileName("");
logV("IGFD: OpenCurrentPath()");
ScanDir(vFileDialogInternal, GetCurrentPath());
}
void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal, const SortingFieldEnum& vSortingField, const bool vCanChangeOrder)
{
logV("IGFD: SortFields()");
if (vSortingField != SortingFieldEnum::FIELD_NONE)
{
puHeaderFileName = tableHeaderFileNameString;
@ -1216,10 +1219,17 @@ namespace IGFD
#ifdef USE_THUMBNAILS
puHeaderFileThumbnails = tableHeaderFileThumbnailsString;
#endif // #ifdef USE_THUMBNAILS
}
} else {
logV("IGFD: sorting by NONE!");
}
if (prFileList.empty()) {
logV("IGFD: with an empty file list?");
}
if (vSortingField == SortingFieldEnum::FIELD_FILENAME)
{
logV("IGFD: sorting by name");
if (vCanChangeOrder && puSortingField == vSortingField) {
//printf("Change the sorting\n");
puSortingDirection[0] = true;//!puSortingDirection[0];
@ -1289,6 +1299,7 @@ namespace IGFD
}
else if (vSortingField == SortingFieldEnum::FIELD_TYPE)
{
logV("IGFD: sorting by type");
if (vCanChangeOrder && puSortingField == vSortingField)
puSortingDirection[1] = !puSortingDirection[1];
@ -1327,6 +1338,7 @@ namespace IGFD
}
else if (vSortingField == SortingFieldEnum::FIELD_SIZE)
{
logV("IGFD: sorting by size");
if (vCanChangeOrder && puSortingField == vSortingField)
puSortingDirection[2] = !puSortingDirection[2];
@ -1367,6 +1379,7 @@ namespace IGFD
}
else if (vSortingField == SortingFieldEnum::FIELD_DATE)
{
logV("IGFD: sorting by date");
if (vCanChangeOrder && puSortingField == vSortingField)
puSortingDirection[3] = !puSortingDirection[3];
@ -1458,6 +1471,8 @@ namespace IGFD
puSortingField = vSortingField;
}
logV("IGFD: applying filtering on file list");
ApplyFilteringOnFileList(vFileDialogInternal);
}
@ -1518,14 +1533,17 @@ namespace IGFD
void IGFD::FileManager::ScanDir(const FileDialogInternal& vFileDialogInternal, const std::string& vPath)
{
std::string path = vPath;
logV("IGFD: ScanDir(%s)",vPath);
if (prCurrentPathDecomposition.empty())
{
logV("IGFD: the current path decomposition is empty. setting.");
SetCurrentDir(path);
}
if (!prCurrentPathDecomposition.empty())
{
logV("IGFD: the current path decomposition is not empty. trying.");
#ifdef WIN32
if (path == puFsRoot)
path += std::string(1u, PATH_SEP);
@ -1553,6 +1571,7 @@ namespace IGFD
#else // dirent
struct dirent** files = nullptr;
int n = scandir(path.c_str(), &files, nullptr, inAlphaSort);
logV("IGFD: %d entries in directory",n);
if (n>0)
{
int i;
@ -1620,11 +1639,18 @@ namespace IGFD
}
free(files);
}
} else {
logV("IGFD: it's empty");
}
#endif // USE_STD_FILESYSTEM
logV("IGFD: sorting fields...");
SortFields(vFileDialogInternal, puSortingField, false);
}
} else {
logE("IGFD: current path decomposition is empty!");
}
fileListActuallyEmpty=prFileList.empty();
}
bool IGFD::FileManager::GetDrives()
@ -2436,7 +2462,7 @@ namespace IGFD
void IGFD::FileDialogInternal::ResetForNewDialog()
{
puFileManager.fileListActuallyEmpty=false;
}
/////////////////////////////////////////////////////////////////////////////////////
@ -3737,16 +3763,17 @@ namespace IGFD
fdFilter.SetDefaultFilterIfNotDefined();
// init list of files
if (fdFile.IsFileListEmpty() && !fdFile.puShowDrives)
if (fdFile.IsFileListEmpty() && !fdFile.puShowDrives && !fdFile.fileListActuallyEmpty)
{
IGFD::Utils::ReplaceString(fdFile.puDLGDefaultFileName, fdFile.puDLGpath, ""); // local path
if (!fdFile.puDLGDefaultFileName.empty())
{
fdFile.SetDefaultFileName(fdFile.puDLGDefaultFileName);
fdFilter.SetSelectedFilterWithExt(fdFilter.puDLGdefaultExt);
}
else if (fdFile.puDLGDirectoryMode) // directory mode
} else if (fdFile.puDLGDirectoryMode) { // directory mode
fdFile.SetDefaultFileName(".");
}
logV("IGFD: fdFile.IsFileListEmpty() and !fdFile.puShowDrives");
fdFile.ScanDir(prFileDialogInternal, fdFile.puDLGpath);
}

View File

@ -875,6 +875,7 @@ namespace IGFD
#endif
SortingFieldEnum puSortingField = SortingFieldEnum::FIELD_FILENAME; // detail view sorting column
bool puShowDrives = false; // drives are shown (only on os windows)
bool fileListActuallyEmpty = false;
std::string puDLGpath; // base path set by user when OpenDialog/OpenModal was called
std::string puDLGDefaultFileName; // base default file path name set by user when OpenDialog/OpenModal was called