Add "No to All" and "Yes to All" options in Save dialog

It allows users, while closing files, to reply Yes or No only for once in Save dialog for the all rest of modified files.

Close #5835 , close #4385,  close #4392
pull/5875/head
Don HO 2019-07-03 09:41:35 +02:00
parent bfd8cd0702
commit 3f7956dc1b
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
11 changed files with 297 additions and 29 deletions

View File

@ -981,6 +981,14 @@
<Item id="1718" name="延伸(\n, \r, \t, \0, \x..."/>
<Item id="1720" name="「.」包含換行"/>
</FindInFinder>
<DoSaveOrNot title="儲存檔案">
<Item id="1761" name="您要儲存「$STR_REPLACE$」嗎?"/>
<Item id="6" name="好吧"/>
<Item id="7" name="不要啦"/>
<Item id="2" name="取消"/>
<Item id="4" name="全部存檔"/>
<Item id="5" name="全部棄存"/>
</DoSaveOrNot>
</Dialog>
<MessageBox>
<ContextMenuXmlEditWarning title="編輯快顯功能表" message="編輯 contextMenu.xml Notepad++
@ -1006,7 +1014,6 @@
<SortingError title="排序錯誤" message="第 $INT_REPLACE$ 行無法執行數字排序。"/>
<ColumnModeTip title="多欄選取提示" message="請使用「ALT + 滑鼠選擇」或「Alt + Shift + 方向鍵」以切換到多欄選取。"/>
<BufferInvalidWarning title="儲存失敗" message="緩衝區無效。"/>
<DoSaveOrNot title="儲存檔案" message="您要儲存「$STR_REPLACE$」嗎?"/>
<DoCloseOrNot title="保留文件" message="檔案「$STR_REPLACE$」已不存在。
您在 Notepad++ 中保存這個文件嗎?"/>
<DoDeleteOrNot title="刪除檔案" message="您確定要刪除並關閉「$STR_REPLACE$」嗎?"/>

View File

@ -981,6 +981,14 @@
<Item id="1718" name="E&amp;xtended (\n, \r, \t, \0, \x...)"/>
<Item id="1720" name="&amp;. matches newline"/>
</FindInFinder>
<DoSaveOrNot title="Save">
<Item id="1761" name="Save file &quot;$STR_REPLACE$&quot; ?"/>
<Item id="6" name="Yes"/>
<Item id="7" name="No"/>
<Item id="2" name="Cancel"/>
<Item id="4" name="Yes to all"/>
<Item id="5" name="No to all"/>
</DoSaveOrNot>
</Dialog>
<MessageBox> <!-- $INT_REPLACE$ is a place holder, don't translate it -->
<ContextMenuXmlEditWarning title="Editing contextMenu" message="Editing contextMenu.xml allows you to modify your Notepad++ popup context menu.
@ -1013,7 +1021,6 @@ you have to enable &quot;Open all files of folder instead of launching Folder as
<SortingError title="Sorting Error" message="Unable to perform numeric sorting due to line $INT_REPLACE$."/>
<ColumnModeTip title="Column Mode Tip" message="Please use &quot;ALT+Mouse Selection&quot; or &quot;Alt+Shift+Arrow key&quot; to switch to column mode."/>
<BufferInvalidWarning title="Save failed" message="Cannot save: Buffer is invalid."/>
<DoSaveOrNot title="Save" message="Save file &quot;$STR_REPLACE$&quot; ?"/>
<DoCloseOrNot title="Keep non existing file" message="The file &quot;$STR_REPLACE$&quot; doesn't exist anymore.
Keep this file in editor?"/>
<DoDeleteOrNot title="Delete file" message="The file &quot;$STR_REPLACE$&quot;

View File

@ -966,6 +966,14 @@
<Item id="1718" name="Mode étendu (\n, \r, \t, \0, \x...)"/>
<Item id="1720" name="&amp;. comprend ligne nouvelle"/>
</FindInFinder>
<DoSaveOrNot title="Saugggvegarder">
<Item id="1761" name="Sauvegarder le fichier &quot;$STR_REPLACE$&quot; ?"/>
<Item id="6" name="Oui"/>
<Item id="7" name="Non"/>
<Item id="2" name="Annuler"/>
<Item id="4" name="Oui pour tout"/>
<Item id="5" name="Non pour tout"/>
</DoSaveOrNot>
</Dialog>
<MessageBox>
<CannotMoveDoc title="Déplacement vers une nouvelle instance Notepad++" message="Le document est en cours d'utilisation, le sauvegarder puis réessayer."/>
@ -986,7 +994,6 @@
vous devez activer &quot;Open all files of folder instead of launching Folder as Workspace on folder dropping&quot; in &quot;Default Directory&quot; section of Preferences dialog to make this operation work."/>
<SortingError title="Erreur de tri" message="Impossible d'effectuer le tri numérique à cause de la ligne $INT_REPLACE$."/>
<BufferInvalidWarning title="Échec de sauvegarde" message="Cannot save: Buffer is invalid."/>
<DoSaveOrNot title="Sauvegarder" message="Sauvegarder le fichier &quot;$STR_REPLACE$&quot; ?"/>
<DoCloseOrNot title="Conserver un fichier non existant" message="Le fichier &quot;$STR_REPLACE$&quot; n'existe plus.
Conserver ce fichier dans l'éditeur ?"/>
<DoDeleteOrNot title="Supprimer fichier" message="Le fichier &quot;$STR_REPLACE$&quot;

View File

@ -1862,15 +1862,15 @@ void Notepad_plus::filePrint(bool showDialog)
printer.doPrint();
}
int Notepad_plus::doSaveOrNot(const TCHAR *fn)
int Notepad_plus::doSaveOrNot(const TCHAR* fn, bool isMulti)
{
return _nativeLangSpeaker.messageBox("DoSaveOrNot",
_pPublicInterface->getHSelf(),
TEXT("Save file \"$STR_REPLACE$\" ?"),
TEXT("Save"),
MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL,
0, // not used
fn);
DoSaveOrNotBox doSaveOrNotBox;
doSaveOrNotBox.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), fn, isMulti);
doSaveOrNotBox.doDialog(_nativeLangSpeaker.isRTL());
int buttonID = doSaveOrNotBox.getClickedButtonId();
doSaveOrNotBox.destroy();
return buttonID;
}
int Notepad_plus::doReloadOrNot(const TCHAR *fn, bool dirty)

View File

@ -441,7 +441,7 @@ private:
void performPostReload(int whichOne);
//END: Document management
int doSaveOrNot(const TCHAR *fn);
int doSaveOrNot(const TCHAR *fn, bool isMulti = false);
int doReloadOrNot(const TCHAR *fn, bool dirty);
int doCloseOrNot(const TCHAR *fn);
int doDeleteOrNot(const TCHAR *fn);

View File

@ -1033,6 +1033,18 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,106,160,50,14,BS_FLAT
END
IDD_DOSAVEORNOTBOX DIALOGEX 0, 0, 350, 115
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_THICKFRAME
CAPTION "Save"
FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1
BEGIN
LTEXT "",IDC_DOSAVEORNOTTEX,30,30,126,126
DEFPUSHBUTTON "Yes",IDYES,50,85,50,14,BS_FLAT
PUSHBUTTON "No",IDNO,105,85,50,14,BS_FLAT
PUSHBUTTON "Cancel",IDCANCEL,160,85,50,14,BS_FLAT
PUSHBUTTON "Yes to all",IDRETRY,215,85,60,14,BS_FLAT
PUSHBUTTON "No to all",IDIGNORE,280,85,60,14,BS_FLAT
END
IDD_GOLINE DIALOGEX 26, 41, 261, 88
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU

View File

@ -871,7 +871,6 @@ bool Notepad_plus::fileClose(BufferID id, int curView)
}
else if (buf->isDirty())
{
res = doSaveOrNot(fileNamePath);
if (res == IDYES)
{
@ -899,10 +898,13 @@ bool Notepad_plus::fileClose(BufferID id, int curView)
bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
{
bool noSaveToAll = false;
bool saveToAll = false;
//closes all documents, makes the current view the only one visible
//first check if we need to save any file
for (size_t i = 0; i < _mainDocTab.nbItem(); ++i)
for (size_t i = 0; i < _mainDocTab.nbItem() && !noSaveToAll; ++i)
{
BufferID id = _mainDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id);
@ -929,7 +931,6 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
0, // not used
buf->getFullPathName());
//int res = doSaveOrNot(buf->getFullPathName());
if (res == IDYES)
{
if (!fileSave(id))
@ -947,7 +948,16 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
if (!activateBuffer(id, SUB_VIEW))
switchEditViewTo(MAIN_VIEW);
int res = doSaveOrNot(buf->getFullPathName());
int res = -1;
if (saveToAll)
{
res = IDYES;
}
else
{
res = doSaveOrNot(buf->getFullPathName(), true);
}
if (res == IDYES)
{
if (!fileSave(id))
@ -957,10 +967,22 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
{
return false;
}
else if (res == IDIGNORE)
{
noSaveToAll = true;
}
else if (res == IDRETRY)
{
if (!fileSave(id))
return false; // Abort entire procedure.
saveToAll = true;
}
}
}
for (size_t i = 0; i < _subDocTab.nbItem(); ++i)
}
for (size_t i = 0; i < _subDocTab.nbItem() && !noSaveToAll; ++i)
{
BufferID id = _subDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id);
@ -1002,7 +1024,16 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
activateBuffer(id, SUB_VIEW);
switchEditViewTo(SUB_VIEW);
int res = doSaveOrNot(buf->getFullPathName());
int res = -1;
if (saveToAll)
{
res = IDYES;
}
else
{
res = doSaveOrNot(buf->getFullPathName(), true);
}
if (res == IDYES)
{
if (!fileSave(id))
@ -1013,6 +1044,17 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
return false;
//otherwise continue (IDNO)
}
else if (res == IDIGNORE)
{
noSaveToAll = true;
}
else if (res == IDRETRY)
{
if (!fileSave(id))
return false; // Abort entire procedure.
saveToAll = true;
}
}
}
}
@ -1042,16 +1084,19 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
// First check if we need to save any file.
std::vector<int>::const_iterator itIndexesEnd = krvecBufferIndexes.end();
bool noSaveToAll = false;
bool saveToAll = false;
for (std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex)
{
BufferID id = _pDocTab->getBufferByIndex(*itIndex);
Buffer * buf = MainFileManager->getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0)
{
// Do nothing.
}
else if (buf->isDirty())
else if (buf->isDirty() && !noSaveToAll)
{
if (_activeView == MAIN_VIEW)
{
@ -1065,7 +1110,16 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
switchEditViewTo(SUB_VIEW);
}
int res = doSaveOrNot(buf->getFullPathName());
int res = -1;
if (saveToAll)
{
res = IDYES;
}
else
{
res = doSaveOrNot(buf->getFullPathName(), true);
}
if (res == IDYES)
{
if (!fileSave(id))
@ -1075,6 +1129,17 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
{
return false;
}
else if (res == IDIGNORE)
{
noSaveToAll = true;
}
else if (res == IDRETRY)
{
if (!fileSave(id))
return false; // Abort entire procedure.
saveToAll = true;
}
}
}
@ -1135,10 +1200,13 @@ bool Notepad_plus::fileCloseAllButCurrent()
BufferID current = _pEditView->getCurrentBufferID();
int active = _pDocTab->getCurrentTabIndex();
const int activeViewID = currentView();
bool noSaveToAll = false;
bool saveToAll = false;
//closes all documents, makes the current view the only one visible
//first check if we need to save any file
for (size_t i = 0; i < _mainDocTab.nbItem(); ++i)
for (size_t i = 0; i < _mainDocTab.nbItem() && !noSaveToAll; ++i)
{
BufferID id = _mainDocTab.getBufferByIndex(i);
if (id == current)
@ -1154,7 +1222,16 @@ bool Notepad_plus::fileCloseAllButCurrent()
if (!activateBuffer(id, SUB_VIEW))
switchEditViewTo(MAIN_VIEW);
int res = doSaveOrNot(buf->getFullPathName());
int res = -1;
if (saveToAll)
{
res = IDYES;
}
else
{
res = doSaveOrNot(buf->getFullPathName(), true);
}
if (res == IDYES)
{
if (!fileSave(id))
@ -1164,9 +1241,20 @@ bool Notepad_plus::fileCloseAllButCurrent()
{
return false;
}
else if (res == IDIGNORE)
{
noSaveToAll = true;
}
else if (res == IDRETRY)
{
if (!fileSave(id))
return false; // Abort entire procedure.
saveToAll = true;
}
}
for (size_t i = 0; i < _subDocTab.nbItem(); ++i)
}
for (size_t i = 0; i < _subDocTab.nbItem() && !noSaveToAll; ++i)
{
BufferID id = _subDocTab.getBufferByIndex(i);
Buffer * buf = MainFileManager->getBufferByID(id);
@ -1181,7 +1269,16 @@ bool Notepad_plus::fileCloseAllButCurrent()
activateBuffer(id, SUB_VIEW);
switchEditViewTo(SUB_VIEW);
int res = doSaveOrNot(buf->getFullPathName());
int res = -1;
if (saveToAll)
{
res = IDYES;
}
else
{
res = doSaveOrNot(buf->getFullPathName(), true);
}
if (res == IDYES)
{
if (!fileSave(id))
@ -1191,6 +1288,17 @@ bool Notepad_plus::fileCloseAllButCurrent()
{
return false;
}
else if (res == IDIGNORE)
{
noSaveToAll = true;
}
else if (res == IDRETRY)
{
if (!fileSave(id))
return false; // Abort entire procedure.
saveToAll = true;
}
}
}

View File

@ -32,6 +32,7 @@
#include "AboutDlg.h"
#include "Parameters.h"
#include "localization.h"
INT_PTR CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
@ -225,3 +226,95 @@ void DebugInfoDlg::doDialog()
goToCenter();
}
void DoSaveOrNotBox::doDialog(bool isRTL)
{
if (isRTL)
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_DOSAVEORNOTBOX, &pMyDlgTemplate);
::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
}
else
::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_DOSAVEORNOTBOX), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
}
void DoSaveOrNotBox::changeLang()
{
generic_string msg;
generic_string defaultMessage = TEXT("Save file \"$STR_REPLACE$\" ?");
NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance()->getNativeLangSpeaker();
if (nativeLangSpeaker->changeDlgLang(_hSelf, "DoSaveOrNot"))
{
const unsigned char len = 255;
TCHAR text[len];
::GetDlgItemText(_hSelf, IDC_DOSAVEORNOTTEX, text, len);
msg = text;
}
if (msg.empty())
msg = defaultMessage;
msg = stringReplace(msg, TEXT("$STR_REPLACE$"), _fn);
::SetDlgItemText(_hSelf, IDC_DOSAVEORNOTTEX, msg.c_str());
}
INT_PTR CALLBACK DoSaveOrNotBox::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/)
{
switch (message)
{
case WM_INITDIALOG :
{
changeLang();
::EnableWindow(::GetDlgItem(_hSelf, IDRETRY), _isMulti);
::EnableWindow(::GetDlgItem(_hSelf, IDIGNORE), _isMulti);
goToCenter();
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDCANCEL:
{
::EndDialog(_hSelf, -1);
clickedButtonId = IDCANCEL;
return TRUE;
}
case IDYES:
{
::EndDialog(_hSelf, 0);
clickedButtonId = IDYES;
return TRUE;
}
case IDNO:
{
::EndDialog(_hSelf, 0);
clickedButtonId = IDNO;
return TRUE;
}
case IDIGNORE:
{
::EndDialog(_hSelf, 0);
clickedButtonId = IDIGNORE;
return TRUE;
}
case IDRETRY:
{
::EndDialog(_hSelf, 0);
clickedButtonId = IDRETRY;
return TRUE;
}
}
}
default:
return FALSE;
}
}

View File

@ -96,3 +96,35 @@ private:
URLCtrl _copyToClipboardLink;
};
class DoSaveOrNotBox : public StaticDialog
{
public:
DoSaveOrNotBox() : StaticDialog() {};
void init(HINSTANCE hInst, HWND parent, const TCHAR* fn, bool isMulti) {
Window::init(hInst, parent);
if (fn)
_fn = fn;
_isMulti = isMulti;
};
void doDialog(bool isRTL = false);
virtual void destroy() {
};
int getClickedButtonId() const {
return clickedButtonId;
};
void changeLang();
protected:
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
int clickedButtonId = -1;
generic_string _fn;
bool _isMulti = false;
};

View File

@ -36,7 +36,6 @@
IDD_SHORTCUTMAPPER_DLG DIALOGEX 0, 0, 450, 355
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU | WS_MAXIMIZEBOX | WS_THICKFRAME
//EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Shortcut mapper"
FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1
BEGIN

View File

@ -304,6 +304,9 @@
#define IDC_DEBUGINFO_EDIT 1751
#define IDC_DEBUGINFO_COPYLINK 1752
#define IDD_DOSAVEORNOTBOX 1760
#define IDC_DOSAVEORNOTTEX 1761
//#define IDD_USER_DEFINE_BOX 1800
//#define IDD_RUN_DLG 1900
//#define IDD_MD5FROMFILES_DLG 1920