Improve 'Close all to the left' and 'Close all to the right' user experience

Description of the Issue
Improve "Close all to the left/right" functionality.
This is an enhancement request. Similar request was made in past #2555, but has been closed during tracker cleanup process.

Steps to Reproduce the Issue
1. Create 4 tabs says (tab 1, tab 2, tab 3, tab 4)
2. Make all the tab dirty (I mean type, something in each tab, but don't save any).
3. Now right click on tab 1 and choose "Close All to the right"
4. Three popup for asking to save file will appear (For tab 4, tab 3 and tab 2)
5. Click "No" for tab 4 and tab 3. And click cancel for tab 2.

Expected Behavior:
After step 5, tab 4 and tab 3 should be closed. And for Remaining tabs, operation should be cancelled.

Actual Behavior:
Nothing happens after step 5.

Same defect reproduction steps are applicable for "Close all to the left".

Fix #7501, close #7502
This commit is contained in:
Rajendra Singh 2019-11-01 12:27:40 +05:30 committed by Don HO
parent 485b5aa7c7
commit 4d5c1b6564
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

View File

@ -1074,22 +1074,23 @@ bool Notepad_plus::fileCloseAll(bool doDeleteBackup, bool isSnapshotMode)
return true; return true;
} }
bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes) bool Notepad_plus::fileCloseAllGiven(const std::vector<int>& krvecBufferIndexes)
{ {
// First check if we need to save any file. // First check if we need to save any file.
std::vector<int>::const_iterator itIndexesEnd = krvecBufferIndexes.end();
bool noSaveToAll = false; bool noSaveToAll = false;
bool saveToAll = false; bool saveToAll = false;
std::vector<int> bufferIndexesToClose;
for (std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) for (const auto& index : krvecBufferIndexes)
{ {
BufferID id = _pDocTab->getBufferByIndex(*itIndex); BufferID id = _pDocTab->getBufferByIndex(index);
Buffer * buf = MainFileManager.getBufferByID(id); Buffer* buf = MainFileManager.getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0) if ((buf->isUntitled() && buf->docLength() == 0) || noSaveToAll || !buf->isDirty())
{ {
// Do nothing. // Do nothing, these documents are already ready to close
bufferIndexesToClose.push_back(index);
} }
else if (buf->isDirty() && !noSaveToAll) else if (buf->isDirty() && !noSaveToAll)
{ {
@ -1105,44 +1106,44 @@ bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
switchEditViewTo(SUB_VIEW); switchEditViewTo(SUB_VIEW);
} }
int res = -1; /* Do you want to save
if (saveToAll) * IDYES : Yes
{ * IDRETRY : Yes to All
res = IDYES; * IDNO : No
} * IDIGNORE : No To All
else * IDCANCEL : Cancel Opration
{ */
res = doSaveOrNot(buf->getFullPathName(), true); int res = saveToAll ? IDYES : doSaveOrNot(buf->getFullPathName(), true);
}
if (res == IDYES) if (res == IDYES || res == IDRETRY)
{ {
if (!fileSave(id)) if (!fileSave(id))
return false; // Abort entire procedure. break; // Abort entire procedure, but close whatever processed so far
bufferIndexesToClose.push_back(index);
if (res == IDRETRY)
saveToAll = true;
}
else if (res == IDNO || res == IDIGNORE)
{
bufferIndexesToClose.push_back(index);
if (res == IDIGNORE)
noSaveToAll = true;
} }
else if (res == IDCANCEL) else if (res == IDCANCEL)
{ {
return false; break;
}
else if (res == IDIGNORE)
{
noSaveToAll = true;
}
else if (res == IDRETRY)
{
if (!fileSave(id))
return false; // Abort entire procedure.
saveToAll = true;
} }
} }
} }
// Now we close. // Now we close.
bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode(); bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode();
for (std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) for (const auto& index : bufferIndexesToClose)
{ {
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView(), isSnapshotMode); doClose(_pDocTab->getBufferByIndex(index), currentView(), isSnapshotMode);
} }
return true; return true;