+fix: writing wrong scheme to .ini-file

+chg: using 'Cascadia Mono' as default for pure 'Text File' scheme (if available)
This commit is contained in:
METANEOCORTEX\Kotti 2022-04-14 12:45:19 +02:00
parent 18ccfbc850
commit 059b3e434b
7 changed files with 115 additions and 73 deletions

View File

@ -53,6 +53,7 @@ extern "C" {
#include "Notepad3.h"
#include "MuiLanguage.h"
#include "DynStrg.h"
#include "uthash/utstack.h"
}
#include "DarkMode/DarkMode.h"
@ -336,7 +337,16 @@ extern "C" bool SaveIniFileCache(const HPATHL hpthIniFile)
//
// OpenSettingsFile()
//
extern "C" bool OpenSettingsFile(bool * const pOpenedByMe)
typedef struct iniOpen_t {
WCHAR fctname[80];
struct iniOpen_t* next;
} iniOpen_t;
static iniOpen_t * s_pOpenStackHead = NULL; /* important- initialize to NULL! */
static bool s_bIFCReadOnly = true;
extern "C" bool OpenSettingsFile(LPCWSTR fctname)
{
if (Path_IsNotEmpty(Paths.IniFile)) {
@ -345,15 +355,18 @@ extern "C" bool OpenSettingsFile(bool * const pOpenedByMe)
if (!IsIniFileCached()) {
ResetIniFileCache();
LoadIniFileCache(Paths.IniFile);
if (pOpenedByMe != NULL) {
*pOpenedByMe = true;
}
s_bIFCReadOnly = true;
}
else if (pOpenedByMe != NULL) {
*pOpenedByMe = false;
iniOpen_t* pOpenBy = (iniOpen_t*)AllocMem(sizeof(iniOpen_t), HEAP_ZERO_MEMORY);
if (pOpenBy) {
StringCchCopy(pOpenBy->fctname, COUNTOF(pOpenBy->fctname), fctname);
STACK_PUSH(s_pOpenStackHead, pOpenBy);
}
} else {
Globals.bCanSaveIniFile = false;
assert(!STACK_EMPTY(s_pOpenStackHead));
}
return IsIniFileCached();
}
@ -363,21 +376,36 @@ extern "C" bool OpenSettingsFile(bool * const pOpenedByMe)
//
// CloseSettingsFile()
//
extern "C" bool CloseSettingsFile(bool bSaveChanges, bool bClearCache)
extern "C" bool CloseSettingsFile(LPCWSTR fctname, bool bSaveSettings)
{
if (Globals.bCanSaveIniFile) {
if (bSaveSettings) {
s_bIFCReadOnly = false;
}
if (!IsIniFileCached()) {
assert(STACK_EMPTY(s_pOpenStackHead));
return false;
}
bool const bSaved = bSaveChanges ? SaveIniFileCache(Paths.IniFile) : false;
if (bClearCache) {
else {
assert(!STACK_EMPTY(s_pOpenStackHead));
}
iniOpen_t* pOpenBy = NULL;
STACK_POP(s_pOpenStackHead, pOpenBy);
assert(StringCchCompareX(fctname, pOpenBy->fctname) == 0);
FreeMem(pOpenBy);
bool bSaved = false;
if (STACK_EMPTY(s_pOpenStackHead)) {
if (!s_bIFCReadOnly) {
bSaved = SaveIniFileCache(Paths.IniFile);
}
ResetIniFileCache();
}
return bSaved;
}
if (bClearCache) {
ResetIniFileCache();
}
assert(!STACK_EMPTY(s_pOpenStackHead));
return false;
}
@ -1104,8 +1132,7 @@ void LoadSettings()
bool bDirtyFlag = false; // do we have to save the file on done
bool bOpenedByMe = false;
OpenSettingsFile(&bOpenedByMe);
OpenSettingsFile(L"LoadSettings");
// --------------------------------------------------------------------------
const WCHAR *const IniSecSettings = Constants.Settings_Section;
@ -1784,8 +1811,6 @@ void LoadSettings()
Globals.pMRUreplace = MRU_Create(_s_RecentReplace, (/*IsWindowsNT()*/ true) ? MRU_UTF8 : 0, MRU_ITEMSFNDRPL);
MRU_Load(Globals.pMRUreplace, false);
CloseSettingsFile(bDirtyFlag, false); // keep cached
// --------------------------------------------------------------------------
const WCHAR *const IniSecStyles = Constants.Styles_Section;
// --------------------------------------------------------------------------
@ -1793,7 +1818,7 @@ void LoadSettings()
Style_Prerequisites();
CloseSettingsFile(false, bOpenedByMe);
CloseSettingsFile(L"LoadSettings", bDirtyFlag);
FreeMem(pPathBuffer);
}
@ -2194,8 +2219,7 @@ bool SaveAllSettings(bool bForceSaveSettings)
BeginWaitCursor(true, tchMsg);
bool bOpenedByMe = false;
ok = OpenSettingsFile(&bOpenedByMe);
ok = OpenSettingsFile(L"SaveAllSettings");
if (ok) {
@ -2232,7 +2256,7 @@ bool SaveAllSettings(bool bForceSaveSettings)
}
Style_FileExtToIniSection(false);
ok = CloseSettingsFile(true, bOpenedByMe);
ok = CloseSettingsFile(L"SaveAllSettings", true);
// maybe separate INI files for Style-Themes
if (Globals.uCurrentThemeIndex > 0) {
@ -2460,8 +2484,7 @@ bool MRU_AddPath(LPMRULIST pmru, const HPATHL hpth, bool bRelativePath, bool bUn
static void _MRU_DeleteItemInIniFile(LPCWSTR section, LPMRULIST pmru, const int iIndex)
{
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"DeleteItemInIniFile")) {
WCHAR wchName[32] = { L'\0' };
@ -2487,7 +2510,7 @@ static void _MRU_DeleteItemInIniFile(LPCWSTR section, LPMRULIST pmru, const int
IniSectionDelete(section, wchName, false);
}
}
CloseSettingsFile(bOpenedByMe, bOpenedByMe);
CloseSettingsFile(L"DeleteItemInIniFile", true);
}
}
@ -2535,8 +2558,7 @@ bool MRU_Delete(LPMRULIST pmru, int iIndex)
bool MRU_Empty(LPMRULIST pmru, bool bExceptLeast, bool bDelete)
{
if (pmru) {
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"MRU_Empty")) {
int const beg = bExceptLeast ? 1 : 0;
for (int i = beg; i < pmru->iSize; ++i) {
@ -2555,7 +2577,7 @@ bool MRU_Empty(LPMRULIST pmru, bool bExceptLeast, bool bDelete)
}
}
}
CloseSettingsFile(bOpenedByMe, bOpenedByMe);
CloseSettingsFile(L"MRU_Empty", bDelete);
}
return true;
}
@ -2586,14 +2608,12 @@ int MRU_Enum(LPMRULIST pmru, int iIndex, LPWSTR pszItem, int cchItem)
bool MRU_Load(LPMRULIST pmru, bool bFileProps)
{
if (pmru) {
int n = 0;
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"MRU_Load")) {
MRU_Empty(pmru, false, false);
const WCHAR* const RegKey_Section = pmru->szRegKey;
int n = 0;
for (int i = 0; i < pmru->iSize; ++i) {
WCHAR tchName[32] = { L'\0' };
StringCchPrintf(tchName, COUNTOF(tchName), L"%.2i", i + 1);
@ -2625,7 +2645,7 @@ bool MRU_Load(LPMRULIST pmru, bool bFileProps)
++n;
}
}
CloseSettingsFile(false, bOpenedByMe); // load only
CloseSettingsFile(L"MRU_Load", false); // read only
}
return true;
}
@ -2636,8 +2656,7 @@ bool MRU_Load(LPMRULIST pmru, bool bFileProps)
void MRU_Save(LPMRULIST pmru)
{
if (pmru) {
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"MRU_Save")) {
WCHAR tchName[32] = { L'\0' };
WCHAR tchItem[2048] = { L'\0' };
@ -2670,7 +2689,7 @@ void MRU_Save(LPMRULIST pmru)
}
}
}
CloseSettingsFile(true, bOpenedByMe);
CloseSettingsFile(L"MRU_Save", true);
}
}
}
@ -2679,9 +2698,7 @@ void MRU_Save(LPMRULIST pmru)
bool MRU_MergeSave(LPMRULIST pmru, bool bAddFiles, bool bRelativePath, bool bUnexpandMyDocs)
{
if (pmru) {
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"MRU_MergeSave")) {
LPMRULIST pmruBase = MRU_Create(pmru->szRegKey, pmru->iFlags, pmru->iSize);
MRU_Load(pmruBase, bAddFiles);
@ -2709,7 +2726,7 @@ bool MRU_MergeSave(LPMRULIST pmru, bool bAddFiles, bool bRelativePath, bool bUne
MRU_Save(pmruBase);
pmruBase = NULL;
CloseSettingsFile(bOpenedByMe, bOpenedByMe);
CloseSettingsFile(L"MRU_MergeSave", true);
return true;
}

View File

@ -36,8 +36,8 @@ bool SaveWindowPositionSettings(bool bClearSettings);
bool SaveAllSettings(bool bForceSaveSettings);
void CmdSaveSettingsNow();
bool OpenSettingsFile(bool * const pOpenedByMe);
bool CloseSettingsFile(bool bSaveChanges, bool bClearCache);
bool OpenSettingsFile(LPCWSTR fctname);
bool CloseSettingsFile(LPCWSTR fctname, bool bSaveSettings);
// ----------------------------------------------------------------------------

View File

@ -126,7 +126,7 @@ static LRESULT CALLBACK SetPosRelatedToParent_Hook(INT nCode, WPARAM wParam, LPA
int MessageBoxLng(UINT uType, UINT uidMsg, ...)
{
HSTRINGW hfmt_str = StrgCreate(NULL);
HSTRINGW hfmt_str = StrgCreate(NULL);
LPWSTR const fmt_buf = StrgWriteAccessBuf(hfmt_str, XXXL_BUFFER);
if (!GetLngString(uidMsg, fmt_buf, (int)StrgGetAllocLength(hfmt_str))) {
StrgDestroy(hfmt_str);
@ -134,15 +134,13 @@ int MessageBoxLng(UINT uType, UINT uidMsg, ...)
}
StrgSanitize(hfmt_str);
LPCWSTR pText = fmt_buf;
HSTRINGW htxt_str = StrgCreate(NULL);
HSTRINGW htxt_str = StrgCreate(NULL);
const PUINT_PTR argp = (PUINT_PTR)&uidMsg + 1;
if (argp && *argp) {
bool const bHasArgs = (argp && *argp);
if (bHasArgs) {
LPWSTR const txt_buf = StrgWriteAccessBuf(htxt_str, XXXL_BUFFER);
StringCchVPrintfW(txt_buf, StrgGetAllocLength(htxt_str), fmt_buf, (LPVOID)argp);
StringCchVPrintfW(txt_buf, StrgGetAllocLength(htxt_str), StrgGet(hfmt_str), (LPVOID)argp);
StrgSanitize(htxt_str);
pText = txt_buf;
}
uType |= MB_SETFOREGROUND; //~ MB_TOPMOST
@ -155,7 +153,8 @@ int MessageBoxLng(UINT uType, UINT uidMsg, ...)
HWND const hwnd = focus ? focus : Globals.hwndMain;
s_hCBThook = SetWindowsHookEx(WH_CBT, &SetPosRelatedToParent_Hook, 0, GetCurrentThreadId());
int const res = MessageBoxEx(hwnd, pText, _W(SAPPNAME), uType, GetLangIdByLocaleName(Globals.CurrentLngLocaleName));
int const res = MessageBoxEx(hwnd, bHasArgs ? StrgGet(htxt_str) : StrgGet(hfmt_str),
_W(SAPPNAME), uType, GetLangIdByLocaleName(Globals.CurrentLngLocaleName));
StrgDestroy(htxt_str);
StrgDestroy(hfmt_str);
@ -6357,8 +6356,13 @@ INT_PTR CALLBACK FontDialogHookProc(
}
}
#endif
//WCHAR buf[32] = { L'\0' };
//SendMessage(GetDlgItem(hdlg, stc5), WM_GETTEXT, (WPARAM)30, (LPARAM)buf);
//SendMessage(GetDlgItem(hdlg, stc5), WM_SETTEXT, 0, (LPARAM)buf);
dpi = Scintilla_GetWindowDPI(hdlg);
const CHOOSEFONT *const pChooseFont = ((CHOOSEFONT *)lParam);
if (pChooseFont) {
SendMessage(hdlg, WM_CHOOSEFONT_SETFLAGS, 0, (LPARAM)pChooseFont->Flags);

View File

@ -2811,8 +2811,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance)
DestroyWindow(Globals.hwndToolbar);
}
bool bOpenedByMe = false;
OpenSettingsFile(&bOpenedByMe);
OpenSettingsFile(L"CreateBars");
bool bDirtyFlag = false;
//InitToolbarWndClass(hInstance);
@ -2975,7 +2974,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance)
SendMessage(Globals.hwndToolbar, TB_ADDBUTTONS, COUNTOF(s_tbbMainWnd), (LPARAM)s_tbbMainWnd);
}
CloseSettingsFile(bDirtyFlag, bOpenedByMe);
CloseSettingsFile(L"CreateBars", bDirtyFlag);
// ------------------------------
// Create ReBar and add Toolbar
@ -3120,6 +3119,8 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
bShutdownOK = true;
}
assert(!IsIniFileCached());
if (umsg == WM_DESTROY) {
PostQuitMessage(0);
}
@ -6098,8 +6099,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
InfoBoxLng(MB_OK, L"MsgStickyWinPos", IDS_MUI_STICKYWINPOS);
}
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"IDM_VIEW_STICKYWINPOS")) {
SaveWindowPositionSettings(!Flags.bStickyWindowPosition);
@ -6109,7 +6109,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
else {
IniSectionDelete(Constants.Settings2_Section, L"StickyWindowPosition", false);
}
CloseSettingsFile(true, bOpenedByMe);
CloseSettingsFile(L"IDM_VIEW_STICKYWINPOS", true);
}
}
break;

View File

@ -62,8 +62,8 @@ EDITLEXER lexTEXT =
{
SCLEX_NULL, "null", IDS_LEX_TEXT_FILES, L"Text Files", L"txt; text; tmp; log; asc; doc; scp; wtx", L"",
&KeyWords_NULL,{
//{ {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"font:$Text", L"" },
{ {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"", L"" },
{ {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"font:$Text", L"" },
//{ {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"", L"" },
{ {STYLE_LINENUMBER}, IDS_LEX_STD_MARGIN, L"Margins and Line Numbers", L"font:Consolas; size:-2", L"" },
{ {SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT}, IDS_LEX_STD_X_SPC, L"Extra Line Spacing (Size)", L"size:-1", L"" },
EDITLEXER_SENTINEL

View File

@ -724,8 +724,7 @@ bool Style_Import(HWND hwnd)
//
static void _LoadLexerFileExtensions()
{
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"_LoadLexerFileExtensions")) {
for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) {
@ -758,7 +757,7 @@ static void _LoadLexerFileExtensions()
}
}
CloseSettingsFile(false, bOpenedByMe); // load only
CloseSettingsFile(L"_LoadLexerFileExtensions", false); // read only
}
}
@ -951,11 +950,10 @@ bool Style_ImportFromFile(const HPATHL hpath)
bool const bHaveFileResource = Path_IsNotEmpty(hpath);
bool const bIsStdIniFile = bHaveFileResource ? (Path_StrgComparePath(hpath, Paths.IniFile, Paths.ModuleDirectory) == 0) : false;
bool bOpenedByMe = false;
bool const result = bIsStdIniFile ? OpenSettingsFile(&bOpenedByMe) : (bHaveFileResource ? LoadIniFileCache(hpath) : true);
bool result = bIsStdIniFile ? OpenSettingsFile(L"Style_ImportFromFile") : (bHaveFileResource ? LoadIniFileCache(hpath) : true);
if (result) {
_ReadFromIniCache();
CloseSettingsFile(false, bOpenedByMe); // import only
result = bIsStdIniFile ? CloseSettingsFile(L"Style_ImportFromFile", false) /* import only */ : (bHaveFileResource ? ResetIniFileCache() : true);
}
return result;
}
@ -1183,11 +1181,10 @@ bool Style_ExportToFile(const HPATHL hpath, bool bForceAll)
// special handling of standard .ini-file
bool ok = false;
if (bIsStdIniFile) {
bool bOpenedByMe = false;
if (OpenSettingsFile(&bOpenedByMe)) {
if (OpenSettingsFile(L"Style_ExportToFile")) {
Style_ToIniSection(bForceAll);
Style_FileExtToIniSection(bForceAll);
ok = CloseSettingsFile(bOpenedByMe, bOpenedByMe);
ok = CloseSettingsFile(L"Style_ExportToFile", true);
}
} else {
HPATHL hpth_tmp = Path_Copy(hpath);
@ -2823,8 +2820,8 @@ bool Style_GetFileFilterStr(LPWSTR lpszFilter, int cchFilter, LPWSTR lpszDefExt,
static WCHAR _DefaultCodingFont[LF_FACESIZE] = { L"\0" }; // session static
static inline bool GetDefaultCodeFont(LPWSTR pwchFontName, int cchFont) {
static inline bool GetDefaultCodeFont(LPWSTR pwchFontName, int cchFont)
{
if (StrIsNotEmpty(_DefaultCodingFont)) {
StringCchCopy(pwchFontName, cchFont, _DefaultCodingFont);
return true;
@ -2832,10 +2829,10 @@ static inline bool GetDefaultCodeFont(LPWSTR pwchFontName, int cchFont) {
LPCWSTR const FontNamePrioList[] = {
L"Cascadia Code",
L"Cascadia Mono",
L"Fira Code",
L"Roboto Mono",
L"Source Code Pro",
L"Cascadia Mono",
L"Roboto Mono",
L"DejaVu Sans Mono",
L"Consolas",
L"Lucida Console"
@ -2862,12 +2859,32 @@ static inline bool GetDefaultCodeFont(LPWSTR pwchFontName, int cchFont) {
static WORD _wDTFSize = 9;
static WCHAR _DefaultTextFont[LF_FACESIZE] = { L"\0" }; // session static
static inline unsigned GetDefaultTextFont(LPWSTR pwchFontName) {
static inline unsigned GetDefaultTextFont(LPWSTR pwchFontName, int cchFont)
{
if (StrIsNotEmpty(_DefaultTextFont)) {
StringCchCopy(pwchFontName, LF_FACESIZE, _DefaultTextFont);
return _wDTFSize;
}
GetThemedDialogFont(pwchFontName, &_wDTFSize);
LPCWSTR const FontNamePrioList[] = {
L"Cascadia Mono",
L"Roboto Mono",
L"DejaVu Sans Mono",
};
unsigned const countof = COUNTOF(FontNamePrioList);
unsigned i = 0;
for (; i < countof; ++i) {
LPCWSTR const fontName = FontNamePrioList[i];
if (IsFontAvailable(fontName)) {
StringCchCopy(pwchFontName, cchFont, fontName);
break;
}
}
if (i >= countof) {
GetThemedDialogFont(pwchFontName, &_wDTFSize);
}
StringCchCopy(_DefaultTextFont, COUNTOF(_DefaultTextFont), pwchFontName);
return _wDTFSize;
}
@ -2896,7 +2913,7 @@ bool Style_StrGetFontName(LPCWSTR lpszStyle, LPWSTR lpszFont, int cchFont)
} else if (StringCchCompareXI(lpszFont, L"$Text") == 0) {
GetDefaultTextFont(lpszFont);
GetDefaultTextFont(lpszFont, cchFont);
} else if (!IsFontAvailable(lpszFont)) {

View File

@ -93,7 +93,11 @@
#define VER_CPL MS Visual C++ 2022 v17.0.(0-1)
#endif
#elif (_MSC_VER == 1929)
#if (_MSC_FULL_VER >= 192930140)
#if (_MSC_FULL_VER >= 192930142)
#define VER_CPL MS Visual C++ 2019 v16.11.12
#elif (_MSC_FULL_VER >= 192930141)
#define VER_CPL MS Visual C++ 2019 v16.11.11
#elif (_MSC_FULL_VER >= 192930140)
#define VER_CPL MS Visual C++ 2019 v16.11.10
#elif (_MSC_FULL_VER >= 192930139)
#define VER_CPL MS Visual C++ 2019 v16.11.9