From 084a42a2f8ffaa0382c3ebbd70ea01ff6aa763cb Mon Sep 17 00:00:00 2001 From: SuuperW Date: Fri, 24 Aug 2018 12:37:02 -0500 Subject: [PATCH] (Windows) Ask the user if they want to save changes to the Cheat list when the dialog's close/X button is clicked, if there are changes to save. --- desmume/src/frontend/windows/cheatsWin.cpp | 28 ++++++++++++++++++---- desmume/src/frontend/windows/resources.rc | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index 48e492558..2b323c53f 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -670,6 +670,13 @@ INT_PTR CALLBACK CheatsAdd_XX_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp return FALSE; } //============================================================================== +void AttemptSaveAndClose(HWND dialog) +{ + if (cheats->save()) + EndDialog(dialog, TRUE); + else + MessageBox(dialog, "Can't save cheats to file.\nCheck your path (Menu->Config->Path Settings->\"Cheats\")", "Error", MB_OK); +} INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam) { switch(msg) @@ -823,12 +830,25 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l switch (LOWORD(wparam)) { case IDOK: - if (cheats->save()) - EndDialog(dialog, TRUE); - else - MessageBox(dialog, "Can't save cheats to file.\nCheck your path (Menu->Config->Path Settings->\"Cheats\")","Error",MB_OK); + AttemptSaveAndClose(dialog); return TRUE; + case IDCANCEL: + { + if (IsWindowEnabled(GetDlgItem(dialog, IDOK))) + { + int result = MessageBox(dialog, "Do you wish to save your changes?", "Save?", MB_YESNOCANCEL); + if (result == IDYES) + AttemptSaveAndClose(dialog); + else if (result == IDNO) + EndDialog(dialog, FALSE); + } + else + EndDialog(dialog, FALSE); + } + return TRUE; + + case IDCLOSE: EndDialog(dialog, FALSE); return TRUE; diff --git a/desmume/src/frontend/windows/resources.rc b/desmume/src/frontend/windows/resources.rc index 9626ed4f6..ca2e5172a 100644 --- a/desmume/src/frontend/windows/resources.rc +++ b/desmume/src/frontend/windows/resources.rc @@ -214,7 +214,7 @@ BEGIN PUSHBUTTON "Edit",IDC_BEDIT,245,228,64,14,WS_DISABLED PUSHBUTTON "Remove",IDC_BREMOVE,246,244,63,14,WS_DISABLED DEFPUSHBUTTON "Save",IDOK,109,263,50,14,WS_DISABLED - PUSHBUTTON "Cancel",IDCANCEL,163,263,50,14 + PUSHBUTTON "Cancel",IDCLOSE,163,263,50,14 GROUPBOX " Add cheats code as... ",IDC_STATIC,7,230,205,31 PUSHBUTTON "Cheats Database",IDC_EXPORT,246,263,63,14 END