[NEW_FEATURE] (Author: Andreas Jonsson) Add "close all tab to left" and "close all tab to right" features.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1097 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2013-08-03 23:40:07 +00:00
parent e172c69700
commit 082253c37f
12 changed files with 125 additions and 17 deletions

View File

@ -279,6 +279,9 @@
<Item CMID="13" name="移除檔案唯讀屬性"/>
<Item CMID="14" name="將此檔案移至新啟動的 Notepad++"/>
<Item CMID="15" name="開啟此檔案到新啟動的 Notepad++"/>
<Item CMID="16" name="重新載入"/>
<Item CMID="17" name="關閉左邊所有檔案"/>
<Item CMID="18" name="關閉右邊所有檔案"/>
</TabBar>
</Menu>

View File

@ -278,6 +278,8 @@
<Item CMID="14" name="Move to New Instance"/>
<Item CMID="15" name="Open in New Instance"/>
<Item CMID="16" name="Reload"/>
<Item CMID="17" name="Close All to the Left"/>
<Item CMID="18" name="Close All to the Right"/>
</TabBar>
</Menu>

View File

@ -278,6 +278,8 @@
<Item CMID="14" name="Move to New Instance"/>
<Item CMID="15" name="Open in New Instance"/>
<Item CMID="16" name="Reload"/>
<Item CMID="17" name="Close All to the Left"/>
<Item CMID="18" name="Close All to the Right"/>
</TabBar>
</Menu>

View File

@ -287,6 +287,8 @@
<Item CMID="14" name="Déplacer vers une nouvelle fenêtre"/>
<Item CMID="15" name="Ouvrir dans une nouvelle fenêtre"/>
<Item CMID="16" name="Recharger"/>
<Item CMID="17" name="Fermer les onglets sur la gauche"/>
<Item CMID="18" name="Fermer les onglets sur la droite"/>
</TabBar>
</Menu>
<Dialog>

View File

@ -125,6 +125,7 @@
#endif //SIZE_DLG_H
#include "localization.h"
#include <vector>
#define MENU 0x01
@ -236,6 +237,9 @@ public:
bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from
bool fileCloseAll();
bool fileCloseAllButCurrent();
bool fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes);
bool fileCloseAllToLeft();
bool fileCloseAllToRight();
bool fileSave(BufferID id = BUFFER_INVALID);
bool fileSaveAll();
bool fileSaveAs(BufferID id = BUFFER_INVALID, bool isSaveCopy = false);

View File

@ -209,7 +209,12 @@ BEGIN
MENUITEM "Rename...", IDM_FILE_RENAME
MENUITEM "&Close", IDM_FILE_CLOSE
MENUITEM "Clos&e All", IDM_FILE_CLOSEALL
MENUITEM "Close All but Active Document", IDM_FILE_CLOSEALL_BUT_CURRENT
POPUP "Close More"
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
END
MENUITEM "Move to Recycle Bin", IDM_FILE_DELETE
MENUITEM SEPARATOR
MENUITEM "Load Session...", IDM_FILE_LOADSESSION

View File

@ -112,6 +112,16 @@ void Notepad_plus::command(int id)
checkDocState();
break;
case IDM_FILE_CLOSEALL_TOLEFT :
fileCloseAllToLeft();
checkDocState();
break;
case IDM_FILE_CLOSEALL_TORIGHT :
fileCloseAllToRight();
checkDocState();
break;
case IDM_FILE_SAVE :
fileSave();
break;
@ -2491,6 +2501,8 @@ void Notepad_plus::command(int id)
case IDM_FILE_CLOSE :
case IDM_FILE_CLOSEALL :
case IDM_FILE_CLOSEALL_BUT_CURRENT :
case IDM_FILE_CLOSEALL_TOLEFT :
case IDM_FILE_CLOSEALL_TORIGHT :
case IDM_FILE_SAVE :
case IDM_FILE_SAVEALL :
case IDM_FILE_RELOAD:

View File

@ -638,6 +638,77 @@ bool Notepad_plus::fileCloseAll()
return true;
}
bool Notepad_plus::fileCloseAllGiven(const std::vector<int> &krvecBufferIndexes)
{
// First check if we need to save any file.
std::vector<int>::const_iterator itIndexesEnd = krvecBufferIndexes.end();
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
BufferID id = _pDocTab->getBufferByIndex(*itIndex);
Buffer * buf = MainFileManager->getBufferByID(id);
if (buf->isUntitled() && buf->docLength() == 0)
{
// Do nothing.
}
else if (buf->isDirty())
{
if(_activeView == MAIN_VIEW)
{
activateBuffer(id, MAIN_VIEW);
if(!activateBuffer(id, SUB_VIEW))
switchEditViewTo(MAIN_VIEW);
}
else
{
activateBuffer(id, SUB_VIEW);
switchEditViewTo(SUB_VIEW);
}
int res = doSaveOrNot(buf->getFullPathName());
if (res == IDYES)
{
if (!fileSave(id))
return false; // Abort entire procedure.
}
else if (res == IDCANCEL)
{
return false;
}
}
}
// Now we close.
for(std::vector<int>::const_iterator itIndex = krvecBufferIndexes.begin(); itIndex != itIndexesEnd; ++itIndex) {
doClose(_pDocTab->getBufferByIndex(*itIndex), currentView());
}
return true;
}
bool Notepad_plus::fileCloseAllToLeft()
{
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
// indexes (smaller than the one just closed) will point to the wrong tab.
std::vector<int> vecIndexesToClose;
for(int i = _pDocTab->getCurrentTabIndex() - 1; i >= 0; i--) {
vecIndexesToClose.push_back(i);
}
return fileCloseAllGiven(vecIndexesToClose);
}
bool Notepad_plus::fileCloseAllToRight()
{
// Indexes must go from high to low to deal with the fact that when one index is closed, any remaining
// indexes (smaller than the one just closed) will point to the wrong tab.
const int kiActive = _pDocTab->getCurrentTabIndex();
std::vector<int> vecIndexesToClose;
for(int i = _pDocTab->nbItem() - 1; i > kiActive; i--) {
vecIndexesToClose.push_back(i);
}
return fileCloseAllGiven(vecIndexesToClose);
}
bool Notepad_plus::fileCloseAllButCurrent()
{
BufferID current = _pEditView->getCurrentBufferID();

View File

@ -332,6 +332,8 @@ BOOL Notepad_plus::notify(SCNotification *notification)
vector<MenuItemUnit> itemUnitArray;
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, TEXT("Close")));
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_SAVE, TEXT("Save")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, TEXT("Save As...")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RENAME, TEXT("Rename")));

View File

@ -70,6 +70,8 @@ WinMenuKeyDefinition winKeyDefs[] = {
{VK_W, IDM_FILE_CLOSE, true, false, false, NULL},
{VK_NULL, IDM_FILE_CLOSEALL, false, false, false, NULL},
{VK_NULL, IDM_FILE_CLOSEALL_BUT_CURRENT, false, false, false, NULL},
{VK_NULL, IDM_FILE_CLOSEALL_TOLEFT, false, false, false, NULL},
{VK_NULL, IDM_FILE_CLOSEALL_TORIGHT, false, false, false, NULL},
{VK_NULL, IDM_FILE_DELETE, false, false, false, NULL},
{VK_NULL, IDM_FILE_RENAME, false, false, false, NULL},
{VK_NULL, IDM_FILE_LOADSESSION, false, false, false, NULL},

View File

@ -367,22 +367,23 @@ void NativeLangSpeaker::changeMenuLang(HMENU menuHandle, generic_string & plugin
int tabContextMenuItemPos[] = {
0, // 0 : Close
1, // 1 : Close ALL BUT This
2, // 2 : Save
3, // 3 : Save As
7, // 4 : Print
16,// 5 : Move to Other View
17,// 6 : Clone to Other View
12,// 7 : Full File Path to Clipboard
13,// 8 : Filename to Clipboard
14,// 9 : Current Dir. Path to Clipboard
4, // 10: Rename
5, // 11: Delete
9, // 12: Read-Only
10,// 13: Clear Read-Only Flag
18,// 14: Move to New Instance
19,// 15: Open to New Instance
6, // 16: Reload
4, // 2 : Save
5, // 3 : Save As
9, // 4 : Print
18,// 5 : Move to Other View
19,// 6 : Clone to Other View
14,// 7 : Full File Path to Clipboard
15,// 8 : Filename to Clipboard
16,// 9 : Current Dir. Path to Clipboard
6, // 10: Rename
7, // 11: Delete
11, // 12: Read-Only
12,// 13: Clear Read-Only Flag
20,// 14: Move to New Instance
21,// 15: Open to New Instance
8, // 16: Reload
2, // 17 : Close ALL to the Left
3, // 18 : Close ALL to the Right
-1 //-------End
};

View File

@ -37,6 +37,8 @@
#define IDM_FILE_CLOSE (IDM_FILE + 3)
#define IDM_FILE_CLOSEALL (IDM_FILE + 4)
#define IDM_FILE_CLOSEALL_BUT_CURRENT (IDM_FILE + 5)
#define IDM_FILE_CLOSEALL_TOLEFT (IDM_FILE + 18)
#define IDM_FILE_CLOSEALL_TORIGHT (IDM_FILE + 19)
#define IDM_FILE_SAVE (IDM_FILE + 6)
#define IDM_FILE_SAVEALL (IDM_FILE + 7)
#define IDM_FILE_SAVEAS (IDM_FILE + 8)