From 8318e6fe0287a6779b4bd808b44f7836536941ab Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 4 Feb 2021 22:36:19 +0100 Subject: [PATCH] + chg: use user locale for date/time insert format, can be menu switched to preferred UI language + chg: insert date before time & tab separated --- language/common_res.h | 1 + language/np3_de_de/strings_de_de.rc | 1 + language/np3_en_us/strings_en_us.rc | 1 + src/Config/Config.cpp | 2 + src/Edit.c | 59 ++++++++++------------------- src/Notepad3.c | 11 ++++++ src/TypeDefs.h | 1 + 7 files changed, 37 insertions(+), 39 deletions(-) diff --git a/language/common_res.h b/language/common_res.h index 0caa871df..f74a77166 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -460,6 +460,7 @@ #define IDS_MUI_LANG_VI_VN 34523 #define IDS_MUI_LANG_ZH_CN 34524 #define IDS_MUI_LANG_ZH_TW 34525 +#define IDS_USE_LOCALE_DATEFMT 34700 #define IDS_MUI_MENU_THEMES 37000 #define IDM_THEMES_DEFAULT 37001 diff --git a/language/np3_de_de/strings_de_de.rc b/language/np3_de_de/strings_de_de.rc index e5fee2f7b..757bae9ef 100644 --- a/language/np3_de_de/strings_de_de.rc +++ b/language/np3_de_de/strings_de_de.rc @@ -251,6 +251,7 @@ END STRINGTABLE BEGIN IDS_MUI_MENU_LANGUAGE "&Sprache" + IDS_USE_LOCALE_DATEFMT "Sprache bestimmt &Datumsformat" IDS_MUI_MENU_THEMES "&Schema Sammlung" IDM_THEMES_DEFAULT "&Fabrik-Vorgaben" IDM_THEMES_FILE_ITEM "&Standard" diff --git a/language/np3_en_us/strings_en_us.rc b/language/np3_en_us/strings_en_us.rc index a760bb9fd..ad1c14008 100644 --- a/language/np3_en_us/strings_en_us.rc +++ b/language/np3_en_us/strings_en_us.rc @@ -251,6 +251,7 @@ END STRINGTABLE BEGIN IDS_MUI_MENU_LANGUAGE "&Language" + IDS_USE_LOCALE_DATEFMT "Language defines &Date Format" IDS_MUI_MENU_THEMES "&Scheme Collection" IDM_THEMES_DEFAULT "&Factory Default" IDM_THEMES_FILE_ITEM "&Standard" diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index e146c262b..aad688e9d 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -1510,6 +1510,7 @@ void LoadSettings() GET_BOOL_VALUE_FROM_INISECTION(SplitUndoTypingSeqOnLnBreak, true); GET_BOOL_VALUE_FROM_INISECTION(EditLayoutRTL, false); GET_BOOL_VALUE_FROM_INISECTION(DialogsLayoutRTL, false); + GET_BOOL_VALUE_FROM_INISECTION(PreferredLocale4DateFmt, false); #ifdef D_NP3_WIN10_DARK_MODE Defaults.WinThemeDarkMode = ShouldAppsUseDarkModeEx(); @@ -1936,6 +1937,7 @@ static bool _SaveSettings(bool bForceSaveSettings) SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, SplitUndoTypingSeqOnLnBreak); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, EditLayoutRTL); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, DialogsLayoutRTL); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, PreferredLocale4DateFmt); #ifdef D_NP3_WIN10_DARK_MODE SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WinThemeDarkMode); diff --git a/src/Edit.c b/src/Edit.c index 23eb2c6de..ca7394044 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -2167,35 +2167,6 @@ void EditModifyNumber(HWND hwnd,bool bIncrease) } -//============================================================================= -// -// _GetDateFormatProc() - date format information provided by the EnumDateFormatsExEx() -// -static unsigned int _DateFmtIdx = 0; - -static BOOL CALLBACK _GetDateFormatProc(LPWSTR lpDateFormatString, CALID CalendarID, LPARAM lParam) -{ - UNUSED(CalendarID); - static unsigned int count = 0; - - LPWSTR const pwchFind = (LPWSTR)lParam; - - if (StrIsEmpty(pwchFind)) { - count = 0; // begin - StringCchCopy(pwchFind, SMALL_BUFFER, lpDateFormatString); // default - if (count == _DateFmtIdx) { - return FALSE; // found - } - } else if (count == _DateFmtIdx) { - StringCchCopy(pwchFind, SMALL_BUFFER, lpDateFormatString); - return FALSE; // found - } - ++count; - return TRUE; -} - - - //============================================================================= // // _GetCurrentDateTimeString() @@ -2207,7 +2178,8 @@ static void _GetCurrentDateTimeString(LPWSTR pwchDateTimeStrg, size_t cchBufLen, const WCHAR* const confFormat = bShortFmt ? Settings2.DateTimeFormat : Settings2.DateTimeLongFormat; - if (StrIsNotEmpty(pwchDateTimeStrg) || StrIsNotEmpty(confFormat)) { + if (StrIsNotEmpty(pwchDateTimeStrg) || StrIsNotEmpty(confFormat)) + { WCHAR wchTemplate[MIDSZ_BUFFER] = {L'\0'}; StringCchCopyW(wchTemplate, COUNTOF(wchTemplate), StrIsNotEmpty(pwchDateTimeStrg) ? pwchDateTimeStrg : confFormat); @@ -2225,18 +2197,27 @@ static void _GetCurrentDateTimeString(LPWSTR pwchDateTimeStrg, size_t cchBufLen, if (cnt == 0) { StringCchCopy(pwchDateTimeStrg, cchBufLen, wchTemplate); } - } else { // use configured DateTime Format - WCHAR wchFormat[SMALL_BUFFER] = { L'\0' }; - _DateFmtIdx = 0; - EnumDateFormatsExEx(_GetDateFormatProc, Settings2.PreferredLanguageLocaleName, (bShortFmt ? DATE_SHORTDATE : DATE_LONGDATE), (LPARAM)wchFormat); - - WCHAR wchDate[SMALL_BUFFER] = { L'\0' }; - GetDateFormatEx(Settings2.PreferredLanguageLocaleName, DATE_AUTOLAYOUT, &st, wchFormat, wchDate, COUNTOF(wchDate), NULL); + + } else { // use configured Language Locale DateTime Format WCHAR wchTime[SMALL_BUFFER] = { L'\0' }; - GetTimeFormatEx(Settings2.PreferredLanguageLocaleName, TIME_NOSECONDS, &st, NULL, wchTime, COUNTOF(wchTime)); + WCHAR wchDate[SMALL_BUFFER] = { L'\0' }; + WCHAR wchFormat[SMALL_BUFFER] = { L'\0' }; - StringCchPrintf(pwchDateTimeStrg, cchBufLen, L"%s %s", wchTime, wchDate); + LPCWSTR const pLocaleName = Settings.PreferredLocale4DateFmt ? Settings2.PreferredLanguageLocaleName : LOCALE_NAME_USER_DEFAULT; + + GetLocaleInfoEx(pLocaleName, (bShortFmt ? LOCALE_SSHORTDATE : LOCALE_SLONGDATE), wchFormat, COUNTOF(wchFormat)); + GetDateFormatEx(pLocaleName, DATE_AUTOLAYOUT, &st, wchFormat, wchDate, COUNTOF(wchDate), NULL); + StrDelChrW(wchDate, L"\x200E"); // clear off the Left-to-Right Mark (LRM) + + LPCWSTR const tfmt = bShortFmt ? NULL : wchFormat; + if (tfmt) { + GetLocaleInfoEx(pLocaleName, LOCALE_STIMEFORMAT, wchFormat, COUNTOF(wchFormat)); + } + GetTimeFormatEx(pLocaleName, (bShortFmt ? TIME_NOSECONDS : 0), &st, tfmt, wchTime, COUNTOF(wchTime)); + StrDelChrW(wchTime, L"\x200E"); // clear off the Left-to-Right Mark (LRM) + + StringCchPrintf(pwchDateTimeStrg, cchBufLen, L"%s\t%s", wchDate, wchTime); } } diff --git a/src/Notepad3.c b/src/Notepad3.c index 1e500fbe5..6c260c36b 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -723,10 +723,15 @@ static bool _InsertLanguageMenu(HMENU hMenuBar) GetLngString(IDS_MUI_MENU_LANGUAGE, wchMenuItemStrg, COUNTOF(wchMenuItemStrg)); //return InsertMenu(hMenuBar, pos, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)s_hmenuLanguage, wchMenuItemStrg); bool const res = InsertMenu(hMenuBar, IDM_VIEW_TABSASSPACES, MF_BYCOMMAND | MF_POPUP | MF_STRING, (UINT_PTR)s_hmenuLanguage, wchMenuItemStrg); + GetLngString(IDS_USE_LOCALE_DATEFMT, wchMenuItemStrg, COUNTOF(wchMenuItemStrg)); + InsertMenu(hMenuBar, IDM_VIEW_TABSASSPACES, MF_BYCOMMAND | MF_STRING, (UINT_PTR)IDS_USE_LOCALE_DATEFMT, wchMenuItemStrg); InsertMenu(hMenuBar, IDM_VIEW_TABSASSPACES, MF_BYCOMMAND | MF_SEPARATOR, (UINT_PTR)NULL, NULL); return res; + } else { + Settings.PreferredLocale4DateFmt = false; } + return false; } @@ -3837,6 +3842,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) EnableCmd(hmenu, IDM_SET_BIDIRECTIONAL_L2R, dwr); EnableCmd(hmenu, IDM_SET_BIDIRECTIONAL_R2L, dwr); + CheckCmd(hmenu, IDS_USE_LOCALE_DATEFMT, Settings.PreferredLocale4DateFmt); CheckCmd(hmenu, IDM_VIEW_MUTE_MESSAGEBEEP, Settings.MuteMessageBeep); CheckCmd(hmenu, IDM_VIEW_SAVEBEFORERUNNINGTOOLS, Settings.SaveBeforeRunningTools); @@ -5337,6 +5343,11 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; + case IDS_USE_LOCALE_DATEFMT: + Settings.PreferredLocale4DateFmt = !Settings.PreferredLocale4DateFmt; + break; + + case IDM_VIEW_TABSASSPACES: { Settings.TabsAsSpaces = !Settings.TabsAsSpaces; Globals.fvCurFile.bTabsAsSpaces = Settings.TabsAsSpaces; diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 782f1a2e1..dfe9d59d6 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -505,6 +505,7 @@ typedef struct _settings_t bool EditLayoutRTL; bool DialogsLayoutRTL; int FocusViewMarkerMode; + bool PreferredLocale4DateFmt; #ifdef D_NP3_WIN10_DARK_MODE bool WinThemeDarkMode;