From d0b2a9ff9d872f977793e4f83a07bdd7c9c24882 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 14 Jun 2022 02:52:52 +0200 Subject: [PATCH] Skip save all warning dialg if only current editing file is dirty Here is the behaviour of this commit: 1. If there's only one file dirty, and it's current editing one, then SaveAll dialog won't display. 2. If there's only one file dirty, and it's NOT current editing one, then SaveAll dialog WILL display. 3. If there's 1 editing file which is dirty, and its clone (dirty also) is on the other view, then SaveAll dialog WILL display. Fix #10995 --- PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/NppIO.cpp | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 1a5bd1c40..343af9ff6 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -154,7 +154,7 @@ public: void setTitle(); void getTaskListInfo(TaskListInfo *tli); - + size_t getNbDirtyBuffer(int view); // For filtering the modeless Dialog message //! \name File Operations diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 581f5b43a..f26725209 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1636,9 +1636,41 @@ bool Notepad_plus::fileSaveAllConfirm() return confirmed; } +size_t Notepad_plus::getNbDirtyBuffer(int view) +{ + if (view != MAIN_VIEW && view != SUB_VIEW) + return 0; + DocTabView* pDocTabView = &_mainDocTab; + if (view == SUB_VIEW) + pDocTabView = &_subDocTab; + + size_t count = 0; + for (size_t i = 0; i < pDocTabView->nbItem(); ++i) + { + BufferID id = pDocTabView->getBufferByIndex(i); + Buffer* buf = MainFileManager.getBufferByID(id); + + if (buf->isDirty()) + { + ++count; + } + } + return count; +} + bool Notepad_plus::fileSaveAll() { - if ( fileSaveAllConfirm() ) + int nbDirty = getNbDirtyBuffer(MAIN_VIEW) + getNbDirtyBuffer(SUB_VIEW); + + if (!nbDirty) + return false; + + Buffer* curBuf = _pEditView->getCurrentBuffer(); + if (nbDirty == 1 && curBuf->isDirty()) + { + fileSave(curBuf); + } + else if (fileSaveAllConfirm()) { if (viewVisible(MAIN_VIEW)) {