Add "Close All BUT Pinned" command

Close #15863
This commit is contained in:
Don Ho 2024-11-28 02:33:29 +01:00
parent 6229e0f5d4
commit 61a1ca89ff
7 changed files with 50 additions and 4 deletions

View File

@ -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<BufferViewInfo>& krvecBuffer);
bool fileCloseAllToLeft();
bool fileCloseAllToRight();

View File

@ -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

View File

@ -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:

View File

@ -1436,6 +1436,41 @@ bool Notepad_plus::fileCloseAllToRight()
return fileCloseAllGiven(bufsToClose);
}
void Notepad_plus::fileCloseAllButPinned()
{
std::vector<BufferViewInfo> 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

View File

@ -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"));

View File

@ -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 },

View File

@ -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