From 2b0f5dd6fd4feba74873929167ddcb356eb13445 Mon Sep 17 00:00:00 2001 From: Don HO Date: Fri, 15 Nov 2019 12:20:21 +0100 Subject: [PATCH] Enhance "Close all but This" functionality Old behaviour: While "Close all but This" operation, if user answer Yes or No for some files to Save dialog, then cancel for a file to save dialog, all files will be kept. New behaviour: The files for which user has answered for saving will be close, even the cancel answer at the end. Fix #7553 --- PowerEditor/src/NppIO.cpp | 58 +++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index a37610a4..c29e9633 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1198,6 +1198,9 @@ bool Notepad_plus::fileCloseAllButCurrent() const int activeViewID = currentView(); bool noSaveToAll = false; bool saveToAll = false; + std::vector mainSaveOpIndex, subSaveOpIndex; + + bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode(); //closes all documents, makes the current view the only one visible @@ -1207,6 +1210,7 @@ bool Notepad_plus::fileCloseAllButCurrent() BufferID id = _mainDocTab.getBufferByIndex(i); if (id == current) continue; + Buffer * buf = MainFileManager.getBufferByID(id); if (buf->isUntitled() && buf->docLength() == 0) { @@ -1230,12 +1234,15 @@ bool Notepad_plus::fileCloseAllButCurrent() if (res == IDYES) { - if (!fileSave(id)) - return false; //abort entire procedure + bool isSaved = fileSave(id); + if (isSaved) + mainSaveOpIndex.push_back((unsigned int)i); + else + res = IDCANCEL; //about to abort entire procedure } - else if (res == IDCANCEL) + else if (res == IDNO) { - return false; + mainSaveOpIndex.push_back((unsigned int)i); } else if (res == IDIGNORE) { @@ -1248,14 +1255,28 @@ bool Notepad_plus::fileCloseAllButCurrent() saveToAll = true; } + + + if (res == IDCANCEL) + { + for (int32_t j = static_cast(mainSaveOpIndex.size()) - 1; j >= 0; j--) //close all from right to left + { + doClose(_mainDocTab.getBufferByIndex(mainSaveOpIndex[j]), MAIN_VIEW, isSnapshotMode); + } + + return false; + } + } } + for (size_t i = 0; i < _subDocTab.nbItem() && !noSaveToAll; ++i) { BufferID id = _subDocTab.getBufferByIndex(i); Buffer * buf = MainFileManager.getBufferByID(id); if (id == current) continue; + if (buf->isUntitled() && buf->docLength() == 0) { // Do nothing @@ -1275,14 +1296,18 @@ bool Notepad_plus::fileCloseAllButCurrent() res = doSaveOrNot(buf->getFullPathName(), true); } + if (res == IDYES) { - if (!fileSave(id)) - return false; //abort entire procedure + bool isSaved = fileSave(id); + if (isSaved) + subSaveOpIndex.push_back((unsigned int)i); + else + res = IDCANCEL; //about to abort entire procedure } - else if (res == IDCANCEL) + else if (res == IDNO) { - return false; + subSaveOpIndex.push_back((unsigned int)i); } else if (res == IDIGNORE) { @@ -1295,13 +1320,28 @@ bool Notepad_plus::fileCloseAllButCurrent() saveToAll = true; } + + + if (res == IDCANCEL) + { + for (int32_t j = static_cast(mainSaveOpIndex.size()) - 1; j >= 0; j--) //close all from right to left + { + doClose(_mainDocTab.getBufferByIndex(mainSaveOpIndex[j]), MAIN_VIEW, isSnapshotMode); + } + + for (int32_t j = static_cast(subSaveOpIndex.size()) - 1; j >= 0; j--) //close all from right to left + { + doClose(_subDocTab.getBufferByIndex(subSaveOpIndex[j]), SUB_VIEW, isSnapshotMode); + } + return false; + } + } } // We may have to restore previous view after saving new files switchEditViewTo(activeViewID); - bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode(); //Then start closing, inactive view first so the active is left open if (bothActive()) {