[ENHANCE] Enhance Project Manager.
git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@807 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
parent
bf93a79886
commit
8d137e2457
@ -159,7 +159,10 @@ Notepad_plus::~Notepad_plus()
|
||||
delete _pFileSwitcherPanel;
|
||||
|
||||
if (_pProjectPanel)
|
||||
{
|
||||
_pProjectPanel->destroy();
|
||||
delete _pProjectPanel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#include "ProjectPanel.h"
|
||||
#include "resource.h"
|
||||
#include "tinyxml.h"
|
||||
#include "FileDialog.h"
|
||||
|
||||
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
|
||||
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
|
||||
@ -68,7 +69,7 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
//_fileListView.destroy();
|
||||
_treeView.destroy();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -78,6 +79,26 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
|
||||
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
|
||||
}
|
||||
|
||||
void ProjectPanel::init(HINSTANCE hInst, HWND hPere)
|
||||
{
|
||||
DockingDlgInterface::init(hInst, hPere);
|
||||
|
||||
_hRootMenu = ::CreatePopupMenu();
|
||||
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
|
||||
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("New Folder..."));
|
||||
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, TEXT("Add Files..."));
|
||||
|
||||
_hFolderMenu = ::CreatePopupMenu();
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("New Folder..."));
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFOLDER, TEXT("Delete"));
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, TEXT("Add Files..."));
|
||||
|
||||
_hFileMenu = ::CreatePopupMenu();
|
||||
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
|
||||
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFILE, TEXT("Delete"));
|
||||
}
|
||||
|
||||
bool ProjectPanel::openProject(TCHAR *projectFileName)
|
||||
{
|
||||
TiXmlDocument *pXmlDocProject = new TiXmlDocument(projectFileName);
|
||||
@ -220,7 +241,6 @@ void ProjectPanel::notified(LPNMHDR notification)
|
||||
|
||||
void ProjectPanel::showContextMenu(int x, int y)
|
||||
{
|
||||
//TCHAR textBuffer[MAX_PATH];
|
||||
TVHITTESTINFO tvHitInfo;
|
||||
HTREEITEM hTreeItem;
|
||||
|
||||
@ -239,11 +259,8 @@ void ProjectPanel::showContextMenu(int x, int y)
|
||||
// get clicked item info
|
||||
TVITEM tvItem;
|
||||
tvItem.hItem = tvHitInfo.hItem;
|
||||
tvItem.mask = /*TVIF_TEXT | TVIF_PARAM |*/ TVIF_IMAGE;
|
||||
//tvItem.pszText = textBuffer;
|
||||
//tvItem.cchTextMax = MAX_PATH;
|
||||
tvItem.mask = TVIF_IMAGE;
|
||||
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
|
||||
//printStr(tvItem.pszText);
|
||||
|
||||
HMENU hMenu = NULL;
|
||||
// Root
|
||||
@ -271,26 +288,93 @@ void ProjectPanel::popupMenuCmd(int cmdID)
|
||||
HTREEITEM hTreeItem = TreeView_GetSelection(_treeView.getHSelf());
|
||||
if (!hTreeItem)
|
||||
return;
|
||||
/*
|
||||
TVITEM tvItem;
|
||||
tvItem.hItem = hTreeItem;
|
||||
tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE;
|
||||
//tvItem.pszText = textBuffer;
|
||||
//tvItem.cchTextMax = MAX_PATH;
|
||||
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
|
||||
*/
|
||||
|
||||
switch (cmdID)
|
||||
{
|
||||
case IDM_PROJECT_RENAME :
|
||||
TreeView_EditLabel(_treeView.getHSelf(), hTreeItem);
|
||||
break;
|
||||
|
||||
case IDM_PROJECT_NEWFOLDER :
|
||||
break;
|
||||
{
|
||||
HTREEITEM addedItem = _treeView.addItem(TEXT("Folder Name"), hTreeItem, INDEX_CLOSED_NODE);
|
||||
//TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
|
||||
::SendMessage(_treeView.getHSelf(), TVM_EXPAND, TVE_EXPAND, (LPARAM)hTreeItem);
|
||||
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
|
||||
}
|
||||
break;
|
||||
|
||||
case IDM_PROJECT_ADDFILES :
|
||||
break;
|
||||
{
|
||||
addFiles(hTreeItem);
|
||||
}
|
||||
break;
|
||||
case IDM_PROJECT_DELETEFOLDER :
|
||||
break;
|
||||
{
|
||||
HTREEITEM parent = TreeView_GetParent(_treeView.getHSelf(), hTreeItem);
|
||||
|
||||
if (_treeView.getChildFrom(hTreeItem) != NULL)
|
||||
{
|
||||
TCHAR str2display[MAX_PATH] = TEXT("All the sub-items will be removed.\rAre you sure to remove this folder from the project?");
|
||||
if (::MessageBox(_hSelf, str2display, TEXT("Remove folder from projet"), MB_YESNO) == IDYES)
|
||||
{
|
||||
_treeView.removeItem(hTreeItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_treeView.removeItem(hTreeItem);
|
||||
}
|
||||
|
||||
if (_treeView.getChildFrom(parent) == NULL)
|
||||
{
|
||||
TVITEM tvItem;
|
||||
tvItem.hItem = parent;
|
||||
tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
||||
tvItem.iImage = INDEX_CLOSED_NODE;
|
||||
tvItem.iSelectedImage = INDEX_CLOSED_NODE;
|
||||
TreeView_SetItem(_treeView.getHSelf(), &tvItem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case IDM_PROJECT_DELETEFILE :
|
||||
break;
|
||||
{
|
||||
HTREEITEM parent = TreeView_GetParent(_treeView.getHSelf(), hTreeItem);
|
||||
|
||||
TCHAR str2display[MAX_PATH] = TEXT("Are you sure to remove this file from the project?");
|
||||
if (::MessageBox(_hSelf, str2display, TEXT("Remove file from projet"), MB_YESNO) == IDYES)
|
||||
{
|
||||
_treeView.removeItem(hTreeItem);
|
||||
|
||||
if (_treeView.getChildFrom(parent) == NULL)
|
||||
{
|
||||
TVITEM tvItem;
|
||||
tvItem.hItem = parent;
|
||||
tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
||||
tvItem.iImage = INDEX_CLOSED_NODE;
|
||||
tvItem.iSelectedImage = INDEX_CLOSED_NODE;
|
||||
TreeView_SetItem(_treeView.getHSelf(), &tvItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectPanel::addFiles(HTREEITEM hTreeItem)
|
||||
{
|
||||
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
|
||||
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
|
||||
|
||||
if (stringVector *pfns = fDlg.doOpenMultiFilesDlg())
|
||||
{
|
||||
size_t sz = pfns->size();
|
||||
for (size_t i = 0 ; i < sz ; i++)
|
||||
{
|
||||
TCHAR *strValueLabel = ::PathFindFileName(pfns->at(i).c_str());
|
||||
_treeView.addItem(strValueLabel, hTreeItem, INDEX_LEAF, pfns->at(i).c_str());
|
||||
}
|
||||
TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
|
||||
}
|
||||
}
|
@ -42,24 +42,7 @@ public:
|
||||
ProjectPanel(): DockingDlgInterface(IDD_PROJECTPANEL),\
|
||||
_hRootMenu(NULL), _hFolderMenu(NULL), _hFileMenu(NULL){};
|
||||
|
||||
void init(HINSTANCE hInst, HWND hPere) {
|
||||
DockingDlgInterface::init(hInst, hPere);
|
||||
|
||||
_hRootMenu = ::CreatePopupMenu();
|
||||
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
|
||||
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("New Folder..."));
|
||||
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, TEXT("Add Files..."));
|
||||
|
||||
_hFolderMenu = ::CreatePopupMenu();
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("New Folder..."));
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFOLDER, TEXT("Delete"));
|
||||
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, TEXT("Add Files..."));
|
||||
|
||||
_hFileMenu = ::CreatePopupMenu();
|
||||
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
|
||||
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFILE, TEXT("Delete"));
|
||||
};
|
||||
void init(HINSTANCE hInst, HWND hPere);
|
||||
|
||||
void destroy() {
|
||||
::DestroyMenu(_hRootMenu);
|
||||
@ -76,6 +59,7 @@ public:
|
||||
};
|
||||
|
||||
bool openProject(TCHAR *projectFileName);
|
||||
void addFiles(HTREEITEM hTreeItem);
|
||||
|
||||
protected:
|
||||
TreeView _treeView;
|
||||
|
@ -78,6 +78,8 @@ BOOL TreeView::initImageList(int project_root_id, int open_node_id, int closed_n
|
||||
|
||||
void TreeView::destroy()
|
||||
{
|
||||
HTREEITEM root = TreeView_GetRoot(_hSelf);
|
||||
cleanSubEntries(root);
|
||||
::DestroyWindow(_hSelf);
|
||||
_hSelf = NULL;
|
||||
}
|
||||
@ -111,67 +113,36 @@ HTREEITEM TreeView::addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iI
|
||||
return (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertStruct);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
HTREEITEM TreeView::addItem(const TCHAR *itemName, int nLevel)
|
||||
void TreeView::removeItem(HTREEITEM hTreeItem)
|
||||
{
|
||||
TVITEM tvi;
|
||||
TVINSERTSTRUCT tv_insert_struct;
|
||||
static HTREEITEM hPrev = (HTREEITEM)TVI_FIRST;
|
||||
static HTREEITEM hPrevRootItem = NULL;
|
||||
static HTREEITEM hPrevLev2Item = NULL;
|
||||
HTREEITEM hti;
|
||||
// Deallocate all the sub-entries recursively
|
||||
cleanSubEntries(hTreeItem);
|
||||
|
||||
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
|
||||
// Deallocate current entry
|
||||
TVITEM tvItem;
|
||||
tvItem.hItem = hTreeItem;
|
||||
tvItem.mask = TVIF_PARAM;
|
||||
SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvItem);
|
||||
if (tvItem.lParam)
|
||||
delete (generic_string *)(tvItem.lParam);
|
||||
|
||||
// Set the text of the item.
|
||||
tvi.pszText = (LPTSTR) itemName;
|
||||
tvi.cchTextMax = sizeof(tvi.pszText)/sizeof(tvi.pszText[0]);
|
||||
|
||||
// Assume the item is not a parent item, so give it a
|
||||
// document image.
|
||||
|
||||
tvi.iImage = INDEX_LEAF;
|
||||
tvi.iSelectedImage = INDEX_LEAF;
|
||||
|
||||
// Save the heading level in the item's application-defined
|
||||
// data area.
|
||||
tvi.lParam = (LPARAM)nLevel;
|
||||
tv_insert_struct.item = tvi;
|
||||
tv_insert_struct.hInsertAfter = hPrev;
|
||||
|
||||
// Set the parent item based on the specified level.
|
||||
if (nLevel == 1)
|
||||
tv_insert_struct.hParent = TVI_ROOT;
|
||||
else if (nLevel == 2)
|
||||
tv_insert_struct.hParent = hPrevRootItem;
|
||||
else
|
||||
tv_insert_struct.hParent = hPrevLev2Item;
|
||||
|
||||
// Add the item to the tree-view control.
|
||||
hPrev = (HTREEITEM)SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tv_insert_struct);
|
||||
|
||||
if (hPrev == NULL)
|
||||
return NULL;
|
||||
|
||||
// Save the handle to the item.
|
||||
if (nLevel == 1)
|
||||
hPrevRootItem = hPrev;
|
||||
else if (nLevel == 2)
|
||||
hPrevLev2Item = hPrev;
|
||||
|
||||
// The new item is a child item. Give the parent item a
|
||||
// closed folder bitmap to indicate it now has child items.
|
||||
if (nLevel > 1)
|
||||
{
|
||||
hti = TreeView_GetParent(_hSelf, hPrev);
|
||||
tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
|
||||
tvi.hItem = hti;
|
||||
tvi.iImage = INDEX_CLOSED_NODE;
|
||||
tvi.iSelectedImage = INDEX_CLOSED_NODE;
|
||||
TreeView_SetItem(_hSelf, &tvi);
|
||||
}
|
||||
return hPrev;
|
||||
// Remove the node
|
||||
TreeView_DeleteItem(_hSelf, hTreeItem);
|
||||
}
|
||||
|
||||
void TreeView::cleanSubEntries(HTREEITEM hTreeItem)
|
||||
{
|
||||
for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem))
|
||||
{
|
||||
TVITEM tvItem;
|
||||
tvItem.hItem = hItem;
|
||||
tvItem.mask = TVIF_PARAM;
|
||||
SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvItem);
|
||||
if (tvItem.lParam)
|
||||
{
|
||||
delete (generic_string *)(tvItem.lParam);
|
||||
}
|
||||
cleanSubEntries(hItem);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -34,6 +34,15 @@ public:
|
||||
virtual void init(HINSTANCE hInst, HWND parent, int treeViewID);
|
||||
virtual void destroy();
|
||||
HTREEITEM addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iImage, const TCHAR *filePath = NULL);
|
||||
void removeItem(HTREEITEM hTreeItem);
|
||||
void cleanSubEntries(HTREEITEM hTreeItem);
|
||||
HTREEITEM getChildFrom(HTREEITEM hTreeItem) {
|
||||
return TreeView_GetChild(_hSelf, hTreeItem);
|
||||
};
|
||||
HTREEITEM getNextSibling(HTREEITEM hTreeItem){
|
||||
return TreeView_GetNextSibling(_hSelf ,hTreeItem);
|
||||
};
|
||||
|
||||
BOOL initImageList(int project_root_id, int open_node_id, int closed_node_id, int leaf_id);
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user