[NOTEPAD] Simplify code for UpdateWindowCaption(). Addendum to 1d690f04.

One StringCbPrintf() call is sufficient, that can cover both
clearModifyAlert == TRUE or FALSE cases.
Also, only SendMessage(EM_GETMODIFY) when clearModifyAlert == FALSE
(during text edition).
This commit is contained in:
Hermès Bélusca-Maïto 2022-05-15 19:22:57 +02:00
parent 6612682b87
commit 15be457b6d
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -68,13 +68,25 @@ void UpdateWindowCaption(BOOL clearModifyAlert)
TCHAR szCaption[MAX_STRING_LEN];
TCHAR szNotepad[MAX_STRING_LEN];
TCHAR szFilename[MAX_STRING_LEN];
BOOL isModified = !!SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0);
BOOL isModified;
if (!clearModifyAlert && isModified == Globals.bWasModified)
if (clearModifyAlert)
{
/* We are in the same state as before, don't change the caption */
return;
/* When a file is being opened or created, there is no need to have
* the edited flag shown when the file has not been edited yet. */
isModified = FALSE;
}
else
{
/* Check whether the user has modified the file or not. If we are
* in the same state as before, don't change the caption. */
isModified = !!SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0);
if (isModified == Globals.bWasModified)
return;
}
/* Remember the state for later calls */
Globals.bWasModified = isModified;
/* Load the name of the application */
LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, ARRAY_SIZE(szNotepad));
@ -85,26 +97,10 @@ void UpdateWindowCaption(BOOL clearModifyAlert)
else
LoadString(Globals.hInstance, STRING_UNTITLED, szFilename, ARRAY_SIZE(szFilename));
/* When a file is being opened or created, there is no need to have the edited flag shown
when the new or opened file has not been edited yet */
if (clearModifyAlert)
{
StringCbPrintf(szCaption, sizeof(szCaption), _T("%s - %s"),
szFilename, szNotepad);
/* Update the window caption based upon whether the user has modified the file or not */
StringCbPrintf(szCaption, sizeof(szCaption), _T("%s%s - %s"),
(isModified ? _T("*") : _T("")), szFilename, szNotepad);
Globals.bWasModified = FALSE;
}
else
{
/* Update the caption based upon if the user has modified the contents of the file or not */
StringCbPrintf(szCaption, sizeof(szCaption), _T("%s%s - %s"),
(isModified ? _T("*") : _T("")), szFilename, szNotepad);
/* We will modify the caption below */
Globals.bWasModified = isModified;
}
/* Update the window caption */
SetWindowText(Globals.hMainWnd, szCaption);
}