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