[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
This commit is contained in:
Don Ho 2011-06-11 14:40:44 +00:00
parent c4327b5b34
commit ffb79104f6
8 changed files with 71 additions and 20 deletions

View File

@ -3390,14 +3390,14 @@ void Notepad_plus::getTaskListInfo(TaskListInfo *tli)
BufferID bufID = _pDocTab->getBufferByIndex(i); BufferID bufID = _pDocTab->getBufferByIndex(i);
Buffer * b = MainFileManager->getBufferByID(bufID); Buffer * b = MainFileManager->getBufferByID(bufID);
int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); 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++) for (size_t i = 0 ; i < nonCurrentNbDoc ; i++)
{ {
BufferID bufID = _pNonDocTab->getBufferByIndex(i); BufferID bufID = _pNonDocTab->getBufferByIndex(i);
Buffer * b = MainFileManager->getBufferByID(bufID); Buffer * b = MainFileManager->getBufferByID(bufID);
int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); 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));
} }
} }

View File

@ -50,8 +50,8 @@ void Notepad_plus::command(int id)
case IDM_FILE_OPEN: case IDM_FILE_OPEN:
{ {
fileOpen(); //fileOpen();
//launchFileSwitcherPanel(); launchFileSwitcherPanel();
} }
break; break;

View File

@ -19,7 +19,7 @@
#include "Notepad_plus_Window.h" #include "Notepad_plus_Window.h"
#include "FileDialog.h" #include "FileDialog.h"
#include "EncodingMapper.h" #include "EncodingMapper.h"
#include "VerticalFileSwitcher.h"
BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encoding) 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 // Notify plugins that current file is just opened
scnN.nmhdr.code = NPPN_FILEOPENED; scnN.nmhdr.code = NPPN_FILEOPENED;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
if (_pFileSwitcherPanel)
_pFileSwitcherPanel->newItem((int)buf, fileName);
} }
else else
{ {
@ -324,7 +326,8 @@ void Notepad_plus::doClose(BufferID id, int whichOne) {
// Notify plugins that current file is closed // Notify plugins that current file is closed
scnN.nmhdr.code = NPPN_FILECLOSED; scnN.nmhdr.code = NPPN_FILECLOSED;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
if (_pFileSwitcherPanel)
_pFileSwitcherPanel->closeItem((int)id);
return; return;
} }

View File

@ -42,8 +42,10 @@ struct TaskLstFnStatus {
int _docIndex; int _docIndex;
generic_string _fn; generic_string _fn;
int _status; int _status;
void *_bufID;
TaskLstFnStatus(generic_string str, int status) : _fn(str), _status(status){}; 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 { struct TaskListInfo {

View File

@ -92,7 +92,22 @@ BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPA
void VerticalFileSwitcher::activateDoc(int i) const void VerticalFileSwitcher::activateDoc(int i) const
{ {
int view2set = _fileListView.getViewInfoFromIndex(i); int bufferID = _fileListView.getBufferIDFromIndex(i);
int index2Switch = _fileListView.getDocIndexInfoFromIndex(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); ::SendMessage(_hParent, NPPM_ACTIVATEDOC, view2set, index2Switch);
} }
int VerticalFileSwitcher::newItem(int bufferID, const TCHAR *fn)
{
return _fileListView.newItem(bufferID, fn);
}
int VerticalFileSwitcher::closeItem(int bufferID)
{
return _fileListView.closeItem(bufferID);
}

View File

@ -48,6 +48,9 @@ public:
//Activate document in scintilla by using the internal index //Activate document in scintilla by using the internal index
void activateDoc(int i) const; void activateDoc(int i) const;
int newItem(int bufferID, const TCHAR *fn);
int closeItem(int bufferID);
protected: protected:
virtual BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); virtual BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -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())) if (index < 0 || index >= int(_taskListInfo._tlfsLst.size()))
return -1; return -1;
return _taskListInfo._tlfsLst[index]._iView; return int(_taskListInfo._tlfsLst[index]._bufID);
} }
int VerticalFileSwitcherListView::getDocIndexInfoFromIndex(int index) const { int VerticalFileSwitcherListView::newItem(int bufferID, const TCHAR *fn)
if (index < 0 || index >= int(_taskListInfo._tlfsLst.size())) {
return -1; int index = int(_taskListInfo._tlfsLst.size());
return _taskListInfo._tlfsLst[index]._docIndex; _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;
} }

View File

@ -30,11 +30,12 @@ public:
virtual void init(HINSTANCE hInst, HWND parent, HIMAGELIST hImaLst); virtual void init(HINSTANCE hInst, HWND parent, HIMAGELIST hImaLst);
virtual void destroy(); virtual void destroy();
void initList(); void initList();
int getViewInfoFromIndex(int index) const; int getBufferIDFromIndex(int index) const;
int getDocIndexInfoFromIndex(int index) const;
void setBgColour(int i) { 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: protected:
TaskListInfo _taskListInfo; TaskListInfo _taskListInfo;