ImGuiFileDialog.h 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  1. /*
  2. MIT License
  3. Copyright (c) 2018-2022 Stephane Cuillerdier (aka aiekick)
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. /*
  21. -----------------------------------------------------------------------------------------------------------------
  22. -----------------------------------------------------------------------------------------------------------------
  23. github repo : https://github.com/aiekick/ImGuiFileDialog
  24. this section is the content of the ReadMe.md file
  25. # ImGuiFileDialog
  26. ## Purpose
  27. ImGuiFileDialog is a file selection dialog built for (and using only) [Dear ImGui](https://github.com/ocornut/imgui).
  28. My primary goal was to have a custom pane with widgets according to file extension. This was not possible using other
  29. solutions.
  30. ## ImGui Supported Version
  31. ImGuiFileDialog follow the master and docking branch of ImGui . currently ImGui 1.88 WIP
  32. ## Structure
  33. * The library is in [Lib_Only branch](https://github.com/aiekick/ImGuiFileDialog/tree/Lib_Only)
  34. * A demo app can be found the [master branch](https://github.com/aiekick/ImGuiFileDialog/tree/master)
  35. This library is designed to be dropped into your source code rather than compiled separately.
  36. From your project directory:
  37. ```
  38. mkdir lib <or 3rdparty, or externals, etc.>
  39. cd lib
  40. git clone https://github.com/aiekick/ImGuiFileDialog.git
  41. git checkout Lib_Only
  42. ```
  43. These commands create a `lib` directory where you can store any third-party dependencies used in your project, downloads
  44. the ImGuiFileDialog git repository and checks out the Lib_Only branch where the actual library code is located.
  45. Add `lib/ImGuiFileDialog/ImGuiFileDialog.cpp` to your build system and include
  46. `lib/ImGuiFileDialog/ImGuiFileDialog.h` in your source code. ImGuiFileLib will compile with and be included directly in
  47. your executable file.
  48. If, for example, your project uses cmake, look for a line like `add_executable(my_project_name main.cpp)`
  49. and change it to `add_executable(my_project_name lib/ImGuiFileDialog/ImGuiFileDialog.cpp main.cpp)`. This tells the
  50. compiler where to find the source code declared in `ImGuiFileDialog.h` which you included in your own source code.
  51. ## Requirements:
  52. You must also, of course, have added [Dear ImGui](https://github.com/ocornut/imgui) to your project for this to work at
  53. all.
  54. [dirent v1.23](https://github.com/tronkko/dirent/tree/v1.23) is required to use ImGuiFileDialog under Windows. It is
  55. included in the Lib_Only branch for your convenience.
  56. ## Features
  57. - Separate system for call and display
  58. - Can have many function calls with different parameters for one display function, for example
  59. - Can create a custom pane with any widgets via function binding
  60. - This pane can block the validation of the dialog
  61. - Can also display different things according to current filter and UserDatas
  62. - Advanced file style for file/dir/link coloring / icons / font
  63. - Multi-selection (ctrl/shift + click) :
  64. - 0 => Infinite
  65. - 1 => One file (default)
  66. - n => n files
  67. - Compatible with MacOs, Linux, Windows
  68. - Windows version can list drives
  69. - Supports modal or standard dialog types
  70. - Select files or directories
  71. - Filter groups and custom filter names
  72. - can ignore filter Case for file searching
  73. - Keyboard navigation (arrows, backspace, enter)
  74. - Exploring by entering characters (case insensitive)
  75. - Directory bookmarks
  76. - Directory manual entry (right click on any path element)
  77. - Optional 'Confirm to Overwrite" dialog if file exists
  78. - C Api (succesfully tested with CimGui)
  79. - Thumbnails Display (agnostic way for compatibility with any backend, sucessfully tested with OpenGl and Vulkan)
  80. - The dialog can be embedded in another user frame than the standard or modal dialog
  81. - Can tune validation buttons (placements, widths, inversion)
  82. - Can quick select a parrallel directory of a path, in the path composer (when you clikc on a / you have a popup)
  83. - regex support for filters, collection of fitler and filestyle (the regex is recognized when between ( and ) in a filter
  84. ## Singleton Pattern vs. Multiple Instances
  85. ### Single Dialog :
  86. If you only need to display one file dialog at a time, use ImGuiFileDialog's singleton pattern to avoid explicitly
  87. declaring an object:
  88. ```cpp
  89. ImGuiFileDialog::Instance()->method_of_your_choice();
  90. ```
  91. ### Multiple Dialogs :
  92. If you need to have multiple file dialogs open at once, declare each dialog explicity:
  93. ```cpp
  94. ImGuiFileDialog instance_a;
  95. instance_a.method_of_your_choice();
  96. ImGuiFileDialog instance_b;
  97. instance_b.method_of_your_choice();
  98. ```
  99. ## Simple Dialog :
  100. ```cpp
  101. void drawGui()
  102. {
  103. // open Dialog Simple
  104. if (ImGui::Button("Open File Dialog"))
  105. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp", ".");
  106. // display
  107. if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey"))
  108. {
  109. // action if OK
  110. if (ImGuiFileDialog::Instance()->IsOk())
  111. {
  112. std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
  113. std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
  114. // action
  115. }
  116. // close
  117. ImGuiFileDialog::Instance()->Close();
  118. }
  119. }
  120. ```
  121. ![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/dlg_simple.gif)
  122. ## Modal dialog :
  123. you have now a flag for open modal dialog :
  124. ```cpp
  125. ImGuiFileDialogFlags_Modal
  126. ```
  127. you can use it like that :
  128. ```cpp
  129. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp",
  130. ".", 1, nullptr, ImGuiFileDialogFlags_Modal);
  131. ```
  132. ## Directory Chooser :
  133. To have a directory chooser, set the file extension filter to nullptr:
  134. ```cpp
  135. ImGuiFileDialog::Instance()->OpenDialog("ChooseDirDlgKey", "Choose a Directory", nullptr, ".");
  136. ```
  137. In this mode you can select any directory with one click and open a directory with a double-click.
  138. ![directoryChooser](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/directoryChooser.gif)
  139. ## Dialog with Custom Pane :
  140. The signature of the custom pane callback is:
  141. ### for C++ :
  142. ```cpp
  143. void(const char *vFilter, IGFDUserDatas vUserDatas, bool *vCantContinue)
  144. ```
  145. ### for C :
  146. ```c
  147. void(const char *vFilter, void* vUserDatas, bool *vCantContinue)
  148. ```
  149. ### Example :
  150. ```cpp
  151. static bool canValidateDialog = false;
  152. inline void InfosPane(cosnt char *vFilter, IGFDUserDatas vUserDatas, bool *vCantContinue) // if vCantContinue is false, the user cant validate the dialog
  153. {
  154. ImGui::TextColored(ImVec4(0, 1, 1, 1), "Infos Pane");
  155. ImGui::Text("Selected Filter : %s", vFilter.c_str());
  156. if (vUserDatas)
  157. ImGui::Text("UserDatas : %s", vUserDatas);
  158. ImGui::Checkbox("if not checked you cant validate the dialog", &canValidateDialog);
  159. if (vCantContinue)
  160. *vCantContinue = canValidateDialog;
  161. }
  162. void drawGui()
  163. {
  164. // open Dialog with Pane
  165. if (ImGui::Button("Open File Dialog with a custom pane"))
  166. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".cpp,.h,.hpp",
  167. ".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1, UserDatas("InfosPane"));
  168. // display and action if ok
  169. if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey"))
  170. {
  171. if (ImGuiFileDialog::Instance()->IsOk())
  172. {
  173. std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
  174. std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
  175. std::string filter = ImGuiFileDialog::Instance()->GetCurrentFilter();
  176. // here convert from string because a string was passed as a userDatas, but it can be what you want
  177. std::string userDatas;
  178. if (ImGuiFileDialog::Instance()->GetUserDatas())
  179. userDatas = std::string((const char*)ImGuiFileDialog::Instance()->GetUserDatas());
  180. auto selection = ImGuiFileDialog::Instance()->GetSelection(); // multiselection
  181. // action
  182. }
  183. // close
  184. ImGuiFileDialog::Instance()->Close();
  185. }
  186. }
  187. ```
  188. ![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/doc/dlg_with_pane.gif)
  189. ## File Style : Custom icons and colors by extension
  190. You can define style for files/dirs/links in many ways :
  191. the style can be colors, icons and fonts
  192. the general form is :
  193. ```cpp
  194. ImGuiFileDialog::Instance()->SetFileStyle(styleType, criteria, color, icon, font);
  195. styleType can be thoses :
  196. IGFD_FileStyleByTypeFile // define style for all files
  197. IGFD_FileStyleByTypeDir // define style for all dir
  198. IGFD_FileStyleByTypeLink // define style for all link
  199. IGFD_FileStyleByExtention // define style by extention, for files or links
  200. IGFD_FileStyleByFullName // define style for particular file/dir/link full name (filename + extention)
  201. IGFD_FileStyleByContainedInFullName // define style for file/dir/link when criteria is contained in full name
  202. ```
  203. ImGuiFileDialog accepts icon font macros as well as text tags for file types.
  204. [ImGuIFontStudio](https://github.com/aiekick/ImGuiFontStudio) is useful here. I wrote it to make it easy to create
  205. custom icon sets for use with Dear ImGui.
  206. It is inspired by [IconFontCppHeaders](https://github.com/juliettef/IconFontCppHeaders), which can also be used with
  207. ImGuiFileDialog.
  208. samples :
  209. ```cpp
  210. // define style by file extention and Add an icon for .png files
  211. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".png", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC, font1);
  212. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".gif", ImVec4(0.0f, 1.0f, 0.5f, 0.9f), "[GIF]");
  213. // define style for all directories
  214. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER);
  215. // can be for a specific directory
  216. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER);
  217. // define style for all files
  218. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FILE);
  219. // can be for a specific file
  220. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, ".git", ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FILE);
  221. // define style for all links
  222. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeLink, "", ImVec4(0.5f, 1.0f, 0.9f, 0.9f));
  223. // can be for a specific link
  224. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeLink, "Readme.md", ImVec4(0.5f, 1.0f, 0.9f, 0.9f));
  225. // define style for any files/dirs/links by fullname
  226. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "doc", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_FILE_PIC);
  227. // define style by file who are containing this string
  228. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK);
  229. all of theses can be miwed with IGFD_FileStyleByTypeDir / IGFD_FileStyleByTypeFile / IGFD_FileStyleByTypeLink
  230. like theses by ex :
  231. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir | IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK);
  232. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile | IGFD_FileStyleByFullName, "cmake", ImVec4(0.5f, 0.8f, 0.5f, 0.9f), ICON_IGFD_SAVE);
  233. // for all these,s you can use a regex
  234. // ex for color files like Custom*.h
  235. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "(Custom.+[.]h)", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC, font1);
  236. ```
  237. this sample code of [master/main.cpp](https://github.com/aiekick/ImGuiFileDialog/blob/master/main.cpp) produce the picture above :
  238. ```cpp
  239. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".cpp", ImVec4(1.0f, 1.0f, 0.0f, 0.9f));
  240. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".h", ImVec4(0.0f, 1.0f, 0.0f, 0.9f));
  241. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".hpp", ImVec4(0.0f, 0.0f, 1.0f, 0.9f));
  242. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".md", ImVec4(1.0f, 0.0f, 1.0f, 0.9f));
  243. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".png", ImVec4(0.0f, 1.0f, 1.0f, 0.9f), ICON_IGFD_FILE_PIC); // add an icon for the filter type
  244. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtention, ".gif", ImVec4(0.0f, 1.0f, 0.5f, 0.9f), "[GIF]"); // add an text for a filter type
  245. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir, nullptr, ImVec4(0.5f, 1.0f, 0.9f, 0.9f), ICON_IGFD_FOLDER); // for all dirs
  246. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile, "CMakeLists.txt", ImVec4(0.1f, 0.5f, 0.5f, 0.9f), ICON_IGFD_ADD);
  247. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByFullName, "doc", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_FILE_PIC);
  248. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeDir | IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.9f, 0.2f, 0.0f, 0.9f), ICON_IGFD_BOOKMARK);
  249. ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByTypeFile | IGFD_FileStyleByContainedInFullName, ".git", ImVec4(0.5f, 0.8f, 0.5f, 0.9f), ICON_IGFD_SAVE);
  250. ```
  251. ![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/color_filter.png)
  252. ## Filter Collections
  253. You can define a custom filter name that corresponds to a group of filters using this syntax:
  254. ```custom_name1{filter1,filter2,filter3},custom_name2{filter1,filter2},filter1```
  255. When you select custom_name1, filters 1 to 3 will be applied. The characters `{` and `}` are reserved. Don't use them
  256. for filter names.
  257. this code :
  258. ```cpp
  259. const char *filters = "Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp},Image files (*.png *.gif *.jpg *.jpeg){.png,.gif,.jpg,.jpeg},.md";
  260. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", ICON_IMFDLG_FOLDER_OPEN " Choose a File", filters, ".");
  261. ```
  262. will produce :
  263. ![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/collectionFilters.gif)
  264. ## Multi Selection
  265. You can define in OpenDialog call the count file you want to select :
  266. - 0 => infinite
  267. - 1 => one file only (default)
  268. - n => n files only
  269. See the define at the end of these funcs after path.
  270. ```cpp
  271. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".*,.cpp,.h,.hpp", ".");
  272. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 1 File", ".*,.cpp,.h,.hpp", ".", 1);
  273. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose 5 File", ".*,.cpp,.h,.hpp", ".", 5);
  274. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose many File", ".*,.cpp,.h,.hpp", ".", 0);
  275. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey", "Choose File", ".png,.jpg",
  276. ".", "", std::bind(&InfosPane, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), 350, 1, "SaveFile"); // 1 file
  277. ```
  278. ![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/multiSelection.gif)
  279. ## File Dialog Constraints
  280. You can set the minimum and/or maximum size of the dialog:
  281. ```cpp
  282. ImVec2 maxSize = ImVec2((float)display_w, (float)display_h); // The full display area
  283. ImVec2 minSize = maxSize * 0.5f; // Half the display area
  284. ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey", ImGuiWindowFlags_NoCollapse, minSize, maxSize);
  285. ```
  286. ![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/dialog_constraints.gif)
  287. ## Exploring by keys
  288. You can activate this feature by uncommenting `#define USE_EXPLORATION_BY_KEYS`
  289. in your custom config file (CustomImGuiFileDialogConfig.h)
  290. You can also uncomment the next lines to define navigation keys:
  291. * IGFD_KEY_UP => Up key for explore to the top
  292. * IGFD_KEY_DOWN => Down key for explore to the bottom
  293. * IGFD_KEY_ENTER => Enter key for open directory
  294. * IGFD_KEY_BACKSPACE => BackSpace for comming back to the last directory
  295. You can also jump to a point in the file list by pressing the corresponding key of the first filename character.
  296. ![alt text](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/explore_ny_keys.gif)
  297. As you see the current item is flashed by default for 1 second. You can define the flashing lifetime with the function
  298. ```cpp
  299. ImGuiFileDialog::Instance()->SetFlashingAttenuationInSeconds(1.0f);
  300. ```
  301. ## Bookmarks
  302. You can create/edit/call path bookmarks and load/save them.
  303. Activate this feature by uncommenting: `#define USE_BOOKMARK` in your custom config file (CustomImGuiFileDialogConfig.h)
  304. More customization options:
  305. ```cpp
  306. #define bookmarkPaneWith 150.0f => width of the bookmark pane
  307. #define IMGUI_TOGGLE_BUTTON ToggleButton => customize the Toggled button (button stamp must be : (const char* label, bool *toggle)
  308. #define bookmarksButtonString "Bookmark" => the text in the toggle button
  309. #define bookmarksButtonHelpString "Bookmark" => the helper text when mouse over the button
  310. #define addBookmarkButtonString "+" => the button for add a bookmark
  311. #define removeBookmarkButtonString "-" => the button for remove the selected bookmark
  312. ```
  313. * You can select each bookmark to edit the displayed name corresponding to a path
  314. * Double-click on the label to apply the bookmark
  315. ![bookmarks.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/bookmarks.gif)
  316. You can also serialize/deserialize bookmarks (for example to load/save from/to a file):
  317. ```cpp
  318. Load => ImGuiFileDialog::Instance()->DeserializeBookmarks(bookmarString);
  319. Save => std::string bookmarkString = ImGuiFileDialog::Instance()->SerializeBookmarks();
  320. ```
  321. (please see example code for details)
  322. you can also add/remove bookmark by code :
  323. and in this case, you can also avoid serialization of code based bookmark
  324. ```cpp
  325. Add => ImGuiFileDialog::Instance()->AddBookmark(bookmark_name, bookmark_path);
  326. Remove => ImGuiFileDialog::Instance()->RemoveBookmark(bookmark_name);
  327. Save => std::string bookmarkString = ImGuiFileDialog::Instance()->SerializeBookmarks(true); // true for prevent serialization of code based bookmarks
  328. ```
  329. ## Path Edition :
  330. Right clicking on any path element button allows the user to manually edit the path from that portion of the tree.
  331. Pressing the completion key (GLFW uses `enter` by default) validates the new path. Pressing the cancel key (GLFW
  332. uses`escape` by default) cancels the manual entry and restores the original path.
  333. Here's the manual entry operation in action:
  334. ![inputPathEdition.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/inputPathEdition.gif)
  335. ## Confirm Overwrite Dialog :
  336. If you want avoid overwriting files after selection, ImGuiFileDialog can show a dialog to confirm or cancel the
  337. operation.
  338. To do so, define the flag ImGuiFileDialogFlags_ConfirmOverwrite in your call to OpenDialog.
  339. By default this flag is not set since there is no pre-defined way to define if a dialog will be for Open or Save
  340. behavior. (by design! :) )
  341. Example code For Standard Dialog :
  342. ```cpp
  343. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey",
  344. ICON_IGFD_SAVE " Choose a File", filters,
  345. ".", "", 1, nullptr, ImGuiFileDialogFlags_ConfirmOverwrite);
  346. ```
  347. Example code For Modal Dialog :
  348. ```cpp
  349. ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey",
  350. ICON_IGFD_SAVE " Choose a File", filters,
  351. ".", "", 1, nullptr, ImGuiFileDialogFlags_Modal | ImGuiFileDialogFlags_ConfirmOverwrite);
  352. ```
  353. This dialog will only verify the file in the file field, not with `GetSelection()`.
  354. The confirmation dialog will be a non-movable modal (input blocking) dialog displayed in the middle of the current
  355. ImGuiFileDialog window.
  356. As usual, you can customize the dialog in your custom config file (CustomImGuiFileDialogConfig.h in this example)
  357. Uncomment these line for customization options:
  358. ```cpp
  359. //#define OverWriteDialogTitleString "The file Already Exist !"
  360. //#define OverWriteDialogMessageString "Would you like to OverWrite it ?"
  361. //#define OverWriteDialogConfirmButtonString "Confirm"
  362. //#define OverWriteDialogCancelButtonString "Cancel"
  363. ```
  364. See the result :
  365. ![ConfirmToOverWrite.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/ConfirmToOverWrite.gif)
  366. ## Open / Save dialog Behavior :
  367. ImGuiFileDialog uses the same code internally for Open and Save dialogs. To distinguish between them access the various
  368. data return functions depending on what the dialog is doing.
  369. When selecting an existing file (for example, a Load or Open dialog), use
  370. ```cpp
  371. std::map<std::string, std::string> GetSelection(); // Returns selection via a map<FileName, FilePathName>
  372. UserDatas GetUserDatas(); // Get user data provided by the Open dialog
  373. ```
  374. To selecting a new file (for example, a Save As... dialog), use:
  375. ```cpp
  376. std::string GetFilePathName(); // Returns the content of the selection field with current file extension and current path
  377. std::string GetCurrentFileName(); // Returns the content of the selection field with current file extension but no path
  378. std::string GetCurrentPath(); // Returns current path only
  379. std::string GetCurrentFilter(); // The file extension
  380. ```
  381. ## Thumbnails Display
  382. You can now, display thumbnails of pictures.
  383. ![thumbnails.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/thumbnails.gif)
  384. The file resize use stb/image so the following files extentions are supported :
  385. * .png (tested sucessfully)
  386. * .bmp (tested sucessfully)
  387. * .tga (tested sucessfully)
  388. * .jpg (tested sucessfully)
  389. * .jpeg (tested sucessfully)
  390. * .gif (tested sucessfully_ but not animation just first frame)
  391. * .psd (not tested)
  392. * .pic (not tested)
  393. * .ppm (not tested)
  394. * .pgm (not tested)
  395. Corresponding to your backend (ex : OpenGl) you need to define two callbacks :
  396. * the first is a callback who will be called by ImGuiFileDialog for create the backend texture
  397. * the second is a callback who will be called by ImGuiFileDialog for destroy the backend texture
  398. After that you need to call the function who is responsible to create / destroy the textures.
  399. this function must be called in your GPU Rendering zone for avoid destroying of used texture.
  400. if you do that at the same place of your imgui code, some backend can crash your app, by ex with vulkan.
  401. To Clarify :
  402. This feature is spliited in two zones :
  403. - CPU Zone : for load/destroy picture file
  404. - GPU Zone : for load/destroy gpu textures.
  405. This modern behavior for avoid destroying of used texture,
  406. was needed for vulkan.
  407. This feature was Successfully tested on my side with Opengl and Vulkan.
  408. But im sure is perfectly compatible with other modern apis like DirectX and Metal
  409. ex, for opengl :
  410. ```cpp
  411. // Create thumbnails texture
  412. ImGuiFileDialog::Instance()->SetCreateThumbnailCallback([](IGFD_Thumbnail_Info *vThumbnail_Info) -> void
  413. {
  414. if (vThumbnail_Info &&
  415. vThumbnail_Info->isReadyToUpload &&
  416. vThumbnail_Info->textureFileDatas)
  417. {
  418. GLuint textureId = 0;
  419. glGenTextures(1, &textureId);
  420. vThumbnail_Info->textureID = (void*)textureId;
  421. glBindTexture(GL_TEXTURE_2D, textureId);
  422. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  423. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  424. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  425. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  426. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
  427. (GLsizei)vThumbnail_Info->textureWidth, (GLsizei)vThumbnail_Info->textureHeight,
  428. 0, GL_RGBA, GL_UNSIGNED_BYTE, vThumbnail_Info->textureFileDatas);
  429. glFinish();
  430. glBindTexture(GL_TEXTURE_2D, 0);
  431. delete[] vThumbnail_Info->textureFileDatas;
  432. vThumbnail_Info->textureFileDatas = nullptr;
  433. vThumbnail_Info->isReadyToUpload = false;
  434. vThumbnail_Info->isReadyToDisplay = true;
  435. }
  436. });
  437. ```
  438. ```cpp
  439. // Destroy thumbnails texture
  440. ImGuiFileDialog::Instance()->SetDestroyThumbnailCallback([](IGFD_Thumbnail_Info* vThumbnail_Info)
  441. {
  442. if (vThumbnail_Info)
  443. {
  444. GLuint texID = (GLuint)vThumbnail_Info->textureID;
  445. glDeleteTextures(1, &texID);
  446. glFinish();
  447. }
  448. });
  449. ```
  450. ```cpp
  451. // GPU Rendering Zone // To call for Create/ Destroy Textures
  452. ImGuiFileDialog::Instance()->ManageGPUThumbnails();
  453. ```
  454. ## Embedded in other frames :
  455. The dialog can be embedded in another user frame than the standard or modal dialog
  456. You have to create a variable of type ImGuiFileDialog. (if you are suing the singleton, you will not have the possibility to open other dialog)
  457. ex :
  458. ```cpp
  459. ImGuiFileDialog fileDialog;
  460. // open dialog; in this case, Bookmark, directory creation are disabled with, and also the file input field is readonly.
  461. // btw you can od what you want
  462. fileDialog.OpenDialog("embedded", "Select File", ".*", "", -1, nullptr,
  463. ImGuiFileDialogFlags_NoDialog |
  464. ImGuiFileDialogFlags_DisableBookmarkMode |
  465. ImGuiFileDialogFlags_DisableCreateDirectoryButton |
  466. ImGuiFileDialogFlags_ReadOnlyFileNameField);
  467. // then display, here
  468. // to note, when embedded the ImVec2(0,0) (MinSize) do nothing, only the ImVec2(0,350) (MaxSize) can size the dialog frame
  469. fileDialog.Display("embedded", ImGuiWindowFlags_NoCollapse, ImVec2(0,0), ImVec2(0,350)))
  470. ```
  471. the result :
  472. ![Embedded.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/Embedded.gif)
  473. ## Quick Parallel Path Selection in Path Composer
  474. you have a separator between two directories in the path composer
  475. when you click on it you can explore a list of parrallels directories of this point
  476. this feature is disabled by default
  477. you can enable it with the compiler flag : #define USE_QUICK_PATH_SELECT
  478. you can also customize the spacing between path button's with and without this mode
  479. you can do that by define the compiler flag : #define CUSTOM_PATH_SPACING 2
  480. if undefined the spacing is defined by the imgui theme
  481. ![quick_composer_path_select.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/quick_composer_path_select.gif)
  482. ## Case Insensitive Filtering
  483. you can use this flag 'ImGuiFileDialogFlags_CaseInsensitiveExtention' when you call the display function
  484. ```
  485. by ex :
  486. if the flag ImGuiFileDialogFlags_CaseInsensitiveExtention is used
  487. with filters like .jpg or .Jpg or .JPG
  488. all files with extentions by ex : .jpg and .JPG will be displayed
  489. ```
  490. ## Tune the validations button group
  491. You can specify :
  492. - the width of "ok" and "cancel" buttons, by the set the defines "okButtonWidth" and "cancelButtonWidth"
  493. - the alignement of the button group (left, right, middle, etc..) by set the define "okCancelButtonAlignement"
  494. - if you want to have the ok button on the left and cancel button on the right or inverted by set the define "invertOkAndCancelButtons"
  495. just see theses defines in the config file
  496. ```cpp
  497. //Validation buttons
  498. //#define okButtonString " OK"
  499. //#define okButtonWidth 0.0f
  500. //#define cancelButtonString " Cancel"
  501. //#define cancelButtonWidth 0.0f
  502. //alignement [0:1], 0.0 is left, 0.5 middle, 1.0 right, and other ratios
  503. //#define okCancelButtonAlignement 0.0f
  504. //#define invertOkAndCancelButtons false
  505. ```
  506. with Alignement 0.0 => left
  507. ![alignement_0.0.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/alignement_0.0.png)
  508. with Alignement 1.0 => right
  509. ![alignement_1.0.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/alignement_1.0.png)
  510. with Alignement 0.5 => middle
  511. ![alignement_0.5.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/alignement_0.5.png)
  512. ok and cancel buttons inverted (cancel on the left and ok on the right)
  513. ![validation_buttons_inverted.gif](https://github.com/aiekick/ImGuiFileDialog/blob/master/doc/validation_buttons_inverted.png)
  514. ## Filtering by a regex :
  515. you can use a regex for filtering and file coloring
  516. for have a filter recognized as a regex, you must have it between a ( and a )
  517. this one will filter files who start by the word "Common" and finish by ".h"
  518. ```cpp
  519. ex : "(Custom.+[.]h)"
  520. ```
  521. use cases :
  522. * Simple filter :
  523. ```cpp
  524. OpenDialog("toto", "Choose File", "(Custom.+[.]h)");
  525. ```
  526. * Collections filter :
  527. for this one the filter is between "{" and "}", so you can use the "(" and ")" outside
  528. ```cpp
  529. OpenDialog("toto", "Choose File", "Source files (*.cpp *.h *.hpp){(Custom.+[.]h),.h,.hpp}");
  530. ```
  531. * file coloring :
  532. this one will colorized all files who start by the word "Common" and finish by ".h"
  533. ```cpp
  534. SetFileStyle(IGFD_FileStyleByFullName, "(Custom.+[.]h)", ImVec4(1.0f, 1.0f, 0.0f, 0.9f));
  535. ```
  536. * with this feature you can by ex filter and colorize render frame pictures who have ext like .000, .001, .002, etc..
  537. ```cpp
  538. OpenDialog("toto", "Choose File", "([.][0-9]{3})");
  539. SetFileStyle(IGFD_FileStyleByFullName, "([.][0-9]{3})", ImVec4(1.0f, 1.0f, 0.0f, 0.9f));
  540. ```
  541. ## How to Integrate ImGuiFileDialog in your project
  542. ### Customize ImGuiFileDialog :
  543. You can customize many aspects of ImGuiFileDialog by overriding `ImGuiFileDialogConfig.h`.
  544. To enable your customizations, define the preprocessor directive CUSTOM_IMGUIFILEDIALOG_CONFIG with the path of your
  545. custom config file. This path must be relative to the directory where you put the ImGuiFileDialog module.
  546. This operation is demonstrated in `CustomImGuiFileDialog.h` in the example project to:
  547. * Have a custom icon font instead of labels for buttons or message titles
  548. * Customize the button text (the button call signature must be the same, by the way! :)
  549. The custom icon font used in the example code ([CustomFont.cpp](CustomFont.cpp) and [CustomFont.h](CustomFont.h)) was made
  550. with [ImGuiFontStudio](https://github.com/aiekick/ImGuiFontStudio), which I wrote. :)
  551. ImGuiFontStudio uses ImGuiFileDialog! Check it out.
  552. ## Api's C/C++ :
  553. ### the C Api
  554. this api was sucessfully tested with CImGui
  555. A C API is available let you include ImGuiFileDialog in your C project.
  556. btw, ImGuiFileDialog depend of ImGui and dirent (for windows)
  557. Sample code with cimgui :
  558. ```cpp
  559. // create ImGuiFileDialog
  560. ImGuiFileDialog *cfileDialog = IGFD_Create();
  561. // open dialog
  562. if (igButton("Open File", buttonSize))
  563. {
  564. IGFD_OpenDialog(cfiledialog,
  565. "filedlg", // dialog key (make it possible to have different treatment reagrding the dialog key
  566. "Open a File", // dialog title
  567. "c files(*.c *.h){.c,.h}", // dialog filter syntax : simple => .h,.c,.pp, etc and collections : text1{filter0,filter1,filter2}, text2{filter0,filter1,filter2}, etc..
  568. ".", // base directory for files scan
  569. "", // base filename
  570. 0, // a fucntion for display a right pane if you want
  571. 0.0f, // base width of the pane
  572. 0, // count selection : 0 infinite, 1 one file (default), n (n files)
  573. "User data !", // some user datas
  574. ImGuiFileDialogFlags_ConfirmOverwrite); // ImGuiFileDialogFlags
  575. }
  576. ImGuiIO* ioptr = igGetIO();
  577. ImVec2 maxSize;
  578. maxSize.x = ioptr->DisplaySize.x * 0.8f;
  579. maxSize.y = ioptr->DisplaySize.y * 0.8f;
  580. ImVec2 minSize;
  581. minSize.x = maxSize.x * 0.25f;
  582. minSize.y = maxSize.y * 0.25f;
  583. // display dialog
  584. if (IGFD_DisplayDialog(cfiledialog, "filedlg", ImGuiWindowFlags_NoCollapse, minSize, maxSize))
  585. {
  586. if (IGFD_IsOk(cfiledialog)) // result ok
  587. {
  588. char* cfilePathName = IGFD_GetFilePathName(cfiledialog);
  589. printf("GetFilePathName : %s\n", cfilePathName);
  590. char* cfilePath = IGFD_GetCurrentPath(cfiledialog);
  591. printf("GetCurrentPath : %s\n", cfilePath);
  592. char* cfilter = IGFD_GetCurrentFilter(cfiledialog);
  593. printf("GetCurrentFilter : %s\n", cfilter);
  594. // here convert from string because a string was passed as a userDatas, but it can be what you want
  595. void* cdatas = IGFD_GetUserDatas(cfiledialog);
  596. if (cdatas)
  597. printf("GetUserDatas : %s\n", (const char*)cdatas);
  598. struct IGFD_Selection csel = IGFD_GetSelection(cfiledialog); // multi selection
  599. printf("Selection :\n");
  600. for (int i = 0; i < (int)csel.count; i++)
  601. {
  602. printf("(%i) FileName %s => path %s\n", i, csel.table[i].fileName, csel.table[i].filePathName);
  603. }
  604. // action
  605. // destroy
  606. if (cfilePathName) free(cfilePathName);
  607. if (cfilePath) free(cfilePath);
  608. if (cfilter) free(cfilter);
  609. IGFD_Selection_DestroyContent(&csel);
  610. }
  611. IGFD_CloseDialog(cfiledialog);
  612. }
  613. // destroy ImGuiFileDialog
  614. IGFD_Destroy(cfiledialog);
  615. ```
  616. -----------------------------------------------------------------------------------------------------------------
  617. -----------------------------------------------------------------------------------------------------------------
  618. Thats all.
  619. You can check by example in this repo with the file CustomImGuiFileDialogConfig.h :
  620. - this trick was used for have custom icon font instead of labels for buttons or messages titles
  621. - you can also use your custom imgui button, the button call stamp must be same by the way :)
  622. The Custom Icon Font (in CustomFont.cpp and CustomFont.h) was made with ImGuiFontStudio (https://github.com/aiekick/ImGuiFontStudio) i wrote for that :)
  623. ImGuiFontStudio is using also ImGuiFileDialog.
  624. -----------------------------------------------------------------------------------------------------------------
  625. -----------------------------------------------------------------------------------------------------------------
  626. */
  627. #ifndef IMGUIFILEDIALOG_H
  628. #define IMGUIFILEDIALOG_H
  629. // compatible with 1.88 WIP
  630. #define IMGUIFILEDIALOG_VERSION "v0.6.5"
  631. #ifndef CUSTOM_IMGUIFILEDIALOG_CONFIG
  632. #include "ImGuiFileDialogConfig.h"
  633. #else // CUSTOM_IMGUIFILEDIALOG_CONFIG
  634. #include CUSTOM_IMGUIFILEDIALOG_CONFIG
  635. #endif // CUSTOM_IMGUIFILEDIALOG_CONFIG
  636. // file style enum for file display (color, icon, font)
  637. typedef int IGFD_FileStyleFlags; // -> enum IGFD_FileStyleFlags_
  638. enum IGFD_FileStyleFlags_ // by evaluation / priority order
  639. {
  640. IGFD_FileStyle_None = 0, // define none style
  641. IGFD_FileStyleByTypeFile = (1 << 0), // define style for all files
  642. IGFD_FileStyleByTypeDir = (1 << 1), // define style for all dir
  643. IGFD_FileStyleByTypeLink = (1 << 2), // define style for all link
  644. IGFD_FileStyleByExtention = (1 << 3), // define style by extention, for files or links
  645. IGFD_FileStyleByFullName = (1 << 4), // define style for particular file/dir/link full name (filename + extention)
  646. IGFD_FileStyleByContainedInFullName = (1 << 5), // define style for file/dir/link when criteria is contained in full name
  647. };
  648. typedef int ImGuiFileDialogFlags; // -> enum ImGuiFileDialogFlags_
  649. enum ImGuiFileDialogFlags_
  650. {
  651. ImGuiFileDialogFlags_None = 0, // define none default flag
  652. ImGuiFileDialogFlags_ConfirmOverwrite = (1 << 0), // show confirm to overwrite dialog
  653. ImGuiFileDialogFlags_DontShowHiddenFiles = (1 << 1), // dont show hidden file (file starting with a .)
  654. ImGuiFileDialogFlags_DisableCreateDirectoryButton = (1 << 2), // disable the create directory button
  655. ImGuiFileDialogFlags_HideColumnType = (1 << 3), // hide column file type
  656. ImGuiFileDialogFlags_HideColumnSize = (1 << 4), // hide column file size
  657. ImGuiFileDialogFlags_HideColumnDate = (1 << 5), // hide column file date
  658. ImGuiFileDialogFlags_NoDialog = (1 << 6), // let the dialog embedded in your own imgui begin / end scope
  659. ImGuiFileDialogFlags_ReadOnlyFileNameField = (1 << 7), // don't let user type in filename field for file open style dialogs
  660. ImGuiFileDialogFlags_CaseInsensitiveExtention = (1 << 8), // the file extentions treatments will not take into account the case
  661. ImGuiFileDialogFlags_Modal = (1 << 9), // modal
  662. #ifdef USE_THUMBNAILS
  663. ImGuiFileDialogFlags_DisableThumbnailMode = (1 << 10), // disable the thumbnail mode
  664. #endif // USE_THUMBNAILS
  665. #ifdef USE_BOOKMARK
  666. ImGuiFileDialogFlags_DisableBookmarkMode = (1 << 11), // disable the bookmark mode
  667. #endif // USE_BOOKMARK
  668. ImGuiFileDialogFlags_Default = ImGuiFileDialogFlags_ConfirmOverwrite
  669. };
  670. #ifdef USE_THUMBNAILS
  671. struct IGFD_Thumbnail_Info
  672. {
  673. int isReadyToDisplay = 0; // ready to be rendered, so texture created
  674. int isReadyToUpload = 0; // ready to upload to gpu
  675. int isLoadingOrLoaded = 0; // was sent to laoding or loaded
  676. int textureWidth = 0; // width of the texture to upload
  677. int textureHeight = 0; // height of the texture to upload
  678. int textureChannels = 0; // count channels of the texture to upload
  679. unsigned char* textureFileDatas = 0; // file texture datas, will be rested to null after gpu upload
  680. void* textureID = 0; // 2d texture id (void* is like ImtextureID type) (GL, DX, VK, Etc..)
  681. void* userDatas = 0; // user datas
  682. };
  683. #endif // USE_THUMBNAILS
  684. #ifdef __cplusplus
  685. #include <imgui.h>
  686. #include <cfloat>
  687. #include <utility>
  688. #include <fstream>
  689. #include <vector>
  690. #include <memory>
  691. #include <string>
  692. #include <set>
  693. #include <map>
  694. #include <unordered_map>
  695. #include <functional>
  696. #include <string>
  697. #include <vector>
  698. #include <list>
  699. #include <thread>
  700. #include <mutex>
  701. #include <regex>
  702. namespace IGFD
  703. {
  704. #ifndef defaultSortField
  705. #define defaultSortField FIELD_FILENAME
  706. #endif // defaultSortField
  707. #ifndef defaultSortOrderFilename
  708. #define defaultSortOrderFilename true
  709. #endif // defaultSortOrderFilename
  710. #ifndef defaultSortOrderType
  711. #define defaultSortOrderType true
  712. #endif // defaultSortOrderType
  713. #ifndef defaultSortOrderSize
  714. #define defaultSortOrderSize true
  715. #endif // defaultSortOrderSize
  716. #ifndef defaultSortOrderDate
  717. #define defaultSortOrderDate true
  718. #endif // defaultSortOrderDate
  719. #ifndef defaultSortOrderThumbnails
  720. #define defaultSortOrderThumbnails true
  721. #endif // defaultSortOrderThumbnails
  722. #ifndef MAX_FILE_DIALOG_NAME_BUFFER
  723. #define MAX_FILE_DIALOG_NAME_BUFFER 1024
  724. #endif // MAX_FILE_DIALOG_NAME_BUFFER
  725. #ifndef MAX_PATH_BUFFER_SIZE
  726. #define MAX_PATH_BUFFER_SIZE 1024
  727. #endif // MAX_PATH_BUFFER_SIZE
  728. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  729. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  730. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  731. class FileDialogInternal;
  732. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  733. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  734. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  735. class SearchManager
  736. {
  737. public:
  738. std::string puSearchTag;
  739. char puSearchBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = "";
  740. bool puSearchInputIsActive = false;
  741. public:
  742. void Clear(); // clear datas
  743. void DrawSearchBar(FileDialogInternal& vFileDialogInternal); // draw the search bar
  744. };
  745. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  746. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  747. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  748. class Utils
  749. {
  750. public:
  751. struct PathStruct
  752. {
  753. std::string path;
  754. std::string name;
  755. std::string ext;
  756. bool isOk = false;
  757. };
  758. public:
  759. static bool Splitter(bool split_vertically, float thickness, float* size1, float* size2, float min_size1, float min_size2, float splitter_long_axis_size = -1.0f);
  760. static bool ReplaceString(std::string& str, const std::string& oldStr, const std::string& newStr);
  761. static bool IsDirectoryCanBeOpened(const std::string& name); // by ex protected dirs (not user rights)
  762. static bool IsDirectoryExist(const std::string& name);
  763. static bool CreateDirectoryIfNotExist(const std::string& name);
  764. static PathStruct ParsePathFileName(const std::string& vPathFileName);
  765. static void AppendToBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr);
  766. static void ResetBuffer(char* vBuffer);
  767. static void SetBuffer(char* vBuffer, size_t vBufferLen, const std::string& vStr);
  768. static bool WReplaceString(std::wstring& str, const std::wstring& oldStr, const std::wstring& newStr);
  769. static std::vector<std::wstring> WSplitStringToVector(const std::wstring& text, char delimiter, bool pushEmpty);
  770. static std::string utf8_encode(const std::wstring& wstr);
  771. static std::wstring utf8_decode(const std::string& str);
  772. static std::vector<std::string> SplitStringToVector(const std::string& text, char delimiter, bool pushEmpty);
  773. static std::vector<std::string> GetDrivesList();
  774. static std::string LowerCaseString(const std::string& vString); // turn all text in lower case for search facilitie
  775. };
  776. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  777. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  778. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  779. class FileStyle
  780. {
  781. public:
  782. ImVec4 color = ImVec4(0, 0, 0, 0);
  783. std::string icon;
  784. ImFont* font = nullptr;
  785. IGFD_FileStyleFlags flags = 0;
  786. public:
  787. FileStyle();
  788. FileStyle(const FileStyle& vStyle);
  789. FileStyle(const ImVec4& vColor, const std::string& vIcon = "", ImFont* vFont = nullptr);
  790. };
  791. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  792. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  793. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  794. class FileInfos;
  795. class FilterManager
  796. {
  797. public:
  798. class FilterInfos
  799. {
  800. public:
  801. std::string filter; // simple filter
  802. std::regex filter_regex; // filter fo type regex
  803. std::set<std::string> collectionfilters; // collections of filters
  804. std::string filter_optimized; // opitmized for case insensitive search
  805. std::set<std::string> collectionfilters_optimized; // optimized collections of filters for case insensitive search
  806. std::vector<std::regex> collectionfilters_regex; // collection of regex filter type
  807. public:
  808. void clear(); // clear the datas
  809. bool empty() const; // is filter empty
  810. bool exist(const std::string& vFilter, bool vIsCaseInsensitive) const; // is filter exist
  811. bool regex_exist(const std::string& vFilter) const; // is regex filter exist
  812. };
  813. private:
  814. #ifdef NEED_TO_BE_PUBLIC_FOR_TESTS
  815. public:
  816. #endif
  817. std::vector<FilterInfos> prParsedFilters;
  818. std::unordered_map<IGFD_FileStyleFlags, std::unordered_map<std::string, std::shared_ptr<FileStyle>>> prFilesStyle; // file infos for file extention only
  819. FilterInfos prSelectedFilter;
  820. public:
  821. std::string puDLGFilters;
  822. std::string puDLGdefaultExt;
  823. public:
  824. void ParseFilters(const char* vFilters); // Parse filter syntax, detect and parse filter collection
  825. void SetSelectedFilterWithExt(const std::string& vFilter); // Select filter
  826. bool prFillFileStyle(std::shared_ptr<FileInfos> vFileInfos) const; // fill with the good style
  827. void SetFileStyle(
  828. const IGFD_FileStyleFlags& vFlags,
  829. const char* vCriteria,
  830. const FileStyle& vInfos); // Set FileStyle
  831. void SetFileStyle(
  832. const IGFD_FileStyleFlags& vFlags,
  833. const char* vCriteria,
  834. const ImVec4& vColor,
  835. const std::string& vIcon,
  836. ImFont* vFont); // link file style to Color and Icon and Font
  837. bool GetFileStyle(
  838. const IGFD_FileStyleFlags& vFlags,
  839. const std::string& vCriteria,
  840. ImVec4* vOutColor,
  841. std::string* vOutIcon,
  842. ImFont** vOutFont); // Get Color and Icon for Filter
  843. void ClearFilesStyle(); // clear prFileStyle
  844. bool IsCoveredByFilters( // check if current file extention (vExt) is covered by current filter, ro by regex (vNameExt)
  845. const std::string& vNameExt,
  846. const std::string& vExt,
  847. bool vIsCaseInsensitive) const;
  848. bool DrawFilterComboBox(FileDialogInternal& vFileDialogInternal); // draw the filter combobox
  849. FilterInfos GetSelectedFilter(); // get the current selected filter
  850. std::string ReplaceExtentionWithCurrentFilter(const std::string& vFile) const; // replace the extention of the current file by the selected filter
  851. void SetDefaultFilterIfNotDefined(); // define the first filter if no filter is selected
  852. };
  853. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  854. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  855. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  856. class FileType
  857. {
  858. public:
  859. enum class ContentType {
  860. // The ordering will be used during sort.
  861. Invalid = -1,
  862. Directory = 0,
  863. File = 1,
  864. LinkToUnknown = 2, // link to something that is not a regular file or directory.
  865. };
  866. private:
  867. ContentType m_Content = ContentType::Invalid;
  868. bool m_Symlink = false;
  869. public:
  870. FileType() = default;
  871. FileType(const ContentType& vContentType, const bool& vIsSymlink)
  872. : m_Content(vContentType), m_Symlink(vIsSymlink)
  873. {}
  874. void SetContent(const ContentType& vContentType) { m_Content = vContentType; }
  875. void SetSymLink(const bool& vIsSymlink) { m_Symlink = vIsSymlink; }
  876. bool isValid () const { return m_Content != ContentType::Invalid; }
  877. bool isDir () const { return m_Content == ContentType::Directory; }
  878. bool isFile () const { return m_Content == ContentType::File; }
  879. bool isLinkToUnknown () const { return m_Content == ContentType::LinkToUnknown; }
  880. bool isSymLink() const { return m_Symlink; }
  881. // Comparisons only care about the content type, ignoring whether it's a symlink or not.
  882. bool operator== (const FileType& rhs) const { return m_Content == rhs.m_Content; }
  883. bool operator!= (const FileType& rhs) const { return m_Content != rhs.m_Content; }
  884. bool operator< (const FileType& rhs) const { return m_Content < rhs.m_Content; }
  885. bool operator> (const FileType& rhs) const { return m_Content > rhs.m_Content; }
  886. };
  887. class FileInfos
  888. {
  889. public:
  890. FileType fileType; // fileType
  891. std::string filePath; // path of the file
  892. std::string fileNameExt; // filename of the file (file name + extention) (but no path)
  893. std::string fileNameExt_optimized; // optimized for search => insensitivecase
  894. std::string fileExt; // extention of the file
  895. size_t fileSize = 0; // for sorting operations
  896. std::string formatedFileSize; // file size formated (10 o, 10 ko, 10 mo, 10 go)
  897. std::string fileModifDate; // file user defined format of the date (data + time by default)
  898. std::shared_ptr<FileStyle> fileStyle = nullptr; // style of the file
  899. #ifdef USE_THUMBNAILS
  900. IGFD_Thumbnail_Info thumbnailInfo; // structre for the display for image file tetxure
  901. #endif // USE_THUMBNAILS
  902. public:
  903. bool IsTagFound(const std::string& vTag) const;
  904. };
  905. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  906. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  907. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  908. class FileManager
  909. {
  910. public: // types
  911. enum class SortingFieldEnum // sorting for filetering of the file lsit
  912. {
  913. FIELD_NONE = 0, // no sorting preference, result indetermined haha..
  914. FIELD_FILENAME, // sorted by filename
  915. FIELD_TYPE, // sorted by filetype
  916. FIELD_SIZE, // sorted by filesize (formated file size)
  917. FIELD_DATE, // sorted by filedate
  918. #ifdef USE_THUMBNAILS
  919. FIELD_THUMBNAILS, // sorted by thumbnails (comparaison by width then by height)
  920. #endif // USE_THUMBNAILS
  921. };
  922. private:
  923. std::string prCurrentPath; // current path (to be decomposed in prCurrentPathDecomposition
  924. std::vector<std::string> prCurrentPathDecomposition; // part words
  925. std::vector<std::shared_ptr<FileInfos>> prFileList; // base container
  926. std::vector<std::shared_ptr<FileInfos>> prFilteredFileList; // filtered container (search, sorting, etc..)
  927. std::vector<std::shared_ptr<FileInfos>> prPathList; // base container for path selection
  928. std::vector<std::shared_ptr<FileInfos>> prFilteredPathList; // filtered container for path selection (search, sorting, etc..)
  929. std::vector<std::string>::iterator prPopupComposedPath; // iterator on prCurrentPathDecomposition for Current Path popup
  930. std::string prLastSelectedFileName; // for shift multi selection
  931. std::set<std::string> prSelectedFileNames; // the user selection of FilePathNames
  932. bool prCreateDirectoryMode = false; // for create directory widget
  933. public:
  934. char puVariadicBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // called by prSelectableItem
  935. bool puInputPathActivated = false; // show input for path edition
  936. bool puDrivesClicked = false; // event when a drive button is clicked
  937. bool puPathClicked = false; // event when a path button was clicked
  938. char puInputPathBuffer[MAX_PATH_BUFFER_SIZE] = ""; // input path buffer for imgui widget input text (displayed in palce of composer)
  939. char puFileNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // file name buffer in footer for imgui widget input text
  940. char puDirectoryNameBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = ""; // directory name buffer in footer for imgui widget input text (when is directory mode)
  941. std::string puHeaderFileName; // detail view name of column file
  942. std::string puHeaderFileType; // detail view name of column type
  943. std::string puHeaderFileSize; // detail view name of column size
  944. std::string puHeaderFileDate; // detail view name of column date + time
  945. #ifdef USE_THUMBNAILS
  946. std::string puHeaderFileThumbnails; // detail view name of column thumbnails
  947. bool puSortingDirection[5] = { // true => Ascending, false => Descending
  948. defaultSortOrderFilename,
  949. defaultSortOrderType,
  950. defaultSortOrderSize,
  951. defaultSortOrderDate,
  952. defaultSortOrderThumbnails };
  953. #else
  954. bool puSortingDirection[4] = { // true => Ascending, false => Descending
  955. defaultSortOrderFilename,
  956. defaultSortOrderType,
  957. defaultSortOrderSize,
  958. defaultSortOrderDate };
  959. #endif
  960. SortingFieldEnum puSortingField = SortingFieldEnum::FIELD_FILENAME; // detail view sorting column
  961. bool puShowDrives = false; // drives are shown (only on os windows)
  962. std::string puDLGpath; // base path set by user when OpenDialog was called
  963. std::string puDLGDefaultFileName; // base default file path name set by user when OpenDialog was called
  964. size_t puDLGcountSelectionMax = 1U; // 0 for infinite // base max selection count set by user when OpenDialog was called
  965. bool puDLGDirectoryMode = false; // is directory mode (defiend like : puDLGDirectoryMode = (filters.empty()))
  966. std::string puFsRoot;
  967. private:
  968. static std::string prRoundNumber(double vvalue, int n); // custom rounding number
  969. static std::string prFormatFileSize(size_t vByteSize); // format file size field
  970. static void prCompleteFileInfos(const std::shared_ptr<FileInfos>& FileInfos); // set time and date infos of a file (detail view mode)
  971. void prRemoveFileNameInSelection(const std::string& vFileName); // selection : remove a file name
  972. void prAddFileNameInSelection(const std::string& vFileName, bool vSetLastSelectionFileName); // selection : add a file name
  973. void AddFile(const FileDialogInternal& vFileDialogInternal,
  974. const std::string& vPath, const std::string& vFileName, const FileType& vFileType); // add file called by scandir
  975. void AddPath(const FileDialogInternal& vFileDialogInternal,
  976. const std::string& vPath, const std::string& vFileName, const FileType& vFileType); // add file called by scandir
  977. #if defined(USE_QUICK_PATH_SELECT)
  978. void ScanDirForPathSelection(const FileDialogInternal& vFileDialogInternal, const std::string& vPath); // scan the directory for retrieve the path list
  979. void OpenPathPopup(const FileDialogInternal& vFileDialogInternal, std::vector<std::string>::iterator vPathIter);
  980. #endif // USE_QUICK_PATH_SELECT
  981. void SetCurrentPath(std::vector<std::string>::iterator vPathIter);
  982. void ApplyFilteringOnFileList(
  983. const FileDialogInternal& vFileDialogInternal,
  984. std::vector<std::shared_ptr<FileInfos>>& vFileInfosList,
  985. std::vector<std::shared_ptr<FileInfos>>& vFileInfosFilteredList);
  986. void SortFields(
  987. const FileDialogInternal& vFileDialogInternal,
  988. std::vector<std::shared_ptr<FileInfos>>& vFileInfosList,
  989. std::vector<std::shared_ptr<FileInfos>>& vFileInfosFilteredList); // will sort a column
  990. public:
  991. FileManager();
  992. bool IsComposerEmpty();
  993. size_t GetComposerSize();
  994. bool IsFileListEmpty();
  995. bool IsPathListEmpty();
  996. bool IsFilteredListEmpty();
  997. bool IsPathFilteredListEmpty();
  998. size_t GetFullFileListSize();
  999. std::shared_ptr<FileInfos> GetFullFileAt(size_t vIdx);
  1000. size_t GetFilteredListSize();
  1001. size_t GetPathFilteredListSize();
  1002. std::shared_ptr<FileInfos> GetFilteredFileAt(size_t vIdx);
  1003. std::shared_ptr<FileInfos> GetFilteredPathAt(size_t vIdx);
  1004. std::vector<std::string>::iterator GetCurrentPopupComposedPath();
  1005. bool IsFileNameSelected(const std::string& vFileName);
  1006. std::string GetBack();
  1007. void ClearComposer();
  1008. void ClearFileLists(); // clear file list, will destroy thumbnail textures
  1009. void ClearPathLists(); // clear path list, will destroy thumbnail textures
  1010. void ClearAll();
  1011. void ApplyFilteringOnFileList(const FileDialogInternal& vFileDialogInternal);
  1012. void SortFields(const FileDialogInternal& vFileDialogInternal); // will sort a column
  1013. void OpenCurrentPath(const FileDialogInternal& vFileDialogInternal); // set the path of the dialog, will launch the directory scan for populate the file listview
  1014. bool GetDrives(); // list drives on windows platform
  1015. bool CreateDir(const std::string& vPath); // create a directory on the file system
  1016. std::string ComposeNewPath(std::vector<std::string>::iterator vIter); // compose a path from the compose path widget
  1017. bool SetPathOnParentDirectoryIfAny(); // compose paht on parent directory
  1018. std::string GetCurrentPath(); // get the current path
  1019. void SetCurrentPath(const std::string& vCurrentPath); // set the current path
  1020. static bool IsFileExist(const std::string& vFile);
  1021. void SetDefaultFileName(const std::string& vFileName);
  1022. bool SelectDirectory(const std::shared_ptr<FileInfos>& vInfos); // enter directory
  1023. void SelectFileName(const FileDialogInternal& vFileDialogInternal,
  1024. const std::shared_ptr<FileInfos>& vInfos); // select filename
  1025. //depend of dirent.h
  1026. void SetCurrentDir(const std::string& vPath); // define current directory for scan
  1027. void ScanDir(const FileDialogInternal& vFileDialogInternal, const std::string& vPath); // scan the directory for retrieve the file list
  1028. public:
  1029. std::string GetResultingPath();
  1030. std::string GetResultingFileName(FileDialogInternal& vFileDialogInternal);
  1031. std::string GetResultingFilePathName(FileDialogInternal& vFileDialogInternal);
  1032. std::map<std::string, std::string> GetResultingSelection();
  1033. public:
  1034. void DrawDirectoryCreation(const FileDialogInternal& vFileDialogInternal); // draw directory creation widget
  1035. void DrawPathComposer(const FileDialogInternal& vFileDialogInternal); // draw path composer widget
  1036. };
  1037. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1038. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1039. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1040. #ifdef USE_THUMBNAILS
  1041. typedef std::function<void(IGFD_Thumbnail_Info*)> CreateThumbnailFun; // texture 2d creation function binding
  1042. typedef std::function<void(IGFD_Thumbnail_Info*)> DestroyThumbnailFun; // texture 2d destroy function binding
  1043. #endif
  1044. class ThumbnailFeature
  1045. {
  1046. protected:
  1047. ThumbnailFeature();
  1048. ~ThumbnailFeature();
  1049. void NewThumbnailFrame(FileDialogInternal& vFileDialogInternal);
  1050. void EndThumbnailFrame(FileDialogInternal& vFileDialogInternal);
  1051. void QuitThumbnailFrame(FileDialogInternal& vFileDialogInternal);
  1052. #ifdef USE_THUMBNAILS
  1053. protected:
  1054. enum class DisplayModeEnum
  1055. {
  1056. FILE_LIST = 0,
  1057. THUMBNAILS_LIST,
  1058. THUMBNAILS_GRID
  1059. };
  1060. private:
  1061. uint32_t prCountFiles = 0U;
  1062. bool prIsWorking = false;
  1063. std::shared_ptr<std::thread> prThumbnailGenerationThread = nullptr;
  1064. std::list<std::shared_ptr<FileInfos>> prThumbnailFileDatasToGet; // base container
  1065. std::mutex prThumbnailFileDatasToGetMutex;
  1066. std::list<std::shared_ptr<FileInfos>> prThumbnailToCreate; // base container
  1067. std::mutex prThumbnailToCreateMutex;
  1068. std::list<IGFD_Thumbnail_Info> prThumbnailToDestroy; // base container
  1069. std::mutex prThumbnailToDestroyMutex;
  1070. CreateThumbnailFun prCreateThumbnailFun = nullptr;
  1071. DestroyThumbnailFun prDestroyThumbnailFun = nullptr;
  1072. protected:
  1073. DisplayModeEnum prDisplayMode = DisplayModeEnum::FILE_LIST;
  1074. protected:
  1075. // will be call in cpu zone (imgui computations, will call a texture file retrieval thread)
  1076. void prStartThumbnailFileDatasExtraction(); // start the thread who will get byte buffer from image files
  1077. bool prStopThumbnailFileDatasExtraction(); // stop the thread who will get byte buffer from image files
  1078. void prThreadThumbnailFileDatasExtractionFunc(); // the thread who will get byte buffer from image files
  1079. void prDrawThumbnailGenerationProgress(); // a little progressbar who will display the texture gen status
  1080. void prAddThumbnailToLoad(const std::shared_ptr<FileInfos>& vFileInfos); // add texture to load in the thread
  1081. void prAddThumbnailToCreate(const std::shared_ptr<FileInfos>& vFileInfos);
  1082. void prAddThumbnailToDestroy(const IGFD_Thumbnail_Info& vIGFD_Thumbnail_Info);
  1083. void prDrawDisplayModeToolBar(); // draw display mode toolbar (file list, thumbnails list, small thumbnails grid, big thumbnails grid)
  1084. void prClearThumbnails(FileDialogInternal& vFileDialogInternal);
  1085. public:
  1086. void SetCreateThumbnailCallback(const CreateThumbnailFun& vCreateThumbnailFun);
  1087. void SetDestroyThumbnailCallback(const DestroyThumbnailFun& vCreateThumbnailFun);
  1088. // must be call in gpu zone (rendering, possibly one rendering thread)
  1089. void ManageGPUThumbnails(); // in gpu rendering zone, whill create or destroy texture
  1090. #endif
  1091. };
  1092. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1093. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1094. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1095. class BookMarkFeature
  1096. {
  1097. protected:
  1098. BookMarkFeature();
  1099. #ifdef USE_BOOKMARK
  1100. private:
  1101. struct BookmarkStruct
  1102. {
  1103. std::string name; // name of the bookmark
  1104. // todo: the path could be relative, better if the app is movedn but bookmarked path can be outside of the app
  1105. std::string path; // absolute path of the bookmarked directory
  1106. bool defined_by_code = false; // defined by code, can be used for rpevent serialization / deserialization
  1107. };
  1108. private:
  1109. ImGuiListClipper prBookmarkClipper;
  1110. std::vector<BookmarkStruct> prBookmarks;
  1111. char prBookmarkEditBuffer[MAX_FILE_DIALOG_NAME_BUFFER] = "";
  1112. protected:
  1113. float prBookmarkWidth = 200.0f;
  1114. bool prBookmarkPaneShown = false;
  1115. protected:
  1116. void prDrawBookmarkButton(); // draw bookmark button
  1117. bool prDrawBookmarkPane(FileDialogInternal& vFileDialogInternal, const ImVec2& vSize); // draw bookmark Pane
  1118. public:
  1119. std::string SerializeBookmarks( // serialize bookmarks : return bookmark buffer to save in a file
  1120. const bool& vDontSerializeCodeBasedBookmarks = true); // for avoid serialization of bookmarks added by code
  1121. void DeserializeBookmarks( // deserialize bookmarks : load bookmark buffer to load in the dialog (saved from previous use with SerializeBookmarks())
  1122. const std::string& vBookmarks); // bookmark buffer to load
  1123. void AddBookmark( // add a bookmark by code
  1124. const std::string& vBookMarkName, // bookmark name
  1125. const std::string& vBookMarkPath); // bookmark path
  1126. bool RemoveBookmark( // remove a bookmark by code, return true if succeed
  1127. const std::string& vBookMarkName); // bookmark name to remove
  1128. #endif // USE_BOOKMARK
  1129. };
  1130. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1131. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1132. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1133. // file localization by input chat // widget flashing
  1134. class KeyExplorerFeature
  1135. {
  1136. protected:
  1137. KeyExplorerFeature();
  1138. #ifdef USE_EXPLORATION_BY_KEYS
  1139. private:
  1140. bool prLocateFileByInputChar_lastFound = false;
  1141. ImWchar prLocateFileByInputChar_lastChar = 0;
  1142. float prFlashAlpha = 0.0f; // flash when select by char
  1143. float prFlashAlphaAttenInSecs = 1.0f; // fps display dependant
  1144. int prLocateFileByInputChar_InputQueueCharactersSize = 0;
  1145. size_t prFlashedItem = 0; // flash when select by char
  1146. size_t prLocateFileByInputChar_lastFileIdx = 0;
  1147. protected:
  1148. void prLocateByInputKey(FileDialogInternal& vFileDialogInternal); // select a file line in listview according to char key
  1149. bool prLocateItem_Loop(FileDialogInternal& vFileDialogInternal, ImWchar vC); // restrat for start of list view if not found a corresponding file
  1150. void prExploreWithkeys(FileDialogInternal& vFileDialogInternal, ImGuiID vListViewID); // select file/directory line in listview accroding to up/down enter/backspace keys
  1151. static bool prFlashableSelectable( // custom flashing selectable widgets, for flash the selected line in a short time
  1152. const char* label, bool selected = false, ImGuiSelectableFlags flags = 0,
  1153. bool vFlashing = false, const ImVec2& size = ImVec2(0, 0));
  1154. void prStartFlashItem(size_t vIdx); // define than an item must be flashed
  1155. bool prBeginFlashItem(size_t vIdx); // start the flashing of a line in lsit view
  1156. static void prEndFlashItem(); // end the fleshing accrdoin to var prFlashAlphaAttenInSecs
  1157. public:
  1158. void SetFlashingAttenuationInSeconds( // set the flashing time of the line in file list when use exploration keys
  1159. float vAttenValue); // set the attenuation (from flashed to not flashed) in seconds
  1160. #endif // USE_EXPLORATION_BY_KEYS
  1161. };
  1162. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1163. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1164. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1165. typedef void* UserDatas;
  1166. typedef std::function<void(const char*, UserDatas, bool*)> PaneFun; // side pane function binding
  1167. class FileDialogInternal
  1168. {
  1169. public:
  1170. FileManager puFileManager;
  1171. FilterManager puFilterManager;
  1172. SearchManager puSearchManager;
  1173. public:
  1174. std::string puName;
  1175. bool puShowDialog = false;
  1176. ImVec2 puDialogCenterPos = ImVec2(0, 0); // center pos for display the confirm overwrite dialog
  1177. int puLastImGuiFrameCount = 0; // to be sure than only one dialog displayed per frame
  1178. float puFooterHeight = 0.0f;
  1179. bool puCanWeContinue = true; // events
  1180. bool puOkResultToConfirm = false; // to confim if ok for OverWrite
  1181. bool puIsOk = false;
  1182. bool puFileInputIsActive = false; // when input text for file or directory is active
  1183. bool puFileListViewIsActive = false; // when list view is active
  1184. std::string puDLGkey;
  1185. std::string puDLGtitle;
  1186. ImGuiFileDialogFlags puDLGflags = ImGuiFileDialogFlags_None;
  1187. UserDatas puDLGuserDatas = nullptr;
  1188. PaneFun puDLGoptionsPane = nullptr;
  1189. float puDLGoptionsPaneWidth = 0.0f;
  1190. bool puNeedToExitDialog = false;
  1191. bool puUseCustomLocale = false;
  1192. int puLocaleCategory = LC_ALL; // locale category to use
  1193. std::string puLocaleBegin; // the locale who will be applied at start of the display dialog
  1194. std::string puLocaleEnd; // the locale who will be applaied at end of the display dialog
  1195. public:
  1196. void NewFrame(); // new frame, so maybe neded to do somethings, like reset events
  1197. void EndFrame(); // end frame, so maybe neded to do somethings fater all
  1198. void ResetForNewDialog(); // reset what is needed to reset for the openging of a new dialog
  1199. };
  1200. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1201. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1202. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1203. class FileDialog :
  1204. public BookMarkFeature,
  1205. public KeyExplorerFeature,
  1206. public ThumbnailFeature
  1207. {
  1208. private:
  1209. FileDialogInternal prFileDialogInternal;
  1210. ImGuiListClipper prFileListClipper;
  1211. ImGuiListClipper prPathListClipper;
  1212. float prOkCancelButtonWidth = 0.0f;
  1213. public:
  1214. bool puAnyWindowsHovered = false; // not remember why haha :) todo : to check if we can remove
  1215. public:
  1216. // Singleton for easier accces form anywhere but only one dialog at a time
  1217. // vCopy or vForce can be used for share a memory pointer in a new memory space like a dll module
  1218. static FileDialog* Instance(FileDialog* vCopy = nullptr, bool vForce = false)
  1219. {
  1220. static FileDialog _instance;
  1221. static FileDialog* _instance_copy = nullptr;
  1222. if (vCopy || vForce)
  1223. {
  1224. _instance_copy = vCopy;
  1225. }
  1226. if (_instance_copy)
  1227. {
  1228. return _instance_copy;
  1229. }
  1230. return &_instance;
  1231. }
  1232. public:
  1233. FileDialog(); // ImGuiFileDialog Constructor. can be used for have many dialog at same tiem (not possible with singleton)
  1234. virtual ~FileDialog(); // ImGuiFileDialog Destructor
  1235. // standard dialog
  1236. void OpenDialog( // open simple dialog (path and fileName can be specified)
  1237. const std::string& vKey, // key dialog
  1238. const std::string& vTitle, // title
  1239. const char* vFilters, // filters
  1240. const std::string& vPath, // path
  1241. const std::string& vFileName, // defaut file name
  1242. const int& vCountSelectionMax = 1, // count selection max
  1243. UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane)
  1244. ImGuiFileDialogFlags vFlags = 0); // ImGuiFileDialogFlags
  1245. void OpenDialog( // open simple dialog (path and filename are obtained from filePathName)
  1246. const std::string& vKey, // key dialog
  1247. const std::string& vTitle, // title
  1248. const char* vFilters, // filters
  1249. const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName)
  1250. const int& vCountSelectionMax = 1, // count selection max
  1251. UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane)
  1252. ImGuiFileDialogFlags vFlags = 0); // ImGuiFileDialogFlags
  1253. // with pane
  1254. void OpenDialog( // open dialog with custom right pane (path and fileName can be specified)
  1255. const std::string& vKey, // key dialog
  1256. const std::string& vTitle, // title
  1257. const char* vFilters, // filters
  1258. const std::string& vPath, // path
  1259. const std::string& vFileName, // defaut file name
  1260. const PaneFun& vSidePane, // side pane
  1261. const float& vSidePaneWidth = 250.0f, // side pane width
  1262. const int& vCountSelectionMax = 1, // count selection max
  1263. UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane)
  1264. ImGuiFileDialogFlags vFlags = 0); // ImGuiFileDialogFlags
  1265. void OpenDialog( // open dialog with custom right pane (path and filename are obtained from filePathName)
  1266. const std::string& vKey, // key dialog
  1267. const std::string& vTitle, // title
  1268. const char* vFilters, // filters
  1269. const std::string& vFilePathName, // file path name (will be decompsoed in path and fileName)
  1270. const PaneFun& vSidePane, // side pane
  1271. const float& vSidePaneWidth = 250.0f, // side pane width
  1272. const int& vCountSelectionMax = 1, // count selection max
  1273. UserDatas vUserDatas = nullptr, // user datas (can be retrieved in pane)
  1274. ImGuiFileDialogFlags vFlags = 0); // ImGuiFileDialogFlags
  1275. // Display / Close dialog form
  1276. bool Display( // Display the dialog. return true if a result was obtained (Ok or not)
  1277. const std::string& vKey, // key dialog to display (if not the same key as defined by OpenDialog => no opening)
  1278. ImGuiWindowFlags vFlags = ImGuiWindowFlags_NoCollapse, // ImGuiWindowFlags
  1279. ImVec2 vMinSize = ImVec2(0, 0), // mininmal size contraint for the ImGuiWindow
  1280. ImVec2 vMaxSize = ImVec2(FLT_MAX, FLT_MAX)); // maximal size contraint for the ImGuiWindow
  1281. void Close(); // close dialog
  1282. // queries
  1283. bool WasOpenedThisFrame(const std::string& vKey) const; // say if the dialog key was already opened this frame
  1284. bool WasOpenedThisFrame() const; // say if the dialog was already opened this frame
  1285. bool IsOpened(const std::string& vKey) const; // say if the key is opened
  1286. bool IsOpened() const; // say if the dialog is opened somewhere
  1287. std::string GetOpenedKey() const; // return the dialog key who is opened, return nothing if not opened
  1288. // get result
  1289. bool IsOk() const; // true => Dialog Closed with Ok result / false : Dialog closed with cancel result
  1290. std::map<std::string, std::string> GetSelection(); // Open File behavior : will return selection via a map<FileName, FilePathName>
  1291. std::string GetFilePathName(); // Save File behavior : will always return the content of the field with current filter extention and current path
  1292. std::string GetCurrentFileName(); // Save File behavior : will always return the content of the field with current filter extention
  1293. std::string GetCurrentPath(); // will return current path
  1294. std::string GetCurrentFilter(); // will return selected filter
  1295. UserDatas GetUserDatas() const; // will return user datas send with Open Dialog
  1296. // file style by extentions
  1297. void SetFileStyle( // SetExtention datas for have custom display of particular file type
  1298. const IGFD_FileStyleFlags& vFlags, // file style
  1299. const char* vCriteria, // extention filter to tune
  1300. const FileStyle& vInfos); // Filter Extention Struct who contain Color and Icon/Text for the display of the file with extention filter
  1301. void SetFileStyle( // SetExtention datas for have custom display of particular file type
  1302. const IGFD_FileStyleFlags& vFlags, // file style
  1303. const char* vCriteria, // extention filter to tune
  1304. const ImVec4& vColor, // wanted color for the display of the file with extention filter
  1305. const std::string& vIcon = "", // wanted text or icon of the file with extention filter
  1306. ImFont *vFont = nullptr); // wantes font
  1307. bool GetFileStyle( // GetExtention datas. return true is extention exist
  1308. const IGFD_FileStyleFlags& vFlags, // file style
  1309. const std::string& vCriteria, // extention filter (same as used in SetExtentionInfos)
  1310. ImVec4* vOutColor, // color to retrieve
  1311. std::string* vOutIcon = nullptr, // icon or text to retrieve
  1312. ImFont** vOutFont = nullptr); // font to retreive
  1313. void ClearFilesStyle(); // clear extentions setttings
  1314. void SetLocales( // set locales to use before and after the dialog display
  1315. const int& vLocaleCategory, // set local category
  1316. const std::string& vLocaleBegin, // locale to use at begining of the dialog display
  1317. const std::string& vLocaleEnd); // locale to use at the end of the dialog display
  1318. protected:
  1319. void NewFrame(); // new frame just at begining of display
  1320. void EndFrame(); // end frame just at end of display
  1321. void QuitFrame(); // quit frame when qui quit the dialog
  1322. // others
  1323. bool prConfirm_Or_OpenOverWriteFileDialog_IfNeeded(
  1324. bool vLastAction, ImGuiWindowFlags vFlags); // treatment of the result, start the confirm to overwrite dialog if needed (if defined with flag)
  1325. public:
  1326. // dialog parts
  1327. virtual void prDrawHeader(); // draw header part of the dialog (bookmark btn, dir creation, path composer, search bar)
  1328. virtual void prDrawContent(); // draw content part of the dialog (bookmark pane, file list, side pane)
  1329. virtual bool prDrawFooter(); // draw footer part of the dialog (file field, fitler combobox, ok/cancel btn's)
  1330. // widgets components
  1331. #if defined(USE_QUICK_PATH_SELECT)
  1332. virtual void DisplayPathPopup(ImVec2 vSize); // draw path popup when click on a \ or /
  1333. #endif // USE_QUICK_PATH_SELECT
  1334. virtual bool prDrawValidationButtons(); // draw validations btns, ok, cancel buttons
  1335. virtual bool prDrawOkButton(); // draw ok button
  1336. virtual bool prDrawCancelButton(); // draw cancel button
  1337. virtual void prDrawSidePane(float vHeight); // draw side pane
  1338. virtual void prSelectableItem(int vidx,
  1339. std::shared_ptr<FileInfos> vInfos,
  1340. bool vSelected, const char* vFmt, ...); // draw a custom selectable behavior item
  1341. virtual void prDrawFileListView(ImVec2 vSize); // draw file list view (default mode)
  1342. #ifdef USE_THUMBNAILS
  1343. virtual void prDrawThumbnailsListView(ImVec2 vSize); // draw file list view with small thumbnails on the same line
  1344. virtual void prDrawThumbnailsGridView(ImVec2 vSize); // draw a grid of small thumbnails
  1345. #endif
  1346. // to be called only by these function and theirs overrides
  1347. // - prDrawFileListView
  1348. // - prDrawThumbnailsListView
  1349. // - prDrawThumbnailsGridView
  1350. void prBeginFileColorIconStyle(
  1351. std::shared_ptr<FileInfos> vFileInfos,
  1352. bool& vOutShowColor,
  1353. std::string& vOutStr,
  1354. ImFont** vOutFont); // begin style apply of filter with color an icon if any
  1355. void prEndFileColorIconStyle(
  1356. const bool& vShowColor,
  1357. ImFont* vFont); // end style apply of filter
  1358. };
  1359. }
  1360. typedef IGFD::UserDatas IGFDUserDatas;
  1361. typedef IGFD::PaneFun IGFDPaneFun;
  1362. typedef IGFD::FileDialog ImGuiFileDialog;
  1363. #else // __cplusplus
  1364. typedef struct ImGuiFileDialog ImGuiFileDialog;
  1365. typedef struct IGFD_Selection_Pair IGFD_Selection_Pair;
  1366. typedef struct IGFD_Selection IGFD_Selection;
  1367. #endif // __cplusplus
  1368. // C Interface
  1369. #include <stdint.h>
  1370. #if defined _WIN32 || defined __CYGWIN__
  1371. #ifdef IMGUIFILEDIALOG_NO_EXPORT
  1372. #define API
  1373. #else // IMGUIFILEDIALOG_NO_EXPORT
  1374. #define API __declspec(dllexport)
  1375. #endif // IMGUIFILEDIALOG_NO_EXPORT
  1376. #else // defined _WIN32 || defined __CYGWIN__
  1377. #ifdef __GNUC__
  1378. #define API __attribute__((__visibility__("default")))
  1379. #else // __GNUC__
  1380. #define API
  1381. #endif // __GNUC__
  1382. #endif // defined _WIN32 || defined __CYGWIN__
  1383. #ifdef __cplusplus
  1384. #define IMGUIFILEDIALOG_API extern "C" API
  1385. #else // __cplusplus
  1386. #define IMGUIFILEDIALOG_API
  1387. #endif // __cplusplus
  1388. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1389. ///// C API ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1390. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1391. struct IGFD_Selection_Pair
  1392. {
  1393. char* fileName;
  1394. char* filePathName;
  1395. };
  1396. IMGUIFILEDIALOG_API IGFD_Selection_Pair IGFD_Selection_Pair_Get(); // return an initialized IGFD_Selection_Pair
  1397. IMGUIFILEDIALOG_API void IGFD_Selection_Pair_DestroyContent(IGFD_Selection_Pair* vSelection_Pair); // destroy the content of a IGFD_Selection_Pair
  1398. struct IGFD_Selection
  1399. {
  1400. IGFD_Selection_Pair* table; // 0
  1401. size_t count; // 0U
  1402. };
  1403. IMGUIFILEDIALOG_API IGFD_Selection IGFD_Selection_Get(); // return an initialized IGFD_Selection
  1404. IMGUIFILEDIALOG_API void IGFD_Selection_DestroyContent(IGFD_Selection* vSelection); // destroy the content of a IGFD_Selection
  1405. // constructor / destructor
  1406. IMGUIFILEDIALOG_API ImGuiFileDialog* IGFD_Create(void); // create the filedialog context
  1407. IMGUIFILEDIALOG_API void IGFD_Destroy(ImGuiFileDialog* vContext); // destroy the filedialog context
  1408. typedef void (*IGFD_PaneFun)(const char*, void*, bool*); // callback fucntion for display the pane
  1409. #ifdef USE_THUMBNAILS
  1410. typedef void (*IGFD_CreateThumbnailFun)(IGFD_Thumbnail_Info*); // callback function for create thumbnail texture
  1411. typedef void (*IGFD_DestroyThumbnailFun)(IGFD_Thumbnail_Info*); // callback fucntion for destroy thumbnail texture
  1412. #endif // USE_THUMBNAILS
  1413. IMGUIFILEDIALOG_API void IGFD_OpenDialog( // open a standard dialog
  1414. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1415. const char* vKey, // key dialog
  1416. const char* vTitle, // title
  1417. const char* vFilters, // filters/filter collections. set it to null for directory mode
  1418. const char* vPath, // path
  1419. const char* vFileName, // defaut file name
  1420. const int vCountSelectionMax, // count selection max
  1421. void* vUserDatas, // user datas (can be retrieved in pane)
  1422. ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags
  1423. IMGUIFILEDIALOG_API void IGFD_OpenDialog2( // open a standard dialog
  1424. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1425. const char* vKey, // key dialog
  1426. const char* vTitle, // title
  1427. const char* vFilters, // filters/filter collections. set it to null for directory mode
  1428. const char* vFilePathName, // defaut file path name (path and filename witl be extracted from it)
  1429. const int vCountSelectionMax, // count selection max
  1430. void* vUserDatas, // user datas (can be retrieved in pane)
  1431. ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags
  1432. IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog( // open a standard dialog with pane
  1433. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1434. const char* vKey, // key dialog
  1435. const char* vTitle, // title
  1436. const char* vFilters, // filters/filter collections. set it to null for directory mode
  1437. const char* vPath, // path
  1438. const char* vFileName, // defaut file name
  1439. const IGFD_PaneFun vSidePane, // side pane
  1440. const float vSidePaneWidth, // side pane base width
  1441. const int vCountSelectionMax, // count selection max
  1442. void* vUserDatas, // user datas (can be retrieved in pane)
  1443. ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags
  1444. IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog2( // open a standard dialog with pane
  1445. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1446. const char* vKey, // key dialog
  1447. const char* vTitle, // title
  1448. const char* vFilters, // filters/filter collections. set it to null for directory mode
  1449. const char* vFilePathName, // defaut file name (path and filename witl be extracted from it)
  1450. const IGFD_PaneFun vSidePane, // side pane
  1451. const float vSidePaneWidth, // side pane base width
  1452. const int vCountSelectionMax, // count selection max
  1453. void* vUserDatas, // user datas (can be retrieved in pane)
  1454. ImGuiFileDialogFlags vFlags); // ImGuiFileDialogFlags
  1455. IMGUIFILEDIALOG_API bool IGFD_DisplayDialog( // Display the dialog
  1456. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1457. const char* vKey, // key dialog to display (if not the same key as defined by OpenDialog => no opening)
  1458. ImGuiWindowFlags vFlags, // ImGuiWindowFlags
  1459. ImVec2 vMinSize, // mininmal size contraint for the ImGuiWindow
  1460. ImVec2 vMaxSize); // maximal size contraint for the ImGuiWindow
  1461. IMGUIFILEDIALOG_API void IGFD_CloseDialog( // Close the dialog
  1462. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1463. IMGUIFILEDIALOG_API bool IGFD_IsOk( // true => Dialog Closed with Ok result / false : Dialog closed with cancel result
  1464. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1465. IMGUIFILEDIALOG_API bool IGFD_WasKeyOpenedThisFrame( // say if the dialog key was already opened this frame
  1466. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1467. const char* vKey);
  1468. IMGUIFILEDIALOG_API bool IGFD_WasOpenedThisFrame( // say if the dialog was already opened this frame
  1469. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1470. IMGUIFILEDIALOG_API bool IGFD_IsKeyOpened( // say if the dialog key is opened
  1471. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1472. const char* vCurrentOpenedKey); // the dialog key
  1473. IMGUIFILEDIALOG_API bool IGFD_IsOpened( // say if the dialog is opened somewhere
  1474. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1475. IMGUIFILEDIALOG_API IGFD_Selection IGFD_GetSelection( // Open File behavior : will return selection via a map<FileName, FilePathName>
  1476. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1477. IMGUIFILEDIALOG_API char* IGFD_GetFilePathName( // Save File behavior : will always return the content of the field with current filter extention and current path, WARNINGS you are responsible to free it
  1478. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1479. IMGUIFILEDIALOG_API char* IGFD_GetCurrentFileName( // Save File behavior : will always return the content of the field with current filter extention, WARNINGS you are responsible to free it
  1480. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1481. IMGUIFILEDIALOG_API char* IGFD_GetCurrentPath( // will return current path, WARNINGS you are responsible to free it
  1482. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1483. IMGUIFILEDIALOG_API char* IGFD_GetCurrentFilter( // will return selected filter, WARNINGS you are responsible to free it
  1484. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1485. IMGUIFILEDIALOG_API void* IGFD_GetUserDatas( // will return user datas send with Open Dialog
  1486. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1487. IMGUIFILEDIALOG_API void IGFD_SetFileStyle( // SetExtention datas for have custom display of particular file type
  1488. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1489. IGFD_FileStyleFlags vFileStyleFlags, // file style type
  1490. const char* vFilter, // extention filter to tune
  1491. ImVec4 vColor, // wanted color for the display of the file with extention filter
  1492. const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon)
  1493. ImFont* vFont); // wanted font pointer
  1494. IMGUIFILEDIALOG_API void IGFD_SetFileStyle2( // SetExtention datas for have custom display of particular file type
  1495. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1496. IGFD_FileStyleFlags vFileStyleFlags, // file style type
  1497. const char* vFilter, // extention filter to tune
  1498. float vR, float vG, float vB, float vA, // wanted color channels RGBA for the display of the file with extention filter
  1499. const char* vIconText, // wanted text or icon of the file with extention filter (can be sued with font icon)
  1500. ImFont* vFont); // wanted font pointer
  1501. IMGUIFILEDIALOG_API bool IGFD_GetFileStyle(
  1502. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1503. IGFD_FileStyleFlags vFileStyleFlags, // file style type
  1504. const char* vFilter, // extention filter (same as used in SetExtentionInfos)
  1505. ImVec4* vOutColor, // color to retrieve
  1506. char** vOutIconText, // icon or text to retrieve, WARNINGS you are responsible to free it
  1507. ImFont** vOutFont); // font pointer to retrived
  1508. IMGUIFILEDIALOG_API void IGFD_ClearFilesStyle( // clear extentions setttings
  1509. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1510. IMGUIFILEDIALOG_API void SetLocales( // set locales to use before and after display
  1511. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1512. const int vCategory, // set local category
  1513. const char* vBeginLocale, // locale to use at begining of the dialog display
  1514. const char* vEndLocale); // locale to set at end of the dialog display
  1515. #ifdef USE_EXPLORATION_BY_KEYS
  1516. IMGUIFILEDIALOG_API void IGFD_SetFlashingAttenuationInSeconds( // set the flashing time of the line in file list when use exploration keys
  1517. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1518. float vAttenValue); // set the attenuation (from flashed to not flashed) in seconds
  1519. #endif
  1520. #ifdef USE_BOOKMARK
  1521. IMGUIFILEDIALOG_API char* IGFD_SerializeBookmarks( // serialize bookmarks : return bookmark buffer to save in a file, WARNINGS you are responsible to free it
  1522. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1523. bool vDontSerializeCodeBasedBookmarks); // for avoid serialization of bookmarks added by code
  1524. IMGUIFILEDIALOG_API void IGFD_DeserializeBookmarks( // deserialize bookmarks : load bookmar buffer to load in the dialog (saved from previous use with SerializeBookmarks())
  1525. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1526. const char* vBookmarks); // bookmark buffer to load
  1527. IMGUIFILEDIALOG_API void IGFD_AddBookmark( // add a bookmark by code
  1528. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1529. const char* vBookMarkName, // bookmark name
  1530. const char* vBookMarkPath); // bookmark path
  1531. IMGUIFILEDIALOG_API void IGFD_RemoveBookmark( // remove a bookmark by code, return true if succeed
  1532. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1533. const char* vBookMarkName); // bookmark name to remove
  1534. #endif
  1535. #ifdef USE_THUMBNAILS
  1536. IMGUIFILEDIALOG_API void SetCreateThumbnailCallback( // define the callback for create the thumbnails texture
  1537. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1538. IGFD_CreateThumbnailFun vCreateThumbnailFun); // the callback for create the thumbnails texture
  1539. IMGUIFILEDIALOG_API void SetDestroyThumbnailCallback( // define the callback for destroy the thumbnails texture
  1540. ImGuiFileDialog* vContext, // ImGuiFileDialog context
  1541. IGFD_DestroyThumbnailFun vDestroyThumbnailFun); // the callback for destroy the thumbnails texture
  1542. IMGUIFILEDIALOG_API void ManageGPUThumbnails( // must be call in gpu zone, possibly a thread, will call the callback for create / destroy the textures
  1543. ImGuiFileDialog* vContext); // ImGuiFileDialog context
  1544. #endif // USE_THUMBNAILS
  1545. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1546. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1547. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1548. #endif // IMGUIFILEDIALOG_H