From db19cf8d6adac6ed559335c3b66c3b2ae510f373 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 1 May 2013 15:43:51 +0000 Subject: [PATCH] [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 --- PowerEditor/src/Notepad_plus.cpp | 5 ++- PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/NppCommands.cpp | 17 ++++++++++ PowerEditor/src/NppNotification.cpp | 21 ++++++++++-- .../VerticalFileSwitcher.cpp | 24 ++++++++------ .../VerticalFileSwitcher.h | 9 ++++++ .../VerticalFileSwitcherListView.cpp | 32 ++++++++++++++++++- .../VerticalFileSwitcherListView.h | 10 ++++++ PowerEditor/src/menuCmdID.h | 6 +++- 9 files changed, 110 insertions(+), 16 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 42bc327d..91bc6108 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -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); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 0278b976..93570029 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -330,7 +330,7 @@ private: SplitterContainer *_pMainSplitter; SplitterContainer _subSplitter; - ContextMenu _tabPopupMenu, _tabPopupDropMenu; + ContextMenu _tabPopupMenu, _tabPopupDropMenu, _fileSwitcherMultiFilePopupMenu; ToolBar _toolBar; IconList _docTabIconList; diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 8bd5504d..79811350 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -70,6 +70,23 @@ void Notepad_plus::command(int id) fileReload(); break; + case IDM_FILESWITCHER_FILESCLOSE: + case IDM_FILESWITCHER_FILESCLOSEOTHERS: + if (_pFileSwitcherPanel) + { + vector 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(); diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 15f9eae0..d08af4d1 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -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,13 +305,25 @@ 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 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()) { diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 50e2bf1e..41b1dc58 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -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,18 +108,21 @@ 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()); - int i = lpnmitem->iItem; - if (i == -1 || i >= nbItem) - return TRUE; - LVITEM item; - item.mask = LVIF_PARAM; - item.iItem = i; - ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item); - TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam; + if (nbItem == 1) + { + int i = lpnmitem->iItem; + if (i == -1 || i >= nbItem) + return TRUE; - activateDoc(tlfs); + LVITEM item; + item.mask = LVIF_PARAM; + item.iItem = i; + ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item); + TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam; + activateDoc(tlfs); + } // Redirect NM_RCLICK message to Notepad_plus handle NMHDR nmhdr; nmhdr.code = NM_RCLICK; diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h index 9a9e88c3..d1058221 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h @@ -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 getSelectedFiles(bool reverse = false) const { + return _fileListView.getSelectedFiles(reverse); + }; + protected: virtual BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp index 7aaa3bdc..63c4182f 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp @@ -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 VerticalFileSwitcherListView::getSelectedFiles(bool reverse) const +{ + std::vector 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; +} diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h index 00de5f68..1aebbe93 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h @@ -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 getSelectedFiles(bool reverse = false) const; protected: HIMAGELIST _hImaLst; diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 04fc69bc..fa5fecc1 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -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)