2021-12-11 07:10:09 +00:00
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
/*
MIT License
Copyright ( c ) 2019 - 2020 Stephane Cuillerdier ( aka aiekick )
Permission is hereby granted , free of charge , to any person obtaining a copy
of this software and associated documentation files ( the " Software " ) , to deal
in the Software without restriction , including without limitation the rights
to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
copies of the Software , and to permit persons to whom the Software is
furnished to do so , subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software .
THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE .
*/
2023-06-08 06:00:47 +00:00
# ifndef IMGUI_DEFINE_MATH_OPERATORS
2023-06-16 21:26:22 +00:00
# define IMGUI_DEFINE_MATH_OPERATORS
2023-06-08 06:00:47 +00:00
# endif // IMGUI_DEFINE_MATH_OPERATORS
2021-12-11 07:10:09 +00:00
# include "ImGuiFileDialog.h"
2023-03-24 05:52:11 +00:00
# include "../../src/ta-log.h"
2021-12-11 07:10:09 +00:00
# ifdef __cplusplus
# include <cfloat>
# include <cstring> // stricmp / strcasecmp
# include <cstdarg> // variadic
# include <sstream>
# include <iomanip>
# include <ctime>
# include <sys/stat.h>
# include <cstdio>
# if defined (__EMSCRIPTEN__) // EMSCRIPTEN
2023-06-16 21:26:22 +00:00
# include <emscripten.h>
2021-12-11 07:10:09 +00:00
# endif // EMSCRIPTEN
2022-05-07 22:29:43 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
# define stricmp _stricmp
# include <cctype>
# include "dirent/dirent.h" // directly open the dirent file attached to this lib
# define PATH_SEP '\\'
2023-07-02 07:12:26 +00:00
# define PATH_SEP_STR "\\"
2023-06-16 21:26:22 +00:00
# ifndef PATH_MAX
# define PATH_MAX 260
# endif // PATH_MAX
2024-05-05 22:22:22 +00:00
# elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined (__EMSCRIPTEN__) || defined(__HAIKU__)
2023-06-16 21:26:22 +00:00
# define UNIX
# define stricmp strcasecmp
# include <sys/types.h>
# include <dirent.h>
# define PATH_SEP ' / '
2023-07-02 07:12:26 +00:00
# define PATH_SEP_STR " / "
2021-12-11 07:10:09 +00:00
# endif // defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
# include "imgui.h"
# include "imgui_internal.h"
2022-12-03 05:51:57 +00:00
# include <IconsFontAwesome4.h>
2021-12-11 07:10:09 +00:00
# include <cstdlib>
# include <algorithm>
# include <iostream>
2022-12-02 21:52:47 +00:00
# define DOUBLE_CLICKED ((singleClickSel && ImGui::IsMouseReleased(0)) || (!singleClickSel && ImGui::IsMouseDoubleClicked(0)))
2021-12-11 07:10:09 +00:00
# ifdef USE_THUMBNAILS
# ifndef DONT_DEFINE_AGAIN__STB_IMAGE_IMPLEMENTATION
# ifndef STB_IMAGE_IMPLEMENTATION
# define STB_IMAGE_IMPLEMENTATION
# endif // STB_IMAGE_IMPLEMENTATION
# endif // DONT_DEFINE_AGAIN__STB_IMAGE_IMPLEMENTATION
# include "stb/stb_image.h"
# ifndef DONT_DEFINE_AGAIN__STB_IMAGE_RESIZE_IMPLEMENTATION
# ifndef STB_IMAGE_RESIZE_IMPLEMENTATION
# define STB_IMAGE_RESIZE_IMPLEMENTATION
# endif // STB_IMAGE_RESIZE_IMPLEMENTATION
# endif // DONT_DEFINE_AGAIN__STB_IMAGE_RESIZE_IMPLEMENTATION
# include "stb/stb_image_resize.h"
# endif // USE_THUMBNAILS
namespace IGFD
{
// float comparisons
# ifndef IS_FLOAT_DIFFERENT
# define IS_FLOAT_DIFFERENT(a,b) (fabs((a) - (b)) > FLT_EPSILON)
# endif // IS_FLOAT_DIFFERENT
# ifndef IS_FLOAT_EQUAL
# define IS_FLOAT_EQUAL(a,b) (fabs((a) - (b)) < FLT_EPSILON)
# endif // IS_FLOAT_EQUAL
// width of filter combobox
# ifndef FILTER_COMBO_WIDTH
# define FILTER_COMBO_WIDTH 150.0f
# endif // FILTER_COMBO_WIDTH
// for lets you define your button widget
// if you have like me a special bi-color button
# ifndef IMGUI_PATH_BUTTON
# define IMGUI_PATH_BUTTON ImGui::Button
# endif // IMGUI_PATH_BUTTON
# ifndef IMGUI_BUTTON
# define IMGUI_BUTTON ImGui::Button
# endif // IMGUI_BUTTON
// locales
# ifndef createDirButtonString
2022-12-03 05:51:57 +00:00
# define createDirButtonString ICON_FA_PLUS
2021-12-11 07:10:09 +00:00
# endif // createDirButtonString
# ifndef resetButtonString
2022-12-03 05:51:57 +00:00
# define resetButtonString ICON_FA_REPEAT
2021-12-11 07:10:09 +00:00
# endif // resetButtonString
2023-06-16 20:43:41 +00:00
# ifndef homeButtonString
# define homeButtonString ICON_FA_HOME
# endif // bomeButtonString
2021-12-11 07:10:09 +00:00
# ifndef drivesButtonString
2023-03-12 06:48:01 +00:00
# define drivesButtonString ICON_FA_HDD_O
2021-12-11 07:10:09 +00:00
# endif // drivesButtonString
2023-03-12 06:48:01 +00:00
# ifndef parentDirString
# define parentDirString ICON_FA_CHEVRON_UP
# endif // parentDirString
2021-12-11 07:10:09 +00:00
# ifndef editPathButtonString
2022-12-03 05:51:57 +00:00
# define editPathButtonString ICON_FA_PENCIL
2021-12-11 07:10:09 +00:00
# endif // editPathButtonString
# ifdef USE_THUMBNAILS
# ifndef tableHeaderFileThumbnailsString
# define tableHeaderFileThumbnailsString "Thumbnails"
# endif // tableHeaderFileThumbnailsString
# ifndef DisplayMode_FilesList_ButtonString
# define DisplayMode_FilesList_ButtonString "FL"
# endif // DisplayMode_FilesList_ButtonString
# ifndef DisplayMode_FilesList_ButtonHelp
# define DisplayMode_FilesList_ButtonHelp "File List"
# endif // DisplayMode_FilesList_ButtonHelp
# ifndef DisplayMode_ThumbailsList_ButtonString
# define DisplayMode_ThumbailsList_ButtonString "TL"
# endif // DisplayMode_ThumbailsList_ButtonString
# ifndef DisplayMode_ThumbailsList_ButtonHelp
# define DisplayMode_ThumbailsList_ButtonHelp "Thumbnails List"
# endif // DisplayMode_ThumbailsList_ButtonHelp
# ifndef DisplayMode_ThumbailsGrid_ButtonString
# define DisplayMode_ThumbailsGrid_ButtonString "TG"
# endif // DisplayMode_ThumbailsGrid_ButtonString
# ifndef DisplayMode_ThumbailsGrid_ButtonHelp
# define DisplayMode_ThumbailsGrid_ButtonHelp "Thumbnails Grid"
# endif // DisplayMode_ThumbailsGrid_ButtonHelp
# ifndef DisplayMode_ThumbailsList_ImageHeight
# define DisplayMode_ThumbailsList_ImageHeight 32.0f
# endif // DisplayMode_ThumbailsList_ImageHeight
# ifndef IMGUI_RADIO_BUTTON
2023-06-16 21:26:22 +00:00
inline bool inRadioButton ( const char * vLabel , bool vToggled )
{
bool pressed = false ;
if ( vToggled )
{
ImVec4 bua = ImGui : : GetStyleColorVec4 ( ImGuiCol_ButtonActive ) ;
ImVec4 te = ImGui : : GetStyleColorVec4 ( ImGuiCol_Text ) ;
ImGui : : PushStyleColor ( ImGuiCol_Button , te ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , te ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , te ) ;
ImGui : : PushStyleColor ( ImGuiCol_Text , bua ) ;
}
pressed = IMGUI_BUTTON ( vLabel ) ;
if ( vToggled )
{
ImGui : : PopStyleColor ( 4 ) ; //-V112
}
return pressed ;
}
2021-12-11 07:10:09 +00:00
# define IMGUI_RADIO_BUTTON inRadioButton
# endif // IMGUI_RADIO_BUTTON
# endif // USE_THUMBNAILS
# ifdef USE_BOOKMARK
# ifndef defaultBookmarkPaneWith
# define defaultBookmarkPaneWith 150.0f
# endif // defaultBookmarkPaneWith
# ifndef bookmarksButtonString
# define bookmarksButtonString "Bookmark"
# endif // bookmarksButtonString
# ifndef bookmarksButtonHelpString
# define bookmarksButtonHelpString "Bookmark"
# endif // bookmarksButtonHelpString
# ifndef addBookmarkButtonString
# define addBookmarkButtonString "+"
# endif // addBookmarkButtonString
# ifndef removeBookmarkButtonString
# define removeBookmarkButtonString "-"
# endif // removeBookmarkButtonString
# ifndef IMGUI_TOGGLE_BUTTON
2023-06-16 21:26:22 +00:00
inline bool inToggleButton ( const char * vLabel , bool * vToggled )
{
bool pressed = false ;
if ( vToggled & & * vToggled )
{
ImVec4 bua = ImGui : : GetStyleColorVec4 ( ImGuiCol_ButtonActive ) ;
//ImVec4 buh = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered);
//ImVec4 bu = ImGui::GetStyleColorVec4(ImGuiCol_Button);
ImVec4 te = ImGui : : GetStyleColorVec4 ( ImGuiCol_Text ) ;
ImGui : : PushStyleColor ( ImGuiCol_Button , te ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , te ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , te ) ;
ImGui : : PushStyleColor ( ImGuiCol_Text , bua ) ;
}
pressed = IMGUI_BUTTON ( vLabel ) ;
if ( vToggled & & * vToggled )
{
ImGui : : PopStyleColor ( 4 ) ; //-V112
}
if ( vToggled & & pressed )
* vToggled = ! * vToggled ;
return pressed ;
}
2021-12-11 07:10:09 +00:00
# define IMGUI_TOGGLE_BUTTON inToggleButton
# endif // IMGUI_TOGGLE_BUTTON
# endif // USE_BOOKMARK
2023-06-16 21:26:22 +00:00
/////////////////////////////////////////////////////////////////////////////////////
//// INLINE FUNCTIONS ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
inline int inAlphaSort ( const struct dirent * * a , const struct dirent * * b )
{
return strcoll ( ( * a ) - > d_name , ( * b ) - > d_name ) ;
}
/////////////////////////////////////////////////////////////////////////////////////
//// FILE EXTENTIONS INFOS //////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
IGFD : : FileStyle : : FileStyle ( )
: color ( 0 , 0 , 0 , 0 )
{
}
IGFD : : FileStyle : : FileStyle ( const FileStyle & vStyle )
{
color = vStyle . color ;
icon = vStyle . icon ;
font = vStyle . font ;
flags = vStyle . flags ;
}
IGFD : : FileStyle : : FileStyle ( const ImVec4 & vColor , const std : : string & vIcon , ImFont * vFont )
: color ( vColor ) , icon ( vIcon ) , font ( vFont )
{
}
/////////////////////////////////////////////////////////////////////////////////////
//// FILE INFOS /////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// https://github.com/ocornut/imgui/issues/1720
bool IGFD : : Utils : : Splitter ( bool split_vertically , float thickness , float * size1 , float * size2 , float min_size1 , float min_size2 , float splitter_long_axis_size )
{
using namespace ImGui ;
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
ImGuiID id = window - > GetID ( " ##Splitter " ) ;
ImRect bb ;
bb . Min = window - > DC . CursorPos + ( split_vertically ? ImVec2 ( * size1 , 0.0f ) : ImVec2 ( 0.0f , * size1 ) ) ;
bb . Max = bb . Min + CalcItemSize ( split_vertically ? ImVec2 ( thickness , splitter_long_axis_size ) : ImVec2 ( splitter_long_axis_size , thickness ) , 0.0f , 0.0f ) ;
return SplitterBehavior ( bb , id , split_vertically ? ImGuiAxis_X : ImGuiAxis_Y , size1 , size2 , min_size1 , min_size2 , 1.0f ) ;
}
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
bool IGFD : : Utils : : WReplaceString ( std : : wstring & str , const std : : wstring & oldStr , const std : : wstring & newStr )
{
bool found = false ;
size_t pos = 0 ;
while ( ( pos = str . find ( oldStr , pos ) ) ! = std : : wstring : : npos )
{
found = true ;
str . replace ( pos , oldStr . length ( ) , newStr ) ;
pos + = newStr . length ( ) ;
}
return found ;
}
std : : vector < std : : wstring > IGFD : : Utils : : WSplitStringToVector ( const std : : wstring & text , char delimiter , bool pushEmpty )
{
std : : vector < std : : wstring > arr ;
if ( ! text . empty ( ) )
{
std : : wstring : : size_type start = 0 ;
std : : wstring : : size_type end = text . find ( delimiter , start ) ;
while ( end ! = std : : wstring : : npos )
{
std : : wstring token = text . substr ( start , end - start ) ;
if ( ! token . empty ( ) | | ( token . empty ( ) & & pushEmpty ) ) //-V728
arr . push_back ( token ) ;
start = end + 1 ;
end = text . find ( delimiter , start ) ;
}
std : : wstring token = text . substr ( start ) ;
if ( ! token . empty ( ) | | ( token . empty ( ) & & pushEmpty ) ) //-V728
arr . push_back ( token ) ;
}
return arr ;
}
std : : wstring IGFD : : Utils : : string_to_wstring ( const std : : string & str )
{
std : : wstring ret ;
if ( ! str . empty ( ) )
{
size_t sz = std : : mbstowcs ( nullptr , str . c_str ( ) , str . size ( ) ) ;
if ( sz )
{
ret . resize ( sz ) ;
std : : mbstowcs ( ( wchar_t * ) ret . data ( ) , str . c_str ( ) , sz ) ;
}
}
return ret ;
}
std : : string IGFD : : Utils : : wstring_to_string ( const std : : wstring & str )
{
std : : string ret ;
if ( ! str . empty ( ) )
{
size_t sz = std : : wcstombs ( nullptr , str . c_str ( ) , str . size ( ) ) ;
if ( sz )
{
ret . resize ( sz ) ;
std : : wcstombs ( ( char * ) ret . data ( ) , str . c_str ( ) , sz ) ;
}
}
return ret ;
}
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
bool IGFD : : Utils : : ReplaceString ( std : : string & str , const std : : string & oldStr , const std : : string & newStr )
{
bool found = false ;
size_t pos = 0 ;
while ( ( pos = str . find ( oldStr , pos ) ) ! = std : : string : : npos )
{
found = true ;
str . replace ( pos , oldStr . length ( ) , newStr ) ;
pos + = newStr . length ( ) ;
}
return found ;
}
std : : vector < std : : string > IGFD : : Utils : : SplitStringToVector ( const std : : string & text , char delimiter , bool pushEmpty )
{
std : : vector < std : : string > arr ;
if ( ! text . empty ( ) )
{
size_t start = 0 ;
size_t end = text . find ( delimiter , start ) ;
while ( end ! = std : : string : : npos )
{
auto token = text . substr ( start , end - start ) ;
if ( ! token . empty ( ) | | ( token . empty ( ) & & pushEmpty ) ) //-V728
arr . push_back ( token ) ;
start = end + 1 ;
end = text . find ( delimiter , start ) ;
}
auto token = text . substr ( start ) ;
if ( ! token . empty ( ) | | ( token . empty ( ) & & pushEmpty ) ) //-V728
arr . push_back ( token ) ;
}
return arr ;
}
std : : vector < std : : string > IGFD : : Utils : : GetDrivesList ( )
{
std : : vector < std : : string > res ;
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
const DWORD mydrives = 2048 ;
char lpBuffer [ 2048 ] ;
2021-12-11 07:10:09 +00:00
# define mini(a,b) (((a) < (b)) ? (a) : (b))
2023-06-16 21:26:22 +00:00
const DWORD countChars = mini ( GetLogicalDriveStringsA ( mydrives , lpBuffer ) , 2047 ) ;
2021-12-11 07:10:09 +00:00
# undef mini
2023-06-16 21:26:22 +00:00
if ( countChars > 0 )
{
std : : string var = std : : string ( lpBuffer , ( size_t ) countChars ) ;
IGFD : : Utils : : ReplaceString ( var , " \\ " , " " ) ;
res = IGFD : : Utils : : SplitStringToVector ( var , ' \0 ' , false ) ;
}
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
return res ;
}
bool IGFD : : Utils : : IsDirectoryExist ( const std : : string & name )
{
bool bExists = false ;
if ( ! name . empty ( ) )
{
DIR * pDir = nullptr ;
pDir = opendir ( name . c_str ( ) ) ;
if ( pDir ! = nullptr )
{
bExists = true ;
( void ) closedir ( pDir ) ;
}
}
return bExists ; // this is not a directory!
}
bool IGFD : : Utils : : CreateDirectoryIfNotExist ( const std : : string & name )
{
bool res = false ;
if ( ! name . empty ( ) )
{
if ( ! IsDirectoryExist ( name ) )
{
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
std : : wstring wname = IGFD : : Utils : : string_to_wstring ( name ) ;
if ( CreateDirectoryW ( wname . c_str ( ) , nullptr ) )
{
res = true ;
}
2021-12-11 07:10:09 +00:00
# elif defined(__EMSCRIPTEN__)
2023-06-16 21:26:22 +00:00
std : : string str = std : : string ( " FS.mkdir(' " ) + name + " '); " ;
emscripten_run_script ( str . c_str ( ) ) ;
res = true ;
2021-12-11 07:10:09 +00:00
# elif defined(UNIX)
2023-06-16 21:26:22 +00:00
char buffer [ PATH_MAX ] = { } ;
snprintf ( buffer , PATH_MAX , " mkdir -p %s " , name . c_str ( ) ) ;
const int dir_err = std : : system ( buffer ) ;
if ( dir_err ! = - 1 )
{
res = true ;
}
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
if ( ! res ) {
std : : cout < < " Error creating directory " < < name < < std : : endl ;
}
}
}
return res ;
}
IGFD : : Utils : : PathStruct IGFD : : Utils : : ParsePathFileName ( const std : : string & vPathFileName )
{
PathStruct res ;
if ( ! vPathFileName . empty ( ) )
{
std : : string pfn = vPathFileName ;
std : : string separator ( 1u , PATH_SEP ) ;
IGFD : : Utils : : ReplaceString ( pfn , " \\ " , separator ) ;
IGFD : : Utils : : ReplaceString ( pfn , " / " , separator ) ;
size_t lastSlash = pfn . find_last_of ( separator ) ;
if ( lastSlash ! = std : : string : : npos )
{
res . name = pfn . substr ( lastSlash + 1 ) ;
res . path = pfn . substr ( 0 , lastSlash ) ;
res . isOk = true ;
}
size_t lastPoint = pfn . find_last_of ( ' . ' ) ;
if ( lastPoint ! = std : : string : : npos )
{
if ( ! res . isOk )
{
res . name = pfn ;
res . isOk = true ;
}
res . ext = pfn . substr ( lastPoint + 1 ) ;
IGFD : : Utils : : ReplaceString ( res . name , " . " + res . ext , " " ) ;
}
2023-03-12 07:06:02 +00:00
if ( res . path . empty ( ) ) {
res . path = separator ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( ! res . isOk )
{
res . name = std : : move ( pfn ) ;
res . isOk = true ;
}
}
return res ;
}
void IGFD : : Utils : : AppendToBuffer ( char * vBuffer , size_t vBufferLen , const std : : string & vStr )
{
std : : string st = vStr ;
size_t len = vBufferLen - 1u ;
size_t slen = strlen ( vBuffer ) ;
if ( ! st . empty ( ) & & st ! = " \n " )
{
IGFD : : Utils : : ReplaceString ( st , " \n " , " " ) ;
IGFD : : Utils : : ReplaceString ( st , " \r " , " " ) ;
}
vBuffer [ slen ] = ' \0 ' ;
std : : string str = std : : string ( vBuffer ) ;
//if (!str.empty()) str += "\n";
str + = vStr ;
if ( len > str . size ( ) ) len = str . size ( ) ;
2021-12-11 07:10:09 +00:00
# ifdef MSVC
2023-06-16 21:26:22 +00:00
strncpy_s ( vBuffer , vBufferLen , str . c_str ( ) , len ) ;
2021-12-11 07:10:09 +00:00
# else // MSVC
2023-06-16 21:26:22 +00:00
strncpy ( vBuffer , str . c_str ( ) , len ) ;
2021-12-11 07:10:09 +00:00
# endif // MSVC
2023-06-16 21:26:22 +00:00
vBuffer [ len ] = ' \0 ' ;
}
void IGFD : : Utils : : ResetBuffer ( char * vBuffer )
{
vBuffer [ 0 ] = ' \0 ' ;
}
void IGFD : : Utils : : SetBuffer ( char * vBuffer , size_t vBufferLen , const std : : string & vStr )
{
ResetBuffer ( vBuffer ) ;
AppendToBuffer ( vBuffer , vBufferLen , vStr ) ;
}
/////////////////////////////////////////////////////////////////////////////////////
//// FILE INFOS /////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
bool IGFD : : FileInfos : : IsTagFound ( const std : : string & vTag ) const
{
if ( ! vTag . empty ( ) )
{
if ( fileNameExt_optimized = = " .. " ) return true ;
return
fileNameExt_optimized . find ( vTag ) ! = std : : string : : npos | | // first try wihtout case and accents
fileNameExt . find ( vTag ) ! = std : : string : : npos ; // second if searched with case and accents
}
// if tag is empty => its a special case but all is found
return true ;
}
/////////////////////////////////////////////////////////////////////////////////////
//// SEARCH MANAGER /////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
void IGFD : : SearchManager : : Clear ( )
{
puSearchTag . clear ( ) ;
IGFD : : Utils : : ResetBuffer ( puSearchBuffer ) ;
}
void IGFD : : SearchManager : : DrawSearchBar ( FileDialogInternal & vFileDialogInternal )
{
// search field
if ( IMGUI_BUTTON ( resetButtonString " ##BtnImGuiFileDialogSearchField " ) )
{
Clear ( ) ;
vFileDialogInternal . puFileManager . ApplyFilteringOnFileList ( vFileDialogInternal ) ;
}
if ( ImGui : : IsItemHovered ( ) )
2024-06-12 20:44:55 +00:00
ImGui : : SetTooltip ( " %s " , FileDialog : : Instance ( ) - > buttonResetSearchString ) ;
2023-06-16 21:26:22 +00:00
ImGui : : SameLine ( ) ;
ImGui : : PushItemWidth ( ImGui : : GetContentRegionAvail ( ) . x ) ;
2024-06-12 20:44:55 +00:00
bool edited = ImGui : : InputTextWithHint ( " ##InputImGuiFileDialogSearchField " , FileDialog : : Instance ( ) - > searchString , puSearchBuffer , MAX_FILE_DIALOG_NAME_BUFFER ) ;
2023-06-16 21:26:22 +00:00
if ( ImGui : : GetItemID ( ) = = ImGui : : GetActiveID ( ) )
puSearchInputIsActive = true ;
ImGui : : PopItemWidth ( ) ;
if ( edited )
{
puSearchTag = puSearchBuffer ;
vFileDialogInternal . puFileManager . ApplyFilteringOnFileList ( vFileDialogInternal ) ;
}
}
/////////////////////////////////////////////////////////////////////////////////////
//// FILTER INFOS ///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
void IGFD : : FilterManager : : FilterInfos : : clear ( )
{
filter . clear ( ) ;
collectionfilters . clear ( ) ;
}
bool IGFD : : FilterManager : : FilterInfos : : empty ( ) const
{
return filter . empty ( ) & & collectionfilters . empty ( ) ;
}
bool IGFD : : FilterManager : : FilterInfos : : exist ( const std : : string & vFilter ) const
{
return filter = = vFilter | | ( collectionfilters . find ( vFilter ) ! = collectionfilters . end ( ) ) ;
}
/////////////////////////////////////////////////////////////////////////////////////
//// FILTER MANAGER /////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
void IGFD : : FilterManager : : ParseFilters ( const char * vFilters )
{
prParsedFilters . clear ( ) ;
if ( vFilters )
puDLGFilters = vFilters ; // file mode
else
puDLGFilters . clear ( ) ; // directory mode
if ( ! puDLGFilters . empty ( ) )
{
// ".*,.cpp,.h,.hpp"
// "Source files{.cpp,.h,.hpp},Image files{.png,.gif,.jpg,.jpeg},.md"
bool currentFilterFound = false ;
size_t nan = std : : string : : npos ;
size_t p = 0 , lp = 0 ;
while ( ( p = puDLGFilters . find_first_of ( " {, " , p ) ) ! = nan )
{
FilterInfos infos ;
if ( puDLGFilters [ p ] = = ' { ' ) // {
{
infos . filter = puDLGFilters . substr ( lp , p - lp ) ;
p + + ;
lp = puDLGFilters . find ( ' } ' , p ) ;
if ( lp ! = nan )
{
std : : string fs = puDLGFilters . substr ( p , lp - p ) ;
auto arr = IGFD : : Utils : : SplitStringToVector ( fs , ' , ' , false ) ;
for ( auto a : arr )
{
2023-09-02 00:59:43 +00:00
infos . firstFilter = a ;
2023-06-16 21:26:22 +00:00
infos . collectionfilters . emplace ( a ) ;
}
}
p = lp + 1 ;
}
else // ,
{
infos . filter = puDLGFilters . substr ( lp , p - lp ) ;
p + + ;
}
if ( ! currentFilterFound & & prSelectedFilter . filter = = infos . filter )
{
currentFilterFound = true ;
prSelectedFilter = infos ;
}
lp = p ;
if ( ! infos . empty ( ) )
prParsedFilters . emplace_back ( infos ) ;
}
std : : string token = puDLGFilters . substr ( lp ) ;
if ( ! token . empty ( ) )
{
FilterInfos infos ;
infos . filter = std : : move ( token ) ;
prParsedFilters . emplace_back ( infos ) ;
}
if ( ! currentFilterFound )
if ( ! prParsedFilters . empty ( ) )
prSelectedFilter = * prParsedFilters . begin ( ) ;
}
}
void IGFD : : FilterManager : : SetSelectedFilterWithExt ( const std : : string & vFilter )
{
if ( ! prParsedFilters . empty ( ) )
{
if ( ! vFilter . empty ( ) )
{
// std::map<std::string, FilterInfos>
for ( const auto & infos : prParsedFilters )
{
if ( vFilter = = infos . filter )
{
prSelectedFilter = infos ;
}
else
{
// maybe this ext is in an extention so we will
// explore the collections is they are existing
for ( const auto & filter : infos . collectionfilters )
{
if ( vFilter = = filter )
{
prSelectedFilter = infos ;
}
}
}
}
}
if ( prSelectedFilter . empty ( ) )
prSelectedFilter = * prParsedFilters . begin ( ) ;
}
}
void IGFD : : FilterManager : : SetFileStyle ( const IGFD_FileStyleFlags & vFlags , const char * vCriteria , const FileStyle & vInfos )
{
std : : string _criteria ;
if ( vCriteria )
_criteria = std : : string ( vCriteria ) ;
prFilesStyle [ vFlags ] [ _criteria ] = std : : make_shared < FileStyle > ( vInfos ) ;
prFilesStyle [ vFlags ] [ _criteria ] - > flags = vFlags ;
}
// will be called internally
// will not been exposed to IGFD API
2023-07-27 05:33:28 +00:00
bool IGFD : : FilterManager : : prFillFileStyle ( FileInfos & vFileInfos ) const
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( ! prFilesStyle . empty ( ) )
2023-06-16 21:26:22 +00:00
{
for ( const auto & _flag : prFilesStyle )
{
for ( const auto & _file : _flag . second )
{
2023-07-27 05:33:28 +00:00
if ( _flag . first & IGFD_FileStyleByTypeDir & & vFileInfos . fileType = = ' d ' )
2023-06-16 21:26:22 +00:00
{
if ( _file . first . empty ( ) ) // for all dirs
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
2023-07-27 05:33:28 +00:00
else if ( _file . first = = vFileInfos . fileNameExt ) // for dirs who are equal to style criteria
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeFile & & vFileInfos . fileType = = ' f ' )
2023-06-16 21:26:22 +00:00
{
if ( _file . first . empty ( ) ) // for all files
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
2023-07-27 05:33:28 +00:00
else if ( _file . first = = vFileInfos . fileNameExt ) // for files who are equal to style criteria
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeLink & & vFileInfos . fileType = = ' l ' )
2023-06-16 21:26:22 +00:00
{
if ( _file . first . empty ( ) ) // for all links
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
2023-07-27 05:33:28 +00:00
else if ( _file . first = = vFileInfos . fileNameExt ) // for links who are equal to style criteria
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
if ( _flag . first & IGFD_FileStyleByExtention )
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
// can make sense for some dirs like the hidden by ex ".git"
2023-07-27 05:33:28 +00:00
if ( _flag . first & IGFD_FileStyleByTypeDir & & vFileInfos . fileType = = ' d ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeFile & & vFileInfos . fileType = = ' f ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeLink & & vFileInfos . fileType = = ' l ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
}
if ( _flag . first & IGFD_FileStyleByFullName )
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileNameExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
2023-07-27 05:33:28 +00:00
if ( _flag . first & IGFD_FileStyleByTypeDir & & vFileInfos . fileType = = ' d ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileNameExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeFile & & vFileInfos . fileType = = ' f ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileNameExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeLink & & vFileInfos . fileType = = ' l ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( _file . first = = vFileInfos . fileNameExt )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
}
if ( _flag . first & IGFD_FileStyleByContainedInFullName )
{
2023-07-27 05:33:28 +00:00
if ( vFileInfos . fileNameExt . find ( _file . first ) ! = std : : string : : npos )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
2023-07-27 05:33:28 +00:00
if ( _flag . first & IGFD_FileStyleByTypeDir & & vFileInfos . fileType = = ' d ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( vFileInfos . fileNameExt . find ( _file . first ) ! = std : : string : : npos )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeFile & & vFileInfos . fileType = = ' f ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( vFileInfos . fileNameExt . find ( _file . first ) ! = std : : string : : npos )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
2023-07-27 05:33:28 +00:00
else if ( _flag . first & IGFD_FileStyleByTypeLink & & vFileInfos . fileType = = ' l ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( vFileInfos . fileNameExt . find ( _file . first ) ! = std : : string : : npos )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vFileInfos . fileStyle = _file . second ;
2023-06-16 21:26:22 +00:00
}
}
}
2023-07-27 05:33:28 +00:00
if ( vFileInfos . fileStyle . use_count ( ) )
2023-06-16 21:26:22 +00:00
return true ;
}
}
}
return false ;
}
void IGFD : : FilterManager : : SetFileStyle ( const IGFD_FileStyleFlags & vFlags , const char * vCriteria , const ImVec4 & vColor , const std : : string & vIcon , ImFont * vFont )
{
std : : string _criteria ;
if ( vCriteria )
_criteria = std : : string ( vCriteria ) ;
prFilesStyle [ vFlags ] [ _criteria ] = std : : make_shared < FileStyle > ( vColor , vIcon , vFont ) ;
prFilesStyle [ vFlags ] [ _criteria ] - > flags = vFlags ;
}
// todo : to refactor this fucking function
bool IGFD : : FilterManager : : GetFileStyle ( const IGFD_FileStyleFlags & vFlags , const std : : string & vCriteria , ImVec4 * vOutColor , std : : string * vOutIcon , ImFont * * vOutFont )
{
if ( vOutColor )
{
if ( ! prFilesStyle . empty ( ) )
{
if ( prFilesStyle . find ( vFlags ) ! = prFilesStyle . end ( ) ) // found
{
if ( vFlags & IGFD_FileStyleByContainedInFullName )
{
// search for vCriteria who are containing the criteria
for ( const auto & _file : prFilesStyle . at ( vFlags ) )
{
if ( vCriteria . find ( _file . first ) ! = std : : string : : npos )
{
if ( _file . second . use_count ( ) )
{
* vOutColor = _file . second - > color ;
if ( vOutIcon )
* vOutIcon = _file . second - > icon ;
if ( vOutFont )
* vOutFont = _file . second - > font ;
return true ;
}
}
}
}
else
{
if ( prFilesStyle . at ( vFlags ) . find ( vCriteria ) ! = prFilesStyle . at ( vFlags ) . end ( ) ) // found
{
* vOutColor = prFilesStyle [ vFlags ] [ vCriteria ] - > color ;
if ( vOutIcon )
* vOutIcon = prFilesStyle [ vFlags ] [ vCriteria ] - > icon ;
if ( vOutFont )
* vOutFont = prFilesStyle [ vFlags ] [ vCriteria ] - > font ;
return true ;
}
}
}
else
{
// search for flag composition
for ( const auto & _flag : prFilesStyle )
{
if ( _flag . first & vFlags )
{
if ( _flag . first & IGFD_FileStyleByContainedInFullName )
{
// search for vCriteria who are containing the criteria
for ( const auto & _file : prFilesStyle . at ( _flag . first ) )
{
if ( vCriteria . find ( _file . first ) ! = std : : string : : npos )
{
if ( _file . second . use_count ( ) )
{
* vOutColor = _file . second - > color ;
if ( vOutIcon )
* vOutIcon = _file . second - > icon ;
if ( vOutFont )
* vOutFont = _file . second - > font ;
return true ;
}
}
}
}
else
{
if ( prFilesStyle . at ( _flag . first ) . find ( vCriteria ) ! = prFilesStyle . at ( _flag . first ) . end ( ) ) // found
{
* vOutColor = prFilesStyle [ _flag . first ] [ vCriteria ] - > color ;
if ( vOutIcon )
* vOutIcon = prFilesStyle [ _flag . first ] [ vCriteria ] - > icon ;
if ( vOutFont )
* vOutFont = prFilesStyle [ _flag . first ] [ vCriteria ] - > font ;
return true ;
}
}
}
}
}
}
}
return false ;
}
void IGFD : : FilterManager : : ClearFilesStyle ( )
{
prFilesStyle . clear ( ) ;
}
bool IGFD : : FilterManager : : IsCoveredByFilters ( const std : : string & vTag ) const
{
if ( ! puDLGFilters . empty ( ) & & ! prSelectedFilter . empty ( ) )
{
// check if current file extention is covered by current filter
// we do that here, for avoid doing that during filelist display
// for better fps
2023-09-02 00:59:43 +00:00
if ( prSelectedFilter . exist ( vTag ) | | prSelectedFilter . firstFilter = = " .* " )
2023-06-16 21:26:22 +00:00
{
return true ;
}
}
return false ;
}
bool IGFD : : FilterManager : : DrawFilterComboBox ( FileDialogInternal & vFileDialogInternal )
{
// combobox of filters
if ( ! puDLGFilters . empty ( ) )
{
ImGui : : SameLine ( ) ;
bool needToApllyNewFilter = false ;
ImGui : : PushItemWidth ( FILTER_COMBO_WIDTH * FileDialog : : Instance ( ) - > DpiScale ) ;
if ( ImGui : : BeginCombo ( " ##Filters " , prSelectedFilter . filter . c_str ( ) , ImGuiComboFlags_None ) )
{
intptr_t i = 0 ;
for ( const auto & filter : prParsedFilters )
{
const bool item_selected = ( filter . filter = = prSelectedFilter . filter ) ;
ImGui : : PushID ( ( void * ) ( intptr_t ) i + + ) ;
if ( ImGui : : Selectable ( filter . filter . c_str ( ) , item_selected ) )
{
prSelectedFilter = filter ;
needToApllyNewFilter = true ;
}
ImGui : : PopID ( ) ;
}
ImGui : : EndCombo ( ) ;
}
ImGui : : PopItemWidth ( ) ;
if ( needToApllyNewFilter )
{
vFileDialogInternal . puFileManager . OpenCurrentPath ( vFileDialogInternal ) ;
}
return needToApllyNewFilter ;
}
return false ;
}
IGFD : : FilterManager : : FilterInfos IGFD : : FilterManager : : GetSelectedFilter ( )
{
return prSelectedFilter ;
}
std : : string IGFD : : FilterManager : : ReplaceExtentionWithCurrentFilter ( const std : : string & vFile ) const
{
auto result = vFile ;
if ( ! result . empty ( ) )
{
// if not a collection we can replace the filter by the extention we want
if ( prSelectedFilter . collectionfilters . empty ( ) )
{
size_t lastPoint = vFile . find_last_of ( ' . ' ) ;
if ( lastPoint ! = std : : string : : npos )
{
result = result . substr ( 0 , lastPoint ) ;
}
result + = prSelectedFilter . filter ;
}
}
return result ;
}
void IGFD : : FilterManager : : SetDefaultFilterIfNotDefined ( )
{
if ( prSelectedFilter . empty ( ) & & // no filter selected
! prParsedFilters . empty ( ) ) // filter exist
prSelectedFilter = * prParsedFilters . begin ( ) ; // we take the first filter
}
/////////////////////////////////////////////////////////////////////////////////////
//// FILE MANAGER ///////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
IGFD : : FileManager : : FileManager ( )
{
puFsRoot = std : : string ( 1u , PATH_SEP ) ;
2023-06-21 09:27:31 +00:00
puSortingDirection [ 0 ] = true ;
for ( int i = 1 ; i < 4 ; i + + ) {
puSortingDirection [ i ] = false ;
2023-06-10 19:37:08 +00:00
}
2023-07-27 05:33:28 +00:00
invalidFile . isValid = false ;
2023-06-16 21:26:22 +00:00
}
void IGFD : : FileManager : : OpenCurrentPath ( const FileDialogInternal & vFileDialogInternal )
{
puShowDrives = false ;
ClearComposer ( ) ;
ClearFileLists ( ) ;
if ( puDLGDirectoryMode ) // directory mode
SetDefaultFileName ( " . " ) ;
else
SetDefaultFileName ( " " ) ;
2023-03-24 05:52:11 +00:00
logV ( " IGFD: OpenCurrentPath() " ) ;
2023-06-16 21:26:22 +00:00
ScanDir ( vFileDialogInternal , GetCurrentPath ( ) ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
void IGFD : : FileManager : : SortFields ( const FileDialogInternal & vFileDialogInternal , const SortingFieldEnum & vSortingField , const bool vCanChangeOrder )
{
2023-03-24 05:52:11 +00:00
logV ( " IGFD: SortFields() " ) ;
2023-06-16 21:26:22 +00:00
if ( vSortingField ! = SortingFieldEnum : : FIELD_NONE )
{
2024-06-12 20:44:55 +00:00
puHeaderFileName = FileDialog : : Instance ( ) - > tableHeaderFileNameString ;
puHeaderFileType = FileDialog : : Instance ( ) - > tableHeaderFileTypeString ;
puHeaderFileSize = FileDialog : : Instance ( ) - > tableHeaderFileSizeString ;
puHeaderFileDate = FileDialog : : Instance ( ) - > tableHeaderFileDateString ;
2021-12-11 07:10:09 +00:00
# ifdef USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
puHeaderFileThumbnails = tableHeaderFileThumbnailsString ;
2021-12-11 07:10:09 +00:00
# endif // #ifdef USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
} else {
2023-03-24 05:52:11 +00:00
logV ( " IGFD: sorting by NONE! " ) ;
}
if ( prFileList . empty ( ) ) {
logV ( " IGFD: with an empty file list? " ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( vSortingField = = SortingFieldEnum : : FIELD_FILENAME )
{
2023-03-24 05:52:11 +00:00
logV ( " IGFD: sorting by name " ) ;
2023-06-16 21:26:22 +00:00
if ( vCanChangeOrder & & puSortingField = = vSortingField ) {
2021-12-11 07:10:09 +00:00
//printf("Change the sorting\n");
2023-06-16 21:26:22 +00:00
puSortingDirection [ 0 ] = ! puSortingDirection [ 0 ] ;
2021-12-11 07:10:09 +00:00
}
2023-06-16 21:26:22 +00:00
if ( puSortingDirection [ 0 ] )
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileName = tableHeaderDescendingIcon + puHeaderFileName ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
// this code fail in c:\\Users with the link "All users". got a invalid comparator
/*
// use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571
// strict ordering for file/directory types beginning in '.'
// common on Linux platforms
2023-07-27 05:33:28 +00:00
if ( a . fileNameExt [ 0 ] = = ' . ' & & b . fileNameExt [ 0 ] ! = ' . ' )
2023-06-16 21:26:22 +00:00
return false ;
2023-07-27 05:33:28 +00:00
if ( a . fileNameExt [ 0 ] ! = ' . ' & & b . fileNameExt [ 0 ] = = ' . ' )
2023-06-16 21:26:22 +00:00
return true ;
2023-07-27 05:33:28 +00:00
if ( a . fileNameExt [ 0 ] = = ' . ' & & b . fileNameExt [ 0 ] = = ' . ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
return ( stricmp ( a . fileNameExt . c_str ( ) , b . fileNameExt . c_str ( ) ) < 0 ) ; // sort in insensitive case
2023-06-16 21:26:22 +00:00
}
*/
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType = = ' d ' ) ; // directory in first
return ( stricmp ( a . fileNameExt . c_str ( ) , b . fileNameExt . c_str ( ) ) < 0 ) ; // sort in insensitive case
2023-06-16 21:26:22 +00:00
} ) ;
}
else
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileName = tableHeaderAscendingIcon + puHeaderFileName ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
// this code fail in c:\\Users with the link "All users". got a invalid comparator
/*
// use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571
// strict ordering for file/directory types beginning in '.'
// common on Linux platforms
2023-07-27 05:33:28 +00:00
if ( a . fileNameExt [ 0 ] = = ' . ' & & b . fileNameExt [ 0 ] ! = ' . ' )
2023-06-16 21:26:22 +00:00
return false ;
2023-07-27 05:33:28 +00:00
if ( a . fileNameExt [ 0 ] ! = ' . ' & & b . fileNameExt [ 0 ] = = ' . ' )
2023-06-16 21:26:22 +00:00
return true ;
2023-07-27 05:33:28 +00:00
if ( a . fileNameExt [ 0 ] = = ' . ' & & b . fileNameExt [ 0 ] = = ' . ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
return ( stricmp ( a . fileNameExt . c_str ( ) , b . fileNameExt . c_str ( ) ) > 0 ) ; // sort in insensitive case
2023-06-16 21:26:22 +00:00
}
*/
2023-07-27 05:33:28 +00:00
return ( stricmp ( a . fileNameExt . c_str ( ) , b . fileNameExt . c_str ( ) ) > 0 ) ; // sort in insensitive case
2023-06-16 21:26:22 +00:00
} ) ;
}
}
else if ( vSortingField = = SortingFieldEnum : : FIELD_TYPE )
{
2023-03-24 05:52:11 +00:00
logV ( " IGFD: sorting by type " ) ;
2023-06-16 21:26:22 +00:00
if ( vCanChangeOrder & & puSortingField = = vSortingField )
puSortingDirection [ 1 ] = ! puSortingDirection [ 1 ] ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( puSortingDirection [ 1 ] )
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileType = tableHeaderDescendingIcon + puHeaderFileType ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType = = ' d ' ) ; // directory in first
return ( a . fileExt < b . fileExt ) ; // else
2023-06-16 21:26:22 +00:00
} ) ;
}
else
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileType = tableHeaderAscendingIcon + puHeaderFileType ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType ! = ' d ' ) ; // directory in last
return ( a . fileExt > b . fileExt ) ; // else
2023-06-16 21:26:22 +00:00
} ) ;
}
}
else if ( vSortingField = = SortingFieldEnum : : FIELD_SIZE )
{
2023-03-24 05:52:11 +00:00
logV ( " IGFD: sorting by size " ) ;
2023-06-16 21:26:22 +00:00
if ( vCanChangeOrder & & puSortingField = = vSortingField )
puSortingDirection [ 2 ] = ! puSortingDirection [ 2 ] ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( puSortingDirection [ 2 ] )
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileSize = tableHeaderDescendingIcon + puHeaderFileSize ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType = = ' d ' ) ; // directory in first
return ( a . fileSize < b . fileSize ) ; // else
2023-06-16 21:26:22 +00:00
} ) ;
}
else
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileSize = tableHeaderAscendingIcon + puHeaderFileSize ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType ! = ' d ' ) ; // directory in last
return ( a . fileSize > b . fileSize ) ; // else
2023-06-16 21:26:22 +00:00
} ) ;
}
}
else if ( vSortingField = = SortingFieldEnum : : FIELD_DATE )
{
2023-03-24 05:52:11 +00:00
logV ( " IGFD: sorting by date " ) ;
2023-06-16 21:26:22 +00:00
if ( vCanChangeOrder & & puSortingField = = vSortingField )
puSortingDirection [ 3 ] = ! puSortingDirection [ 3 ] ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( puSortingDirection [ 3 ] )
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileDate = tableHeaderDescendingIcon + puHeaderFileDate ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType = = ' d ' ) ; // directory in first
return ( a . fileModifDate < b . fileModifDate ) ; // else
2023-06-16 21:26:22 +00:00
} ) ;
}
else
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileDate = tableHeaderAscendingIcon + puHeaderFileDate ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType ! = ' d ' ) ; // directory in last
return ( a . fileModifDate > b . fileModifDate ) ; // else
2023-06-16 21:26:22 +00:00
} ) ;
}
}
2021-12-11 07:10:09 +00:00
# ifdef USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
else if ( vSortingField = = SortingFieldEnum : : FIELD_THUMBNAILS )
{
if ( vCanChangeOrder & & puSortingField = = vSortingField )
puSortingDirection [ 4 ] = ! puSortingDirection [ 4 ] ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
// we will compare thumbnails by :
// 1) width
// 2) height
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( puSortingDirection [ 4 ] )
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileThumbnails = tableHeaderDescendingIcon + puHeaderFileThumbnails ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType = = ' d ' ) ; // directory in first
if ( a . thumbnailInfo . textureWidth = = b . thumbnailInfo . textureWidth )
return ( a . thumbnailInfo . textureHeight < b . thumbnailInfo . textureHeight ) ;
return ( a . thumbnailInfo . textureWidth < b . thumbnailInfo . textureWidth ) ;
2023-06-16 21:26:22 +00:00
} ) ;
}
else
{
2021-12-11 07:10:09 +00:00
# ifdef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
puHeaderFileThumbnails = tableHeaderAscendingIcon + puHeaderFileThumbnails ;
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
std : : sort ( prFileList . begin ( ) , prFileList . end ( ) ,
2023-07-27 05:33:28 +00:00
[ ] ( const FileInfos & a , const FileInfos & b ) - > bool
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( a . fileType ! = b . fileType ) return ( a . fileType ! = ' d ' ) ; // directory in last
if ( a . thumbnailInfo . textureWidth = = b . thumbnailInfo . textureWidth )
return ( a . thumbnailInfo . textureHeight > b . thumbnailInfo . textureHeight ) ;
return ( a . thumbnailInfo . textureWidth > b . thumbnailInfo . textureWidth ) ;
2023-06-16 21:26:22 +00:00
} ) ;
}
}
2021-12-11 07:10:09 +00:00
# endif // USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
if ( vSortingField ! = SortingFieldEnum : : FIELD_NONE )
{
puSortingField = vSortingField ;
}
2021-12-11 07:10:09 +00:00
2023-03-24 05:52:11 +00:00
logV ( " IGFD: applying filtering on file list " ) ;
2023-06-16 21:26:22 +00:00
ApplyFilteringOnFileList ( vFileDialogInternal ) ;
}
void IGFD : : FileManager : : ClearFileLists ( )
{
prFilteredFileList . clear ( ) ;
prFileList . clear ( ) ;
}
std : : string IGFD : : FileManager : : prOptimizeFilenameForSearchOperations ( const std : : string & vFileNameExt )
{
auto fileNameExt = vFileNameExt ;
// convert to lower case
for ( char & c : fileNameExt )
c = ( char ) std : : tolower ( c ) ;
return fileNameExt ;
}
2023-07-27 05:33:28 +00:00
void IGFD : : FileManager : : AddFile ( const FileDialogInternal & vFileDialogInternal , const std : : string & vPath , const std : : string & vFileName , char vFileType , void * ent )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
FileInfos infos ;
2023-06-16 21:26:22 +00:00
2023-07-02 07:17:52 +00:00
# ifdef _WIN32
2023-07-02 07:12:26 +00:00
struct dirent * dent = ( struct dirent * ) ent ;
2023-07-02 07:17:52 +00:00
# endif
2023-07-02 07:12:26 +00:00
2023-07-27 05:33:28 +00:00
infos . filePath = vPath ;
infos . fileNameExt = vFileName ;
infos . fileNameExt_optimized = prOptimizeFilenameForSearchOperations ( infos . fileNameExt ) ;
infos . fileType = vFileType ;
2023-06-16 21:26:22 +00:00
2023-07-27 05:33:28 +00:00
if ( infos . fileNameExt . empty ( ) | | ( ( infos . fileNameExt = = " . " | | infos . fileNameExt = = " .. " ) & & ! vFileDialogInternal . puFilterManager . puDLGFilters . empty ( ) ) ) return ; // filename empty or filename is the current dir '.' //-V807
if ( infos . fileNameExt ! = " .. " & & ( vFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_DontShowHiddenFiles ) & & infos . fileNameExt [ 0 ] = = ' . ' ) // dont show hidden files
if ( ! vFileDialogInternal . puFilterManager . puDLGFilters . empty ( ) | | ( vFileDialogInternal . puFilterManager . puDLGFilters . empty ( ) & & infos . fileNameExt ! = " . " ) ) // except "." if in directory mode //-V728
2023-06-16 21:26:22 +00:00
return ;
2023-07-27 05:33:28 +00:00
if ( infos . fileType = = ' f ' | |
infos . fileType = = ' l ' ) // link can have the same extention of a file
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
size_t lpt = infos . fileNameExt . find_last_of ( ' . ' ) ;
2023-06-16 21:26:22 +00:00
if ( lpt ! = std : : string : : npos )
{
2023-07-27 05:33:28 +00:00
infos . fileExt = infos . fileNameExt . substr ( lpt ) ;
2023-06-16 21:26:22 +00:00
}
2021-12-11 07:10:09 +00:00
2023-07-27 05:33:28 +00:00
for ( char & i : infos . fileExt ) {
2022-02-09 04:13:54 +00:00
if ( i > = ' A ' & & i < = ' Z ' ) i + = ' a ' - ' A ' ;
}
2023-07-27 05:33:28 +00:00
if ( ! vFileDialogInternal . puFilterManager . IsCoveredByFilters ( infos . fileExt ) )
2023-06-16 21:26:22 +00:00
{
return ;
}
}
2021-12-11 07:10:09 +00:00
2023-07-02 07:12:26 +00:00
# ifdef _WIN32
SYSTEMTIME systemTime ;
SYSTEMTIME localTime ;
char timebuf [ 100 ] ;
2023-07-27 06:07:57 +00:00
infos . fileSize = dent - > dwin_size ;
if ( FileTimeToSystemTime ( & dent - > dwin_mtime , & systemTime ) = = TRUE ) {
2023-07-02 07:12:26 +00:00
if ( SystemTimeToTzSpecificLocalTime ( NULL , & systemTime , & localTime ) = = TRUE ) {
snprintf ( timebuf , 99 , " %d/%.2d/%.2d %.2d:%.2d " , localTime . wYear , localTime . wMonth , localTime . wDay , localTime . wHour , localTime . wMinute ) ;
} else {
snprintf ( timebuf , 99 , " %d/%.2d/%.2d %.2d:%.2d " , systemTime . wYear , systemTime . wMonth , systemTime . wDay , systemTime . wHour , systemTime . wMinute ) ;
}
2023-07-27 05:33:28 +00:00
infos . fileModifDate = timebuf ;
2023-07-02 07:12:26 +00:00
} else {
2023-07-27 05:33:28 +00:00
infos . fileModifDate = " ??? " ;
2023-07-02 07:12:26 +00:00
}
# endif
2023-06-16 21:26:22 +00:00
vFileDialogInternal . puFilterManager . prFillFileStyle ( infos ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prCompleteFileInfos ( infos ) ;
prFileList . push_back ( infos ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
void IGFD : : FileManager : : ScanDir ( const FileDialogInternal & vFileDialogInternal , const std : : string & vPath )
{
std : : string path = vPath ;
2023-03-24 05:52:11 +00:00
logV ( " IGFD: ScanDir(%s) " , vPath ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( prCurrentPathDecomposition . empty ( ) )
{
2023-03-24 05:52:11 +00:00
logV ( " IGFD: the current path decomposition is empty. setting. " ) ;
2023-06-16 21:26:22 +00:00
SetCurrentDir ( path ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( ! prCurrentPathDecomposition . empty ( ) )
{
2023-03-24 05:52:11 +00:00
logV ( " IGFD: the current path decomposition is not empty. trying. " ) ;
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
if ( path = = puFsRoot )
path + = std : : string ( 1u , PATH_SEP ) ;
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
ClearFileLists ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
struct dirent * * files = nullptr ;
int n = scandir ( path . c_str ( ) , & files , nullptr , inAlphaSort ) ;
2023-03-24 05:52:11 +00:00
logV ( " IGFD: %d entries in directory " , n ) ;
2023-06-16 21:26:22 +00:00
if ( n > 0 )
{
int i ;
for ( i = 0 ; i < n ; i + + )
{
struct dirent * ent = files [ i ] ;
2023-07-02 07:12:26 +00:00
std : : string where = path + std : : string ( PATH_SEP_STR ) + std : : string ( ent - > d_name ) ;
2023-07-27 05:33:28 +00:00
char fileType = ' f ' ;
2023-07-02 07:12:26 +00:00
# if defined(HAVE_DIRENT_TYPE) || defined(_WIN32)
2023-06-16 21:26:22 +00:00
if ( ent - > d_type ! = DT_UNKNOWN )
{
switch ( ent - > d_type )
{
case DT_REG :
fileType = ' f ' ; break ;
case DT_DIR :
fileType = ' d ' ; break ;
2023-07-27 05:33:28 +00:00
case DT_LNK : {
2023-07-02 07:12:26 +00:00
# ifdef _WIN32
fileType = ' f ' ;
# else
2023-06-16 21:26:22 +00:00
DIR * dirTest = opendir ( where . c_str ( ) ) ;
if ( dirTest = = NULL )
{
if ( errno = = ENOTDIR )
{
fileType = ' f ' ;
}
else
{
2023-07-27 05:33:28 +00:00
// why does 'l' make it crash?
fileType = ' f ' ;
2023-06-16 21:26:22 +00:00
}
}
else
{
fileType = ' d ' ;
closedir ( dirTest ) ;
}
2023-07-02 07:12:26 +00:00
# endif
2023-06-16 21:26:22 +00:00
break ;
}
2023-07-27 05:33:28 +00:00
default :
fileType = ' f ' ; break ;
}
2023-06-16 21:26:22 +00:00
}
else
2022-07-24 03:11:30 +00:00
# endif // HAVE_DIRENT_TYPE
2023-06-16 21:26:22 +00:00
{
2023-07-02 07:12:26 +00:00
# ifndef _WIN32
2023-06-16 21:26:22 +00:00
struct stat filestat ;
if ( stat ( where . c_str ( ) , & filestat ) = = 0 )
{
if ( S_ISDIR ( filestat . st_mode ) )
{
fileType = ' d ' ;
}
else
{
fileType = ' f ' ;
}
}
2023-07-02 07:12:26 +00:00
# endif
2023-06-16 21:26:22 +00:00
}
auto fileNameExt = ent - > d_name ;
2023-07-02 07:12:26 +00:00
AddFile ( vFileDialogInternal , path , fileNameExt , fileType , ent ) ;
2023-06-16 21:26:22 +00:00
}
for ( i = 0 ; i < n ; i + + )
{
free ( files [ i ] ) ;
}
free ( files ) ;
} else {
2023-03-24 05:52:11 +00:00
logV ( " IGFD: it's empty " ) ;
}
2021-12-11 07:10:09 +00:00
2023-03-24 05:52:11 +00:00
logV ( " IGFD: sorting fields... " ) ;
2023-06-16 21:26:22 +00:00
SortFields ( vFileDialogInternal , puSortingField , false ) ;
} else {
2023-03-24 05:52:11 +00:00
logE ( " IGFD: current path decomposition is empty! " ) ;
}
fileListActuallyEmpty = prFileList . empty ( ) ;
2023-06-16 21:26:22 +00:00
}
bool IGFD : : FileManager : : GetDrives ( )
{
auto drives = IGFD : : Utils : : GetDrivesList ( ) ;
if ( ! drives . empty ( ) )
{
prCurrentPath . clear ( ) ;
prCurrentPathDecomposition . clear ( ) ;
ClearFileLists ( ) ;
for ( auto & drive : drives )
{
2023-07-27 05:33:28 +00:00
FileInfos info ;
info . fileNameExt = drive ;
info . fileNameExt_optimized = prOptimizeFilenameForSearchOperations ( drive ) ;
info . fileType = ' d ' ;
2023-06-16 21:26:22 +00:00
2023-07-27 05:33:28 +00:00
if ( ! info . fileNameExt . empty ( ) )
2023-06-16 21:26:22 +00:00
{
prFileList . push_back ( info ) ;
}
}
puShowDrives = true ;
return true ;
}
return false ;
}
bool IGFD : : FileManager : : IsComposerEmpty ( )
{
return prCurrentPathDecomposition . empty ( ) ;
}
size_t IGFD : : FileManager : : GetComposerSize ( )
{
return prCurrentPathDecomposition . size ( ) ;
}
bool IGFD : : FileManager : : IsFileListEmpty ( )
{
return prFileList . empty ( ) ;
}
size_t IGFD : : FileManager : : GetFullFileListSize ( )
{
return prFileList . size ( ) ;
}
2023-07-27 05:33:28 +00:00
const FileInfos & IGFD : : FileManager : : GetFullFileAt ( size_t vIdx )
2023-06-16 21:26:22 +00:00
{
if ( vIdx < prFileList . size ( ) )
return prFileList [ vIdx ] ;
2023-07-27 05:33:28 +00:00
return invalidFile ;
2023-06-16 21:26:22 +00:00
}
bool IGFD : : FileManager : : IsFilteredListEmpty ( )
{
return prFilteredFileList . empty ( ) ;
}
size_t IGFD : : FileManager : : GetFilteredListSize ( )
{
return prFilteredFileList . size ( ) ;
}
2023-07-27 05:33:28 +00:00
const FileInfos & IGFD : : FileManager : : GetFilteredFileAt ( size_t vIdx )
2023-06-16 21:26:22 +00:00
{
if ( vIdx < prFilteredFileList . size ( ) )
return prFilteredFileList [ vIdx ] ;
2023-07-27 05:33:28 +00:00
return invalidFile ;
2023-06-16 21:26:22 +00:00
}
bool IGFD : : FileManager : : IsFileNameSelected ( const std : : string & vFileName )
{
return prSelectedFileNames . find ( vFileName ) ! = prSelectedFileNames . end ( ) ;
}
std : : string IGFD : : FileManager : : GetBack ( )
{
return prCurrentPathDecomposition . back ( ) ;
}
void IGFD : : FileManager : : ClearComposer ( )
{
prCurrentPathDecomposition . clear ( ) ;
}
void IGFD : : FileManager : : ClearAll ( )
{
ClearComposer ( ) ;
ClearFileLists ( ) ;
}
void IGFD : : FileManager : : ApplyFilteringOnFileList ( const FileDialogInternal & vFileDialogInternal )
{
prFilteredFileList . clear ( ) ;
2023-07-27 05:33:28 +00:00
for ( const FileInfos & file : prFileList )
2023-06-16 21:26:22 +00:00
{
bool show = true ;
2023-07-27 05:33:28 +00:00
if ( ! file . IsTagFound ( vFileDialogInternal . puSearchManager . puSearchTag ) ) // if search tag
2023-06-16 21:26:22 +00:00
show = false ;
2023-07-27 05:33:28 +00:00
if ( puDLGDirectoryMode & & file . fileType ! = ' d ' ) // directory mode
2023-06-16 21:26:22 +00:00
show = false ;
if ( show )
prFilteredFileList . push_back ( file ) ;
}
}
std : : string IGFD : : FileManager : : prRoundNumber ( double vvalue , int n )
{
std : : stringstream tmp ;
tmp < < std : : setprecision ( n ) < < std : : fixed < < vvalue ;
return tmp . str ( ) ;
}
std : : string IGFD : : FileManager : : prFormatFileSize ( size_t vByteSize )
{
if ( vByteSize ! = 0 )
{
static double lo = 1024.0 ;
static double ko = 1024.0 * 1024.0 ;
static double mo = 1024.0 * 1024.0 * 1024.0 ;
auto v = ( double ) vByteSize ;
if ( v < lo )
return prRoundNumber ( v , 0 ) ; // octet
else if ( v < ko )
return prRoundNumber ( v / lo , 2 ) + " K " ; // ko
else if ( v < mo )
return prRoundNumber ( v / ko , 2 ) + " M " ; // Mo
else
return prRoundNumber ( v / mo , 2 ) + " G " ; // Go
}
return " " ;
}
2023-07-27 05:33:28 +00:00
void IGFD : : FileManager : : prCompleteFileInfos ( FileInfos & vInfos )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
if ( vInfos . fileNameExt ! = " . " & &
vInfos . fileNameExt ! = " .. " )
2023-06-16 21:26:22 +00:00
{
// _stat struct :
//dev_t st_dev; /* ID of device containing file */
//ino_t st_ino; /* inode number */
//mode_t st_mode; /* protection */
//nlink_t st_nlink; /* number of hard links */
//uid_t st_uid; /* user ID of owner */
//gid_t st_gid; /* group ID of owner */
//dev_t st_rdev; /* device ID (if special file) */
//off_t st_size; /* total size, in bytes */
//blksize_t st_blksize; /* blocksize for file system I/O */
//blkcnt_t st_blocks; /* number of 512B blocks allocated */
//time_t st_atime; /* time of last access - not sure out of ntfs */
//time_t st_mtime; /* time of last modification - not sure out of ntfs */
//time_t st_ctime; /* time of last status change - not sure out of ntfs */
2023-07-02 07:12:26 +00:00
# ifdef _WIN32
2023-07-27 06:28:03 +00:00
if ( vInfos . fileType ! = ' d ' )
2023-07-02 07:12:26 +00:00
{
2023-07-27 06:28:03 +00:00
vInfos . formatedFileSize = prFormatFileSize ( vInfos . fileSize ) ;
2023-07-02 07:12:26 +00:00
}
# else
2023-06-16 21:26:22 +00:00
std : : string fpn ;
2023-07-27 05:33:28 +00:00
if ( vInfos . fileType = = ' f ' | | vInfos . fileType = = ' l ' | | vInfos . fileType = = ' d ' ) // file
fpn = vInfos . filePath + std : : string ( 1u , PATH_SEP ) + vInfos . fileNameExt ;
2023-06-16 21:26:22 +00:00
struct stat statInfos = { } ;
char timebuf [ 100 ] ;
int result = stat ( fpn . c_str ( ) , & statInfos ) ;
if ( result ! = - 1 )
{
2023-07-27 05:33:28 +00:00
if ( vInfos . fileType ! = ' d ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
vInfos . fileSize = ( size_t ) statInfos . st_size ;
vInfos . formatedFileSize = prFormatFileSize ( vInfos . fileSize ) ;
2023-06-16 21:26:22 +00:00
}
size_t len = 0 ;
2021-12-11 07:10:09 +00:00
# ifdef MSVC
2023-06-16 21:26:22 +00:00
struct tm _tm ;
errno_t err = localtime_s ( & _tm , & statInfos . st_mtime ) ;
2024-06-12 20:44:55 +00:00
if ( ! err ) len = strftime ( timebuf , 99 , FileDialog : : Instance ( ) - > DateTimeFormat , & _tm ) ;
2021-12-11 07:10:09 +00:00
# else // MSVC
2023-06-16 21:26:22 +00:00
struct tm * _tm = localtime ( & statInfos . st_mtime ) ;
2024-06-12 20:44:55 +00:00
if ( _tm ) len = strftime ( timebuf , 99 , FileDialog : : Instance ( ) - > DateTimeFormat , _tm ) ;
2021-12-11 07:10:09 +00:00
# endif // MSVC
2023-06-16 21:26:22 +00:00
if ( len )
{
2023-07-27 05:33:28 +00:00
vInfos . fileModifDate = std : : string ( timebuf , len ) ;
2023-06-16 21:26:22 +00:00
}
} else {
2023-07-27 05:33:28 +00:00
vInfos . fileSize = 0 ;
vInfos . formatedFileSize = prFormatFileSize ( vInfos . fileSize ) ;
vInfos . fileModifDate = " ??? " ;
2022-06-15 07:03:20 +00:00
}
2023-07-02 07:12:26 +00:00
# endif
2023-06-16 21:26:22 +00:00
}
}
void IGFD : : FileManager : : prRemoveFileNameInSelection ( const std : : string & vFileName )
{
prSelectedFileNames . erase ( vFileName ) ;
if ( prSelectedFileNames . size ( ) = = 1 )
{
snprintf ( puFileNameBuffer , MAX_FILE_DIALOG_NAME_BUFFER , " %s " , vFileName . c_str ( ) ) ;
}
else
{
snprintf ( puFileNameBuffer , MAX_FILE_DIALOG_NAME_BUFFER , " %zu files Selected " , prSelectedFileNames . size ( ) ) ;
}
}
void IGFD : : FileManager : : prAddFileNameInSelection ( const std : : string & vFileName , bool vSetLastSelectionFileName )
{
prSelectedFileNames . emplace ( vFileName ) ;
if ( prSelectedFileNames . size ( ) = = 1 )
{
snprintf ( puFileNameBuffer , MAX_FILE_DIALOG_NAME_BUFFER , " %s " , vFileName . c_str ( ) ) ;
}
else
{
snprintf ( puFileNameBuffer , MAX_FILE_DIALOG_NAME_BUFFER , " %zu files Selected " , prSelectedFileNames . size ( ) ) ;
}
if ( vSetLastSelectionFileName )
prLastSelectedFileName = vFileName ;
}
void IGFD : : FileManager : : SetCurrentDir ( const std : : string & vPath )
{
std : : string path = vPath ;
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
if ( puFsRoot = = path )
path + = std : : string ( 1u , PATH_SEP ) ;
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
DIR * dir = opendir ( path . c_str ( ) ) ;
if ( dir = = nullptr )
{
path = " . " ;
dir = opendir ( path . c_str ( ) ) ;
}
if ( dir ! = nullptr )
{
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
DWORD numchar = 0 ;
// numchar = GetFullPathNameA(path.c_str(), PATH_MAX, real_path, nullptr);
std : : wstring wpath = IGFD : : Utils : : string_to_wstring ( path ) ;
numchar = GetFullPathNameW ( wpath . c_str ( ) , 0 , nullptr , nullptr ) ;
std : : wstring fpath ( numchar , 0 ) ;
GetFullPathNameW ( wpath . c_str ( ) , numchar , ( wchar_t * ) fpath . data ( ) , nullptr ) ;
std : : string real_path = IGFD : : Utils : : wstring_to_string ( fpath ) ;
if ( real_path . back ( ) = = ' \0 ' ) // for fix issue we can have with std::string concatenation.. if there is a \0 at end
real_path = real_path . substr ( 0 , real_path . size ( ) - 1U ) ;
if ( ! real_path . empty ( ) )
2021-12-11 07:10:09 +00:00
# elif defined(UNIX) // UNIX is LINUX or APPLE
2023-06-16 21:26:22 +00:00
char real_path [ PATH_MAX ] ;
char * numchar = realpath ( path . c_str ( ) , real_path ) ;
if ( numchar ! = nullptr )
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
{
prCurrentPath = std : : move ( real_path ) ;
if ( prCurrentPath [ prCurrentPath . size ( ) - 1 ] = = PATH_SEP )
{
prCurrentPath = prCurrentPath . substr ( 0 , prCurrentPath . size ( ) - 1 ) ;
}
IGFD : : Utils : : SetBuffer ( puInputPathBuffer , MAX_PATH_BUFFER_SIZE , prCurrentPath ) ;
prCurrentPathDecomposition = IGFD : : Utils : : SplitStringToVector ( prCurrentPath , PATH_SEP , false ) ;
2021-12-11 07:10:09 +00:00
# ifdef UNIX // UNIX is LINUX or APPLE
2023-06-16 21:26:22 +00:00
prCurrentPathDecomposition . insert ( prCurrentPathDecomposition . begin ( ) , std : : string ( 1u , PATH_SEP ) ) ;
2021-12-11 07:10:09 +00:00
# endif // UNIX
2023-06-16 21:26:22 +00:00
if ( ! prCurrentPathDecomposition . empty ( ) )
{
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
puFsRoot = prCurrentPathDecomposition [ 0 ] ;
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
}
}
closedir ( dir ) ;
}
}
bool IGFD : : FileManager : : CreateDir ( const std : : string & vPath )
{
bool res = false ;
if ( ! vPath . empty ( ) )
{
std : : string path = prCurrentPath + std : : string ( 1u , PATH_SEP ) + vPath ;
res = IGFD : : Utils : : CreateDirectoryIfNotExist ( path ) ;
}
return res ;
}
void IGFD : : FileManager : : ComposeNewPath ( std : : vector < std : : string > : : iterator vIter )
{
std : : string res ;
while ( true )
{
if ( ! res . empty ( ) )
{
2021-12-11 07:10:09 +00:00
# ifdef WIN32
2023-06-16 21:26:22 +00:00
res = * vIter + std : : string ( 1u , PATH_SEP ) + res ;
2021-12-11 07:10:09 +00:00
# elif defined(UNIX) // UNIX is LINUX or APPLE
2023-06-16 21:26:22 +00:00
if ( * vIter = = puFsRoot )
res = * vIter + res ;
else
res = * vIter + PATH_SEP + res ;
# endif // WIN32
}
else
res = * vIter ;
if ( vIter = = prCurrentPathDecomposition . begin ( ) )
{
# if defined(UNIX) // UNIX is LINUX or APPLE
if ( res [ 0 ] ! = PATH_SEP )
res = PATH_SEP + res ;
# endif // defined(UNIX)
break ;
}
- - vIter ;
}
prCurrentPath = std : : move ( res ) ;
}
bool IGFD : : FileManager : : SetPathOnParentDirectoryIfAny ( )
{
if ( prCurrentPathDecomposition . size ( ) > 1 )
{
ComposeNewPath ( prCurrentPathDecomposition . end ( ) - 2 ) ;
return true ;
}
return false ;
}
std : : string IGFD : : FileManager : : GetCurrentPath ( )
{
if ( prCurrentPath . empty ( ) )
prCurrentPath = " . " ;
return prCurrentPath ;
}
void IGFD : : FileManager : : SetCurrentPath ( const std : : string & vCurrentPath )
{
if ( vCurrentPath . empty ( ) )
prCurrentPath = " . " ;
else
prCurrentPath = vCurrentPath ;
}
2023-09-10 08:38:10 +00:00
bool IGFD : : FileManager : : IsFileExist ( const std : : string & vFile , const std : : string & vFileExt )
2023-06-16 21:26:22 +00:00
{
std : : ifstream docFile ( vFile , std : : ios : : in ) ;
2023-09-10 08:38:10 +00:00
logV ( " IGFD: IsFileExist(%s) " , vFile ) ;
2023-06-16 21:26:22 +00:00
if ( docFile . is_open ( ) )
{
docFile . close ( ) ;
return true ;
}
2023-09-10 08:38:10 +00:00
std : : ifstream docFileE ( vFile + vFileExt , std : : ios : : in ) ;
logV ( " IGFD: IsFileExist(%s) " , vFile + vFileExt ) ;
if ( docFileE . is_open ( ) )
{
docFileE . close ( ) ;
return true ;
}
2023-06-16 21:26:22 +00:00
return false ;
}
void IGFD : : FileManager : : SetDefaultFileName ( const std : : string & vFileName )
{
puDLGDefaultFileName = vFileName ;
IGFD : : Utils : : SetBuffer ( puFileNameBuffer , MAX_FILE_DIALOG_NAME_BUFFER , vFileName ) ;
}
2023-07-27 05:33:28 +00:00
bool IGFD : : FileManager : : SelectDirectory ( const FileInfos & vInfos )
2023-06-16 21:26:22 +00:00
{
bool pathClick = false ;
2023-07-27 05:33:28 +00:00
if ( vInfos . fileNameExt = = " .. " )
2023-06-16 21:26:22 +00:00
{
pathClick = SetPathOnParentDirectoryIfAny ( ) ;
}
else
{
std : : string newPath ;
if ( puShowDrives )
{
2023-07-27 05:33:28 +00:00
newPath = vInfos . fileNameExt + std : : string ( 1u , PATH_SEP ) ;
2023-06-16 21:26:22 +00:00
}
else
{
# ifdef __linux__
if ( puFsRoot = = prCurrentPath )
2023-07-27 05:33:28 +00:00
newPath = prCurrentPath + vInfos . fileNameExt ;
2023-06-16 21:26:22 +00:00
else
# endif // __linux__
2023-07-27 05:33:28 +00:00
newPath = prCurrentPath + std : : string ( 1u , PATH_SEP ) + vInfos . fileNameExt ;
2023-06-16 21:26:22 +00:00
}
if ( IGFD : : Utils : : IsDirectoryExist ( newPath ) )
{
if ( puShowDrives )
{
2023-07-27 05:33:28 +00:00
prCurrentPath = vInfos . fileNameExt ;
2023-06-16 21:26:22 +00:00
puFsRoot = prCurrentPath ;
}
else
{
prCurrentPath = newPath ; //-V820
}
pathClick = true ;
}
}
return pathClick ;
}
2023-07-27 05:33:28 +00:00
void IGFD : : FileManager : : SelectFileName ( const FileDialogInternal & vFileDialogInternal , const FileInfos & vInfos )
2023-06-16 21:26:22 +00:00
{
if ( ImGui : : GetIO ( ) . KeyCtrl )
{
if ( puDLGcountSelectionMax = = 0 ) // infinite selection
{
2023-07-27 05:33:28 +00:00
if ( prSelectedFileNames . find ( vInfos . fileNameExt ) = = prSelectedFileNames . end ( ) ) // not found +> add
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
prAddFileNameInSelection ( vInfos . fileNameExt , true ) ;
2023-06-16 21:26:22 +00:00
}
else // found +> remove
{
2023-07-27 05:33:28 +00:00
prRemoveFileNameInSelection ( vInfos . fileNameExt ) ;
2023-06-16 21:26:22 +00:00
}
}
else // selection limited by size
{
if ( prSelectedFileNames . size ( ) < puDLGcountSelectionMax )
{
2023-07-27 05:33:28 +00:00
if ( prSelectedFileNames . find ( vInfos . fileNameExt ) = = prSelectedFileNames . end ( ) ) // not found +> add
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
prAddFileNameInSelection ( vInfos . fileNameExt , true ) ;
2023-06-16 21:26:22 +00:00
}
else // found +> remove
{
2023-07-27 05:33:28 +00:00
prRemoveFileNameInSelection ( vInfos . fileNameExt ) ;
2023-06-16 21:26:22 +00:00
}
}
}
}
else if ( ImGui : : GetIO ( ) . KeyShift )
{
if ( puDLGcountSelectionMax ! = 1 )
{
prSelectedFileNames . clear ( ) ;
// we will iterate filelist and get the last selection after the start selection
bool startMultiSelection = false ;
2023-07-27 05:33:28 +00:00
std : : string fileNameToSelect = vInfos . fileNameExt ;
2023-06-16 21:26:22 +00:00
std : : string savedLastSelectedFileName ; // for invert selection mode
2023-07-27 05:33:28 +00:00
for ( const FileInfos & file : prFileList )
2023-06-16 21:26:22 +00:00
{
bool canTake = true ;
2023-07-27 05:33:28 +00:00
if ( ! file . IsTagFound ( vFileDialogInternal . puSearchManager . puSearchTag ) ) canTake = false ;
2023-06-16 21:26:22 +00:00
if ( canTake ) // if not filtered, we will take files who are filtered by the dialog
{
2023-07-27 05:33:28 +00:00
if ( file . fileNameExt = = prLastSelectedFileName )
2023-06-16 21:26:22 +00:00
{
startMultiSelection = true ;
prAddFileNameInSelection ( prLastSelectedFileName , false ) ;
}
else if ( startMultiSelection )
{
if ( puDLGcountSelectionMax = = 0 ) // infinite selection
{
2023-07-27 05:33:28 +00:00
prAddFileNameInSelection ( file . fileNameExt , false ) ;
2023-06-16 21:26:22 +00:00
}
else // selection limited by size
{
if ( prSelectedFileNames . size ( ) < puDLGcountSelectionMax )
{
2023-07-27 05:33:28 +00:00
prAddFileNameInSelection ( file . fileNameExt , false ) ;
2023-06-16 21:26:22 +00:00
}
else
{
startMultiSelection = false ;
if ( ! savedLastSelectedFileName . empty ( ) )
prLastSelectedFileName = savedLastSelectedFileName ;
break ;
}
}
}
2023-07-27 05:33:28 +00:00
if ( file . fileNameExt = = fileNameToSelect )
2023-06-16 21:26:22 +00:00
{
if ( ! startMultiSelection ) // we are before the last Selected FileName, so we must inverse
{
savedLastSelectedFileName = prLastSelectedFileName ;
prLastSelectedFileName = fileNameToSelect ;
fileNameToSelect = savedLastSelectedFileName ;
startMultiSelection = true ;
prAddFileNameInSelection ( prLastSelectedFileName , false ) ;
}
else
{
startMultiSelection = false ;
if ( ! savedLastSelectedFileName . empty ( ) )
prLastSelectedFileName = savedLastSelectedFileName ;
break ;
}
}
}
}
}
}
else
{
prSelectedFileNames . clear ( ) ;
IGFD : : Utils : : ResetBuffer ( puFileNameBuffer ) ;
2023-07-27 05:33:28 +00:00
prAddFileNameInSelection ( vInfos . fileNameExt , true ) ;
2023-06-16 21:26:22 +00:00
}
}
void IGFD : : FileManager : : DrawDirectoryCreation ( const FileDialogInternal & vFileDialogInternal )
{
if ( vFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_DisableCreateDirectoryButton )
return ;
if ( IMGUI_BUTTON ( createDirButtonString ) )
{
if ( ! prCreateDirectoryMode )
{
prCreateDirectoryMode = true ;
IGFD : : Utils : : ResetBuffer ( puDirectoryNameBuffer ) ;
}
}
if ( ImGui : : IsItemHovered ( ) )
2024-06-12 20:44:55 +00:00
ImGui : : SetTooltip ( " %s " , FileDialog : : Instance ( ) - > buttonCreateDirString ) ;
2023-06-16 21:26:22 +00:00
if ( prCreateDirectoryMode )
{
ImGui : : SameLine ( ) ;
ImGui : : PushItemWidth ( 100.0f ) ;
ImGui : : InputText ( " ##DirectoryFileName " , puDirectoryNameBuffer , MAX_FILE_DIALOG_NAME_BUFFER ) ;
ImGui : : PopItemWidth ( ) ;
ImGui : : SameLine ( ) ;
2024-06-12 20:44:55 +00:00
if ( IMGUI_BUTTON ( FileDialog : : Instance ( ) - > okButtonString ) )
2023-06-16 21:26:22 +00:00
{
std : : string newDir = std : : string ( puDirectoryNameBuffer ) ;
if ( CreateDir ( newDir ) )
{
SetCurrentPath ( prCurrentPath + std : : string ( 1u , PATH_SEP ) + newDir ) ;
OpenCurrentPath ( vFileDialogInternal ) ;
}
prCreateDirectoryMode = false ;
}
ImGui : : SameLine ( ) ;
2024-06-12 20:44:55 +00:00
if ( IMGUI_BUTTON ( FileDialog : : Instance ( ) - > cancelButtonString ) )
2023-06-16 21:26:22 +00:00
{
prCreateDirectoryMode = false ;
}
}
}
void IGFD : : FileManager : : DrawPathComposer ( const FileDialogInternal & vFileDialogInternal )
{
if ( IMGUI_BUTTON ( homeButtonString ) )
{
SetCurrentPath ( FileDialog : : Instance ( ) - > homePath ) ;
OpenCurrentPath ( vFileDialogInternal ) ;
}
if ( ImGui : : IsItemHovered ( ) )
2024-06-12 20:44:55 +00:00
ImGui : : SetTooltip ( " %s " , FileDialog : : Instance ( ) - > buttonResetPathString ) ;
2023-06-16 21:26:22 +00:00
ImGui : : SameLine ( ) ;
if ( IMGUI_BUTTON ( parentDirString ) )
{
if ( SetPathOnParentDirectoryIfAny ( ) ) {
OpenCurrentPath ( vFileDialogInternal ) ;
}
}
if ( ImGui : : IsItemHovered ( ) )
2024-06-12 20:44:55 +00:00
ImGui : : SetTooltip ( " %s " , FileDialog : : Instance ( ) - > buttonParentDirString ) ;
2023-06-16 21:26:22 +00:00
# ifdef WIN32
ImGui : : SameLine ( ) ;
if ( IMGUI_BUTTON ( drivesButtonString ) )
{
puDrivesClicked = true ;
}
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( buttonDriveString ) ;
2021-12-11 07:10:09 +00:00
# endif // WIN32
2023-06-16 21:26:22 +00:00
ImGui : : SameLine ( ) ;
if ( IMGUI_BUTTON ( editPathButtonString ) )
{
puInputPathActivated = true ;
}
if ( ImGui : : IsItemHovered ( ) )
2024-06-12 20:44:55 +00:00
ImGui : : SetTooltip ( " %s " , FileDialog : : Instance ( ) - > buttonEditPathString ) ;
2023-06-16 21:26:22 +00:00
ImGui : : SameLine ( ) ;
ImGui : : SeparatorEx ( ImGuiSeparatorFlags_Vertical ) ;
// show current path
if ( ! prCurrentPathDecomposition . empty ( ) )
{
ImGui : : SameLine ( ) ;
if ( puInputPathActivated )
{
ImGui : : PushItemWidth ( ImGui : : GetContentRegionAvail ( ) . x ) ;
ImGui : : InputText ( " ##pathedition " , puInputPathBuffer , MAX_PATH_BUFFER_SIZE ) ;
ImGui : : PopItemWidth ( ) ;
}
else
{
int _id = 0 ;
for ( auto itPathDecomp = prCurrentPathDecomposition . begin ( ) ;
itPathDecomp ! = prCurrentPathDecomposition . end ( ) ; + + itPathDecomp )
{
if ( itPathDecomp ! = prCurrentPathDecomposition . begin ( ) )
ImGui : : SameLine ( ) ;
ImGui : : PushID ( _id + + ) ;
bool click = IMGUI_PATH_BUTTON ( ( * itPathDecomp ) . c_str ( ) ) ;
ImGui : : PopID ( ) ;
if ( click )
{
ComposeNewPath ( itPathDecomp ) ;
puPathClicked = true ;
break ;
}
// activate input for path
if ( ImGui : : IsItemClicked ( ImGuiMouseButton_Right ) )
{
ComposeNewPath ( itPathDecomp ) ;
IGFD : : Utils : : SetBuffer ( puInputPathBuffer , MAX_PATH_BUFFER_SIZE , prCurrentPath ) ;
puInputPathActivated = true ;
break ;
}
}
}
}
}
std : : string IGFD : : FileManager : : GetResultingPath ( )
{
std : : string path = prCurrentPath ;
if ( puDLGDirectoryMode ) // if directory mode
{
std : : string selectedDirectory = puFileNameBuffer ;
if ( ! selectedDirectory . empty ( ) & &
selectedDirectory ! = " . " )
path + = std : : string ( 1u , PATH_SEP ) + selectedDirectory ;
}
return path ;
}
std : : string IGFD : : FileManager : : GetResultingFileName ( FileDialogInternal & vFileDialogInternal )
{
if ( ! puDLGDirectoryMode ) // if not directory mode
{
return puFileNameBuffer ; //vFileDialogInternal.puFilterManager.ReplaceExtentionWithCurrentFilter(std::string(puFileNameBuffer));
}
return " " ; // directory mode
}
std : : string IGFD : : FileManager : : GetResultingFilePathName ( FileDialogInternal & vFileDialogInternal )
{
std : : string result = GetResultingPath ( ) ;
std : : string filename = GetResultingFileName ( vFileDialogInternal ) ;
if ( ! filename . empty ( ) )
{
# ifdef UNIX
if ( puFsRoot ! = result )
# endif // UNIX
result + = std : : string ( 1u , PATH_SEP ) ;
result + = filename ;
}
return result ;
}
std : : map < std : : string , std : : string > IGFD : : FileManager : : GetResultingSelection ( )
{
std : : map < std : : string , std : : string > res ;
for ( auto & selectedFileName : prSelectedFileNames )
{
std : : string result = GetResultingPath ( ) ;
# ifdef UNIX
if ( puFsRoot ! = result )
# endif // UNIX
result + = std : : string ( 1u , PATH_SEP ) ;
result + = selectedFileName ;
res [ selectedFileName ] = result ;
}
return res ;
}
/////////////////////////////////////////////////////////////////////////////////////
//// FILE DIALOG INTERNAL ///////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
void IGFD : : FileDialogInternal : : NewFrame ( )
{
puCanWeContinue = true ; // reset flag for possibily validate the dialog
puIsOk = false ; // reset dialog result
puFileManager . puDrivesClicked = false ;
puFileManager . puPathClicked = false ;
puNeedToExitDialog = false ;
# ifdef USE_DIALOG_EXIT_WITH_KEY
if ( ImGui : : IsKeyPressed ( IGFD_EXIT_KEY ) )
{
// we do that here with the data's defined at the last frame
// because escape key can quit input activation and at the end of the frame all flag will be false
// so we will detect nothing
if ( ! ( puFileManager . puInputPathActivated | |
puSearchManager . puSearchInputIsActive | |
puFileInputIsActive | |
puFileListViewIsActive ) )
{
puNeedToExitDialog = true ; // need to quit dialog
}
}
else
# endif
{
puSearchManager . puSearchInputIsActive = false ;
puFileInputIsActive = false ;
puFileListViewIsActive = false ;
}
}
void IGFD : : FileDialogInternal : : EndFrame ( )
{
// directory change
if ( puFileManager . puPathClicked )
{
puFileManager . OpenCurrentPath ( * this ) ;
}
if ( puFileManager . puDrivesClicked )
{
if ( puFileManager . GetDrives ( ) )
{
puFileManager . ApplyFilteringOnFileList ( * this ) ;
}
}
if ( puFileManager . puInputPathActivated )
{
auto gio = ImGui : : GetIO ( ) ;
if ( ImGui : : IsKeyReleased ( ImGuiKey_Enter ) )
{
puFileManager . SetCurrentPath ( std : : string ( puFileManager . puInputPathBuffer ) ) ;
puFileManager . OpenCurrentPath ( * this ) ;
puFileManager . puInputPathActivated = false ;
}
if ( ImGui : : IsKeyReleased ( ImGuiKey_Escape ) )
{
puFileManager . puInputPathActivated = false ;
}
}
}
void IGFD : : FileDialogInternal : : ResetForNewDialog ( )
{
puFileManager . fileListActuallyEmpty = false ;
}
/////////////////////////////////////////////////////////////////////////////////////
//// THUMBNAIL FEATURE //////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
IGFD : : ThumbnailFeature : : ThumbnailFeature ( )
{
# ifdef USE_THUMBNAILS
prDisplayMode = DisplayModeEnum : : FILE_LIST ;
# endif
}
IGFD : : ThumbnailFeature : : ~ ThumbnailFeature ( ) = default ;
void IGFD : : ThumbnailFeature : : NewThumbnailFrame ( FileDialogInternal & vFileDialogInternal )
{
( void ) vFileDialogInternal ;
# ifdef USE_THUMBNAILS
prStartThumbnailFileDatasExtraction ( ) ;
# endif
}
void IGFD : : ThumbnailFeature : : EndThumbnailFrame ( FileDialogInternal & vFileDialogInternal )
{
# ifdef USE_THUMBNAILS
prClearThumbnails ( vFileDialogInternal ) ;
# endif
}
void IGFD : : ThumbnailFeature : : QuitThumbnailFrame ( FileDialogInternal & vFileDialogInternal )
{
# ifdef USE_THUMBNAILS
prStopThumbnailFileDatasExtraction ( ) ;
prClearThumbnails ( vFileDialogInternal ) ;
# endif
}
# ifdef USE_THUMBNAILS
void IGFD : : ThumbnailFeature : : prStartThumbnailFileDatasExtraction ( )
{
const bool res = prThumbnailGenerationThread . use_count ( ) & & prThumbnailGenerationThread - > joinable ( ) ;
if ( ! res )
{
prIsWorking = true ;
prCountFiles = 0U ;
prThumbnailGenerationThread = std : : shared_ptr < std : : thread > (
new std : : thread ( & IGFD : : ThumbnailFeature : : prThreadThumbnailFileDatasExtractionFunc , this ) ,
[ this ] ( std : : thread * obj )
{
prIsWorking = false ;
if ( obj )
obj - > join ( ) ;
} ) ;
}
}
bool IGFD : : ThumbnailFeature : : prStopThumbnailFileDatasExtraction ( )
{
const bool res = prThumbnailGenerationThread . use_count ( ) & & prThumbnailGenerationThread - > joinable ( ) ;
if ( res )
{
prThumbnailGenerationThread . reset ( ) ;
}
return res ;
}
void IGFD : : ThumbnailFeature : : prThreadThumbnailFileDatasExtractionFunc ( )
{
prCountFiles = 0U ;
prIsWorking = true ;
// infinite loop while is thread working
while ( prIsWorking )
{
if ( ! prThumbnailFileDatasToGet . empty ( ) )
{
std : : shared_ptr < FileInfos > file = nullptr ;
prThumbnailFileDatasToGetMutex . lock ( ) ;
//get the first file in the list
file = ( * prThumbnailFileDatasToGet . begin ( ) ) ;
prThumbnailFileDatasToGetMutex . unlock ( ) ;
// retrieve datas of the texture file if its an image file
if ( file . use_count ( ) )
{
if ( file - > fileType = = ' f ' ) //-V522
{
if ( file - > fileExt = = " .png "
| | file - > fileExt = = " .bmp "
| | file - > fileExt = = " .tga "
| | file - > fileExt = = " .jpg " | | file - > fileExt = = " .jpeg "
| | file - > fileExt = = " .gif "
| | file - > fileExt = = " .psd "
| | file - > fileExt = = " .pic "
| | file - > fileExt = = " .ppm " | | file - > fileExt = = " .pgm "
//|| file->fileExt == ".hdr" => format float so in few times
)
{
auto fpn = file - > filePath + std : : string ( 1u , PATH_SEP ) + file - > fileNameExt ;
int w = 0 ;
int h = 0 ;
int chans = 0 ;
uint8_t * datas = stbi_load ( fpn . c_str ( ) , & w , & h , & chans , STBI_rgb_alpha ) ;
if ( datas )
{
if ( w & & h )
{
// resize with respect to glyph ratio
const float ratioX = ( float ) w / ( float ) h ;
const float newX = DisplayMode_ThumbailsList_ImageHeight * ratioX ;
float newY = w / ratioX ;
if ( newX < w )
newY = DisplayMode_ThumbailsList_ImageHeight ;
const auto newWidth = ( int ) newX ;
const auto newHeight = ( int ) newY ;
const auto newBufSize = ( size_t ) ( newWidth * newHeight * 4U ) ; //-V112 //-V1028
auto resizedData = new uint8_t [ newBufSize ] ;
const int resizeSucceeded = stbir_resize_uint8 (
datas , w , h , 0 ,
resizedData , newWidth , newHeight , 0 ,
4 ) ; //-V112
if ( resizeSucceeded )
{
auto th = & file - > thumbnailInfo ;
th - > textureFileDatas = resizedData ;
th - > textureWidth = newWidth ;
th - > textureHeight = newHeight ;
th - > textureChannels = 4 ; //-V112
// we set that at least, because will launch the gpu creation of the texture in the main thread
th - > isReadyToUpload = true ;
// need gpu loading
prAddThumbnailToCreate ( file ) ;
}
}
else
{
printf ( " image loading fail : w:%i h:%i c:%i \n " , w , h , 4 ) ; //-V112
}
stbi_image_free ( datas ) ;
}
}
}
// peu importe le resultat on vire le fichicer
// remove form this list
// write => thread concurency issues
prThumbnailFileDatasToGetMutex . lock ( ) ;
prThumbnailFileDatasToGet . pop_front ( ) ;
prThumbnailFileDatasToGetMutex . unlock ( ) ;
}
}
}
}
inline void inVariadicProgressBar ( float fraction , const ImVec2 & size_arg , const char * fmt , . . . )
{
va_list args ;
va_start ( args , fmt ) ;
char TempBuffer [ 512 ] ;
const int w = vsnprintf ( TempBuffer , 511 , fmt , args ) ;
va_end ( args ) ;
if ( w )
{
ImGui : : ProgressBar ( fraction , size_arg , TempBuffer ) ;
}
}
void IGFD : : ThumbnailFeature : : prDrawThumbnailGenerationProgress ( )
{
if ( prThumbnailGenerationThread . use_count ( ) & & prThumbnailGenerationThread - > joinable ( ) )
{
if ( ! prThumbnailFileDatasToGet . empty ( ) )
{
const auto p = ( float ) ( ( double ) prCountFiles / ( double ) prThumbnailFileDatasToGet . size ( ) ) ; // read => no thread concurency issues
inVariadicProgressBar ( p , ImVec2 ( 50 , 0 ) , " %u/%u " , prCountFiles , ( uint32_t ) prThumbnailFileDatasToGet . size ( ) ) ; // read => no thread concurency issues
ImGui : : SameLine ( ) ;
}
}
}
void IGFD : : ThumbnailFeature : : prAddThumbnailToLoad ( const std : : shared_ptr < FileInfos > & vFileInfos )
{
if ( vFileInfos . use_count ( ) )
{
if ( vFileInfos - > fileType = = ' f ' )
{
if ( vFileInfos - > fileExt = = " .png "
| | vFileInfos - > fileExt = = " .bmp "
| | vFileInfos - > fileExt = = " .tga "
| | vFileInfos - > fileExt = = " .jpg " | | vFileInfos - > fileExt = = " .jpeg "
| | vFileInfos - > fileExt = = " .gif "
| | vFileInfos - > fileExt = = " .psd "
| | vFileInfos - > fileExt = = " .pic "
| | vFileInfos - > fileExt = = " .ppm " | | vFileInfos - > fileExt = = " .pgm "
//|| file->fileExt == ".hdr" => format float so in few times
)
{
// write => thread concurency issues
prThumbnailFileDatasToGetMutex . lock ( ) ;
prThumbnailFileDatasToGet . push_back ( vFileInfos ) ;
vFileInfos - > thumbnailInfo . isLoadingOrLoaded = true ;
prThumbnailFileDatasToGetMutex . unlock ( ) ;
}
}
}
}
void IGFD : : ThumbnailFeature : : prAddThumbnailToCreate ( const std : : shared_ptr < FileInfos > & vFileInfos )
{
if ( vFileInfos . use_count ( ) )
{
// write => thread concurency issues
prThumbnailToCreateMutex . lock ( ) ;
prThumbnailToCreate . push_back ( vFileInfos ) ;
prThumbnailToCreateMutex . unlock ( ) ;
}
}
void IGFD : : ThumbnailFeature : : prAddThumbnailToDestroy ( const IGFD_Thumbnail_Info & vIGFD_Thumbnail_Info )
{
// write => thread concurency issues
prThumbnailToDestroyMutex . lock ( ) ;
prThumbnailToDestroy . push_back ( vIGFD_Thumbnail_Info ) ;
prThumbnailToDestroyMutex . unlock ( ) ;
}
void IGFD : : ThumbnailFeature : : prDrawDisplayModeToolBar ( )
{
if ( IMGUI_RADIO_BUTTON ( DisplayMode_FilesList_ButtonString ,
prDisplayMode = = DisplayModeEnum : : FILE_LIST ) )
prDisplayMode = DisplayModeEnum : : FILE_LIST ;
if ( ImGui : : IsItemHovered ( ) ) ImGui : : SetTooltip ( DisplayMode_FilesList_ButtonHelp ) ;
ImGui : : SameLine ( ) ;
if ( IMGUI_RADIO_BUTTON ( DisplayMode_ThumbailsList_ButtonString ,
prDisplayMode = = DisplayModeEnum : : THUMBNAILS_LIST ) )
prDisplayMode = DisplayModeEnum : : THUMBNAILS_LIST ;
if ( ImGui : : IsItemHovered ( ) ) ImGui : : SetTooltip ( DisplayMode_ThumbailsList_ButtonHelp ) ;
ImGui : : SameLine ( ) ;
/* todo
if ( IMGUI_RADIO_BUTTON ( DisplayMode_ThumbailsGrid_ButtonString ,
prDisplayMode = = DisplayModeEnum : : THUMBNAILS_GRID ) )
prDisplayMode = DisplayModeEnum : : THUMBNAILS_GRID ;
if ( ImGui : : IsItemHovered ( ) ) ImGui : : SetTooltip ( DisplayMode_ThumbailsGrid_ButtonHelp ) ;
ImGui : : SameLine ( ) ;
*/
prDrawThumbnailGenerationProgress ( ) ;
}
void IGFD : : ThumbnailFeature : : prClearThumbnails ( FileDialogInternal & vFileDialogInternal )
{
// directory wil be changed so the file list will be erased
if ( vFileDialogInternal . puFileManager . puPathClicked )
{
size_t count = vFileDialogInternal . puFileManager . GetFullFileListSize ( ) ;
for ( size_t idx = 0U ; idx < count ; idx + + )
{
auto file = vFileDialogInternal . puFileManager . GetFullFileAt ( idx ) ;
if ( file . use_count ( ) )
{
if ( file - > thumbnailInfo . isReadyToDisplay ) //-V522
{
prAddThumbnailToDestroy ( file - > thumbnailInfo ) ;
}
}
}
}
}
void IGFD : : ThumbnailFeature : : SetCreateThumbnailCallback ( const CreateThumbnailFun & vCreateThumbnailFun )
{
prCreateThumbnailFun = vCreateThumbnailFun ;
}
void IGFD : : ThumbnailFeature : : SetDestroyThumbnailCallback ( const DestroyThumbnailFun & vCreateThumbnailFun )
{
prDestroyThumbnailFun = vCreateThumbnailFun ;
}
void IGFD : : ThumbnailFeature : : ManageGPUThumbnails ( )
{
if ( prCreateThumbnailFun )
{
if ( ! prThumbnailToCreate . empty ( ) )
{
for ( const auto & file : prThumbnailToCreate )
{
if ( file . use_count ( ) )
{
prCreateThumbnailFun ( & file - > thumbnailInfo ) ;
}
}
prThumbnailToCreateMutex . lock ( ) ;
prThumbnailToCreate . clear ( ) ;
prThumbnailToCreateMutex . unlock ( ) ;
}
}
else
{
printf ( " No Callback found for create texture \n You need to define the callback with a call to SetCreateThumbnailCallback \n " ) ;
}
if ( prDestroyThumbnailFun )
{
if ( ! prThumbnailToDestroy . empty ( ) )
{
for ( auto thumbnail : prThumbnailToDestroy )
{
prDestroyThumbnailFun ( & thumbnail ) ;
}
prThumbnailToDestroyMutex . lock ( ) ;
prThumbnailToDestroy . clear ( ) ;
prThumbnailToDestroyMutex . unlock ( ) ;
}
}
else
{
printf ( " No Callback found for destroy texture \n You need to define the callback with a call to SetCreateThumbnailCallback \n " ) ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
# endif // USE_THUMBNAILS
/////////////////////////////////////////////////////////////////////////////////////
//// BOOKMARK FEATURE ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
IGFD : : BookMarkFeature : : BookMarkFeature ( )
{
# ifdef USE_BOOKMARK
prBookmarkWidth = defaultBookmarkPaneWith ;
# endif // USE_BOOKMARK
}
# ifdef USE_BOOKMARK
void IGFD : : BookMarkFeature : : prDrawBookmarkButton ( )
{
IMGUI_TOGGLE_BUTTON ( bookmarksButtonString , & prBookmarkPaneShown ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( bookmarksButtonHelpString ) ;
}
bool IGFD : : BookMarkFeature : : prDrawBookmarkPane ( FileDialogInternal & vFileDialogInternal , const ImVec2 & vSize )
{
bool res = false ;
ImGui : : BeginChild ( " ##bookmarkpane " , vSize ) ;
static int selectedBookmarkForEdition = - 1 ;
if ( IMGUI_BUTTON ( addBookmarkButtonString " ##ImGuiFileDialogAddBookmark " ) )
{
if ( ! vFileDialogInternal . puFileManager . IsComposerEmpty ( ) )
{
BookmarkStruct bookmark ;
bookmark . name = vFileDialogInternal . puFileManager . GetBack ( ) ;
bookmark . path = vFileDialogInternal . puFileManager . GetCurrentPath ( ) ;
prBookmarks . push_back ( bookmark ) ;
}
}
if ( selectedBookmarkForEdition > = 0 & &
selectedBookmarkForEdition < ( int ) prBookmarks . size ( ) )
{
ImGui : : SameLine ( ) ;
if ( IMGUI_BUTTON ( removeBookmarkButtonString " ##ImGuiFileDialogAddBookmark " ) )
{
prBookmarks . erase ( prBookmarks . begin ( ) + selectedBookmarkForEdition ) ;
if ( selectedBookmarkForEdition = = ( int ) prBookmarks . size ( ) )
selectedBookmarkForEdition - - ;
2023-03-12 06:48:01 +00:00
}
2023-06-16 21:26:22 +00:00
if ( selectedBookmarkForEdition > = 0 & &
selectedBookmarkForEdition < ( int ) prBookmarks . size ( ) )
{
ImGui : : SameLine ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : PushItemWidth ( vSize . x - ImGui : : GetCursorPosX ( ) ) ;
if ( ImGui : : InputText ( " ##ImGuiFileDialogBookmarkEdit " , prBookmarkEditBuffer , MAX_FILE_DIALOG_NAME_BUFFER ) )
{
prBookmarks [ ( size_t ) selectedBookmarkForEdition ] . name = std : : string ( prBookmarkEditBuffer ) ;
}
ImGui : : PopItemWidth ( ) ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : Separator ( ) ;
if ( ! prBookmarks . empty ( ) )
{
prBookmarkClipper . Begin ( ( int ) prBookmarks . size ( ) , ImGui : : GetTextLineHeightWithSpacing ( ) ) ;
while ( prBookmarkClipper . Step ( ) )
{
for ( int i = prBookmarkClipper . DisplayStart ; i < prBookmarkClipper . DisplayEnd ; i + + )
{
if ( i < 0 ) continue ;
const BookmarkStruct & bookmark = prBookmarks [ ( size_t ) i ] ;
ImGui : : PushID ( i ) ;
if ( ImGui : : Selectable ( bookmark . name . c_str ( ) , selectedBookmarkForEdition = = i ,
ImGuiSelectableFlags_AllowDoubleClick ) |
( selectedBookmarkForEdition = = - 1 & &
bookmark . path = = vFileDialogInternal . puFileManager . GetCurrentPath ( ) ) ) // select if path is current
{
selectedBookmarkForEdition = i ;
IGFD : : Utils : : ResetBuffer ( prBookmarkEditBuffer ) ;
IGFD : : Utils : : AppendToBuffer ( prBookmarkEditBuffer , MAX_FILE_DIALOG_NAME_BUFFER , bookmark . name ) ;
if ( ImGui : : IsMouseDoubleClicked ( 0 ) ) // apply path
{
vFileDialogInternal . puFileManager . SetCurrentPath ( bookmark . path ) ;
vFileDialogInternal . puFileManager . OpenCurrentPath ( vFileDialogInternal ) ;
res = true ;
}
}
ImGui : : PopID ( ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " %s " , bookmark . path . c_str ( ) ) ; //-V111
}
}
prBookmarkClipper . End ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : EndChild ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
std : : string IGFD : : BookMarkFeature : : SerializeBookmarks ( )
{
std : : string res ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
size_t idx = 0 ;
for ( auto & it : prBookmarks )
{
if ( idx + + ! = 0 )
res + = " ## " ; // ## because reserved by imgui, so an input text cant have ##
res + = it . name + " ## " + it . path ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
}
void IGFD : : BookMarkFeature : : DeserializeBookmarks ( const std : : string & vBookmarks )
{
if ( ! vBookmarks . empty ( ) )
{
prBookmarks . clear ( ) ;
auto arr = IGFD : : Utils : : SplitStringToVector ( vBookmarks , ' # ' , false ) ;
for ( size_t i = 0 ; i < arr . size ( ) ; i + = 2 )
{
BookmarkStruct bookmark ;
bookmark . name = arr [ i ] ;
if ( i + 1 < arr . size ( ) ) // for avoid crash if arr size is impair due to user mistake after edition
{
// if bad format we jump this bookmark
bookmark . path = arr [ i + 1 ] ;
prBookmarks . push_back ( bookmark ) ;
}
}
}
}
# endif // USE_BOOKMARK
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
/////////////////////////////////////////////////////////////////////////////////////
//// KEY EXPLORER FEATURE ///////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
KeyExplorerFeature : : KeyExplorerFeature ( ) = default ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
# ifdef USE_EXPLORATION_BY_KEYS
bool IGFD : : KeyExplorerFeature : : prLocateItem_Loop ( FileDialogInternal & vFileDialogInternal , ImWchar vC )
{
bool found = false ;
auto & fdi = vFileDialogInternal . puFileManager ;
if ( ! fdi . IsFilteredListEmpty ( ) )
{
auto countFiles = fdi . GetFilteredListSize ( ) ;
for ( size_t i = prLocateFileByInputChar_lastFileIdx ; i < countFiles ; i + + )
{
auto nfo = fdi . GetFilteredFileAt ( i ) ;
if ( nfo . use_count ( ) )
{
if ( nfo - > fileNameExt_optimized [ 0 ] = = vC | | // lower case search //-V522
nfo - > fileNameExt [ 0 ] = = vC ) // maybe upper case search
{
//float p = ((float)i) * ImGui::GetTextLineHeightWithSpacing();
float p = ( float ) ( ( double ) i / ( double ) countFiles ) * ImGui : : GetScrollMaxY ( ) ;
ImGui : : SetScrollY ( p ) ;
prLocateFileByInputChar_lastFound = true ;
prLocateFileByInputChar_lastFileIdx = i ;
prStartFlashItem ( prLocateFileByInputChar_lastFileIdx ) ;
auto infos = fdi . GetFilteredFileAt ( prLocateFileByInputChar_lastFileIdx ) ;
if ( infos . use_count ( ) )
{
if ( infos - > fileType = = ' d ' ) //-V522
{
if ( fdi . puDLGDirectoryMode ) // directory chooser
{
fdi . SelectFileName ( vFileDialogInternal , infos ) ;
}
}
else
{
fdi . SelectFileName ( vFileDialogInternal , infos ) ;
}
found = true ;
break ;
}
}
}
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return found ;
}
void IGFD : : KeyExplorerFeature : : prLocateByInputKey ( FileDialogInternal & vFileDialogInternal )
{
ImGuiContext & g = * GImGui ;
auto & fdi = vFileDialogInternal . puFileManager ;
if ( ! g . ActiveId & & ! fdi . IsFilteredListEmpty ( ) )
{
auto & queueChar = ImGui : : GetIO ( ) . InputQueueCharacters ;
auto countFiles = fdi . GetFilteredListSize ( ) ;
// point by char
if ( ! queueChar . empty ( ) )
{
ImWchar c = queueChar . back ( ) ;
if ( prLocateFileByInputChar_InputQueueCharactersSize ! = queueChar . size ( ) )
{
if ( c = = prLocateFileByInputChar_lastChar ) // next file starting with same char until
{
if ( prLocateFileByInputChar_lastFileIdx < countFiles - 1U )
prLocateFileByInputChar_lastFileIdx + + ;
else
prLocateFileByInputChar_lastFileIdx = 0 ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( ! prLocateItem_Loop ( vFileDialogInternal , c ) )
{
// not found, loop again from 0 this time
prLocateFileByInputChar_lastFileIdx = 0 ;
prLocateItem_Loop ( vFileDialogInternal , c ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prLocateFileByInputChar_lastChar = c ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prLocateFileByInputChar_InputQueueCharactersSize = queueChar . size ( ) ;
}
}
void IGFD : : KeyExplorerFeature : : prExploreWithkeys ( FileDialogInternal & vFileDialogInternal , ImGuiID vListViewID )
{
auto & fdi = vFileDialogInternal . puFileManager ;
if ( ! fdi . IsFilteredListEmpty ( ) )
{
bool canWeExplore = false ;
bool hasNav = ( ImGui : : GetIO ( ) . ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard ) ;
ImGuiContext & g = * GImGui ;
if ( ! hasNav & & ! g . ActiveId ) // no nav and no activated inputs
canWeExplore = true ;
if ( g . NavId & & g . NavId = = vListViewID )
{
if ( ImGui : : IsKeyPressedMap ( IGFD_KEY_ENTER ) | |
ImGui : : IsKeyPressedMap ( ImGuiKey_KeyPadEnter ) | |
ImGui : : IsKeyPressedMap ( ImGuiKey_Space ) )
{
ImGui : : ActivateItem ( vListViewID ) ;
ImGui : : SetActiveID ( vListViewID , g . CurrentWindow ) ;
}
}
if ( vListViewID = = g . LastActiveId - 1 ) // if listview id is the last acticated nav id (ImGui::ActivateItem(vListViewID);)
canWeExplore = true ;
if ( canWeExplore )
{
if ( ImGui : : IsKeyPressedMap ( ImGuiKey_Escape ) )
{
ImGui : : ClearActiveID ( ) ;
g . LastActiveId = 0 ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
auto countFiles = fdi . GetFilteredListSize ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
// explore
bool exploreByKey = false ;
bool enterInDirectory = false ;
bool exitDirectory = false ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( ( hasNav & & ImGui : : IsKeyPressedMap ( ImGuiKey_UpArrow ) ) | | ( ! hasNav & & ImGui : : IsKeyPressed ( IGFD_KEY_UP ) ) )
{
exploreByKey = true ;
if ( prLocateFileByInputChar_lastFileIdx > 0 )
prLocateFileByInputChar_lastFileIdx - - ;
else
prLocateFileByInputChar_lastFileIdx = countFiles - 1U ;
}
else if ( ( hasNav & & ImGui : : IsKeyPressedMap ( ImGuiKey_DownArrow ) ) | | ( ! hasNav & & ImGui : : IsKeyPressed ( IGFD_KEY_DOWN ) ) )
{
exploreByKey = true ;
if ( prLocateFileByInputChar_lastFileIdx < countFiles - 1U )
prLocateFileByInputChar_lastFileIdx + + ;
else
prLocateFileByInputChar_lastFileIdx = 0U ;
}
else if ( ImGui : : IsKeyReleased ( IGFD_KEY_ENTER ) )
{
exploreByKey = true ;
enterInDirectory = true ;
}
else if ( ImGui : : IsKeyReleased ( IGFD_KEY_BACKSPACE ) )
{
exploreByKey = true ;
exitDirectory = true ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( exploreByKey )
{
//float totalHeight = prFilteredFileList.size() * ImGui::GetTextLineHeightWithSpacing();
float p = ( float ) ( ( double ) prLocateFileByInputChar_lastFileIdx / ( double ) ( countFiles - 1U ) ) * ImGui : : GetScrollMaxY ( ) ; // seems not udpated in tables version outside tables
//float p = ((float)locateFileByInputChar_lastFileIdx) * ImGui::GetTextLineHeightWithSpacing();
ImGui : : SetScrollY ( p ) ;
prStartFlashItem ( prLocateFileByInputChar_lastFileIdx ) ;
auto infos = fdi . GetFilteredFileAt ( prLocateFileByInputChar_lastFileIdx ) ;
if ( infos . use_count ( ) )
{
if ( infos - > fileType = = ' d ' ) //-V522
{
if ( ! fdi . puDLGDirectoryMode | | enterInDirectory )
{
if ( enterInDirectory )
{
if ( fdi . SelectDirectory ( infos ) )
{
// changement de repertoire
vFileDialogInternal . puFileManager . OpenCurrentPath ( vFileDialogInternal ) ;
if ( prLocateFileByInputChar_lastFileIdx > countFiles - 1U )
{
prLocateFileByInputChar_lastFileIdx = 0 ;
}
}
}
}
else // directory chooser
{
fdi . SelectFileName ( vFileDialogInternal , infos ) ;
}
}
else
{
fdi . SelectFileName ( vFileDialogInternal , infos ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( exitDirectory )
{
auto nfo = std : : make_shared < FileInfos > ( ) ;
nfo - > fileNameExt = " .. " ;
if ( fdi . SelectDirectory ( nfo ) )
{
// changement de repertoire
vFileDialogInternal . puFileManager . OpenCurrentPath ( vFileDialogInternal ) ;
if ( prLocateFileByInputChar_lastFileIdx > countFiles - 1U )
{
prLocateFileByInputChar_lastFileIdx = 0 ;
}
}
# ifdef WIN32
else
{
if ( fdi . GetComposerSize ( ) = = 1U )
{
if ( fdi . GetDrives ( ) )
{
fdi . ApplyFilteringOnFileList ( vFileDialogInternal ) ;
}
}
}
# endif // WIN32
}
}
}
}
}
}
bool IGFD : : KeyExplorerFeature : : prFlashableSelectable ( const char * label , bool selected ,
ImGuiSelectableFlags flags , bool vFlashing , const ImVec2 & size_arg )
{
using namespace ImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return false ;
ImGuiContext & g = * GImGui ;
const ImGuiStyle & style = g . Style ;
// Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle.
ImGuiID id = window - > GetID ( label ) ;
ImVec2 label_size = CalcTextSize ( label , nullptr , true ) ;
ImVec2 size ( size_arg . x ! = 0.0f ? size_arg . x : label_size . x , size_arg . y ! = 0.0f ? size_arg . y : label_size . y ) ; //-V550
ImVec2 pos = window - > DC . CursorPos ;
pos . y + = window - > DC . CurrLineTextBaseOffset ;
ItemSize ( size , 0.0f ) ;
// Fill horizontal space
// We don't support (size < 0.0f) in Selectable() because the ItemSpacing extension would make explicitly right-aligned sizes not visibly match other widgets.
const bool span_all_columns = ( flags & ImGuiSelectableFlags_SpanAllColumns ) ! = 0 ;
const float min_x = span_all_columns ? window - > ParentWorkRect . Min . x : pos . x ;
const float max_x = span_all_columns ? window - > ParentWorkRect . Max . x : window - > WorkRect . Max . x ;
if ( fabs ( size_arg . x ) < FLT_EPSILON | | ( flags & ImGuiSelectableFlags_SpanAvailWidth ) )
size . x = ImMax ( label_size . x , max_x - min_x ) ;
// Text stays at the submission position, but bounding box may be extended on both sides
const ImVec2 text_min = pos ;
const ImVec2 text_max ( min_x + size . x , pos . y + size . y ) ;
// Selectables are meant to be tightly packed together with no click-gap, so we extend their box to cover spacing between selectable.
ImRect bb ( min_x , pos . y , text_max . x , text_max . y ) ;
if ( ( flags & ImGuiSelectableFlags_NoPadWithHalfSpacing ) = = 0 )
{
const float spacing_x = span_all_columns ? 0.0f : style . ItemSpacing . x ;
const float spacing_y = style . ItemSpacing . y ;
const float spacing_L = IM_FLOOR ( spacing_x * 0.50f ) ;
const float spacing_U = IM_FLOOR ( spacing_y * 0.50f ) ;
bb . Min . x - = spacing_L ;
bb . Min . y - = spacing_U ;
bb . Max . x + = ( spacing_x - spacing_L ) ;
bb . Max . y + = ( spacing_y - spacing_U ) ;
}
//if (g.IO.KeyCtrl) { GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(0, 255, 0, 255)); }
// Modify ClipRect for the ItemAdd(), faster than doing a PushColumnsBackground/PushTableBackground for every Selectable..
const float backup_clip_rect_min_x = window - > ClipRect . Min . x ;
const float backup_clip_rect_max_x = window - > ClipRect . Max . x ;
if ( span_all_columns )
{
window - > ClipRect . Min . x = window - > ParentWorkRect . Min . x ;
window - > ClipRect . Max . x = window - > ParentWorkRect . Max . x ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
bool item_add ;
const bool disabled_item = ( flags & ImGuiSelectableFlags_Disabled ) ! = 0 ;
if ( disabled_item )
{
ImGuiItemFlags backup_item_flags = g . CurrentItemFlags ;
g . CurrentItemFlags | = ImGuiItemFlags_Disabled ;
item_add = ItemAdd ( bb , id ) ;
g . CurrentItemFlags = backup_item_flags ;
}
else
{
item_add = ItemAdd ( bb , id ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( span_all_columns )
{
window - > ClipRect . Min . x = backup_clip_rect_min_x ;
window - > ClipRect . Max . x = backup_clip_rect_max_x ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( ! item_add )
return false ;
const bool disabled_global = ( g . CurrentItemFlags & ImGuiItemFlags_Disabled ) ! = 0 ;
if ( disabled_item & & ! disabled_global ) // Only testing this as an optimization
BeginDisabled ( true ) ;
// FIXME: We can standardize the behavior of those two, we could also keep the fast path of override ClipRect + full push on render only,
// which would be advantageous since most selectable are not selected.
if ( span_all_columns & & window - > DC . CurrentColumns )
PushColumnsBackground ( ) ;
else if ( span_all_columns & & g . CurrentTable )
TablePushBackgroundChannel ( ) ;
// We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries
ImGuiButtonFlags button_flags = 0 ;
if ( flags & ImGuiSelectableFlags_NoHoldingActiveID ) { button_flags | = ImGuiButtonFlags_NoHoldingActiveId ; }
if ( flags & ImGuiSelectableFlags_SelectOnClick ) { button_flags | = ImGuiButtonFlags_PressedOnClick ; }
if ( flags & ImGuiSelectableFlags_SelectOnRelease ) { button_flags | = ImGuiButtonFlags_PressedOnRelease ; }
if ( flags & ImGuiSelectableFlags_AllowDoubleClick ) { button_flags | = ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnDoubleClick ; }
if ( flags & ImGuiSelectableFlags_AllowItemOverlap ) { button_flags | = ImGuiButtonFlags_AllowItemOverlap ; }
const bool was_selected = selected ;
bool hovered , held ;
bool pressed = ButtonBehavior ( bb , id , & hovered , & held , button_flags ) ;
// Auto-select when moved into
// - This will be more fully fleshed in the range-select branch
// - This is not exposed as it won't nicely work with some user side handling of shift/control
// - We cannot do 'if (g.NavJustMovedToId != id) { selected = false; pressed = was_selected; }' for two reasons
// - (1) it would require focus scope to be set, need exposing PushFocusScope() or equivalent (e.g. BeginSelection() calling PushFocusScope())
// - (2) usage will fail with clipped items
// The multi-select API aim to fix those issues, e.g. may be replaced with a BeginSelection() API.
if ( ( flags & ImGuiSelectableFlags_SelectOnNav ) & & g . NavJustMovedToId ! = 0 & & g . NavJustMovedToFocusScopeId = = window - > DC . NavFocusScopeIdCurrent )
if ( g . NavJustMovedToId = = id )
selected = pressed = true ;
// Update NavId when clicking or when Hovering (this doesn't happen on most widgets), so navigation can be resumed with gamepad/keyboard
if ( pressed | | ( hovered & & ( flags & ImGuiSelectableFlags_SetNavIdOnHover ) ) )
{
if ( ! g . NavDisableMouseHover & & g . NavWindow = = window & & g . NavLayer = = window - > DC . NavLayerCurrent )
{
SetNavID ( id , window - > DC . NavLayerCurrent , window - > DC . NavFocusScopeIdCurrent , ImRect ( bb . Min - window - > Pos , bb . Max - window - > Pos ) ) ;
g . NavDisableHighlight = true ;
}
}
if ( pressed )
MarkItemEdited ( id ) ;
if ( flags & ImGuiSelectableFlags_AllowItemOverlap )
SetItemAllowOverlap ( ) ;
// In this branch, Selectable() cannot toggle the selection so this will never trigger.
if ( selected ! = was_selected ) //-V547
g . LastItemData . StatusFlags | = ImGuiItemStatusFlags_ToggledSelection ;
// Render
if ( ( held & & ( flags & ImGuiSelectableFlags_DrawHoveredWhenHeld ) ) | | vFlashing )
hovered = true ;
if ( hovered | | selected )
{
const ImU32 col = GetColorU32 ( ( held & & hovered ) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header ) ;
RenderFrame ( bb . Min , bb . Max , col , false , 0.0f ) ;
}
RenderNavHighlight ( bb , id , ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding ) ;
if ( span_all_columns & & window - > DC . CurrentColumns )
PopColumnsBackground ( ) ;
else if ( span_all_columns & & g . CurrentTable )
TablePopBackgroundChannel ( ) ;
RenderTextClipped ( text_min , text_max , label , nullptr , & label_size , style . SelectableTextAlign , & bb ) ;
// Automatically close popups
if ( pressed & & ( window - > Flags & ImGuiWindowFlags_Popup ) & & ! ( flags & ImGuiSelectableFlags_DontClosePopups ) & & ! ( g . LastItemData . InFlags & ImGuiItemFlags_SelectableDontClosePopup ) )
CloseCurrentPopup ( ) ;
if ( disabled_item & & ! disabled_global )
EndDisabled ( ) ;
IMGUI_TEST_ENGINE_ITEM_INFO ( id , label , g . LastItemData . StatusFlags ) ;
return pressed ; //-V1020
}
void IGFD : : KeyExplorerFeature : : prStartFlashItem ( size_t vIdx )
{
prFlashAlpha = 1.0f ;
prFlashedItem = vIdx ;
}
bool IGFD : : KeyExplorerFeature : : prBeginFlashItem ( size_t vIdx )
{
bool res = false ;
if ( prFlashedItem = = vIdx & &
std : : abs ( prFlashAlpha - 0.0f ) > 0.00001f )
{
prFlashAlpha - = prFlashAlphaAttenInSecs * ImGui : : GetIO ( ) . DeltaTime ;
if ( prFlashAlpha < 0.0f ) prFlashAlpha = 0.0f ;
ImVec4 hov = ImGui : : GetStyleColorVec4 ( ImGuiCol_HeaderHovered ) ;
hov . w = prFlashAlpha ;
ImGui : : PushStyleColor ( ImGuiCol_HeaderHovered , hov ) ;
res = true ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
void IGFD : : KeyExplorerFeature : : prEndFlashItem ( )
{
ImGui : : PopStyleColor ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
void IGFD : : KeyExplorerFeature : : SetFlashingAttenuationInSeconds ( float vAttenValue )
{
prFlashAlphaAttenInSecs = 1.0f / ImMax ( vAttenValue , 0.01f ) ;
}
2021-12-11 07:10:09 +00:00
# endif // USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
/////////////////////////////////////////////////////////////////////////////////////
//// FILE DIALOG CONSTRUCTOR / DESTRUCTOR ///////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
IGFD : : FileDialog : : FileDialog ( ) : BookMarkFeature ( ) , KeyExplorerFeature ( ) , ThumbnailFeature ( ) { DpiScale = 1.0f ; singleClickSel = false ; mobileMode = false ; }
IGFD : : FileDialog : : ~ FileDialog ( ) = default ;
//////////////////////////////////////////////////////////////////////////////////////////////////
///// FILE DIALOG STANDARD DIALOG ////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
// path and fileNameExt can be specified
void IGFD : : FileDialog : : OpenDialog (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vPath ,
const std : : string & vFileName ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
2022-04-25 23:58:17 +00:00
SelectFun vSelectFun )
2023-06-16 21:26:22 +00:00
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . ResetForNewDialog ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puDLGkey = vKey ;
prFileDialogInternal . puDLGtitle = vTitle ;
prFileDialogInternal . puDLGuserDatas = vUserDatas ;
prFileDialogInternal . puDLGflags = vFlags ;
2022-04-25 23:58:17 +00:00
prFileDialogInternal . puDLGselFun = vSelectFun ;
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puDLGoptionsPane = nullptr ;
prFileDialogInternal . puDLGoptionsPaneWidth = 0.0f ;
prFileDialogInternal . puDLGmodal = false ;
prFileDialogInternal . puFilterManager . puDLGdefaultExt . clear ( ) ;
prFileDialogInternal . puFilterManager . ParseFilters ( vFilters ) ;
prFileDialogInternal . puFileManager . puDLGDirectoryMode = ( vFilters = = nullptr ) ;
if ( vPath . empty ( ) )
prFileDialogInternal . puFileManager . puDLGpath = prFileDialogInternal . puFileManager . GetCurrentPath ( ) ;
else
prFileDialogInternal . puFileManager . puDLGpath = vPath ;
prFileDialogInternal . puFileManager . SetCurrentPath ( vPath ) ;
prFileDialogInternal . puFileManager . puDLGcountSelectionMax = ( size_t ) vCountSelectionMax ;
prFileDialogInternal . puFileManager . SetDefaultFileName ( vFileName ) ;
prFileDialogInternal . puFileManager . ClearAll ( ) ;
prFileDialogInternal . puShowDialog = true ; // open dialog
}
// path and filename are obtained from filePathName
void IGFD : : FileDialog : : OpenDialog (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vFilePathName ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
2022-04-25 23:58:17 +00:00
SelectFun vSelectFun )
2023-06-16 21:26:22 +00:00
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
prFileDialogInternal . ResetForNewDialog ( ) ;
prFileDialogInternal . puDLGkey = vKey ;
prFileDialogInternal . puDLGtitle = vTitle ;
prFileDialogInternal . puDLGoptionsPane = nullptr ;
prFileDialogInternal . puDLGoptionsPaneWidth = 0.0f ;
prFileDialogInternal . puDLGuserDatas = vUserDatas ;
prFileDialogInternal . puDLGflags = vFlags ;
2022-04-25 23:58:17 +00:00
prFileDialogInternal . puDLGselFun = vSelectFun ;
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puDLGmodal = false ;
auto ps = IGFD : : Utils : : ParsePathFileName ( vFilePathName ) ;
if ( ps . isOk )
{
prFileDialogInternal . puFileManager . puDLGpath = ps . path ;
prFileDialogInternal . puFileManager . SetDefaultFileName ( " " ) ;
prFileDialogInternal . puFilterManager . puDLGdefaultExt = " . " + ps . ext ;
}
else
{
prFileDialogInternal . puFileManager . puDLGpath = prFileDialogInternal . puFileManager . GetCurrentPath ( ) ;
prFileDialogInternal . puFileManager . SetDefaultFileName ( " " ) ;
prFileDialogInternal . puFilterManager . puDLGdefaultExt . clear ( ) ;
}
prFileDialogInternal . puFilterManager . ParseFilters ( vFilters ) ;
prFileDialogInternal . puFilterManager . SetSelectedFilterWithExt (
prFileDialogInternal . puFilterManager . puDLGdefaultExt ) ;
prFileDialogInternal . puFileManager . SetCurrentPath ( prFileDialogInternal . puFileManager . puDLGpath ) ;
prFileDialogInternal . puFileManager . puDLGDirectoryMode = ( vFilters = = nullptr ) ;
prFileDialogInternal . puFileManager . puDLGcountSelectionMax = vCountSelectionMax ; //-V101
prFileDialogInternal . puFileManager . ClearAll ( ) ;
prFileDialogInternal . puShowDialog = true ;
}
// with pane
// path and fileNameExt can be specified
void IGFD : : FileDialog : : OpenDialog (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vPath ,
const std : : string & vFileName ,
const PaneFun & vSidePane ,
const float & vSidePaneWidth ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
2022-04-25 23:58:17 +00:00
SelectFun vSelectFun )
2023-06-16 21:26:22 +00:00
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . ResetForNewDialog ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puDLGkey = vKey ;
prFileDialogInternal . puDLGtitle = vTitle ;
prFileDialogInternal . puDLGuserDatas = vUserDatas ;
prFileDialogInternal . puDLGflags = vFlags ;
2022-04-25 23:58:17 +00:00
prFileDialogInternal . puDLGselFun = vSelectFun ;
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puDLGoptionsPane = vSidePane ;
prFileDialogInternal . puDLGoptionsPaneWidth = vSidePaneWidth ;
prFileDialogInternal . puDLGmodal = false ;
prFileDialogInternal . puFilterManager . puDLGdefaultExt . clear ( ) ;
prFileDialogInternal . puFilterManager . ParseFilters ( vFilters ) ;
prFileDialogInternal . puFileManager . puDLGcountSelectionMax = ( size_t ) vCountSelectionMax ;
prFileDialogInternal . puFileManager . puDLGDirectoryMode = ( vFilters = = nullptr ) ;
if ( vPath . empty ( ) )
prFileDialogInternal . puFileManager . puDLGpath = prFileDialogInternal . puFileManager . GetCurrentPath ( ) ;
else
prFileDialogInternal . puFileManager . puDLGpath = vPath ;
prFileDialogInternal . puFileManager . SetCurrentPath ( prFileDialogInternal . puFileManager . puDLGpath ) ;
prFileDialogInternal . puFileManager . SetDefaultFileName ( vFileName ) ;
prFileDialogInternal . puFileManager . ClearAll ( ) ;
prFileDialogInternal . puShowDialog = true ; // open dialog
}
// with pane
// path and filename are obtained from filePathName
void IGFD : : FileDialog : : OpenDialog (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vFilePathName ,
const PaneFun & vSidePane ,
const float & vSidePaneWidth ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
2022-04-25 23:58:17 +00:00
SelectFun vSelectFun )
2023-06-16 21:26:22 +00:00
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
prFileDialogInternal . ResetForNewDialog ( ) ;
prFileDialogInternal . puDLGkey = vKey ;
prFileDialogInternal . puDLGtitle = vTitle ;
prFileDialogInternal . puDLGoptionsPane = vSidePane ;
prFileDialogInternal . puDLGoptionsPaneWidth = vSidePaneWidth ;
prFileDialogInternal . puDLGuserDatas = vUserDatas ;
prFileDialogInternal . puDLGflags = vFlags ;
2022-04-25 23:58:17 +00:00
prFileDialogInternal . puDLGselFun = vSelectFun ;
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puDLGmodal = false ;
auto ps = IGFD : : Utils : : ParsePathFileName ( vFilePathName ) ;
if ( ps . isOk )
{
prFileDialogInternal . puFileManager . puDLGpath = ps . path ;
prFileDialogInternal . puFileManager . SetDefaultFileName ( vFilePathName ) ;
prFileDialogInternal . puFilterManager . puDLGdefaultExt = " . " + ps . ext ;
}
else
{
prFileDialogInternal . puFileManager . puDLGpath = prFileDialogInternal . puFileManager . GetCurrentPath ( ) ;
prFileDialogInternal . puFileManager . SetDefaultFileName ( " " ) ;
prFileDialogInternal . puFilterManager . puDLGdefaultExt . clear ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puFileManager . SetCurrentPath ( prFileDialogInternal . puFileManager . puDLGpath ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puFileManager . puDLGcountSelectionMax = vCountSelectionMax ; //-V101
prFileDialogInternal . puFileManager . puDLGDirectoryMode = ( vFilters = = nullptr ) ;
prFileDialogInternal . puFilterManager . ParseFilters ( vFilters ) ;
prFileDialogInternal . puFilterManager . SetSelectedFilterWithExt (
prFileDialogInternal . puFilterManager . puDLGdefaultExt ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puFileManager . ClearAll ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puShowDialog = true ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
//////////////////////////////////////////////////////////////////////////////////////////////////
///// FILE DIALOG MODAL DIALOG ///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
void IGFD : : FileDialog : : OpenModal (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vPath ,
const std : : string & vFileName ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
SelectFun vSelectFun )
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
OpenDialog (
vKey , vTitle , vFilters ,
vPath , vFileName ,
vCountSelectionMax , vUserDatas , vFlags , vSelectFun ) ;
prFileDialogInternal . puDLGmodal = true ;
}
void IGFD : : FileDialog : : OpenModal (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vFilePathName ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
SelectFun vSelectFun )
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
OpenDialog (
vKey , vTitle , vFilters ,
vFilePathName ,
vCountSelectionMax , vUserDatas , vFlags , vSelectFun ) ;
prFileDialogInternal . puDLGmodal = true ;
}
// with pane
// path and fileNameExt can be specified
void IGFD : : FileDialog : : OpenModal (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vPath ,
const std : : string & vFileName ,
const PaneFun & vSidePane ,
const float & vSidePaneWidth ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
SelectFun vSelectFun )
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
OpenDialog (
vKey , vTitle , vFilters ,
vPath , vFileName ,
vSidePane , vSidePaneWidth ,
vCountSelectionMax , vUserDatas , vFlags , vSelectFun ) ;
prFileDialogInternal . puDLGmodal = true ;
}
// with pane
// path and filename are obtained from filePathName
void IGFD : : FileDialog : : OpenModal (
const std : : string & vKey ,
const std : : string & vTitle ,
const char * vFilters ,
const std : : string & vFilePathName ,
const PaneFun & vSidePane ,
const float & vSidePaneWidth ,
const int & vCountSelectionMax ,
UserDatas vUserDatas ,
ImGuiFileDialogFlags vFlags ,
SelectFun vSelectFun )
{
if ( prFileDialogInternal . puShowDialog ) // if already opened, quit
return ;
OpenDialog (
vKey , vTitle , vFilters ,
vFilePathName ,
vSidePane , vSidePaneWidth ,
vCountSelectionMax , vUserDatas , vFlags , vSelectFun ) ;
prFileDialogInternal . puDLGmodal = true ;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
///// FILE DIALOG DISPLAY FUNCTION ///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
bool IGFD : : FileDialog : : Display ( const std : : string & vKey , ImGuiWindowFlags vFlags , ImVec2 vMinSize , ImVec2 vMaxSize )
{
bool res = false ;
if ( prFileDialogInternal . puShowDialog & & prFileDialogInternal . puDLGkey = = vKey )
{
if ( prFileDialogInternal . puUseCustomLocale )
setlocale ( prFileDialogInternal . puLocaleCategory , prFileDialogInternal . puLocaleBegin . c_str ( ) ) ;
auto & fdFile = prFileDialogInternal . puFileManager ;
auto & fdFilter = prFileDialogInternal . puFilterManager ;
static ImGuiWindowFlags flags ;
// to be sure than only one dialog is displayed per frame
ImGuiContext & g = * GImGui ;
if ( g . FrameCount = = prFileDialogInternal . puLastImGuiFrameCount ) // one instance was displayed this frame before for this key +> quit
return res ;
prFileDialogInternal . puLastImGuiFrameCount = g . FrameCount ; // mark this instance as used this frame
std : : string name = prFileDialogInternal . puDLGtitle + " ## " + prFileDialogInternal . puDLGkey ;
if ( prFileDialogInternal . puName ! = name )
{
fdFile . ClearComposer ( ) ;
fdFile . ClearFileLists ( ) ;
flags = vFlags ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
NewFrame ( ) ;
2021-12-11 07:10:09 +00:00
# ifdef IMGUI_HAS_VIEWPORT
2023-06-16 21:26:22 +00:00
if ( ! ImGui : : GetIO ( ) . ConfigViewportsNoDecoration )
{
// https://github.com/ocornut/imgui/issues/4534
ImGuiWindowClass window_class ;
window_class . ViewportFlagsOverrideClear = ImGuiViewportFlags_NoDecoration ;
ImGui : : SetNextWindowClass ( & window_class ) ;
}
2021-12-11 07:10:09 +00:00
# endif // IMGUI_HAS_VIEWPORT
2023-06-16 21:26:22 +00:00
ImGui : : SetNextWindowSizeConstraints ( vMinSize , vMaxSize ) ;
bool beg = false ;
if ( prFileDialogInternal . puDLGmodal & &
! prFileDialogInternal . puOkResultToConfirm ) // disable modal because the confirm dialog for overwrite is a new modal
{
ImGui : : OpenPopup ( name . c_str ( ) ) ;
beg = ImGui : : BeginPopupModal ( name . c_str ( ) , ( bool * ) nullptr ,
flags | ImGuiWindowFlags_NoScrollbar ) ;
}
else
{
beg = ImGui : : Begin ( name . c_str ( ) , ( bool * ) nullptr , flags | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking ) ;
}
if ( beg )
{
2022-01-20 05:31:36 +00:00
ImGui : : SetWindowPos ( ImVec2 ( ( ImGui : : GetMainViewport ( ) - > Size . x - ImGui : : GetWindowWidth ( ) ) * 0.5f , ( ImGui : : GetMainViewport ( ) - > Size . y - ImGui : : GetWindowHeight ( ) ) * 0.5f ) ) ;
2022-01-31 20:03:10 +00:00
if ( ImGui : : GetWindowSize ( ) . x < vMinSize . x | | ImGui : : GetWindowSize ( ) . y < vMinSize . y ) {
ImGui : : SetWindowSize ( vMinSize , ImGuiCond_Always ) ;
}
2021-12-11 07:10:09 +00:00
# ifdef IMGUI_HAS_VIEWPORT
2023-06-16 21:26:22 +00:00
// if decoration is enabled we disable the resizing feature of imgui for avoid crash with SDL2 and GLFW3
if ( ImGui : : GetIO ( ) . ConfigViewportsNoDecoration )
{
flags = vFlags ;
}
else
{
auto win = ImGui : : GetCurrentWindowRead ( ) ;
if ( win - > Viewport - > Idx ! = 0 )
flags | = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar ;
else
flags = vFlags ;
}
2021-12-11 07:10:09 +00:00
# endif // IMGUI_HAS_VIEWPORT
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puName = name ; //-V820
puAnyWindowsHovered | = ImGui : : IsWindowHovered ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( fdFile . puDLGpath . empty ( ) )
fdFile . puDLGpath = " . " ; // defaut path is '.'
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
fdFilter . SetDefaultFilterIfNotDefined ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
// init list of files
if ( fdFile . IsFileListEmpty ( ) & & ! fdFile . puShowDrives & & ! fdFile . fileListActuallyEmpty )
{
IGFD : : Utils : : ReplaceString ( fdFile . puDLGDefaultFileName , fdFile . puDLGpath , " " ) ; // local path
if ( ! fdFile . puDLGDefaultFileName . empty ( ) )
{
fdFile . SetDefaultFileName ( fdFile . puDLGDefaultFileName ) ;
fdFilter . SetSelectedFilterWithExt ( fdFilter . puDLGdefaultExt ) ;
} else if ( fdFile . puDLGDirectoryMode ) { // directory mode
fdFile . SetDefaultFileName ( " . " ) ;
2023-03-24 05:52:11 +00:00
}
logV ( " IGFD: fdFile.IsFileListEmpty() and !fdFile.puShowDrives " ) ;
2023-06-16 21:26:22 +00:00
fdFile . ScanDir ( prFileDialogInternal , fdFile . puDLGpath ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
// draw dialog parts
prDrawHeader ( ) ; // bookmark, directory, path
res = prDrawContent ( ) ; // bookmark, files view, side pane
bool res1 = prDrawFooter ( ) ; // file field, filter combobox, ok/cancel buttons
2022-02-01 07:52:36 +00:00
if ( ! res ) res = res1 ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
EndFrame ( ) ;
// for display in dialog center, the confirm to overwrite dlg
prFileDialogInternal . puDialogCenterPos = ImGui : : GetCurrentWindowRead ( ) - > ContentRegionRect . GetCenter ( ) ;
// when the confirm to overwrite dialog will appear we need to
// disable the modal mode of the main file dialog
// see prOkResultToConfirm under
if ( prFileDialogInternal . puDLGmodal & &
! prFileDialogInternal . puOkResultToConfirm )
ImGui : : EndPopup ( ) ;
}
// same things here regarding prOkResultToConfirm
if ( ! prFileDialogInternal . puDLGmodal | | prFileDialogInternal . puOkResultToConfirm )
ImGui : : End ( ) ;
// confirm the result and show the confirm to overwrite dialog if needed
res = prConfirm_Or_OpenOverWriteFileDialog_IfNeeded ( res , vFlags ) ;
if ( prFileDialogInternal . puUseCustomLocale )
setlocale ( prFileDialogInternal . puLocaleCategory , prFileDialogInternal . puLocaleEnd . c_str ( ) ) ;
}
return res ;
}
void IGFD : : FileDialog : : NewFrame ( )
{
prFileDialogInternal . NewFrame ( ) ;
NewThumbnailFrame ( prFileDialogInternal ) ;
}
void IGFD : : FileDialog : : EndFrame ( )
{
EndThumbnailFrame ( prFileDialogInternal ) ;
prFileDialogInternal . EndFrame ( ) ;
}
void IGFD : : FileDialog : : QuitFrame ( )
{
QuitThumbnailFrame ( prFileDialogInternal ) ;
}
void IGFD : : FileDialog : : prDrawHeader ( )
{
2021-12-11 07:10:09 +00:00
# ifdef USE_BOOKMARK
2023-06-16 21:26:22 +00:00
prDrawBookmarkButton ( ) ;
ImGui : : SameLine ( ) ;
2021-12-11 07:10:09 +00:00
# endif // USE_BOOKMARK
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puFileManager . DrawDirectoryCreation ( prFileDialogInternal ) ;
ImGui : : SameLine ( ) ;
ImGui : : SeparatorEx ( ImGuiSeparatorFlags_Vertical ) ;
ImGui : : SameLine ( ) ;
prFileDialogInternal . puFileManager . DrawPathComposer ( prFileDialogInternal ) ;
2021-12-11 07:10:09 +00:00
# ifdef USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
if ( ! ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_DisableThumbnailMode ) )
{
prDrawDisplayModeToolBar ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : SeparatorEx ( ImGuiSeparatorFlags_Vertical ) ;
ImGui : : SameLine ( ) ;
}
2021-12-11 07:10:09 +00:00
# endif // USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puSearchManager . DrawSearchBar ( prFileDialogInternal ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
bool IGFD : : FileDialog : : prDrawContent ( )
{
2022-02-01 07:52:36 +00:00
bool escape = false ;
2023-06-16 21:26:22 +00:00
ImVec2 size = ImGui : : GetContentRegionAvail ( ) - ImVec2 ( 0.0f , prFileDialogInternal . puFooterHeight ) ;
2021-12-11 07:10:09 +00:00
# ifdef USE_BOOKMARK
2023-06-16 21:26:22 +00:00
if ( prBookmarkPaneShown )
{
//size.x -= prBookmarkWidth;
float otherWidth = size . x - prBookmarkWidth ;
ImGui : : PushID ( " ##splitterbookmark " ) ;
IGFD : : Utils : : Splitter ( true , 4.0f ,
& prBookmarkWidth , & otherWidth , 10.0f ,
10.0f + prFileDialogInternal . puDLGoptionsPaneWidth , size . y ) ;
ImGui : : PopID ( ) ;
size . x - = otherWidth ;
prDrawBookmarkPane ( prFileDialogInternal , size ) ;
ImGui : : SameLine ( ) ;
}
2021-12-11 07:10:09 +00:00
# endif // USE_BOOKMARK
2023-06-16 21:26:22 +00:00
size . x = ImGui : : GetContentRegionAvail ( ) . x - prFileDialogInternal . puDLGoptionsPaneWidth ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
if ( prFileDialogInternal . puDLGoptionsPane )
{
ImGui : : PushID ( " ##splittersidepane " ) ;
IGFD : : Utils : : Splitter ( true , 4.0f , & size . x , & prFileDialogInternal . puDLGoptionsPaneWidth , 10.0f , 10.0f , size . y ) ;
ImGui : : PopID ( ) ;
}
2021-12-11 07:10:09 +00:00
# ifdef USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
if ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_DisableThumbnailMode )
{
prDrawFileListView ( size ) ;
}
else
{
switch ( prDisplayMode )
{
case DisplayModeEnum : : FILE_LIST :
prDrawFileListView ( size ) ;
break ;
case DisplayModeEnum : : THUMBNAILS_LIST :
prDrawThumbnailsListView ( size ) ;
break ;
case DisplayModeEnum : : THUMBNAILS_GRID :
prDrawThumbnailsGridView ( size ) ;
}
}
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
escape = prDrawFileListView ( size ) ;
2021-12-11 07:10:09 +00:00
# endif // USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
if ( prFileDialogInternal . puDLGoptionsPane )
{
prDrawSidePane ( size . y ) ;
}
2022-02-01 07:52:36 +00:00
return escape ;
2023-06-16 21:26:22 +00:00
}
2021-12-11 07:10:09 +00:00
2023-08-13 22:38:39 +00:00
int IGFD : : FileDialog : : isFileNameValid ( const char * n ) {
# ifdef _WIN32
char lower [ 6 ] ;
int len = strlen ( n ) ;
for ( int i = 0 ; i < 6 ; i + + ) {
lower [ i ] = 0 ;
}
if ( len > = 3 ) {
if ( len > 5 ) len = 5 ;
for ( int i = 0 ; i < len ; i + + ) {
if ( n [ i ] > = ' A ' & & n [ i ] < = ' Z ' ) {
lower [ i ] = n [ i ] + ( ' a ' - ' A ' ) ;
} else {
lower [ i ] = n [ i ] ;
}
}
if ( ( memcmp ( lower , " con " , 3 ) = = 0 | |
memcmp ( lower , " prn " , 3 ) = = 0 | |
memcmp ( lower , " aux " , 3 ) = = 0 | |
memcmp ( lower , " nul " , 3 ) = = 0 ) & &
( len = = 3 | | lower [ 3 ] = = ' . ' ) ) {
return 2 ;
}
if ( len > = 4 ) {
if ( ( memcmp ( lower , " com " , 3 ) | |
memcmp ( lower , " lpt " , 3 ) ) & &
( lower [ 3 ] > = ' 1 ' & & lower [ 3 ] < = ' 9 ' ) & &
( len = = 4 | | lower [ 4 ] = = ' . ' ) ) {
return 2 ;
}
}
}
# endif
2023-09-24 00:37:36 +00:00
for ( const unsigned char * i = ( const unsigned char * ) n ; * i ; i + + ) {
2023-08-13 22:38:39 +00:00
# ifdef _WIN32
if ( * i < 32 ) {
return 3 ;
}
# endif
switch ( * i ) {
# ifdef _WIN32
case ' < ' :
case ' > ' :
case ' : ' :
case ' " ' :
case ' \\ ' :
case ' | ' :
case ' ? ' :
case ' * ' :
# endif
case ' / ' :
return 1 ;
}
}
return 0 ;
}
2023-06-16 21:26:22 +00:00
bool IGFD : : FileDialog : : prDrawFooter ( )
{
auto & fdFile = prFileDialogInternal . puFileManager ;
float posY = ImGui : : GetCursorPos ( ) . y ; // height of last bar calc
2021-12-11 07:10:09 +00:00
2023-08-19 07:30:04 +00:00
ImGui : : AlignTextToFramePadding ( ) ;
2023-06-16 21:26:22 +00:00
if ( ! fdFile . puDLGDirectoryMode )
2024-06-12 20:44:55 +00:00
ImGui : : Text ( " %s " , FileDialog : : Instance ( ) - > fileNameString ) ;
2023-06-16 21:26:22 +00:00
else // directory chooser
2024-06-12 20:44:55 +00:00
ImGui : : Text ( " %s " , FileDialog : : Instance ( ) - > dirNameString ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : SameLine ( ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
// Input file fields
float width = ImGui : : GetContentRegionAvail ( ) . x ;
2022-02-23 02:54:25 +00:00
// fix this! fix this! fix this!
2023-06-16 21:26:22 +00:00
if ( ! fdFile . puDLGDirectoryMode )
width - = FILTER_COMBO_WIDTH * DpiScale ;
ImGui : : PushItemWidth ( width ) ;
ImGui : : InputText ( " ##FileName " , fdFile . puFileNameBuffer , MAX_FILE_DIALOG_NAME_BUFFER ) ;
if ( ImGui : : GetItemID ( ) = = ImGui : : GetActiveID ( ) )
prFileDialogInternal . puFileInputIsActive = true ;
ImGui : : PopItemWidth ( ) ;
// combobox of filters
prFileDialogInternal . puFilterManager . DrawFilterComboBox ( prFileDialogInternal ) ;
bool res = false ;
// OK Button
2023-08-13 22:38:39 +00:00
bool notEmpty = strlen ( fdFile . puFileNameBuffer ) ;
int fileValid = isFileNameValid ( fdFile . puFileNameBuffer ) ;
if ( ! ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite ) ) fileValid = 0 ;
ImGui : : BeginDisabled ( ! ( prFileDialogInternal . puCanWeContinue & & notEmpty & & fileValid = = 0 ) ) ;
2024-06-12 20:44:55 +00:00
std : : string okbs = std : : string ( FileDialog : : Instance ( ) - > okButtonString ) + " ##validationdialog " ;
if ( IMGUI_BUTTON ( okbs . c_str ( ) ) )
2023-06-16 21:26:22 +00:00
{
2023-08-13 22:38:39 +00:00
prFileDialogInternal . puIsOk = true ;
res = true ;
}
2023-08-19 07:29:23 +00:00
ImGui : : EndDisabled ( ) ;
2023-08-13 22:38:39 +00:00
if ( ! ( prFileDialogInternal . puCanWeContinue & & notEmpty & & fileValid = = 0 ) ) {
2023-08-19 07:29:23 +00:00
if ( ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenDisabled ) ) {
2023-08-13 22:38:39 +00:00
if ( ! notEmpty ) {
if ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite ) {
ImGui : : SetTooltip ( " file name is empty " ) ;
} else {
ImGui : : SetTooltip ( " select a file " ) ;
}
} else if ( ! prFileDialogInternal . puCanWeContinue ) {
ImGui : : SetTooltip ( " we can't continue - this is most likely a bug! " ) ;
} else switch ( fileValid ) {
case 1 :
2023-08-19 07:29:23 +00:00
# ifdef _WIN32
2023-08-13 22:38:39 +00:00
ImGui : : SetTooltip ( " invalid characters in file name \n make sure there aren't any of these: \n < > : \" / \\ | ? * " ) ;
2023-08-19 07:29:23 +00:00
# else
ImGui : : SetTooltip ( " invalid characters in file name \n make sure there aren't any slashes (/) " ) ;
# endif
2023-08-13 22:38:39 +00:00
break ;
case 2 :
ImGui : : SetTooltip ( " this file name is reserved by the system " ) ;
break ;
case 3 :
ImGui : : SetTooltip ( " non-printable characters in file name \n how did you manage to type these? " ) ;
break ;
default :
ImGui : : SetTooltip ( " bug! how did you do this? please fill an issue report now... " ) ;
break ;
}
2023-06-16 21:26:22 +00:00
}
}
2023-08-13 22:38:39 +00:00
ImGui : : SameLine ( ) ;
2023-06-16 21:26:22 +00:00
// Cancel Button
2024-06-12 20:44:55 +00:00
std : : string cbs = std : : string ( cancelButtonString ) + " ##validationdialog " ;
if ( IMGUI_BUTTON ( cbs . c_str ( ) ) | |
2023-06-16 21:26:22 +00:00
prFileDialogInternal . puNeedToExitDialog ) // dialog exit asked
{
prFileDialogInternal . puIsOk = false ;
res = true ;
}
prFileDialogInternal . puFooterHeight = ImGui : : GetCursorPosY ( ) - posY ;
return res ;
}
2021-12-11 07:10:09 +00:00
2022-02-01 07:52:36 +00:00
// returns 0 if not break loop, 1 if break loop, 2 if exit dialog
2023-07-27 05:33:28 +00:00
int IGFD : : FileDialog : : prSelectableItem ( int vidx , const FileInfos & vInfos , bool vSelected , const char * vFmt , . . . )
2023-06-16 21:26:22 +00:00
{
auto & fdi = prFileDialogInternal . puFileManager ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
static ImGuiSelectableFlags selectableFlags = ImGuiSelectableFlags_AllowDoubleClick |
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SpanAvailWidth ;
2021-12-11 07:10:09 +00:00
2022-03-13 22:29:43 +00:00
// TODO BUG?!
2022-10-28 09:16:07 +00:00
// YES BUG: THIS JUST CRASHED FOR SOME REASON
2023-06-16 21:26:22 +00:00
va_list args ;
va_start ( args , vFmt ) ;
vsnprintf ( fdi . puVariadicBuffer , MAX_FILE_DIALOG_NAME_BUFFER , vFmt , args ) ;
va_end ( args ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
float h = /*mobileMode?(ImGui::GetFontSize()+10.0f*DpiScale):*/ 0.0f ;
2021-12-11 07:10:09 +00:00
# ifdef USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
if ( prDisplayMode = = DisplayModeEnum : : THUMBNAILS_LIST )
h = DisplayMode_ThumbailsList_ImageHeight ;
2021-12-11 07:10:09 +00:00
# endif // USE_THUMBNAILS
# ifdef USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
bool flashed = prBeginFlashItem ( ( size_t ) vidx ) ;
bool res = prFlashableSelectable ( fdi . puVariadicBuffer , vSelected , selectableFlags ,
flashed , ImVec2 ( - 1.0f , h ) ) ;
if ( flashed )
prEndFlashItem ( ) ;
2021-12-11 07:10:09 +00:00
# else // USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
( void ) vidx ; // remove a warnings ofr unused var
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
bool res = ImGui : : Selectable ( fdi . puVariadicBuffer , vSelected , selectableFlags , ImVec2 ( - 1.0f , h ) ) ;
2021-12-11 07:10:09 +00:00
# endif // USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
if ( res )
{
2023-07-27 05:33:28 +00:00
if ( vInfos . fileType = = ' d ' )
2023-06-16 21:26:22 +00:00
{
2022-02-01 07:52:36 +00:00
bool isSelectingDir = false ;
2023-06-16 21:26:22 +00:00
// nav system, selectebale cause open directory or select directory
if ( ImGui : : GetIO ( ) . ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard )
{
if ( fdi . puDLGDirectoryMode ) // directory chooser
{
fdi . SelectFileName ( prFileDialogInternal , vInfos ) ;
}
else
{
fdi . puPathClicked = fdi . SelectDirectory ( vInfos ) ;
2022-02-01 07:52:36 +00:00
isSelectingDir = true ;
2023-06-16 21:26:22 +00:00
}
}
else // no nav system => classic behavior
{
if ( DOUBLE_CLICKED ) // 0 -> left mouse button double click
{
2022-02-01 07:52:36 +00:00
isSelectingDir = true ;
2023-06-16 21:26:22 +00:00
fdi . puPathClicked = fdi . SelectDirectory ( vInfos ) ;
}
else if ( fdi . puDLGDirectoryMode ) // directory chooser
{
fdi . SelectFileName ( prFileDialogInternal , vInfos ) ;
}
}
return isSelectingDir ; // needToBreakTheloop
}
else
{
2022-12-02 21:52:47 +00:00
if ( DOUBLE_CLICKED ) {
2022-02-01 07:52:36 +00:00
fdi . SelectFileName ( prFileDialogInternal , vInfos ) ;
prFileDialogInternal . puIsOk = true ;
return 2 ;
} else {
2023-06-16 21:26:22 +00:00
fdi . SelectFileName ( prFileDialogInternal , vInfos ) ;
2022-04-25 23:58:17 +00:00
if ( prFileDialogInternal . puDLGselFun ! = NULL ) {
2022-10-17 00:40:14 +00:00
std : : string argPath ;
for ( auto & i : GetSelection ( ) ) {
argPath = i . second ;
}
if ( ! argPath . empty ( ) ) {
prFileDialogInternal . puDLGselFun ( argPath . c_str ( ) ) ;
}
2022-04-25 23:58:17 +00:00
}
2022-02-01 07:52:36 +00:00
}
2023-06-16 21:26:22 +00:00
}
}
return 0 ;
}
2023-07-27 05:33:28 +00:00
void IGFD : : FileDialog : : prBeginFileColorIconStyle ( const FileInfos & vFileInfos , bool & vOutShowColor , std : : string & vOutStr , ImFont * * vOutFont )
2023-06-16 21:26:22 +00:00
{
vOutStr . clear ( ) ;
vOutShowColor = false ;
2023-07-27 05:33:28 +00:00
if ( vFileInfos . fileStyle . use_count ( ) ) //-V807 //-V522
2023-06-16 21:26:22 +00:00
{
vOutShowColor = true ;
2023-07-27 05:33:28 +00:00
* vOutFont = vFileInfos . fileStyle - > font ;
2023-06-16 21:26:22 +00:00
}
2023-07-27 05:33:28 +00:00
if ( vOutShowColor & & ! vFileInfos . fileStyle - > icon . empty ( ) ) vOutStr = vFileInfos . fileStyle - > icon ;
else if ( vFileInfos . fileType = = ' d ' ) vOutStr = dirEntryString ;
else if ( vFileInfos . fileType = = ' l ' ) vOutStr = linkEntryString ;
else if ( vFileInfos . fileType = = ' f ' ) vOutStr = fileEntryString ;
2023-06-16 21:26:22 +00:00
2023-07-27 05:33:28 +00:00
vOutStr + = " " + vFileInfos . fileNameExt ;
2023-06-16 21:26:22 +00:00
if ( vOutShowColor )
2023-07-27 05:33:28 +00:00
ImGui : : PushStyleColor ( ImGuiCol_Text , vFileInfos . fileStyle - > color ) ;
2023-06-16 21:26:22 +00:00
if ( * vOutFont )
ImGui : : PushFont ( * vOutFont ) ;
}
void IGFD : : FileDialog : : prEndFileColorIconStyle ( const bool & vShowColor , ImFont * vFont )
{
if ( vFont )
ImGui : : PopFont ( ) ;
if ( vShowColor )
ImGui : : PopStyleColor ( ) ;
}
bool IGFD : : FileDialog : : prDrawFileListView ( ImVec2 vSize )
{
2022-02-01 07:52:36 +00:00
bool escape = false ;
2023-06-16 21:26:22 +00:00
auto & fdi = prFileDialogInternal . puFileManager ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : PushID ( this ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg |
ImGuiTableFlags_Hideable | ImGuiTableFlags_ScrollY |
ImGuiTableFlags_NoHostExtendY
2021-12-11 07:10:09 +00:00
# ifndef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
| ImGuiTableFlags_Sortable
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
;
auto listViewID = ImGui : : GetID ( " ##FileDialog_fileTable " ) ;
if ( ImGui : : BeginTableEx ( " ##FileDialog_fileTable " , listViewID , 4 , flags , vSize , 0.0f ) ) //-V112
{
ImGui : : TableSetupScrollFreeze ( 0 , 1 ) ; // Make header always visible
ImGui : : TableSetupColumn ( fdi . puHeaderFileName . c_str ( ) , ImGuiTableColumnFlags_WidthStretch , - 1 , 0 ) ;
ImGui : : TableSetupColumn ( fdi . puHeaderFileType . c_str ( ) , ImGuiTableColumnFlags_WidthFixed |
( ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_HideColumnType ) ? ImGuiTableColumnFlags_DefaultHide : 0 ) , - 1 , 1 ) ;
ImGui : : TableSetupColumn ( fdi . puHeaderFileSize . c_str ( ) , ImGuiTableColumnFlags_WidthFixed |
( ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_HideColumnSize ) ? ImGuiTableColumnFlags_DefaultHide : 0 ) , - 1 , 2 ) ;
ImGui : : TableSetupColumn ( fdi . puHeaderFileDate . c_str ( ) , ImGuiTableColumnFlags_WidthFixed |
( ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_HideColumnDate ) ? ImGuiTableColumnFlags_DefaultHide : 0 ) , - 1 , 3 ) ;
2021-12-11 07:10:09 +00:00
# ifndef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
// Sort our data if sort specs have been changed!
if ( ImGuiTableSortSpecs * sorts_specs = ImGui : : TableGetSortSpecs ( ) )
{
if ( sorts_specs - > SpecsDirty & & ! fdi . IsFileListEmpty ( ) )
{
if ( sorts_specs - > Specs - > ColumnUserID = = 0 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_FILENAME , true ) ;
else if ( sorts_specs - > Specs - > ColumnUserID = = 1 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_TYPE , true ) ;
else if ( sorts_specs - > Specs - > ColumnUserID = = 2 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_SIZE , true ) ;
else //if (sorts_specs->Specs->ColumnUserID == 3) => alwayd true for the moment, to uncomment if we add a fourth column
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_DATE , true ) ;
sorts_specs - > SpecsDirty = false ;
}
}
ImGui : : TableHeadersRow ( ) ;
2021-12-11 07:10:09 +00:00
# else // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
ImGui : : TableNextRow ( ImGuiTableRowFlags_Headers ) ;
for ( int column = 0 ; column < 4 ; column + + ) //-V112
{
ImGui : : TableSetColumnIndex ( column ) ;
const char * column_name = ImGui : : TableGetColumnName ( column ) ; // Retrieve name passed to TableSetupColumn()
ImGui : : PushID ( column ) ;
ImGui : : TableHeader ( column_name ) ;
ImGui : : PopID ( ) ;
if ( ImGui : : IsItemClicked ( ) )
{
if ( column = = 0 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_FILENAME , true ) ;
else if ( column = = 1 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_TYPE , true ) ;
else if ( column = = 2 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_SIZE , true ) ;
else //if (column == 3) => alwayd true for the moment, to uncomment if we add a fourth column
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_DATE , true ) ;
}
}
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
if ( ! fdi . IsFilteredListEmpty ( ) )
{
std : : string _str ;
ImFont * _font = nullptr ;
bool _showColor = false ;
prFileListClipper . Begin ( ( int ) fdi . GetFilteredListSize ( ) , ImGui : : GetTextLineHeightWithSpacing ( ) ) ;
while ( prFileListClipper . Step ( ) )
{
for ( int i = prFileListClipper . DisplayStart ; i < prFileListClipper . DisplayEnd ; i + + )
{
if ( i < 0 ) continue ;
2023-07-27 05:33:28 +00:00
const FileInfos & infos = fdi . GetFilteredFileAt ( ( size_t ) i ) ;
if ( ! infos . isValid )
2023-06-16 21:26:22 +00:00
continue ;
prBeginFileColorIconStyle ( infos , _showColor , _str , & _font ) ;
2023-07-27 05:33:28 +00:00
bool selected = fdi . IsFileNameSelected ( infos . fileNameExt ) ; // found
2023-06-16 21:26:22 +00:00
ImGui : : TableNextRow ( ) ;
int needToBreakTheloop = false ;
if ( ImGui : : TableNextColumn ( ) ) // file name
{
2022-03-13 22:29:43 +00:00
// TODO BUG?!?!?!
2022-10-28 09:16:07 +00:00
// YES BUG
2023-06-16 21:26:22 +00:00
needToBreakTheloop = prSelectableItem ( i , infos , selected , " %s " , _str . c_str ( ) ) ;
2022-02-01 07:52:36 +00:00
if ( needToBreakTheloop = = 2 ) escape = true ;
2023-06-16 21:26:22 +00:00
}
if ( ImGui : : TableNextColumn ( ) ) // file type
{
2023-07-27 05:33:28 +00:00
ImGui : : Text ( " %s " , infos . fileExt . c_str ( ) ) ;
2023-06-16 21:26:22 +00:00
}
if ( ImGui : : TableNextColumn ( ) ) // file size
{
2023-07-27 05:33:28 +00:00
if ( infos . fileType ! = ' d ' )
2023-06-16 21:26:22 +00:00
{
2023-07-27 05:33:28 +00:00
ImGui : : Text ( " %s " , infos . formatedFileSize . c_str ( ) ) ;
2023-06-16 21:26:22 +00:00
}
else
{
ImGui : : Text ( " %s " , " " ) ;
}
}
if ( ImGui : : TableNextColumn ( ) ) // file date + time
{
2023-07-27 05:33:28 +00:00
ImGui : : Text ( " %s " , infos . fileModifDate . c_str ( ) ) ;
2023-06-16 21:26:22 +00:00
}
prEndFileColorIconStyle ( _showColor , _font ) ;
if ( needToBreakTheloop = = 1 )
break ;
}
}
prFileListClipper . End ( ) ;
}
2021-12-11 07:10:09 +00:00
# ifdef USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
if ( ! fdi . puInputPathActivated )
{
prLocateByInputKey ( prFileDialogInternal ) ;
prExploreWithkeys ( prFileDialogInternal , listViewID ) ;
}
2021-12-11 07:10:09 +00:00
# endif // USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
ImGuiContext & g = * GImGui ;
if ( g . LastActiveId - 1 = = listViewID | | g . LastActiveId = = listViewID )
{
prFileDialogInternal . puFileListViewIsActive = true ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : EndTable ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : PopID ( ) ;
2022-02-01 07:52:36 +00:00
return escape ;
2023-06-16 21:26:22 +00:00
}
2021-12-11 07:10:09 +00:00
# ifdef USE_THUMBNAILS
2023-06-16 21:26:22 +00:00
void IGFD : : FileDialog : : prDrawThumbnailsListView ( ImVec2 vSize )
{
auto & fdi = prFileDialogInternal . puFileManager ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : PushID ( this ) ;
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg |
ImGuiTableFlags_Hideable | ImGuiTableFlags_ScrollY |
ImGuiTableFlags_NoHostExtendY
2021-12-11 07:10:09 +00:00
# ifndef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
| ImGuiTableFlags_Sortable
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
;
auto listViewID = ImGui : : GetID ( " ##FileDialog_fileTable " ) ;
if ( ImGui : : BeginTableEx ( " ##FileDialog_fileTable " , listViewID , 5 , flags , vSize , 0.0f ) )
{
ImGui : : TableSetupScrollFreeze ( 0 , 1 ) ; // Make header always visible
ImGui : : TableSetupColumn ( fdi . puHeaderFileName . c_str ( ) , ImGuiTableColumnFlags_WidthStretch , - 1 , 0 ) ;
ImGui : : TableSetupColumn ( fdi . puHeaderFileType . c_str ( ) , ImGuiTableColumnFlags_WidthFixed |
( ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_HideColumnType ) ? ImGuiTableColumnFlags_DefaultHide : 0 ) , - 1 , 1 ) ;
ImGui : : TableSetupColumn ( fdi . puHeaderFileSize . c_str ( ) , ImGuiTableColumnFlags_WidthFixed |
( ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_HideColumnSize ) ? ImGuiTableColumnFlags_DefaultHide : 0 ) , - 1 , 2 ) ;
ImGui : : TableSetupColumn ( fdi . puHeaderFileDate . c_str ( ) , ImGuiTableColumnFlags_WidthFixed |
( ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_HideColumnDate ) ? ImGuiTableColumnFlags_DefaultHide : 0 ) , - 1 , 3 ) ;
// not needed to have an option for hide the thumbnails since this is why this view is used
ImGui : : TableSetupColumn ( fdi . puHeaderFileThumbnails . c_str ( ) , ImGuiTableColumnFlags_WidthFixed , - 1 , 4 ) ; //-V112
2021-12-11 07:10:09 +00:00
# ifndef USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
// Sort our data if sort specs have been changed!
if ( ImGuiTableSortSpecs * sorts_specs = ImGui : : TableGetSortSpecs ( ) )
{
if ( sorts_specs - > SpecsDirty & & ! fdi . IsFileListEmpty ( ) )
{
if ( sorts_specs - > Specs - > ColumnUserID = = 0 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_FILENAME , true ) ;
else if ( sorts_specs - > Specs - > ColumnUserID = = 1 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_TYPE , true ) ;
else if ( sorts_specs - > Specs - > ColumnUserID = = 2 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_SIZE , true ) ;
else if ( sorts_specs - > Specs - > ColumnUserID = = 3 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_DATE , true ) ;
else // if (sorts_specs->Specs->ColumnUserID == 4) = > always true for the moment, to uncomment if we add another column
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_THUMBNAILS , true ) ;
sorts_specs - > SpecsDirty = false ;
}
}
ImGui : : TableHeadersRow ( ) ;
2021-12-11 07:10:09 +00:00
# else // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
ImGui : : TableNextRow ( ImGuiTableRowFlags_Headers ) ;
for ( int column = 0 ; column < 5 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
const char * column_name = ImGui : : TableGetColumnName ( column ) ; // Retrieve name passed to TableSetupColumn()
ImGui : : PushID ( column ) ;
ImGui : : TableHeader ( column_name ) ;
ImGui : : PopID ( ) ;
if ( ImGui : : IsItemClicked ( ) )
{
if ( column = = 0 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_FILENAME , true ) ;
else if ( column = = 1 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_TYPE , true ) ;
else if ( column = = 2 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_SIZE , true ) ;
else if ( column = = 3 )
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_DATE , true ) ;
else // if (column == 4) = > always true for the moment, to uncomment if we add another column
fdi . SortFields ( prFileDialogInternal , IGFD : : FileManager : : SortingFieldEnum : : FIELD_THUMBNAILS , true ) ;
}
}
2021-12-11 07:10:09 +00:00
# endif // USE_CUSTOM_SORTING_ICON
2023-06-16 21:26:22 +00:00
if ( ! fdi . IsFilteredListEmpty ( ) )
{
std : : string _str ;
ImFont * _font = nullptr ;
bool _showColor = false ;
ImGuiContext & g = * GImGui ;
const float itemHeight = ImMax ( g . FontSize , DisplayMode_ThumbailsList_ImageHeight ) + g . Style . ItemSpacing . y ;
prFileListClipper . Begin ( ( int ) fdi . GetFilteredListSize ( ) , itemHeight ) ;
while ( prFileListClipper . Step ( ) )
{
for ( int i = prFileListClipper . DisplayStart ; i < prFileListClipper . DisplayEnd ; i + + )
{
if ( i < 0 ) continue ;
auto infos = fdi . GetFilteredFileAt ( ( size_t ) i ) ;
if ( ! infos . use_count ( ) )
continue ;
prBeginFileColorIconStyle ( infos , _showColor , _str , & _font ) ;
bool selected = fdi . IsFileNameSelected ( infos - > fileNameExt ) ; // found
ImGui : : TableNextRow ( ) ;
bool needToBreakTheloop = false ;
if ( ImGui : : TableNextColumn ( ) ) // file name
{
needToBreakTheloop = prSelectableItem ( i , infos , selected , _str . c_str ( ) ) ;
}
if ( ImGui : : TableNextColumn ( ) ) // file type
{
ImGui : : Text ( " %s " , infos - > fileExt . c_str ( ) ) ;
}
if ( ImGui : : TableNextColumn ( ) ) // file size
{
if ( infos - > fileType ! = ' d ' )
{
ImGui : : Text ( " %s " , infos - > formatedFileSize . c_str ( ) ) ;
}
else
{
ImGui : : Text ( " " ) ;
}
}
if ( ImGui : : TableNextColumn ( ) ) // file date + time
{
ImGui : : Text ( " %s " , infos - > fileModifDate . c_str ( ) ) ;
}
if ( ImGui : : TableNextColumn ( ) ) // file thumbnails
{
auto th = & infos - > thumbnailInfo ;
if ( ! th - > isLoadingOrLoaded )
{
prAddThumbnailToLoad ( infos ) ;
}
if ( th - > isReadyToDisplay & &
th - > textureID )
{
ImGui : : Image ( ( ImTextureID ) th - > textureID ,
ImVec2 ( ( float ) th - > textureWidth ,
( float ) th - > textureHeight ) ) ;
}
}
prEndFileColorIconStyle ( _showColor , _font ) ;
if ( needToBreakTheloop )
break ;
}
}
prFileListClipper . End ( ) ;
}
2021-12-11 07:10:09 +00:00
# ifdef USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
if ( ! fdi . puInputPathActivated )
{
prLocateByInputKey ( prFileDialogInternal ) ;
prExploreWithkeys ( prFileDialogInternal , listViewID ) ;
}
2021-12-11 07:10:09 +00:00
# endif // USE_EXPLORATION_BY_KEYS
2023-06-16 21:26:22 +00:00
ImGuiContext & g = * GImGui ;
if ( g . LastActiveId - 1 = = listViewID | | g . LastActiveId = = listViewID )
{
prFileDialogInternal . puFileListViewIsActive = true ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : EndTable ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : PopID ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
void IGFD : : FileDialog : : prDrawThumbnailsGridView ( ImVec2 vSize )
{
if ( ImGui : : BeginChild ( " ##thumbnailsGridsFiles " , vSize ) )
{
// todo
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
ImGui : : EndChild ( ) ;
}
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
void IGFD : : FileDialog : : prDrawSidePane ( float vHeight )
{
ImGui : : SameLine ( ) ;
ImGui : : BeginChild ( " ##FileTypes " , ImVec2 ( 0 , vHeight ) ) ;
prFileDialogInternal . puDLGoptionsPane (
prFileDialogInternal . puFilterManager . GetSelectedFilter ( ) . filter . c_str ( ) ,
prFileDialogInternal . puDLGuserDatas , & prFileDialogInternal . puCanWeContinue ) ;
ImGui : : EndChild ( ) ;
}
void IGFD : : FileDialog : : Close ( )
{
prFileDialogInternal . puDLGkey . clear ( ) ;
prFileDialogInternal . puShowDialog = false ;
}
bool IGFD : : FileDialog : : WasOpenedThisFrame ( const std : : string & vKey ) const
{
bool res = prFileDialogInternal . puShowDialog & & prFileDialogInternal . puDLGkey = = vKey ;
if ( res )
{
ImGuiContext & g = * GImGui ;
res & = prFileDialogInternal . puLastImGuiFrameCount = = g . FrameCount ; // return true if a dialog was displayed in this frame
}
return res ;
}
bool IGFD : : FileDialog : : WasOpenedThisFrame ( ) const
{
bool res = prFileDialogInternal . puShowDialog ;
if ( res )
{
ImGuiContext & g = * GImGui ;
res & = prFileDialogInternal . puLastImGuiFrameCount = = g . FrameCount ; // return true if a dialog was displayed in this frame
}
return res ;
}
bool IGFD : : FileDialog : : IsOpened ( const std : : string & vKey ) const
{
return ( prFileDialogInternal . puShowDialog & & prFileDialogInternal . puDLGkey = = vKey ) ;
}
bool IGFD : : FileDialog : : IsOpened ( ) const
{
return prFileDialogInternal . puShowDialog ;
}
std : : string IGFD : : FileDialog : : GetOpenedKey ( ) const
{
if ( prFileDialogInternal . puShowDialog )
return prFileDialogInternal . puDLGkey ;
return " " ;
}
std : : string IGFD : : FileDialog : : GetFilePathName ( )
{
return prFileDialogInternal . puFileManager . GetResultingFilePathName ( prFileDialogInternal ) ;
}
std : : string IGFD : : FileDialog : : GetCurrentPath ( )
{
return prFileDialogInternal . puFileManager . GetResultingPath ( ) ;
}
std : : string IGFD : : FileDialog : : GetCurrentFileName ( )
{
return prFileDialogInternal . puFileManager . GetResultingFileName ( prFileDialogInternal ) ;
}
std : : string IGFD : : FileDialog : : GetCurrentFilter ( )
{
return prFileDialogInternal . puFilterManager . GetSelectedFilter ( ) . filter ;
}
std : : map < std : : string , std : : string > IGFD : : FileDialog : : GetSelection ( )
{
return prFileDialogInternal . puFileManager . GetResultingSelection ( ) ;
}
UserDatas IGFD : : FileDialog : : GetUserDatas ( ) const
{
return prFileDialogInternal . puDLGuserDatas ;
}
bool IGFD : : FileDialog : : IsOk ( ) const
{
return prFileDialogInternal . puIsOk ;
}
void IGFD : : FileDialog : : SetFileStyle ( const IGFD_FileStyleFlags & vFlags , const char * vCriteria , const FileStyle & vInfos )
{
prFileDialogInternal . puFilterManager . SetFileStyle ( vFlags , vCriteria , vInfos ) ;
}
void IGFD : : FileDialog : : SetFileStyle ( const IGFD_FileStyleFlags & vFlags , const char * vCriteria , const ImVec4 & vColor , const std : : string & vIcon , ImFont * vFont )
{
prFileDialogInternal . puFilterManager . SetFileStyle ( vFlags , vCriteria , vColor , vIcon , vFont ) ;
}
bool IGFD : : FileDialog : : GetFileStyle ( const IGFD_FileStyleFlags & vFlags , const std : : string & vCriteria , ImVec4 * vOutColor , std : : string * vOutIcon , ImFont * * vOutFont )
{
return prFileDialogInternal . puFilterManager . GetFileStyle ( vFlags , vCriteria , vOutColor , vOutIcon , vOutFont ) ;
}
void IGFD : : FileDialog : : ClearFilesStyle ( )
{
prFileDialogInternal . puFilterManager . ClearFilesStyle ( ) ;
}
void IGFD : : FileDialog : : SetLocales ( const int & vLocaleCategory , const std : : string & vLocaleBegin , const std : : string & vLocaleEnd )
{
prFileDialogInternal . puUseCustomLocale = true ;
prFileDialogInternal . puLocaleBegin = vLocaleBegin ;
prFileDialogInternal . puLocaleEnd = vLocaleEnd ;
}
//////////////////////////////////////////////////////////////////////////////
//// OVERWRITE DIALOG ////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
bool IGFD : : FileDialog : : prConfirm_Or_OpenOverWriteFileDialog_IfNeeded ( bool vLastAction , ImGuiWindowFlags vFlags )
{
// if confirmation => return true for confirm the overwrite et quit the dialog
// if cancel => return false && set IsOk to false for keep inside the dialog
// if IsOk == false => return false for quit the dialog
if ( ! prFileDialogInternal . puIsOk & & vLastAction )
{
QuitFrame ( ) ;
return true ;
}
// if IsOk == true && no check of overwrite => return true for confirm the dialog
if ( prFileDialogInternal . puIsOk & & vLastAction & & ! ( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite ) )
{
QuitFrame ( ) ;
return true ;
}
// if IsOk == true && check of overwrite => return false and show confirm to overwrite dialog
if ( ( prFileDialogInternal . puOkResultToConfirm | | ( prFileDialogInternal . puIsOk & & vLastAction ) ) & &
( prFileDialogInternal . puDLGflags & ImGuiFileDialogFlags_ConfirmOverwrite ) )
{
if ( prFileDialogInternal . puIsOk ) // catched only one time
{
2023-09-10 08:38:10 +00:00
if ( ! prFileDialogInternal . puFileManager . IsFileExist ( GetFilePathName ( ) , prFileDialogInternal . puFilterManager . GetSelectedFilter ( ) . firstFilter ) ) // not existing => quit dialog
2023-06-16 21:26:22 +00:00
{
QuitFrame ( ) ;
return true ;
}
else // existing => confirm dialog to open
{
prFileDialogInternal . puIsOk = false ;
prFileDialogInternal . puOkResultToConfirm = true ;
}
}
2024-06-12 20:44:55 +00:00
std : : string name = std : : string ( OverWriteDialogTitleString ) + " ## " + prFileDialogInternal . puDLGtitle + prFileDialogInternal . puDLGkey + " OverWriteDialog " ;
2023-06-16 21:26:22 +00:00
bool res = false ;
ImGui : : OpenPopup ( name . c_str ( ) ) ;
if ( ImGui : : BeginPopupModal ( name . c_str ( ) , ( bool * ) 0 ,
vFlags | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove ) )
{
ImGui : : SetWindowPos ( prFileDialogInternal . puDialogCenterPos - ImGui : : GetWindowSize ( ) * 0.5f ) ; // next frame needed for GetWindowSize to work
ImGui : : Text ( " %s " , OverWriteDialogMessageString ) ;
if ( IMGUI_BUTTON ( OverWriteDialogConfirmButtonString ) )
{
prFileDialogInternal . puOkResultToConfirm = false ;
prFileDialogInternal . puIsOk = true ;
res = true ;
ImGui : : CloseCurrentPopup ( ) ;
}
ImGui : : SameLine ( ) ;
if ( IMGUI_BUTTON ( OverWriteDialogCancelButtonString ) )
{
prFileDialogInternal . puOkResultToConfirm = false ;
prFileDialogInternal . puIsOk = false ;
res = false ;
ImGui : : CloseCurrentPopup ( ) ;
}
ImGui : : EndPopup ( ) ;
}
if ( res )
{
QuitFrame ( ) ;
}
return res ;
}
return false ;
}
2021-12-11 07:10:09 +00:00
}
# endif // __cplusplus
/////////////////////////////////////////////////////////////////
///// C Interface ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
// Return an initialized IGFD_Selection_Pair
IMGUIFILEDIALOG_API IGFD_Selection_Pair IGFD_Selection_Pair_Get ( void )
{
2023-06-16 21:26:22 +00:00
IGFD_Selection_Pair res = { } ;
res . fileName = nullptr ;
res . filePathName = nullptr ;
return res ;
2021-12-11 07:10:09 +00:00
}
// destroy only the content of vSelection_Pair
IMGUIFILEDIALOG_API void IGFD_Selection_Pair_DestroyContent ( IGFD_Selection_Pair * vSelection_Pair )
{
2023-06-16 21:26:22 +00:00
if ( vSelection_Pair )
{
delete [ ] vSelection_Pair - > fileName ;
delete [ ] vSelection_Pair - > filePathName ;
}
2021-12-11 07:10:09 +00:00
}
// Return an initialized IGFD_Selection
IMGUIFILEDIALOG_API IGFD_Selection IGFD_Selection_Get ( void )
{
2023-06-16 21:26:22 +00:00
return { nullptr , 0U } ;
2021-12-11 07:10:09 +00:00
}
// destroy only the content of vSelection
IMGUIFILEDIALOG_API void IGFD_Selection_DestroyContent ( IGFD_Selection * vSelection )
{
2023-06-16 21:26:22 +00:00
if ( vSelection )
{
if ( vSelection - > table )
{
for ( size_t i = 0U ; i < vSelection - > count ; i + + )
{
IGFD_Selection_Pair_DestroyContent ( & vSelection - > table [ i ] ) ;
}
delete [ ] vSelection - > table ;
}
vSelection - > count = 0U ;
}
2021-12-11 07:10:09 +00:00
}
// create an instance of ImGuiFileDialog
IMGUIFILEDIALOG_API ImGuiFileDialog * IGFD_Create ( void )
{
2023-06-16 21:26:22 +00:00
return new ImGuiFileDialog ( ) ;
2021-12-11 07:10:09 +00:00
}
// destroy the instance of ImGuiFileDialog
IMGUIFILEDIALOG_API void IGFD_Destroy ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
delete vContext ;
vContext = nullptr ;
}
2021-12-11 07:10:09 +00:00
}
// standard dialog
IMGUIFILEDIALOG_API void IGFD_OpenDialog (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vPath ,
const char * vFileName ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenDialog (
vKey , vTitle , vFilters , vPath , vFileName ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_OpenDialog2 (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vFilePathName ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenDialog (
vKey , vTitle , vFilters , vFilePathName ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vPath ,
const char * vFileName ,
IGFD_PaneFun vSidePane ,
const float vSidePaneWidth ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenDialog (
vKey , vTitle , vFilters ,
vPath , vFileName ,
vSidePane , vSidePaneWidth ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_OpenPaneDialog2 (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vFilePathName ,
IGFD_PaneFun vSidePane ,
const float vSidePaneWidth ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenDialog (
vKey , vTitle , vFilters ,
vFilePathName ,
vSidePane , vSidePaneWidth ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
// modal dialog
IMGUIFILEDIALOG_API void IGFD_OpenModal (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vPath ,
const char * vFileName ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenModal (
vKey , vTitle , vFilters , vPath , vFileName ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_OpenModal2 (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vFilePathName ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenModal (
vKey , vTitle , vFilters , vFilePathName ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_OpenPaneModal (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vPath ,
const char * vFileName ,
IGFD_PaneFun vSidePane ,
const float vSidePaneWidth ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenModal (
vKey , vTitle , vFilters ,
vPath , vFileName ,
vSidePane , vSidePaneWidth ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_OpenPaneModal2 (
2023-06-16 21:26:22 +00:00
ImGuiFileDialog * vContext ,
const char * vKey ,
const char * vTitle ,
const char * vFilters ,
const char * vFilePathName ,
IGFD_PaneFun vSidePane ,
const float vSidePaneWidth ,
const int vCountSelectionMax ,
void * vUserDatas ,
ImGuiFileDialogFlags flags )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > OpenModal (
vKey , vTitle , vFilters ,
vFilePathName ,
vSidePane , vSidePaneWidth ,
vCountSelectionMax , vUserDatas , flags ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API bool IGFD_DisplayDialog ( ImGuiFileDialog * vContext ,
2023-06-16 21:26:22 +00:00
const char * vKey , ImGuiWindowFlags vFlags , ImVec2 vMinSize , ImVec2 vMaxSize )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
return vContext - > Display ( vKey , vFlags , vMinSize , vMaxSize ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return false ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_CloseDialog ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > Close ( ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API bool IGFD_IsOk ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
return vContext - > IsOk ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return false ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API bool IGFD_WasKeyOpenedThisFrame ( ImGuiFileDialog * vContext ,
2023-06-16 21:26:22 +00:00
const char * vKey )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > WasOpenedThisFrame ( vKey ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return false ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API bool IGFD_WasOpenedThisFrame ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > WasOpenedThisFrame ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return false ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API bool IGFD_IsKeyOpened ( ImGuiFileDialog * vContext ,
2023-06-16 21:26:22 +00:00
const char * vCurrentOpenedKey )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > IsOpened ( vCurrentOpenedKey ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return false ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API bool IGFD_IsOpened ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > IsOpened ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return false ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API IGFD_Selection IGFD_GetSelection ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
IGFD_Selection res = IGFD_Selection_Get ( ) ;
if ( vContext )
{
auto sel = vContext - > GetSelection ( ) ;
if ( ! sel . empty ( ) )
{
res . count = sel . size ( ) ;
res . table = new IGFD_Selection_Pair [ res . count ] ;
size_t idx = 0U ;
for ( const auto & s : sel )
{
IGFD_Selection_Pair * pair = res . table + idx + + ;
// fileNameExt
if ( ! s . first . empty ( ) )
{
size_t siz = s . first . size ( ) + 1U ;
pair - > fileName = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( pair - > fileName , s . first . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( pair - > fileName , siz , s . first . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
pair - > fileName [ siz - 1U ] = ' \0 ' ;
}
// filePathName
if ( ! s . second . empty ( ) )
{
size_t siz = s . first . size ( ) + 1U ;
pair - > filePathName = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( pair - > filePathName , s . first . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( pair - > filePathName , siz , s . first . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
pair - > filePathName [ siz - 1U ] = ' \0 ' ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API char * IGFD_GetFilePathName ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
char * res = nullptr ;
if ( vContext )
{
auto s = vContext - > GetFilePathName ( ) ;
if ( ! s . empty ( ) )
{
size_t siz = s . size ( ) + 1U ;
res = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( res , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( res , siz , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
res [ siz - 1U ] = ' \0 ' ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API char * IGFD_GetCurrentFileName ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
char * res = nullptr ;
if ( vContext )
{
auto s = vContext - > GetCurrentFileName ( ) ;
if ( ! s . empty ( ) )
{
size_t siz = s . size ( ) + 1U ;
res = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( res , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( res , siz , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
res [ siz - 1U ] = ' \0 ' ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API char * IGFD_GetCurrentPath ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
char * res = nullptr ;
if ( vContext )
{
auto s = vContext - > GetCurrentPath ( ) ;
if ( ! s . empty ( ) )
{
size_t siz = s . size ( ) + 1U ;
res = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( res , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( res , siz , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
res [ siz - 1U ] = ' \0 ' ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API char * IGFD_GetCurrentFilter ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
char * res = nullptr ;
if ( vContext )
{
auto s = vContext - > GetCurrentFilter ( ) ;
if ( ! s . empty ( ) )
{
size_t siz = s . size ( ) + 1U ;
res = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( res , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( res , siz , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
res [ siz - 1U ] = ' \0 ' ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void * IGFD_GetUserDatas ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
return vContext - > GetUserDatas ( ) ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return nullptr ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_SetFileStyle ( ImGuiFileDialog * vContext ,
2023-06-16 21:26:22 +00:00
IGFD_FileStyleFlags vFlags , const char * vCriteria , ImVec4 vColor , const char * vIcon , ImFont * vFont ) //-V813
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > SetFileStyle ( vFlags , vCriteria , vColor , vIcon , vFont ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_SetFileStyle2 ( ImGuiFileDialog * vContext ,
2023-06-16 21:26:22 +00:00
IGFD_FileStyleFlags vFlags , const char * vCriteria , float vR , float vG , float vB , float vA , const char * vIcon , ImFont * vFont )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > SetFileStyle ( vFlags , vCriteria , ImVec4 ( vR , vG , vB , vA ) , vIcon , vFont ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API bool IGFD_GetFileStyle ( ImGuiFileDialog * vContext ,
2023-06-16 21:26:22 +00:00
IGFD_FileStyleFlags vFlags , const char * vCriteria , ImVec4 * vOutColor , char * * vOutIcon , ImFont * * vOutFont )
2021-12-11 07:10:09 +00:00
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
std : : string icon ;
bool res = vContext - > GetFileStyle ( vFlags , vCriteria , vOutColor , & icon , vOutFont ) ;
if ( ! icon . empty ( ) & & vOutIcon )
{
size_t siz = icon . size ( ) + 1U ;
* vOutIcon = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( * vOutIcon , icon . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( * vOutIcon , siz , icon . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
( * vOutIcon ) [ siz - 1U ] = ' \0 ' ;
}
return res ;
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return false ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_ClearFilesStyle ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > ClearFilesStyle ( ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void SetLocales ( ImGuiFileDialog * vContext , const int vCategory , const char * vBeginLocale , const char * vEndLocale )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > SetLocales ( vCategory , ( vBeginLocale ? vBeginLocale : " " ) , ( vEndLocale ? vEndLocale : " " ) ) ;
}
2021-12-11 07:10:09 +00:00
}
# ifdef USE_EXPLORATION_BY_KEYS
IMGUIFILEDIALOG_API void IGFD_SetFlashingAttenuationInSeconds ( ImGuiFileDialog * vContext , float vAttenValue )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > SetFlashingAttenuationInSeconds ( vAttenValue ) ;
}
2021-12-11 07:10:09 +00:00
}
# endif
# ifdef USE_BOOKMARK
IMGUIFILEDIALOG_API char * IGFD_SerializeBookmarks ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
char * res = nullptr ;
if ( vContext )
{
auto s = vContext - > SerializeBookmarks ( ) ;
if ( ! s . empty ( ) )
{
size_t siz = s . size ( ) + 1U ;
res = new char [ siz ] ;
2021-12-11 07:10:09 +00:00
# ifndef MSVC
2023-06-16 21:26:22 +00:00
strncpy ( res , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# else
2023-06-16 21:26:22 +00:00
strncpy_s ( res , siz , s . c_str ( ) , siz ) ;
2021-12-11 07:10:09 +00:00
# endif
2023-06-16 21:26:22 +00:00
res [ siz - 1U ] = ' \0 ' ;
}
}
2021-12-11 07:10:09 +00:00
2023-06-16 21:26:22 +00:00
return res ;
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void IGFD_DeserializeBookmarks ( ImGuiFileDialog * vContext , const char * vBookmarks )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > DeserializeBookmarks ( vBookmarks ) ;
}
2021-12-11 07:10:09 +00:00
}
# endif
# ifdef USE_THUMBNAILS
IMGUIFILEDIALOG_API void SetCreateThumbnailCallback ( ImGuiFileDialog * vContext , const IGFD_CreateThumbnailFun vCreateThumbnailFun )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > SetCreateThumbnailCallback ( vCreateThumbnailFun ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void SetDestroyThumbnailCallback ( ImGuiFileDialog * vContext , const IGFD_DestroyThumbnailFun vDestroyThumbnailFun )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > SetDestroyThumbnailCallback ( vDestroyThumbnailFun ) ;
}
2021-12-11 07:10:09 +00:00
}
IMGUIFILEDIALOG_API void ManageGPUThumbnails ( ImGuiFileDialog * vContext )
{
2023-06-16 21:26:22 +00:00
if ( vContext )
{
vContext - > ManageGPUThumbnails ( ) ;
}
2021-12-11 07:10:09 +00:00
}
# endif // USE_THUMBNAILS