From b75ccd29e201519b74cb3c3cd74aa27bd50fd597 Mon Sep 17 00:00:00 2001 From: Jon Bockhorst Date: Tue, 1 Jan 2019 03:18:35 -0600 Subject: [PATCH] Added close unchanged tabs command Close #5185, close #5007 --- PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/Notepad_plus.rc | 1 + PowerEditor/src/NppCommands.cpp | 6 +++++ PowerEditor/src/NppIO.cpp | 16 +++++++++++++ PowerEditor/src/NppNotification.cpp | 1 + PowerEditor/src/Parameters.cpp | 1 + PowerEditor/src/localization.cpp | 37 +++++++++++++++-------------- PowerEditor/src/menuCmdID.h | 3 ++- 8 files changed, 47 insertions(+), 19 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 8e60e138..5912b7d6 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -189,6 +189,7 @@ public: bool fileCloseAllGiven(const std::vector& krvecBufferIndexes); bool fileCloseAllToLeft(); bool fileCloseAllToRight(); + bool fileCloseAllUnchanged(); bool fileSave(BufferID id = BUFFER_INVALID); bool fileSaveAll(); bool fileSaveSpecific(const generic_string& fileNameToSave); diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 358fa4b9..5d88228f 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -249,6 +249,7 @@ BEGIN MENUITEM "Close All but Active Document", IDM_FILE_CLOSEALL_BUT_CURRENT 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 END MENUITEM "Move to Recycle Bin", IDM_FILE_DELETE MENUITEM SEPARATOR diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 617157fc..553b07bb 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -215,6 +215,11 @@ void Notepad_plus::command(int id) checkDocState(); break; + case IDM_FILE_CLOSEALL_UNCHANGED: + fileCloseAllUnchanged(); + checkDocState(); + break; + case IDM_FILE_SAVE : fileSave(); break; @@ -3356,6 +3361,7 @@ void Notepad_plus::command(int id) case IDM_FILE_CLOSEALL_BUT_CURRENT : case IDM_FILE_CLOSEALL_TOLEFT : case IDM_FILE_CLOSEALL_TORIGHT : + case IDM_FILE_CLOSEALL_UNCHANGED: case IDM_FILE_SAVE : case IDM_FILE_SAVEALL : case IDM_FILE_RELOAD: diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 0c0b8ab8..263a6dd2 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1106,6 +1106,22 @@ bool Notepad_plus::fileCloseAllToRight() return fileCloseAllGiven(vecIndexesToClose); } +bool Notepad_plus::fileCloseAllUnchanged() +{ + std::vector vecIndexesToClose; + + for (int i = int(_pDocTab->nbItem()) - 1; i >= 0; i--) { + BufferID id = _mainDocTab.getBufferByIndex(i); + Buffer* buf = MainFileManager->getBufferByID(id); + if ((buf->isUntitled() && buf->docLength() == 0) || !buf->isDirty()) + { + vecIndexesToClose.push_back(i); + } + } + + return fileCloseAllGiven(vecIndexesToClose); +} + bool Notepad_plus::fileCloseAllButCurrent() { BufferID current = _pEditView->getCurrentBufferID(); diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index caa55b15..617e0a39 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -522,6 +522,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, TEXT("Close All BUT This"))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TOLEFT, TEXT("Close All to the Left"))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TORIGHT, TEXT("Close All to the Right"))); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_UNCHANGED, TEXT("Close All Unchanged"))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVE, TEXT("Save"))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, TEXT("Save As..."))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RENAME, TEXT("Rename"))); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 96e1696d..8eef120b 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -94,6 +94,7 @@ static const WinMenuKeyDefinition winKeyDefs[] = { VK_NULL, IDM_FILE_CLOSEALL_BUT_CURRENT, 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 }, { VK_NULL, IDM_FILE_DELETE, false, false, false, nullptr }, { VK_NULL, IDM_FILE_LOADSESSION, false, false, false, nullptr }, { VK_NULL, IDM_FILE_SAVESESSION, false, false, false, nullptr }, diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index b656c8bb..89982d8d 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -372,26 +372,27 @@ static const int tabContextMenuItemPos[] = // | | 0, // 0 : Close 1, // 1 : Close ALL BUT This - 4, // 2 : Save - 5, // 3 : Save As - 9, // 4 : Print - 23, // 5 : Move to Other View - 24, // 6 : Clone to Other View - 19, // 7 : Full File Path to Clipboard - 20, // 8 : Filename to Clipboard - 21, // 9 : Current Dir. Path to Clipboard - 6, // 10: Rename - 7, // 11: Move to Recycle Bin - 16, // 12: Read-Only - 17, // 13: Clear Read-Only Flag - 25, // 14: Move to New Instance - 26, // 15: Open to New Instance - 8, // 16: Reload + 5, // 2 : Save + 6, // 3 : Save As + 10, // 4 : Print + 24, // 5 : Move to Other View + 25, // 6 : Clone to Other View + 20, // 7 : Full File Path to Clipboard + 21, // 8 : Filename to Clipboard + 22, // 9 : Current Dir. Path to Clipboard + 7, // 10: Rename + 8, // 11: Move to Recycle Bin + 17, // 12: Read-Only + 18, // 13: Clear Read-Only Flag + 26, // 14: Move to New Instance + 27, // 15: Open to New Instance + 9, // 16: Reload 2, // 17: Close ALL to the Left 3, // 18: Close ALL to the Right - 11, // 19: Open Containing Folder in Explorer - 12, // 20: Open Containing Folder in cmd - 14, // 21: Open in Default Viewer + 12, // 19: Open Containing Folder in Explorer + 13, // 20: Open Containing Folder in cmd + 15, // 21: Open in Default Viewer + 4, // 22: Close ALL Unchanged -1 //-------End }; diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 3e1455ca..b1d7667f 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -57,10 +57,11 @@ #define IDM_FILE_RESTORELASTCLOSEDFILE (IDM_FILE + 21) #define IDM_FILE_OPENFOLDERASWORSPACE (IDM_FILE + 22) #define IDM_FILE_OPEN_DEFAULT_VIEWER (IDM_FILE + 23) + #define IDM_FILE_CLOSEALL_UNCHANGED (IDM_FILE + 24) // 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_OPEN_DEFAULT_VIEWER + #define IDM_FILEMENU_LASTONE IDM_FILE_CLOSEALL_UNCHANGED // 0 based position of command "Exit" including the bars in the file menu // and without counting "Recent files history" items