[NEW_FEATURE] Add Close/Keep the selected files commands in Document List Panel.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1037 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2013-05-01 15:43:51 +00:00
parent d7cce21309
commit db19cf8d6a
9 changed files with 110 additions and 16 deletions

View File

@ -4886,7 +4886,10 @@ bool Notepad_plus::reloadLang()
{
_nativeLangSpeaker.changeLangTabDrapContextMenu(_tabPopupDropMenu.getMenuHandle());
}
if (_fileSwitcherMultiFilePopupMenu.isCreated())
{
//_nativeLangSpeaker.changeLangTabDrapContextMenu(_fileSwitcherMultiFilePopupMenu.getMenuHandle());
}
if (_preference.isCreated())
{
_nativeLangSpeaker.changePrefereceDlgLang(_preference);

View File

@ -330,7 +330,7 @@ private:
SplitterContainer *_pMainSplitter;
SplitterContainer _subSplitter;
ContextMenu _tabPopupMenu, _tabPopupDropMenu;
ContextMenu _tabPopupMenu, _tabPopupDropMenu, _fileSwitcherMultiFilePopupMenu;
ToolBar _toolBar;
IconList _docTabIconList;

View File

@ -70,6 +70,23 @@ void Notepad_plus::command(int id)
fileReload();
break;
case IDM_FILESWITCHER_FILESCLOSE:
case IDM_FILESWITCHER_FILESCLOSEOTHERS:
if (_pFileSwitcherPanel)
{
vector<SwitcherFileInfo> files = _pFileSwitcherPanel->getSelectedFiles(id == IDM_FILESWITCHER_FILESCLOSEOTHERS);
for (size_t i = 0; i < files.size(); i++)
{
fileClose((BufferID)files[i]._bufID, files[i]._iView);
}
if (id == IDM_FILESWITCHER_FILESCLOSEOTHERS)
{
// Get current buffer and its view
_pFileSwitcherPanel->activateItem(int(_pEditView->getCurrentBufferID()), currentView());
}
}
break;
case IDM_FILE_CLOSE:
if (fileClose())
checkDocState();

View File

@ -291,6 +291,9 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case NM_RCLICK :
{
POINT p;
::GetCursorPos(&p);
if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf())
{
switchEditViewTo(MAIN_VIEW);
@ -302,14 +305,26 @@ BOOL Notepad_plus::notify(SCNotification *notification)
else if (_pFileSwitcherPanel && notification->nmhdr.hwndFrom == _pFileSwitcherPanel->getHSelf())
{
// Already switched, so do nothing here.
if (_pFileSwitcherPanel->nbSelectedFiles() > 1)
{
if (!_fileSwitcherMultiFilePopupMenu.isCreated())
{
vector<MenuItemUnit> itemUnitArray;
itemUnitArray.push_back(MenuItemUnit(IDM_FILESWITCHER_FILESCLOSE, TEXT("Close Selected files")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILESWITCHER_FILESCLOSEOTHERS, TEXT("Close others files")));
_fileSwitcherMultiFilePopupMenu.create(_pPublicInterface->getHSelf(), itemUnitArray);
_nativeLangSpeaker.changeLangTabContextMenu(_fileSwitcherMultiFilePopupMenu.getMenuHandle());
}
_fileSwitcherMultiFilePopupMenu.display(p);
return TRUE;
}
}
else // From tool bar or Status Bar
return TRUE;
//break;
POINT p;
::GetCursorPos(&p);
if (!_tabPopupMenu.isCreated())
{
vector<MenuItemUnit> itemUnitArray;

View File

@ -84,6 +84,9 @@ BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPA
case NM_CLICK:
{
if ((0x80 & GetKeyState(VK_CONTROL)) || (0x80 & GetKeyState(VK_SHIFT)))
return TRUE;
LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
int nbItem = ListView_GetItemCount(_fileListView.getHSelf());
int i = lpnmitem->iItem;
@ -105,6 +108,9 @@ BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPA
// Switch to the right document
LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
int nbItem = ListView_GetItemCount(_fileListView.getHSelf());
if (nbItem == 1)
{
int i = lpnmitem->iItem;
if (i == -1 || i >= nbItem)
return TRUE;
@ -116,7 +122,7 @@ BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPA
TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;
activateDoc(tlfs);
}
// Redirect NM_RCLICK message to Notepad_plus handle
NMHDR nmhdr;
nmhdr.code = NM_RCLICK;

View File

@ -37,6 +37,7 @@
#include "VerticalFileSwitcher_rc.h"
#include "VerticalFileSwitcherListView.h"
class VerticalFileSwitcher : public DockingDlgInterface {
public:
VerticalFileSwitcher(): DockingDlgInterface(IDD_FILESWITCHER_PANEL) {};
@ -79,6 +80,14 @@ public:
int setHeaderOrder(LPNMLISTVIEW pnm_list_view);
int nbSelectedFiles() const {
return _fileListView.nbSelectedFiles();
};
std::vector<SwitcherFileInfo> getSelectedFiles(bool reverse = false) const {
return _fileListView.getSelectedFiles(reverse);
};
protected:
virtual BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -42,7 +42,7 @@ void VerticalFileSwitcherListView::init(HINSTANCE hInst, HWND parent, HIMAGELIST
InitCommonControlsEx(&icex);
// Create the list-view window in report view with label editing enabled.
int listViewStyles = LVS_REPORT | LVS_SINGLESEL | LVS_AUTOARRANGE\
int listViewStyles = LVS_REPORT /*| LVS_SINGLESEL*/ | LVS_AUTOARRANGE\
| LVS_SHAREIMAGELISTS | LVS_SHOWSELALWAYS;
_hSelf = ::CreateWindow(WC_LISTVIEW,
@ -199,6 +199,11 @@ int VerticalFileSwitcherListView::closeItem(int bufferID, int iView)
void VerticalFileSwitcherListView::activateItem(int bufferID, int iView)
{
// Clean all selection
int nbItem = ListView_GetItemCount(_hSelf);
for (int i = 0; i < nbItem; i++)
ListView_SetItemState(_hSelf, i, 0, LVIS_FOCUSED|LVIS_SELECTED);
int i = find(bufferID, iView);
if (i == -1)
{
@ -235,6 +240,7 @@ int VerticalFileSwitcherListView::add(int bufferID, int iView)
return index;
}
void VerticalFileSwitcherListView::remove(int index)
{
LVITEM item;
@ -276,3 +282,27 @@ void VerticalFileSwitcherListView::insertColumn(TCHAR *name, int width, int inde
lvColumn.pszText = name;
ListView_InsertColumn(_hSelf, index, &lvColumn);
}
std::vector<SwitcherFileInfo> VerticalFileSwitcherListView::getSelectedFiles(bool reverse) const
{
std::vector<SwitcherFileInfo> files;
LVITEM item;
int nbItem = ListView_GetItemCount(_hSelf);
int i = 0;
for (; i < nbItem ; i++)
{
int isSelected = ListView_GetItemState(_hSelf, i, LVIS_SELECTED);
bool isChosen = reverse?isSelected != LVIS_SELECTED:isSelected == LVIS_SELECTED;
if (isChosen)
{
item.mask = LVIF_PARAM;
item.iItem = i;
ListView_GetItem(_hSelf, &item);
TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;
files.push_back(SwitcherFileInfo(int(tlfs->_bufID), tlfs->_iView));
}
}
return files;
}

View File

@ -35,6 +35,12 @@
#define SORT_DIRECTION_UP 0
#define SORT_DIRECTION_DOWN 1
struct SwitcherFileInfo {
int _bufID;
int _iView;
SwitcherFileInfo(int buf, int view): _bufID(buf), _iView(view){};
};
class VerticalFileSwitcherListView : public Window
{
public:
@ -55,7 +61,11 @@ public:
generic_string getFullFilePath(size_t i) const;
void insertColumn(TCHAR *name, int width, int index);
int nbSelectedFiles() const {
return SendMessage(_hSelf, LVM_GETSELECTEDCOUNT, 0, 0);
};
std::vector<SwitcherFileInfo> getSelectedFiles(bool reverse = false) const;
protected:
HIMAGELIST _hImaLst;

View File

@ -131,7 +131,6 @@
#define IDM_CLEAN_RECENT_FILE_LIST (IDM_EDIT + 41)
#define IDM_SEARCH (IDM + 3000)
#define IDM_SEARCH_FIND (IDM_SEARCH + 1)
#define IDM_SEARCH_FINDNEXT (IDM_SEARCH + 2)
#define IDM_SEARCH_REPLACE (IDM_SEARCH + 3)
@ -186,6 +185,11 @@
#define IDM_SEARCH_DELETEUNMARKEDLINES (IDM_SEARCH + 51)
#define IDM_SEARCH_FINDCHARINRANGE (IDM_SEARCH + 52)
#define IDM_MISC (IDM + 3500)
#define IDM_FILESWITCHER_FILESCLOSE (IDM_MISC + 1)
#define IDM_FILESWITCHER_FILESCLOSEOTHERS (IDM_MISC + 2)
#define IDM_VIEW (IDM + 4000)
//#define IDM_VIEW_TOOLBAR_HIDE (IDM_VIEW + 1)
#define IDM_VIEW_TOOLBAR_REDUCE (IDM_VIEW + 2)