https://git.reactos.org/?p=reactos.git;a=commitdiff;h=15be457b6da32ab89414fe...
commit 15be457b6da32ab89414fe7c3dcba72018bedfe5 Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Sun May 15 19:22:57 2022 +0200 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Sun May 15 19:22:57 2022 +0200
[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). --- base/applications/notepad/dialog.c | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-)
diff --git a/base/applications/notepad/dialog.c b/base/applications/notepad/dialog.c index 7a0e0fac6cc..1b10084e99b 100644 --- a/base/applications/notepad/dialog.c +++ b/base/applications/notepad/dialog.c @@ -68,14 +68,26 @@ 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); - - 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 based upon whether the user has modified the file or not */ + StringCbPrintf(szCaption, sizeof(szCaption), _T("%s%s - %s"), + (isModified ? _T("*") : _T("")), szFilename, szNotepad);
- /* Update the window caption */ SetWindowText(Globals.hMainWnd, szCaption); }