Skip to content

Commit d7d6677

Browse files
committed
[IMP] : improvement of directory mode
* dirNameString changed to "Directory Path" * set selected directory to "." when changing of directory * GetCurrentPath will return path with current selected directory if in directory mode * GetCurrentFileName will return nothing if in directory mode * "." (current) directory is shown only in directory mode [RFR] : change func names and comment for better relation to what they do [IMP] : improvement, virtual funcs was in private, now in protected. make more sense :)
1 parent db30bbc commit d7d6677

3 files changed

Lines changed: 64 additions & 36 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace IGFD
126126
#define fileNameString "File Name :"
127127
#endif // fileNameString
128128
#ifndef dirNameString
129-
#define dirNameString "Directory Name :"
129+
#define dirNameString "Directory Path :"
130130
#endif // dirNameString
131131
#ifndef buttonResetSearchString
132132
#define buttonResetSearchString "Reset search"
@@ -902,7 +902,7 @@ namespace IGFD
902902
!m_Filters.empty()) // filter exist
903903
m_SelectedFilter = *m_Filters.begin(); // we take the first filter
904904

905-
// init list of files
905+
// init list of files
906906
if (m_FileList.empty() && !m_ShowDrives)
907907
{
908908
replaceString(dlg_defaultFileName, dlg_path, ""); // local path
@@ -911,6 +911,8 @@ namespace IGFD
911911
SetDefaultFileName(dlg_defaultFileName);
912912
SetSelectedFilterWithExt(dlg_defaultExt);
913913
}
914+
else if (dlg_filters.empty()) // directory mode
915+
SetDefaultFileName(".");
914916
ScanDir(dlg_path);
915917
}
916918

@@ -1397,9 +1399,9 @@ namespace IGFD
13971399
{
13981400
if (vInfos.type == 'd')
13991401
{
1400-
if (ImGui::IsMouseDoubleClicked(0))
1402+
if (ImGui::IsMouseDoubleClicked(0)) // 0 -> left mouse button double click
14011403
{
1402-
m_PathClicked = SelectDirectory(vInfos);
1404+
m_PathClicked = SelectDirectory(vInfos);
14031405
}
14041406
else if (dlg_filters.empty()) // directory chooser
14051407
{
@@ -1475,40 +1477,59 @@ namespace IGFD
14751477

14761478
std::string IGFD::FileDialog::GetFilePathName()
14771479
{
1478-
std::string result = m_CurrentPath;
1480+
std::string result = GetCurrentPath();
14791481

1482+
std::string filename = GetCurrentFileName();
1483+
if (!filename.empty())
1484+
{
14801485
#ifdef UNIX
1481-
if (s_fs_root != result)
1486+
if (s_fs_root != result)
14821487
#endif // UNIX
1483-
result += PATH_SEP;
1488+
result += PATH_SEP;
14841489

1485-
result += GetCurrentFileName();
1490+
result += filename;
1491+
}
14861492

14871493
return result;
14881494
}
14891495

14901496
std::string IGFD::FileDialog::GetCurrentPath()
14911497
{
1492-
return m_CurrentPath;
1498+
std::string path = m_CurrentPath;
1499+
1500+
if (dlg_filters.empty()) // if directory mode
1501+
{
1502+
std::string selectedDirectory = FileNameBuffer;
1503+
if (!selectedDirectory.empty() &&
1504+
selectedDirectory != ".")
1505+
path += PATH_SEP + selectedDirectory;
1506+
}
1507+
1508+
return path;
14931509
}
14941510

14951511
std::string IGFD::FileDialog::GetCurrentFileName()
14961512
{
1497-
std::string result = FileNameBuffer;
1498-
1499-
// if not a collection we can replace the filter by thee extention we want
1500-
if (m_SelectedFilter.collectionfilters.empty())
1513+
if (!dlg_filters.empty()) // if not directory mode
15011514
{
1502-
size_t lastPoint = result.find_last_of('.');
1503-
if (lastPoint != std::string::npos)
1515+
std::string result = FileNameBuffer;
1516+
1517+
// if not a collection we can replace the filter by the extention we want
1518+
if (m_SelectedFilter.collectionfilters.empty())
15041519
{
1505-
result = result.substr(0, lastPoint);
1520+
size_t lastPoint = result.find_last_of('.');
1521+
if (lastPoint != std::string::npos)
1522+
{
1523+
result = result.substr(0, lastPoint);
1524+
}
1525+
1526+
result += m_SelectedFilter.filter;
15061527
}
15071528

1508-
result += m_SelectedFilter.filter;
1529+
return result;
15091530
}
15101531

1511-
return result;
1532+
return ""; // directory mode
15121533
}
15131534

15141535
std::string IGFD::FileDialog::GetCurrentFilter()
@@ -1532,7 +1553,7 @@ namespace IGFD
15321553

15331554
for (auto& it : m_SelectedFileNames)
15341555
{
1535-
std::string result = m_CurrentPath;
1556+
std::string result = GetCurrentPath();
15361557

15371558
#ifdef UNIX
15381559
if (s_fs_root != result)
@@ -1774,6 +1795,8 @@ namespace IGFD
17741795
m_CurrentPath = vPath;
17751796
m_FileList.clear();
17761797
m_CurrentPath_Decomposition.clear();
1798+
if (dlg_filters.empty()) // directory mode
1799+
SetDefaultFileName(".");
17771800
ScanDir(m_CurrentPath);
17781801
}
17791802

@@ -1805,9 +1828,11 @@ namespace IGFD
18051828
}
18061829
}
18071830

1808-
void IGFD::FileDialog::FillInfos(FileInfoStruct* vFileInfoStruct)
1831+
void IGFD::FileDialog::CompleteFileInfos(FileInfoStruct* vFileInfoStruct)
18091832
{
1810-
if (vFileInfoStruct && vFileInfoStruct->fileName != "..")
1833+
if (vFileInfoStruct &&
1834+
vFileInfoStruct->fileName != "." &&
1835+
vFileInfoStruct->fileName != "..")
18111836
{
18121837
// _stat struct :
18131838
//dev_t st_dev; /* ID of device containing file */
@@ -2004,7 +2029,8 @@ namespace IGFD
20042029
infos.fileName = ent->d_name;
20052030
infos.fileName_optimized = OptimizeFilenameForSearchOperations(infos.fileName);
20062031

2007-
if (("." != infos.fileName))
2032+
if (infos.fileName != "."
2033+
|| dlg_filters.empty()) // in directory mode we must display the curent dir "."
20082034
{
20092035
switch (ent->d_type)
20102036
{
@@ -2028,7 +2054,7 @@ namespace IGFD
20282054
if (!dlg_filters.empty())
20292055
{
20302056
// check if current file extention is covered by current filter
2031-
// we do that here, for avoid doing taht during filelist display
2057+
// we do that here, for avoid doing that during filelist display
20322058
// for better fps
20332059
if (!m_SelectedFilter.empty() && // selected filter exist
20342060
(!m_SelectedFilter.filterExist(infos.ext) && // filter not found
@@ -2039,7 +2065,7 @@ namespace IGFD
20392065
}
20402066
}
20412067

2042-
FillInfos(&infos);
2068+
CompleteFileInfos(&infos);
20432069
m_FileList.push_back(infos);
20442070
}
20452071
}

ImGuiFileDialog.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,14 @@ namespace IGFD
802802
#endif // USE_BOOKMARK
803803

804804
///////////////////////////////////////////////////////////////////////////////////////
805-
/// PRIVATE METHODS ///////////////////////////////////////////////////////////////////
805+
/// PROTECTED'S METHODS ///////////////////////////////////////////////////////////////
806806
///////////////////////////////////////////////////////////////////////////////////////
807807

808-
private:
808+
protected:
809809
// dialog parts
810-
virtual void DrawHeader(); // draw header part of the dialog (bookmark btn, dir creation, path composer, search bar)
811-
virtual void DrawContent(); // draw content part of the dialog (bookmark pane, file list, side pane)
812-
virtual bool DrawFooter(); // draw footer part of the dialog (file field, fitler combobox, ok/cancel btn's)
810+
virtual void DrawHeader(); // draw header part of the dialog (bookmark btn, dir creation, path composer, search bar)
811+
virtual void DrawContent(); // draw content part of the dialog (bookmark pane, file list, side pane)
812+
virtual bool DrawFooter(); // draw footer part of the dialog (file field, fitler combobox, ok/cancel btn's)
813813

814814
// widgets components
815815
virtual void DrawDirectoryCreation(); // draw directory creation widget
@@ -820,19 +820,20 @@ namespace IGFD
820820
#ifdef USE_BOOKMARK
821821
virtual void DrawBookMark(); // draw bookmark button
822822
#endif // USE_BOOKMARK
823+
823824
// others
824825
bool SelectableItem(int vidx, const FileInfoStruct& vInfos, bool vSelected, const char* vFmt, ...); // selectable item for table
825826
void ResetEvents(); // reset events (path, drives, continue)
826-
void SetDefaultFileName(const std::string& vFileName); // set default fiel name
827+
void SetDefaultFileName(const std::string& vFileName); // set default file name
827828
bool SelectDirectory(const FileInfoStruct& vInfos); // enter directory
828829
void SelectFileName(const FileInfoStruct& vInfos); // select filename
829830
void RemoveFileNameInSelection(const std::string& vFileName); // selection : remove a file name
830-
void AddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName); // selection add file name
831-
void SetPath(const std::string& vPath); // set the path of the dialog, will launch the driectory scan for populate the file listview
832-
void FillInfos(FileInfoStruct *vFileInfoStruct); // set time dand date infos of a file (detail view mode)
831+
void AddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName); // selection : add a file name
832+
void SetPath(const std::string& vPath); // set the path of the dialog, will launch the directory scan for populate the file listview
833+
void CompleteFileInfos(FileInfoStruct *vFileInfoStruct); // set time and date infos of a file (detail view mode)
833834
void SortFields(SortingFieldEnum vSortingField = SortingFieldEnum::FIELD_NONE, bool vCanChangeOrder = false); // will sort a column
834-
void ScanDir(const std::string& vPath); // scan the directory for retriev the file list
835-
void SetCurrentDir(const std::string& vPath); // define current directory
835+
void ScanDir(const std::string& vPath); // scan the directory for retrieve the file list
836+
void SetCurrentDir(const std::string& vPath); // define current directory for scan
836837
bool CreateDir(const std::string& vPath); // create a directory on the file system
837838
std::string ComposeNewPath(std::vector<std::string>::iterator vIter); // compose a path from the compose path widget
838839
void GetDrives(); // list drives on windows platform

ImGuiFileDialogConfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
//#define linkEntryString "[LINK] "
3737
//#define fileEntryString "[FILE] "
3838
//#define fileNameString "File Name : "
39+
//#define dirNameString "Directory Path :"
3940
//#define buttonResetSearchString "Reset search"
4041
//#define buttonDriveString "Drives"
4142
//#define buttonResetPathString "Reset to current directory"
@@ -57,7 +58,7 @@
5758
//#define tableHeaderDescendingIcon "D|"
5859
//#define tableHeaderFileNameString " File name"
5960
//#define tableHeaderFileSizeString " Size"
60-
//#define tableHeaderFileDateString " Date"
61+
//#define tableHeaderFileDateTimeString " Date"
6162

6263
#define USE_BOOKMARK
6364
//#define bookmarkPaneWith 150.0f

0 commit comments

Comments
 (0)