From 61a1ca89ff8a7821fbdf4564eb864008702ef2ad Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 28 Nov 2024 02:33:29 +0100 Subject: [PATCH] Add "Close All BUT Pinned" command Close #15863 --- PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/Notepad_plus.rc | 1 + PowerEditor/src/NppCommands.cpp | 10 ++++++-- PowerEditor/src/NppIO.cpp | 37 ++++++++++++++++++++++++++++- PowerEditor/src/NppNotification.cpp | 1 + PowerEditor/src/Parameters.cpp | 1 + PowerEditor/src/menuCmdID.h | 3 ++- 7 files changed, 50 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 2b26c49a3..8f63b33ba 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -179,6 +179,7 @@ public: bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from bool fileCloseAll(bool doDeleteBackup, bool isSnapshotMode = false); bool fileCloseAllButCurrent(); + void fileCloseAllButPinned(); bool fileCloseAllGiven(const std::vector& krvecBuffer); bool fileCloseAllToLeft(); bool fileCloseAllToRight(); diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index fb859d01c..9bebd32aa 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -458,6 +458,7 @@ BEGIN POPUP "Close &Multiple Documents" BEGIN MENUITEM "Close All but Active Document", IDM_FILE_CLOSEALL_BUT_CURRENT + MENUITEM "Close All but Pinned Documents", IDM_FILE_CLOSEALL_BUT_PINNED MENUITEM "Close All to the Left", IDM_FILE_CLOSEALL_TOLEFT MENUITEM "Close All to the Right", IDM_FILE_CLOSEALL_TORIGHT MENUITEM "Close All Unchanged", IDM_FILE_CLOSEALL_UNCHANGED diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 6883538ff..610d72f04 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -277,13 +277,18 @@ void Notepad_plus::command(int id) { bool isSnapshotMode = NppParameters::getInstance().getNppGUI().isSnapshotMode(); fileCloseAll(isSnapshotMode, false); - checkDocState(); + checkDocState(); break; } case IDM_FILE_CLOSEALL_BUT_CURRENT : fileCloseAllButCurrent(); - checkDocState(); + checkDocState(); + break; + + case IDM_FILE_CLOSEALL_BUT_PINNED : + fileCloseAllButPinned(); + checkDocState(); break; case IDM_FILE_CLOSEALL_TOLEFT : @@ -4058,6 +4063,7 @@ void Notepad_plus::command(int id) case IDM_FILE_CLOSE : case IDM_FILE_CLOSEALL : case IDM_FILE_CLOSEALL_BUT_CURRENT : + case IDM_FILE_CLOSEALL_BUT_PINNED : case IDM_FILE_CLOSEALL_TOLEFT : case IDM_FILE_CLOSEALL_TORIGHT : case IDM_FILE_CLOSEALL_UNCHANGED: diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 64336e137..21e9cde0e 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1436,6 +1436,41 @@ bool Notepad_plus::fileCloseAllToRight() return fileCloseAllGiven(bufsToClose); } +void Notepad_plus::fileCloseAllButPinned() +{ + std::vector bufsToClose; + + int iPinned = -1; + for (int j = 0; j < int(_mainDocTab.nbItem()); ++j) + { + if (_mainDocTab.getBufferByIndex(j)->isPinned()) + iPinned++; + else + break; + } + + for (int i = int(_mainDocTab.nbItem()) - 1; i > iPinned; i--) + { + bufsToClose.push_back(BufferViewInfo(_mainDocTab.getBufferByIndex(i), MAIN_VIEW)); + } + + + iPinned = -1; + for (int j = 0; j < int(_subDocTab.nbItem()); ++j) + { + if (_subDocTab.getBufferByIndex(j)->isPinned()) + iPinned++; + else + break; + } + for (int i = int(_subDocTab.nbItem()) - 1; i > iPinned; i--) + { + bufsToClose.push_back(BufferViewInfo(_subDocTab.getBufferByIndex(i), SUB_VIEW)); + } + + fileCloseAllGiven(bufsToClose); +} + bool Notepad_plus::fileCloseAllUnchanged() { // Indexes must go from high to low to deal with the fact that when one index is closed, any remaining @@ -1472,10 +1507,10 @@ bool Notepad_plus::fileCloseAllButCurrent() for (size_t i = 0; i < _mainDocTab.nbItem() && !noSaveToAll; ++i) { BufferID id = _mainDocTab.getBufferByIndex(i); + Buffer* buf = MainFileManager.getBufferByID(id); if (id == current) continue; - Buffer * buf = MainFileManager.getBufferByID(id); if (buf->isUntitled() && buf->docLength() == 0) { // Do nothing diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 1931783f4..7e1ab477c 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -571,6 +571,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, L"Close")); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, L"Close All BUT This", L"Close Multiple Tabs")); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_PINNED, L"Close All BUT Pinned", L"Close Multiple Tabs")); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TOLEFT, L"Close All to the Left", L"Close Multiple Tabs")); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TORIGHT, L"Close All to the Right", L"Close Multiple Tabs")); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_UNCHANGED, L"Close All Unchanged", L"Close Multiple Tabs")); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index c575eb7ee..343908a9f 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -72,6 +72,7 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_W, IDM_FILE_CLOSE, true, false, false, nullptr }, { VK_W, IDM_FILE_CLOSEALL, true, false, true, nullptr }, { VK_NULL, IDM_FILE_CLOSEALL_BUT_CURRENT, false, false, false, nullptr }, + { VK_NULL, IDM_FILE_CLOSEALL_BUT_PINNED, false, false, false, nullptr }, { VK_NULL, IDM_FILE_CLOSEALL_TOLEFT, false, false, false, nullptr }, { VK_NULL, IDM_FILE_CLOSEALL_TORIGHT, false, false, false, nullptr }, { VK_NULL, IDM_FILE_CLOSEALL_UNCHANGED, false, false, false, nullptr }, diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index af743643f..eac1411e4 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -47,10 +47,11 @@ #define IDM_FILE_OPEN_DEFAULT_VIEWER (IDM_FILE + 23) #define IDM_FILE_CLOSEALL_UNCHANGED (IDM_FILE + 24) #define IDM_FILE_CONTAININGFOLDERASWORKSPACE (IDM_FILE + 25) + #define IDM_FILE_CLOSEALL_BUT_PINNED (IDM_FILE + 26) // IMPORTANT: If list above is modified, you have to change the following values: // To be updated if new menu item(s) is (are) added in menu "File" - #define IDM_FILEMENU_LASTONE IDM_FILE_CONTAININGFOLDERASWORKSPACE + #define IDM_FILEMENU_LASTONE IDM_FILE_CLOSEALL_BUT_PINNED // 0 based position of command "Exit" including the bars in the file menu // and without counting "Recent files history" items