From 38db3c150709eb0b805efbf69c15a0ea1b141aa4 Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Sun, 2 Feb 2025 22:27:24 +0100 Subject: [PATCH] fix: titlebar changes (file name instead of simple hash --- src/Dialogs.c | 46 ++++++++++++++++++++++++++++++---------------- src/Helpers.c | 11 ----------- src/Notepad3.c | 34 ++++++++++++++++++---------------- src/Notepad3.h | 1 + 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/Dialogs.c b/src/Dialogs.c index 724b488b9..3a74b5685 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -5263,12 +5263,19 @@ static HPATHL s_pthCachedFilePath = NULL; void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T properties, LPCWSTR lpszExcerpt, bool forceRedraw) { static TITLEPROPS_T s_properties = { 0 }; + static WCHAR s_compTitleExcerpt[MIDSZ_BUFFER] = { L'\0' }; static size_t s_hashFileName = 0; - static size_t s_hashExcerpt = 0; + + bool bExcerptChanged = false; + bool bFilePathChanged = false; if (s_bFreezeAppTitle) { return; } + if (!s_pthCachedFilePath) { + s_pthCachedFilePath = Path_Allocate(L""); + } + if (!forceRedraw) { if (s_properties.iFormat != properties.iFormat) { @@ -5296,16 +5303,17 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop forceRedraw = true; } else { - size_t const hashExcerpt = SimpleHash(lpszExcerpt); - if (s_hashExcerpt != hashExcerpt) { - forceRedraw = true; - } - else { - size_t const hashFileName = SimpleHash(Path_Get(pthFilePath)); - if (s_hashFileName != hashFileName) { + for (int i = 0; i < COUNTOF(s_compTitleExcerpt); ++i) { + if (s_compTitleExcerpt[i] != lpszExcerpt[i]) { forceRedraw = true; + bExcerptChanged = true; + break; } } + if (Path_StrgComparePath(s_pthCachedFilePath, pthFilePath, Paths.WorkingDirectory) != 0) { + forceRedraw = true; + bFilePathChanged = true; + } } } @@ -5315,12 +5323,19 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop // save current state s_properties = properties; - s_hashExcerpt = SimpleHash(lpszExcerpt); - s_hashFileName = SimpleHash(Path_Get(pthFilePath)); - if (!s_pthCachedFilePath) { - s_pthCachedFilePath = Path_Allocate(L""); + if (bExcerptChanged) { + StringCchCopy(s_compTitleExcerpt, COUNTOF(s_compTitleExcerpt), lpszExcerpt); } + if (bFilePathChanged) { + if (Path_IsNotEmpty(pthFilePath)) { + Path_Reset(s_pthCachedFilePath, Path_Get(pthFilePath)); + } + else { + Path_Empty(s_pthCachedFilePath, false); + } + } + WCHAR szAppName[SMALL_BUFFER] = { L'\0' }; if (properties.bPasteBoard) { @@ -5363,11 +5378,11 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop else if (Path_IsNotEmpty(pthFilePath)) { if (properties.iFormat < 2) { - if (Path_StrgComparePath(s_pthCachedFilePath, pthFilePath, Paths.WorkingDirectory) != 0) { - Path_Reset(s_pthCachedFilePath, Path_Get(pthFilePath)); + if (bFilePathChanged) { + //StringCchCopy(s_wchCachedDisplayName, COUNTOF(s_wchCachedDisplayName), Path_FindFileName(s_pthCachedFilePath)); Path_GetDisplayName(s_wchCachedDisplayName, COUNTOF(s_wchCachedDisplayName), s_pthCachedFilePath, s_szUntitled, true); } - StringCchCat(szTitle, COUNTOF(szTitle), Path_FindFileName(s_pthCachedFilePath)); + StringCchCat(szTitle, COUNTOF(szTitle), s_wchCachedDisplayName); if (properties.iFormat == 1) { HPATHL hdir = Path_Copy(s_pthCachedFilePath); if (Path_IsNotEmpty(hdir)) { @@ -5384,7 +5399,6 @@ void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, const TITLEPROPS_T prop } } else { - Path_Empty(s_pthCachedFilePath, false); s_wchCachedDisplayName[0] = L'\0'; StringCchCat(szTitle, COUNTOF(szTitle), s_szUntitled); } diff --git a/src/Helpers.c b/src/Helpers.c index 8ba238aa2..ba0fbe7f9 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -1832,17 +1832,6 @@ int Hex2Char(char* ch, int cnt) } -//============================================================================= - -size_t SimpleHash(LPCWSTR string) -{ - size_t hash = 0; - for (size_t i = 0, l = wcslen(string); i < l; ++i) { - hash += hash * 65599 + string[i]; - } - return hash ^ (hash >> 16); -} - //============================================================================= #ifdef WC2MB_EX diff --git a/src/Notepad3.c b/src/Notepad3.c index 7190175fc..a2cd56a86 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -3598,10 +3598,8 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) s_WinCurrentWidth = cx; - UpdateToolbar(); - UpdateStatusbar(true); + UpdateToolbar_Now(hwnd); UpdateMargins(true); - UpdateTitlebar(hwnd); //~UpdateUI(); //~ recursion return FALSE; @@ -3769,7 +3767,7 @@ LRESULT MsgDropFiles(HWND hwnd, WPARAM wParam, LPARAM lParam) DragFinish(hDrop); Path_Release(hdrop_pth); - UpdateToolbar(hwnd); + UpdateToolbar_Now(hwnd); } return 0; } @@ -3952,8 +3950,7 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam) FreeMem(params); } - UpdateToolbar(); - UpdateStatusbar(true); + UpdateToolbar_Now(hwnd); UpdateMargins(true); } @@ -4686,8 +4683,8 @@ static void _ApplyChangeHistoryMode() else { SciCall_SetChangeHistory(Settings.ChangeHistoryMode); } - UpdateMargins(true); UpdateToolbar(); + UpdateMargins(true); } @@ -4706,7 +4703,6 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) Style_InsertThemesMenu(Globals.hMainMenu); DrawMenuBar(Globals.hwndMain); UpdateToolbar(); - UpdateStatusbar(true); return FALSE; } #endif @@ -10042,6 +10038,13 @@ void UpdateToolbar() _DelayUpdateTitlebar(_MQ_STD, Globals.hwndMain); } +void UpdateToolbar_Now(const HWND hwnd) +{ + _UpdateToolbarDelayed(); + _UpdateStatusbarDelayed(true); + _UpdateTitlebarDelayed(hwnd); +} + //============================================================================= @@ -11552,7 +11555,6 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags, const DocP UpdateToolbar(); UpdateMargins(true); - UpdateStatusbar(true); if (SciCall_GetZoom() != 100) { ShowZoomCallTip(); } @@ -11789,12 +11791,6 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags, const DocP Flags.bHugeFileLoadState = false; // reset } - UpdateToolbar(); - UpdateMargins(true); - UpdateStatusbar(true); - if (SciCall_GetZoom() != 100) { - ShowZoomCallTip(); - } Path_Release(hopen_file); @@ -11807,6 +11803,13 @@ bool FileLoad(const HPATHL hfile_pth, const FileLoadFlags fLoadFlags, const DocP if (visLn > 0) { SciCall_SetFirstVisibleLine(visLn); } + + UpdateMargins(true); + if (SciCall_GetZoom() != 100) { + ShowZoomCallTip(); + } + UpdateToolbar_Now(Globals.hwndMain); + return fSuccess; } @@ -11861,7 +11864,6 @@ bool FileRevert(const HPATHL hfile_pth, bool bIgnoreCmdLnEnc) SetSaveDone(); UpdateToolbar(); UpdateMargins(true); - UpdateStatusbar(true); return result; } diff --git a/src/Notepad3.h b/src/Notepad3.h index 60501bf07..ff33c98a6 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -129,6 +129,7 @@ void ShowWrapAroundCallTip(bool forwardSearch); void MarkAllOccurrences(const LONG64 delay, const bool bForceClear); void UpdateToolbar(); +void UpdateToolbar_Now(const HWND hwnd); void UpdateStatusbar(const bool bForceRedraw); void UpdateMargins(const bool bForce); void UpdateSaveSettingsCmds();