@@ -81,7 +81,7 @@ namespace igfd
81
81
// for lets you define your button widget
82
82
// if you have like me a special bi-color button
83
83
#ifndef IMGUI_PATH_BUTTON
84
- #define IMGUI_PATH_BUTTON ImGui::Button
84
+ #define IMGUI_PATH_BUTTON ImGui::Button
85
85
#endif
86
86
#ifndef IMGUI_BUTTON
87
87
#define IMGUI_BUTTON ImGui::Button
@@ -149,9 +149,25 @@ namespace igfd
149
149
#define tableHeaderFileDateString " Date"
150
150
#endif
151
151
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
154
154
#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
155
171
156
172
#ifdef USE_BOOKMARK
157
173
#ifndef bookmarkPaneWith
@@ -389,6 +405,13 @@ namespace igfd
389
405
vBuffer[0 ] = ' \0 ' ;
390
406
}
391
407
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] = " " ;
392
415
char ImGuiFileDialog::FileNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = " " ;
393
416
char ImGuiFileDialog::DirectoryNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = " " ;
394
417
char ImGuiFileDialog::SearchBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = " " ;
@@ -564,7 +587,7 @@ namespace igfd
564
587
dlg_filters = vFilters;
565
588
ParseFilters (dlg_filters);
566
589
dlg_path = vPath;
567
- dlg_defaultFileName = vDefaultFileName;
590
+ SetDefaultFileName ( vDefaultFileName) ;
568
591
dlg_optionsPane = std::move (vOptionsPane);
569
592
dlg_userDatas = vUserDatas;
570
593
dlg_optionsPaneWidth = vOptionsPaneWidth;
@@ -598,13 +621,13 @@ namespace igfd
598
621
if (ps.isOk )
599
622
{
600
623
dlg_path = ps.path ;
601
- dlg_defaultFileName = vFilePathName;
624
+ SetDefaultFileName ( vFilePathName) ;
602
625
dlg_defaultExt = " ." + ps.ext ;
603
626
}
604
627
else
605
628
{
606
- dlg_path = " ." ;
607
- dlg_defaultFileName. clear ( );
629
+ dlg_path = " ." ;
630
+ SetDefaultFileName ( " " );
608
631
dlg_defaultExt.clear ();
609
632
}
610
633
@@ -638,13 +661,13 @@ namespace igfd
638
661
if (ps.isOk )
639
662
{
640
663
dlg_path = ps.path ;
641
- dlg_defaultFileName = vFilePathName;
664
+ SetDefaultFileName ( vFilePathName) ;
642
665
dlg_defaultExt = " ." + ps.ext ;
643
666
}
644
667
else
645
668
{
646
669
dlg_path = " ." ;
647
- dlg_defaultFileName. clear ( );
670
+ SetDefaultFileName ( " " );
648
671
dlg_defaultExt.clear ();
649
672
}
650
673
@@ -674,7 +697,7 @@ namespace igfd
674
697
dlg_filters = vFilters;
675
698
ParseFilters (dlg_filters);
676
699
dlg_path = vPath;
677
- dlg_defaultFileName = vDefaultFileName;
700
+ SetDefaultFileName ( vDefaultFileName) ;
678
701
dlg_optionsPane = nullptr ;
679
702
dlg_userDatas = vUserDatas;
680
703
dlg_optionsPaneWidth = 0 ;
@@ -802,8 +825,7 @@ namespace igfd
802
825
803
826
if (!dlg_defaultFileName.empty ())
804
827
{
805
- ResetBuffer (FileNameBuffer);
806
- AppendToBuffer (FileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, dlg_defaultFileName);
828
+ SetDefaultFileName (dlg_defaultFileName);
807
829
SetSelectedFilterWithExt (dlg_defaultExt);
808
830
}
809
831
@@ -898,13 +920,13 @@ namespace igfd
898
920
if (m_InputPathActivated)
899
921
{
900
922
ImGui::PushItemWidth (ImGui::GetContentRegionAvail ().x );
901
- ImGui::InputText (" ##path " , m_InputPathBuffer, 1023 );
923
+ ImGui::InputText (" ##pathedition " , InputPathBuffer, MAX_PATH_BUFFER_SIZE );
902
924
ImGui::PopItemWidth ();
903
925
}
904
926
else
905
927
{
906
- int _id = 0 ;
907
- for (auto itPathDecomp = m_CurrentPath_Decomposition.begin ();
928
+ int _id = 0 ;
929
+ for (auto itPathDecomp = m_CurrentPath_Decomposition.begin ();
908
930
itPathDecomp != m_CurrentPath_Decomposition.end (); ++itPathDecomp)
909
931
{
910
932
if (itPathDecomp != m_CurrentPath_Decomposition.begin ())
@@ -914,15 +936,16 @@ namespace igfd
914
936
ImGui::PopID ();
915
937
if (click)
916
938
{
917
- ComposeNewPath (itPathDecomp);
939
+ m_CurrentPath = ComposeNewPath (itPathDecomp);
918
940
pathClick = true ;
919
941
break ;
920
942
}
921
943
// activate input for path
922
944
if (ImGui::IsItemClicked (ImGuiMouseButton_Right))
923
945
{
924
- m_InputPathActivated = true ;
925
- break ;
946
+ SetBuffer (InputPathBuffer, MAX_PATH_BUFFER_SIZE, ComposeNewPath (itPathDecomp));
947
+ m_InputPathActivated = true ;
948
+ break ;
926
949
}
927
950
}
928
951
}
@@ -940,8 +963,7 @@ namespace igfd
940
963
ImGui::SameLine ();
941
964
ImGui::Text (searchString);
942
965
ImGui::SameLine ();
943
- float aw = ImGui::GetContentRegionAvail ().x ;
944
- ImGui::PushItemWidth (aw);
966
+ ImGui::PushItemWidth (ImGui::GetContentRegionAvail ().x );
945
967
bool edited = ImGui::InputText (" ##ImGuiFileDialogSearchFiled" , SearchBuffer, MAX_FILE_DIALOG_NAME_BUFFER);
946
968
ImGui::PopItemWidth ();
947
969
if (edited)
@@ -1105,11 +1127,15 @@ namespace igfd
1105
1127
1106
1128
if (m_InputPathActivated)
1107
1129
{
1108
- if (ImGui::IsKeyReleased (IGFD_KEY_ENTER ))
1130
+ if (ImGui::IsKeyReleased (IGFD_INPUT_PATH_VALIDATION ))
1109
1131
{
1110
- SetPath (std::string (m_InputPathBuffer ));
1132
+ SetPath (std::string (InputPathBuffer ));
1111
1133
m_InputPathActivated = false ;
1112
1134
}
1135
+ if (ImGui::IsKeyReleased (IGFD_INPUT_PATH_ESCAPE))
1136
+ {
1137
+ m_InputPathActivated = false ;
1138
+ }
1113
1139
}
1114
1140
#ifdef USE_EXPLORATION_BY_KEYS
1115
1141
else
@@ -1345,6 +1371,12 @@ namespace igfd
1345
1371
m_FileExtentionInfos.clear ();
1346
1372
}
1347
1373
1374
+ void ImGuiFileDialog::SetDefaultFileName (const std::string& vFileName)
1375
+ {
1376
+ dlg_defaultFileName = vFileName;
1377
+ SetBuffer (FileNameBuffer, MAX_FILE_DIALOG_NAME_BUFFER, vFileName);
1378
+ }
1379
+
1348
1380
bool ImGuiFileDialog::SelectDirectory (const FileInfoStruct& vInfos)
1349
1381
{
1350
1382
bool pathClick = false ;
@@ -1353,7 +1385,7 @@ namespace igfd
1353
1385
{
1354
1386
if (m_CurrentPath_Decomposition.size () > 1 )
1355
1387
{
1356
- ComposeNewPath (m_CurrentPath_Decomposition.end () - 2 );
1388
+ m_CurrentPath = ComposeNewPath (m_CurrentPath_Decomposition.end () - 2 );
1357
1389
pathClick = true ;
1358
1390
}
1359
1391
}
@@ -1846,8 +1878,7 @@ namespace igfd
1846
1878
{
1847
1879
m_CurrentPath = m_CurrentPath.substr (0 , m_CurrentPath.size () - 1 );
1848
1880
}
1849
- ResetBuffer (m_InputPathBuffer);
1850
- AppendToBuffer (m_InputPathBuffer, 1023 , m_CurrentPath);
1881
+ SetBuffer (InputPathBuffer, MAX_PATH_BUFFER_SIZE, m_CurrentPath);
1851
1882
m_CurrentPath_Decomposition = splitStringToVector (m_CurrentPath, PATH_SEP, false );
1852
1883
#if defined(UNIX) // UNIX is LINUX or APPLE
1853
1884
m_CurrentPath_Decomposition.insert (m_CurrentPath_Decomposition.begin (), std::string (1u , PATH_SEP));
@@ -1878,16 +1909,16 @@ namespace igfd
1878
1909
return res;
1879
1910
}
1880
1911
1881
- void ImGuiFileDialog::ComposeNewPath (std::vector<std::string>::iterator vIter)
1912
+ std::string ImGuiFileDialog::ComposeNewPath (std::vector<std::string>::iterator vIter)
1882
1913
{
1883
- m_CurrentPath. clear () ;
1914
+ std::string res ;
1884
1915
1885
1916
while (true )
1886
1917
{
1887
- if (!m_CurrentPath .empty ())
1918
+ if (!res .empty ())
1888
1919
{
1889
1920
#ifdef WIN32
1890
- m_CurrentPath = *vIter + PATH_SEP + m_CurrentPath ;
1921
+ res = *vIter + PATH_SEP + res ;
1891
1922
#elif defined(UNIX) // UNIX is LINUX or APPLE
1892
1923
if (*vIter == s_fs_root)
1893
1924
{
@@ -1901,7 +1932,7 @@ namespace igfd
1901
1932
}
1902
1933
else
1903
1934
{
1904
- m_CurrentPath = *vIter;
1935
+ res = *vIter;
1905
1936
}
1906
1937
1907
1938
if (vIter == m_CurrentPath_Decomposition.begin ())
@@ -1915,6 +1946,8 @@ namespace igfd
1915
1946
1916
1947
--vIter;
1917
1948
}
1949
+
1950
+ return res;
1918
1951
}
1919
1952
1920
1953
void ImGuiFileDialog::GetDrives ()
0 commit comments