@@ -81,7 +81,7 @@ namespace igfd
8181 // for lets you define your button widget
8282 // if you have like me a special bi-color button
8383 #ifndef IMGUI_PATH_BUTTON
84- #define IMGUI_PATH_BUTTON ImGui::Button
84+ #define IMGUI_PATH_BUTTON ImGui::Button
8585 #endif
8686 #ifndef IMGUI_BUTTON
8787 #define IMGUI_BUTTON ImGui::Button
@@ -149,9 +149,25 @@ namespace igfd
149149 #define tableHeaderFileDateString " Date"
150150 #endif
151151
152- #ifndef IGFD_KEY_ENTER
153- #define IGFD_KEY_ENTER GLFW_KEY_ENTER
152+ #ifndef IGFD_INPUT_PATH_VALIDATION
153+ #define IGFD_INPUT_PATH_VALIDATION GLFW_KEY_ENTER
154154 #endif
155+ #ifndef IGFD_INPUT_PATH_ESCAPE
156+ #define IGFD_INPUT_PATH_ESCAPE GLFW_KEY_ESCAPE
157+ #endif
158+
159+ #ifndef IGFD_KEY_UP
160+ #define IGFD_KEY_UP GLFW_KEY_UP
161+ #endif
162+ #ifndef IGFD_KEY_DOWN
163+ #define IGFD_KEY_DOWN GLFW_KEY_DOWN
164+ #endif
165+ #ifndef IGFD_KEY_ENTER
166+ #define IGFD_KEY_ENTER GLFW_KEY_ENTER
167+ #endif
168+ #ifndef IGFD_KEY_BACKSPACE
169+ #define IGFD_KEY_BACKSPACE GLFW_KEY_BACKSPACE
170+ #endif
155171
156172#ifdef USE_BOOKMARK
157173 #ifndef bookmarkPaneWith
@@ -389,6 +405,13 @@ namespace igfd
389405 vBuffer[0 ] = ' \0 ' ;
390406 }
391407
408+ inline void SetBuffer (char * vBuffer, size_t vBufferLen, const std::string& vStr)
409+ {
410+ ResetBuffer (vBuffer);
411+ AppendToBuffer (vBuffer, vBufferLen, vStr);
412+ }
413+
414+ char ImGuiFileDialog::InputPathBuffer[MAX_PATH_BUFFER_SIZE] = " " ;
392415 char ImGuiFileDialog::FileNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = " " ;
393416 char ImGuiFileDialog::DirectoryNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = " " ;
394417 char ImGuiFileDialog::SearchBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = " " ;
@@ -564,7 +587,7 @@ namespace igfd
564587 dlg_filters = vFilters;
565588 ParseFilters (dlg_filters);
566589 dlg_path = vPath;
567- dlg_defaultFileName = vDefaultFileName;
590+ SetDefaultFileName ( vDefaultFileName) ;
568591 dlg_optionsPane = std::move (vOptionsPane);
569592 dlg_userDatas = vUserDatas;
570593 dlg_optionsPaneWidth = vOptionsPaneWidth;
@@ -598,13 +621,13 @@ namespace igfd
598621 if (ps.isOk )
599622 {
600623 dlg_path = ps.path ;
601- dlg_defaultFileName = vFilePathName;
624+ SetDefaultFileName ( vFilePathName) ;
602625 dlg_defaultExt = " ." + ps.ext ;
603626 }
604627 else
605628 {
606- dlg_path = " ." ;
607- dlg_defaultFileName. clear ( );
629+ dlg_path = " ." ;
630+ SetDefaultFileName ( " " );
608631 dlg_defaultExt.clear ();
609632 }
610633
@@ -638,13 +661,13 @@ namespace igfd
638661 if (ps.isOk )
639662 {
640663 dlg_path = ps.path ;
641- dlg_defaultFileName = vFilePathName;
664+ SetDefaultFileName ( vFilePathName) ;
642665 dlg_defaultExt = " ." + ps.ext ;
643666 }
644667 else
645668 {
646669 dlg_path = " ." ;
647- dlg_defaultFileName. clear ( );
670+ SetDefaultFileName ( " " );
648671 dlg_defaultExt.clear ();
649672 }
650673
@@ -674,7 +697,7 @@ namespace igfd
674697 dlg_filters = vFilters;
675698 ParseFilters (dlg_filters);
676699 dlg_path = vPath;
677- dlg_defaultFileName = vDefaultFileName;
700+ SetDefaultFileName ( vDefaultFileName) ;
678701 dlg_optionsPane = nullptr ;
679702 dlg_userDatas = vUserDatas;
680703 dlg_optionsPaneWidth = 0 ;
@@ -802,8 +825,7 @@ namespace igfd
802825
803826 if (!dlg_defaultFileName.empty ())
804827 {
805- ResetBuffer (FileNameBuffer);
806- AppendToBuffer (FileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, dlg_defaultFileName);
828+ SetDefaultFileName (dlg_defaultFileName);
807829 SetSelectedFilterWithExt (dlg_defaultExt);
808830 }
809831
@@ -898,13 +920,13 @@ namespace igfd
898920 if (m_InputPathActivated)
899921 {
900922 ImGui::PushItemWidth (ImGui::GetContentRegionAvail ().x );
901- ImGui::InputText (" ##path " , m_InputPathBuffer, 1023 );
923+ ImGui::InputText (" ##pathedition " , InputPathBuffer, MAX_PATH_BUFFER_SIZE );
902924 ImGui::PopItemWidth ();
903925 }
904926 else
905927 {
906- int _id = 0 ;
907- for (auto itPathDecomp = m_CurrentPath_Decomposition.begin ();
928+ int _id = 0 ;
929+ for (auto itPathDecomp = m_CurrentPath_Decomposition.begin ();
908930 itPathDecomp != m_CurrentPath_Decomposition.end (); ++itPathDecomp)
909931 {
910932 if (itPathDecomp != m_CurrentPath_Decomposition.begin ())
@@ -914,15 +936,16 @@ namespace igfd
914936 ImGui::PopID ();
915937 if (click)
916938 {
917- ComposeNewPath (itPathDecomp);
939+ m_CurrentPath = ComposeNewPath (itPathDecomp);
918940 pathClick = true ;
919941 break ;
920942 }
921943 // activate input for path
922944 if (ImGui::IsItemClicked (ImGuiMouseButton_Right))
923945 {
924- m_InputPathActivated = true ;
925- break ;
946+ SetBuffer (InputPathBuffer, MAX_PATH_BUFFER_SIZE, ComposeNewPath (itPathDecomp));
947+ m_InputPathActivated = true ;
948+ break ;
926949 }
927950 }
928951 }
@@ -940,8 +963,7 @@ namespace igfd
940963 ImGui::SameLine ();
941964 ImGui::Text (searchString);
942965 ImGui::SameLine ();
943- float aw = ImGui::GetContentRegionAvail ().x ;
944- ImGui::PushItemWidth (aw);
966+ ImGui::PushItemWidth (ImGui::GetContentRegionAvail ().x );
945967 bool edited = ImGui::InputText (" ##ImGuiFileDialogSearchFiled" , SearchBuffer, MAX_FILE_DIALOG_NAME_BUFFER);
946968 ImGui::PopItemWidth ();
947969 if (edited)
@@ -1105,11 +1127,15 @@ namespace igfd
11051127
11061128 if (m_InputPathActivated)
11071129 {
1108- if (ImGui::IsKeyReleased (IGFD_KEY_ENTER ))
1130+ if (ImGui::IsKeyReleased (IGFD_INPUT_PATH_VALIDATION ))
11091131 {
1110- SetPath (std::string (m_InputPathBuffer ));
1132+ SetPath (std::string (InputPathBuffer ));
11111133 m_InputPathActivated = false ;
11121134 }
1135+ if (ImGui::IsKeyReleased (IGFD_INPUT_PATH_ESCAPE))
1136+ {
1137+ m_InputPathActivated = false ;
1138+ }
11131139 }
11141140#ifdef USE_EXPLORATION_BY_KEYS
11151141 else
@@ -1345,6 +1371,12 @@ namespace igfd
13451371 m_FileExtentionInfos.clear ();
13461372 }
13471373
1374+ void ImGuiFileDialog::SetDefaultFileName (const std::string& vFileName)
1375+ {
1376+ dlg_defaultFileName = vFileName;
1377+ SetBuffer (FileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, vFileName);
1378+ }
1379+
13481380 bool ImGuiFileDialog::SelectDirectory (const FileInfoStruct& vInfos)
13491381 {
13501382 bool pathClick = false ;
@@ -1353,7 +1385,7 @@ namespace igfd
13531385 {
13541386 if (m_CurrentPath_Decomposition.size () > 1 )
13551387 {
1356- ComposeNewPath (m_CurrentPath_Decomposition.end () - 2 );
1388+ m_CurrentPath = ComposeNewPath (m_CurrentPath_Decomposition.end () - 2 );
13571389 pathClick = true ;
13581390 }
13591391 }
@@ -1846,8 +1878,7 @@ namespace igfd
18461878 {
18471879 m_CurrentPath = m_CurrentPath.substr (0 , m_CurrentPath.size () - 1 );
18481880 }
1849- ResetBuffer (m_InputPathBuffer);
1850- AppendToBuffer (m_InputPathBuffer, 1023 , m_CurrentPath);
1881+ SetBuffer (InputPathBuffer, MAX_PATH_BUFFER_SIZE, m_CurrentPath);
18511882 m_CurrentPath_Decomposition = splitStringToVector (m_CurrentPath, PATH_SEP, false );
18521883#if defined(UNIX) // UNIX is LINUX or APPLE
18531884 m_CurrentPath_Decomposition.insert (m_CurrentPath_Decomposition.begin (), std::string (1u , PATH_SEP));
@@ -1878,16 +1909,16 @@ namespace igfd
18781909 return res;
18791910 }
18801911
1881- void ImGuiFileDialog::ComposeNewPath (std::vector<std::string>::iterator vIter)
1912+ std::string ImGuiFileDialog::ComposeNewPath (std::vector<std::string>::iterator vIter)
18821913 {
1883- m_CurrentPath. clear () ;
1914+ std::string res ;
18841915
18851916 while (true )
18861917 {
1887- if (!m_CurrentPath .empty ())
1918+ if (!res .empty ())
18881919 {
18891920#ifdef WIN32
1890- m_CurrentPath = *vIter + PATH_SEP + m_CurrentPath ;
1921+ res = *vIter + PATH_SEP + res ;
18911922#elif defined(UNIX) // UNIX is LINUX or APPLE
18921923 if (*vIter == s_fs_root)
18931924 {
@@ -1901,7 +1932,7 @@ namespace igfd
19011932 }
19021933 else
19031934 {
1904- m_CurrentPath = *vIter;
1935+ res = *vIter;
19051936 }
19061937
19071938 if (vIter == m_CurrentPath_Decomposition.begin ())
@@ -1915,6 +1946,8 @@ namespace igfd
19151946
19161947 --vIter;
19171948 }
1949+
1950+ return res;
19181951 }
19191952
19201953 void ImGuiFileDialog::GetDrives ()
0 commit comments