Skip to content

Commit 75cb2dc

Browse files
committed
[ADD] : add a function for define locale to use beofre and after the dialog display
1 parent d5ea142 commit 75cb2dc

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,9 +3293,12 @@ namespace IGFD
32933293

32943294
bool IGFD::FileDialog::Display(const std::string& vKey, ImGuiWindowFlags vFlags, ImVec2 vMinSize, ImVec2 vMaxSize)
32953295
{
3296+
bool res = false;
3297+
32963298
if (prFileDialogInternal.puShowDialog && prFileDialogInternal.puDLGkey == vKey)
32973299
{
3298-
bool res = false;
3300+
if (prFileDialogInternal.puUseCustomLocale)
3301+
setlocale(prFileDialogInternal.puLocaleCategory, prFileDialogInternal.puLocaleBegin.c_str());
32993302

33003303
auto& fdFile = prFileDialogInternal.puFileManager;
33013304
auto& fdFilter = prFileDialogInternal.puFilterManager;
@@ -3405,10 +3408,13 @@ namespace IGFD
34053408
ImGui::End();
34063409

34073410
// confirm the result and show the confirm to overwrite dialog if needed
3408-
return prConfirm_Or_OpenOverWriteFileDialog_IfNeeded(res, vFlags);
3411+
res = prConfirm_Or_OpenOverWriteFileDialog_IfNeeded(res, vFlags);
3412+
3413+
if (prFileDialogInternal.puUseCustomLocale)
3414+
setlocale(prFileDialogInternal.puLocaleCategory, prFileDialogInternal.puLocaleEnd.c_str());
34093415
}
34103416

3411-
return false;
3417+
return res;
34123418
}
34133419

34143420
void IGFD::FileDialog::NewFrame()
@@ -4088,6 +4094,13 @@ namespace IGFD
40884094
prFileDialogInternal.puFilterManager.ClearExtentionInfos();
40894095
}
40904096

4097+
void IGFD::FileDialog::SetLocales(const int& vLocaleCategory, const std::string& vLocaleBegin, const std::string& vLocaleEnd)
4098+
{
4099+
prFileDialogInternal.puUseCustomLocale = true;
4100+
prFileDialogInternal.puLocaleBegin = vLocaleBegin;
4101+
prFileDialogInternal.puLocaleEnd = vLocaleEnd;
4102+
}
4103+
40914104
//////////////////////////////////////////////////////////////////////////////
40924105
//// OVERWRITE DIALOG ////////////////////////////////////////////////////////
40934106
//////////////////////////////////////////////////////////////////////////////
@@ -4677,6 +4690,13 @@ IMGUIFILEDIALOG_API void IGFD_ClearExtentionInfos(ImGuiFileDialog* vContext)
46774690
vContext->ClearExtentionInfos();
46784691
}
46794692
}
4693+
IMGUIFILEDIALOG_API void SetLocales(ImGuiFileDialog* vContext, const int vCategory, const char* vBeginLocale, const char* vEndLocale)
4694+
{
4695+
if (vContext)
4696+
{
4697+
vContext->SetLocales(vCategory, (vBeginLocale ? vBeginLocale : ""), (vEndLocale ? vEndLocale : ""));
4698+
}
4699+
}
46804700

46814701
#ifdef USE_EXPLORATION_BY_KEYS
46824702
IMGUIFILEDIALOG_API void IGFD_SetFlashingAttenuationInSeconds(ImGuiFileDialog* vContext, float vAttenValue)

ImGuiFileDialog.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,11 @@ namespace IGFD
10421042
bool puDLGmodal = false;
10431043
bool puNeedToExitDialog = false;
10441044

1045+
bool puUseCustomLocale = false;
1046+
int puLocaleCategory = LC_ALL; // locale category to use
1047+
std::string puLocaleBegin; // the locale who will be applied at start of the display dialog
1048+
std::string puLocaleEnd; // the locale who will be applaied at end of the display dialog
1049+
10451050
public:
10461051
void NewFrame(); // new frame, so maybe neded to do somethings, like reset events
10471052
void EndFrame(); // end frame, so maybe neded to do somethings fater all
@@ -1201,6 +1206,11 @@ namespace IGFD
12011206
std::string* vOutIcon = 0); // icon or text to retrieve
12021207
void ClearExtentionInfos(); // clear extentions setttings
12031208

1209+
void SetLocales( // set locales to use before and after the dialog display
1210+
const int& vLocaleCategory, // set local category
1211+
const std::string& vLocaleBegin, // locale to use at begining of the dialog display
1212+
const std::string& vLocaleEnd); // locale to use at the end of the dialog display
1213+
12041214
protected:
12051215
void NewFrame(); // new frame just at begining of display
12061216
void EndFrame(); // end frame just at end of display
@@ -1451,6 +1461,12 @@ IMGUIFILEDIALOG_API bool IGFD_GetExtentionInfos(
14511461
IMGUIFILEDIALOG_API void IGFD_ClearExtentionInfos( // clear extentions setttings
14521462
ImGuiFileDialog* vContext); // ImGuiFileDialog context
14531463

1464+
IMGUIFILEDIALOG_API void SetLocales( // set locales to use before and after display
1465+
ImGuiFileDialog* vContext, // ImGuiFileDialog context
1466+
const int vCategory, // set local category
1467+
const char* vBeginLocale, // locale to use at begining of the dialog display
1468+
const char* vEndLocale); // locale to set at end of the dialog display
1469+
14541470
#ifdef USE_EXPLORATION_BY_KEYS
14551471
IMGUIFILEDIALOG_API void IGFD_SetFlashingAttenuationInSeconds( // set the flashing time of the line in file list when use exploration keys
14561472
ImGuiFileDialog* vContext, // ImGuiFileDialog context

0 commit comments

Comments
 (0)