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
This commit is contained in:
Ashfaaq18 2021-06-06 13:12:36 +05:30 committed by Don Ho
parent 27524e1d4d
commit 80c285ee2d
9 changed files with 83 additions and 11 deletions

View File

@ -1084,6 +1084,7 @@ You can define several column markers by using white space to separate the diffe
<Item id="6345" name="Peek on tab"/>
<Item id="6346" name="Peek on document map"/>
<Item id="6360" name="Mute all sounds"/>
<Item id="6361" name="Enable Save All confirm dialog"/>
</MISC>
</Preference>
<MultiMacro title="Run a Macro Multiple Times">
@ -1232,6 +1233,10 @@ Do you want to launch Notepad++ in Administrator mode?"/>
Notepad++ will be restarted after all the operations are terminated.
Continue?"/>
<NeedToRestartToLoadPlugins title="Notepad++ need to be relaunched" message="You have to restart Notepad++ to load plugins you installed."/> <!-- HowToReproduce: Import a plugin via menu "Settings->Import->Import Plugin(s)...". -->
<SaveAllConfirm title="Save All Confirmation" message="Are you sure you want to save all documents?
Choose &quot;Cancel&quot; if your answer will always be &quot;Yes&quot; and you won't be asked this question again.
You can re-activate this dialog in Preferences dialog later." /> <!-- HowToReproduce: Check the 'Enable Save All confirm dialog' checkbox in Preference->MISC, now click 'Save all' -->
</MessageBox>
<ClipboardHistory>
<PanelTitle name="Clipboard History"/>

View File

@ -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);

View File

@ -1598,8 +1598,43 @@ bool Notepad_plus::fileSaveSpecific(const generic_string& fileNameToSave)
}
}
bool Notepad_plus::fileSaveAllConfirm()
{
bool confirmed = false;
if (NppParameters::getInstance().getNppGUI()._saveAllConfirm)
{
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)
{
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;
}
bool Notepad_plus::fileSaveAll()
{
if ( fileSaveAllConfirm() )
{
if (viewVisible(MAIN_VIEW))
{
for (size_t i = 0; i < _mainDocTab.nbItem(); ++i)
@ -1618,6 +1653,7 @@ bool Notepad_plus::fileSaveAll()
}
}
checkDocState();
}
return true;
}

View File

@ -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();
@ -6123,6 +6138,11 @@ void NppParameters::createXmlTreeFromGUIParams()
insertGUIConfigBoolNode(newGUIRoot, TEXT("DetectEncoding"), _nppGUI._detectEncoding);
}
// <GUIConfig name = "SaveAllConfirm">yes< / GUIConfig>
{
insertGUIConfigBoolNode(newGUIRoot, TEXT("SaveAllConfirm"), _nppGUI._saveAllConfirm);
}
// <GUIConfig name = "NewDocDefaultSettings" format = "0" encoding = "0" lang = "3" codepage = "-1" openAnsiAsUTF8 = "no" / >
{
TiXmlElement *GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement();

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -242,7 +242,7 @@ private :
class PreferenceDlg : public StaticDialog
{
friend class NativeLangSpeaker;
friend class Notepad_plus;
public :
PreferenceDlg() = default;

View File

@ -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)