From 80c285ee2d49e6975ff996010a639634630d3b5b Mon Sep 17 00:00:00 2001 From: Ashfaaq18 Date: Sun, 6 Jun 2021 13:12:36 +0530 Subject: [PATCH] Add a Save all confirm dialog and add also an option in Preferences dialog to enable or diable the dialog. Fix #2124, fix #9931, close #9968 --- PowerEditor/installer/nativeLang/english.xml | 5 ++ PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/NppIO.cpp | 56 +++++++++++++++---- PowerEditor/src/Parameters.cpp | 20 +++++++ PowerEditor/src/Parameters.h | 1 + .../src/WinControls/Preference/preference.rc | 1 + .../WinControls/Preference/preferenceDlg.cpp | 7 +++ .../WinControls/Preference/preferenceDlg.h | 2 +- .../WinControls/Preference/preference_rc.h | 1 + 9 files changed, 83 insertions(+), 11 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index cc62f914e..a5e813139 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1084,6 +1084,7 @@ You can define several column markers by using white space to separate the diffe + @@ -1232,6 +1233,10 @@ Do you want to launch Notepad++ in Administrator mode?"/> Notepad++ will be restarted after all the operations are terminated. Continue?"/> + diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 8678a22db..6ca59a570 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -182,6 +182,7 @@ public: bool fileCloseAllToRight(); bool fileCloseAllUnchanged(); bool fileSave(BufferID id = BUFFER_INVALID); + bool fileSaveAllConfirm(); bool fileSaveAll(); bool fileSaveSpecific(const generic_string& fileNameToSave); bool fileSaveAs(BufferID id = BUFFER_INVALID, bool isSaveCopy = false); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 7beb0e690..3e694012e 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1598,26 +1598,62 @@ bool Notepad_plus::fileSaveSpecific(const generic_string& fileNameToSave) } } -bool Notepad_plus::fileSaveAll() +bool Notepad_plus::fileSaveAllConfirm() { - if (viewVisible(MAIN_VIEW)) + bool confirmed = false; + + if (NppParameters::getInstance().getNppGUI()._saveAllConfirm) { - for (size_t i = 0; i < _mainDocTab.nbItem(); ++i) + int answer = _nativeLangSpeaker.messageBox("SaveAllConfirm", + _pPublicInterface->getHSelf(), + TEXT("Are you sure you want to save all documents?\r\rChoose \"Cancel\" if your answer will always be \"Yes\" and you won't be asked this question again.\rYou can re-activate this dialog in Preferences dialog later."), + TEXT("Save All Confirmation"), + MB_YESNOCANCEL | MB_DEFBUTTON2); + + if (answer == IDYES) { - BufferID idToSave = _mainDocTab.getBufferByIndex(i); - fileSave(idToSave); + confirmed = true; + } + + if (answer == IDCANCEL) + { + NppParameters::getInstance().getNppGUI()._saveAllConfirm = false; + //uncheck the "Enable save all confirm dialog" checkbox in Preference-> MISC settings + _preference._miscSubDlg.setChecked(IDC_CHECK_SAVEALLCONFIRM, false); + confirmed = true; } } + else + { + confirmed = true; + } + + return confirmed; +} - if (viewVisible(SUB_VIEW)) +bool Notepad_plus::fileSaveAll() +{ + if ( fileSaveAllConfirm() ) { - for (size_t i = 0; i < _subDocTab.nbItem(); ++i) + if (viewVisible(MAIN_VIEW)) { - BufferID idToSave = _subDocTab.getBufferByIndex(i); - fileSave(idToSave); + for (size_t i = 0; i < _mainDocTab.nbItem(); ++i) + { + BufferID idToSave = _mainDocTab.getBufferByIndex(i); + fileSave(idToSave); + } } + + if (viewVisible(SUB_VIEW)) + { + for (size_t i = 0; i < _subDocTab.nbItem(); ++i) + { + BufferID idToSave = _subDocTab.getBufferByIndex(i); + fileSave(idToSave); + } + } + checkDocState(); } - checkDocState(); return true; } diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index f21ec7548..5fc91863e 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4390,6 +4390,21 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) } } } + else if (!lstrcmp(nm, TEXT("SaveAllConfirm"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + const TCHAR* val = n->Value(); + if (val) + { + if (lstrcmp(val, TEXT("yes")) == 0) + _nppGUI._saveAllConfirm = true; + else + _nppGUI._saveAllConfirm = false; + } + } + } else if (lstrcmp(nm, TEXT("MaitainIndent")) == 0) { TiXmlNode *n = childNode->FirstChild(); @@ -6122,6 +6137,11 @@ void NppParameters::createXmlTreeFromGUIParams() { insertGUIConfigBoolNode(newGUIRoot, TEXT("DetectEncoding"), _nppGUI._detectEncoding); } + + // yes< / GUIConfig> + { + insertGUIConfigBoolNode(newGUIRoot, TEXT("SaveAllConfirm"), _nppGUI._saveAllConfirm); + } // { diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index d30fc45ad..2a8540919 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -833,6 +833,7 @@ struct NppGUI final bool _rememberLastSession = true; // remember next session boolean will be written in the settings bool _isCmdlineNosessionActivated = false; // used for if -nosession is indicated on the launch time bool _detectEncoding = true; + bool _saveAllConfirm = true; bool _setSaveDlgExtFiltToAllTypes = false; bool _doTaskList = true; bool _maitainIndent = true; diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index 2fe704b8d..20a9e1e96 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -458,6 +458,7 @@ BEGIN CONTROL "Minimize to system tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,139,217,10 CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,154,217,10 CONTROL "Use DirectWrite (May improve rendering special characters, need to restart Notepad++)",IDC_CHECK_DIRECTWRITE_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,169,377,10 + CONTROL "Enable Save All confirm dialog", IDC_CHECK_SAVEALLCONFIRM, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 37, 184, 217, 10 COMBOBOX IDC_COMBO_FILEUPDATECHOICE,44,16,140,100,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Update silently",IDC_CHECK_UPDATESILENTLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,44,32,140,10 CONTROL "Scroll to the last line after update",IDC_CHECK_UPDATEGOTOEOF,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,44,44,140,10 diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index dbaf3941c..b08de79d2 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -1136,6 +1136,7 @@ INT_PTR CALLBACK MiscSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) ::SendDlgItemMessage(_hSelf, IDC_CHECK_MIN2SYSTRAY, BM_SETCHECK, nppGUI._isMinimizedToTray, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_DETECTENCODING, BM_SETCHECK, nppGUI._detectEncoding, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_SAVEALLCONFIRM, BM_SETCHECK, nppGUI._saveAllConfirm, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_AUTOUPDATE, BM_SETCHECK, nppGUI._autoUpdateOpt._doAutoUpdate, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_DIRECTWRITE_ENABLE, BM_SETCHECK, nppGUI._writeTechnologyEngine == directWriteTechnology, 0); ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLEDOCPEEKER, BM_SETCHECK, nppGUI._isDocPeekOnTab ? BST_CHECKED : BST_UNCHECKED, 0); @@ -1275,6 +1276,12 @@ INT_PTR CALLBACK MiscSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) return TRUE; } + case IDC_CHECK_SAVEALLCONFIRM: + { + nppGUI._saveAllConfirm = isCheckedOrNot(IDC_CHECK_SAVEALLCONFIRM); + return TRUE; + } + default: { if (HIWORD(wParam) == CBN_SELCHANGE) diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.h b/PowerEditor/src/WinControls/Preference/preferenceDlg.h index 5bd57254b..1910dab8a 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.h +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.h @@ -242,7 +242,7 @@ private : class PreferenceDlg : public StaticDialog { friend class NativeLangSpeaker; - +friend class Notepad_plus; public : PreferenceDlg() = default; diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h index d6833421c..5b9af1d9a 100644 --- a/PowerEditor/src/WinControls/Preference/preference_rc.h +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -220,6 +220,7 @@ #define IDC_CHECK_MARKALLWHOLEWORDONLY (IDD_PREFERENCE_SUB_MISC + 53) #define IDC_SMARTHILITEMATCHING_STATIC (IDD_PREFERENCE_SUB_MISC + 54) #define IDC_CHECK_MUTE_SOUNDS (IDD_PREFERENCE_SUB_MISC + 60) + #define IDC_CHECK_SAVEALLCONFIRM (IDD_PREFERENCE_SUB_MISC + 61) #define IDD_PREFERENCE_SUB_NEWDOCUMENT 6400 //(IDD_PREFERENCE_BOX + 400) #define IDC_FORMAT_GB_STATIC (IDD_PREFERENCE_SUB_NEWDOCUMENT + 1)