From ffb79104f6034cd7b31e4d996ffb832f2e949379 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 11 Jun 2011 14:40:44 +0000 Subject: [PATCH] [NEW_FEATURE] Add file switcher (list) dialog (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@773 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 4 +- PowerEditor/src/NppCommands.cpp | 4 +- PowerEditor/src/NppIO.cpp | 7 +++- .../src/WinControls/TaskList/TaskListDlg.h | 4 +- .../VerticalFileSwitcher.cpp | 21 ++++++++-- .../VerticalFileSwitcher.h | 3 ++ .../VerticalFileSwitcherListView.cpp | 41 +++++++++++++++---- .../VerticalFileSwitcherListView.h | 7 ++-- 8 files changed, 71 insertions(+), 20 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e7e906d85..4fde2e54d 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3390,14 +3390,14 @@ void Notepad_plus::getTaskListInfo(TaskListInfo *tli) BufferID bufID = _pDocTab->getBufferByIndex(i); Buffer * b = MainFileManager->getBufferByID(bufID); int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); - tli->_tlfsLst.push_back(TaskLstFnStatus(currentView(), i, b->getFullPathName(), status)); + tli->_tlfsLst.push_back(TaskLstFnStatus(currentView(), i, b->getFullPathName(), status, (void *)bufID)); } for (size_t i = 0 ; i < nonCurrentNbDoc ; i++) { BufferID bufID = _pNonDocTab->getBufferByIndex(i); Buffer * b = MainFileManager->getBufferByID(bufID); int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); - tli->_tlfsLst.push_back(TaskLstFnStatus(otherView(), i, b->getFullPathName(), status)); + tli->_tlfsLst.push_back(TaskLstFnStatus(otherView(), i, b->getFullPathName(), status, (void *)bufID)); } } diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index d1b834cbe..443c80e10 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -50,8 +50,8 @@ void Notepad_plus::command(int id) case IDM_FILE_OPEN: { - fileOpen(); - //launchFileSwitcherPanel(); + //fileOpen(); + launchFileSwitcherPanel(); } break; diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 37061c1d5..9d6b3030d 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -19,7 +19,7 @@ #include "Notepad_plus_Window.h" #include "FileDialog.h" #include "EncodingMapper.h" - +#include "VerticalFileSwitcher.h" BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encoding) @@ -163,6 +163,8 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi // Notify plugins that current file is just opened scnN.nmhdr.code = NPPN_FILEOPENED; _pluginsManager.notify(&scnN); + if (_pFileSwitcherPanel) + _pFileSwitcherPanel->newItem((int)buf, fileName); } else { @@ -324,7 +326,8 @@ void Notepad_plus::doClose(BufferID id, int whichOne) { // Notify plugins that current file is closed scnN.nmhdr.code = NPPN_FILECLOSED; _pluginsManager.notify(&scnN); - + if (_pFileSwitcherPanel) + _pFileSwitcherPanel->closeItem((int)id); return; } diff --git a/PowerEditor/src/WinControls/TaskList/TaskListDlg.h b/PowerEditor/src/WinControls/TaskList/TaskListDlg.h index 95f827019..91cc5de57 100644 --- a/PowerEditor/src/WinControls/TaskList/TaskListDlg.h +++ b/PowerEditor/src/WinControls/TaskList/TaskListDlg.h @@ -42,8 +42,10 @@ struct TaskLstFnStatus { int _docIndex; generic_string _fn; int _status; + void *_bufID; TaskLstFnStatus(generic_string str, int status) : _fn(str), _status(status){}; - TaskLstFnStatus(int iView, int docIndex, generic_string str, int status) : _iView(iView), _docIndex(docIndex), _fn(str), _status(status) {}; + TaskLstFnStatus(int iView, int docIndex, generic_string str, int status, void *bufID) : + _iView(iView), _docIndex(docIndex), _fn(str), _status(status), _bufID(bufID) {}; }; struct TaskListInfo { diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 38a00be5c..27c0b9621 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -92,7 +92,22 @@ BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPA void VerticalFileSwitcher::activateDoc(int i) const { - int view2set = _fileListView.getViewInfoFromIndex(i); - int index2Switch = _fileListView.getDocIndexInfoFromIndex(i); + int bufferID = _fileListView.getBufferIDFromIndex(i); + int docPosInfo = ::SendMessage(_hParent, NPPM_GETPOSFROMBUFFERID, bufferID, 0); + int view2set = docPosInfo >> 30; + int index2Switch = (docPosInfo << 2) >> 2 ; + + //int view2set = _fileListView.getViewInfoFromIndex(i); + //int index2Switch = _fileListView.getDocIndexInfoFromIndex(i); ::SendMessage(_hParent, NPPM_ACTIVATEDOC, view2set, index2Switch); -} \ No newline at end of file +} + +int VerticalFileSwitcher::newItem(int bufferID, const TCHAR *fn) +{ + return _fileListView.newItem(bufferID, fn); +} + +int VerticalFileSwitcher::closeItem(int bufferID) +{ + return _fileListView.closeItem(bufferID); +} diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h index d4bb3d5a4..901c73d8b 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h @@ -48,6 +48,9 @@ public: //Activate document in scintilla by using the internal index void activateDoc(int i) const; + int newItem(int bufferID, const TCHAR *fn); + int closeItem(int bufferID); + 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 36e55f448..58423ab08 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp @@ -102,14 +102,41 @@ void VerticalFileSwitcherListView::initList() } } //{} -int VerticalFileSwitcherListView::getViewInfoFromIndex(int index) const { +int VerticalFileSwitcherListView::getBufferIDFromIndex(int index) const { if (index < 0 || index >= int(_taskListInfo._tlfsLst.size())) return -1; - return _taskListInfo._tlfsLst[index]._iView; + return int(_taskListInfo._tlfsLst[index]._bufID); } -int VerticalFileSwitcherListView::getDocIndexInfoFromIndex(int index) const { - if (index < 0 || index >= int(_taskListInfo._tlfsLst.size())) - return -1; - return _taskListInfo._tlfsLst[index]._docIndex; -} \ No newline at end of file +int VerticalFileSwitcherListView::newItem(int bufferID, const TCHAR *fn) +{ + int index = int(_taskListInfo._tlfsLst.size()); + _taskListInfo._tlfsLst.push_back(TaskLstFnStatus(0, 0, fn, 0, (void *)bufferID)); + + LVITEM item; + item.mask = LVIF_TEXT | LVIF_IMAGE; + + item.pszText = (TCHAR *)::PathFindFileName(fn); + item.iItem = index; + item.iSubItem = 0; + + item.iImage = 0; + ListView_InsertItem(_hSelf, &item); + + return index; +} + +int VerticalFileSwitcherListView::closeItem(int bufferID) +{ + bool found = false; + + for (size_t i = 0 ; i < _taskListInfo._tlfsLst.size() ; i++) + { + if (_taskListInfo._tlfsLst[i]._bufID == (void *)bufferID) + { + found = true; + break; + } + } + return 0; +} diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h index a2bdfa3ab..588b30a8d 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.h @@ -30,11 +30,12 @@ public: virtual void init(HINSTANCE hInst, HWND parent, HIMAGELIST hImaLst); virtual void destroy(); void initList(); - int getViewInfoFromIndex(int index) const; - int getDocIndexInfoFromIndex(int index) const; + int getBufferIDFromIndex(int index) const; void setBgColour(int i) { - ListView_SetItemState(_hSelf, i, LVIS_SELECTED|LVIS_FOCUSED, 0xFF); + ListView_SetItemState(_hSelf, i, LVIS_SELECTED|LVIS_FOCUSED, 0xFF); } + int newItem(int bufferID, const TCHAR *fn); + int closeItem(int bufferID); protected: TaskListInfo _taskListInfo;