[ENHANCE] Enhance Project Manager.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@808 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 13 years ago
parent 8d137e2457
commit 489f63cd6b

@ -35,7 +35,7 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
{
_treeView.init(_hInst, _hSelf, ID_PROJECTTREEVIEW);
_treeView.initImageList(IDI_PROJECT_ROOT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE);
_treeView.initImageList(IDI_PROJECT_ROOT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID);
_treeView.display();
openProject(TEXT("D:\\source\\notepad++\\trunk\\PowerEditor\\src\\WinControls\\ProjectPanel\\demo.xml"));
return TRUE;
@ -143,8 +143,8 @@ bool ProjectPanel::buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem)
{
const TCHAR *strValue = (childNode->ToElement())->Attribute(TEXT("name"));
TCHAR *strValueLabel = ::PathFindFileName(strValue);
_treeView.addItem(strValueLabel, hParentItem, INDEX_LEAF, strValue);
//::MessageBox(NULL, (childNode->ToElement())->Attribute(TEXT("name")), TEXT("File"), MB_OK);
int iImage = ::PathFileExists(strValue)?INDEX_LEAF:INDEX_LEAF_INVALID;
_treeView.addItem(strValueLabel, hParentItem, iImage, strValue);
}
}
return true;
@ -164,11 +164,25 @@ void ProjectPanel::notified(LPNMHDR notification)
{
case NM_DBLCLK:
{
tvItem.hItem = TreeView_GetSelection(_treeView.getHSelf());
tvItem.hItem = _treeView.getSelection();
::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
generic_string *fn = (generic_string *)tvItem.lParam;
if (fn)
::SendMessage(_hParent, NPPM_DOOPEN, 0, (LPARAM)(fn->c_str()));
{
tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
if (::PathFileExists(fn->c_str()))
{
::SendMessage(_hParent, NPPM_DOOPEN, 0, (LPARAM)(fn->c_str()));
tvItem.iImage = INDEX_LEAF;
tvItem.iSelectedImage = INDEX_LEAF;
}
else
{
tvItem.iImage = INDEX_LEAF_INVALID;
tvItem.iSelectedImage = INDEX_LEAF_INVALID;
}
TreeView_SetItem(_treeView.getHSelf(), &tvItem);
}
}
break;
@ -182,7 +196,7 @@ void ProjectPanel::notified(LPNMHDR notification)
if (tvnotif->item.lParam)
{
// Get the old label
tvItem.hItem = TreeView_GetSelection(_treeView.getHSelf());
tvItem.hItem = _treeView.getSelection();
::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
size_t len = lstrlen(tvItem.pszText);
@ -194,6 +208,19 @@ void ProjectPanel::notified(LPNMHDR notification)
if (found != generic_string::npos)
filePath->replace(found, len, tvnotif->item.pszText);
// Check the validity of modified file path
tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
if (::PathFileExists(filePath->c_str()))
{
tvItem.iImage = INDEX_LEAF;
tvItem.iSelectedImage = INDEX_LEAF;
}
else
{
tvItem.iImage = INDEX_LEAF_INVALID;
tvItem.iSelectedImage = INDEX_LEAF_INVALID;
}
TreeView_SetItem(_treeView.getHSelf(), &tvItem);
}
// For File, Folder and Project
@ -285,7 +312,7 @@ void ProjectPanel::showContextMenu(int x, int y)
void ProjectPanel::popupMenuCmd(int cmdID)
{
// get selected item handle
HTREEITEM hTreeItem = TreeView_GetSelection(_treeView.getHSelf());
HTREEITEM hTreeItem = _treeView.getSelection();
if (!hTreeItem)
return;
@ -298,15 +325,16 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_NEWFOLDER :
{
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_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
_treeView.expandItemGUI(hTreeItem);
}
break;
case IDM_PROJECT_ADDFILES :
{
addFiles(hTreeItem);
_treeView.expandItemGUI(hTreeItem);
}
break;
case IDM_PROJECT_DELETEFOLDER :
@ -325,16 +353,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
{
_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);
}
_treeView.collapsItemGUI(parent);
}
break;
@ -346,16 +365,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
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);
}
_treeView.collapsItemGUI(parent);
}
}
break;

@ -32,7 +32,7 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID)
TreeView_SetItemHeight(_hSelf, CY_ITEMHEIGHT);
}
BOOL TreeView::initImageList(int project_root_id, int open_node_id, int closed_node_id, int leaf_id)
BOOL TreeView::initImageList(int project_root_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id)
{
int i;
HBITMAP hbmp;
@ -66,7 +66,13 @@ BOOL TreeView::initImageList(int project_root_id, int open_node_id, int closed_n
i =ImageList_Add(_hImaLst, hbmp, (HBITMAP)NULL);
DeleteObject(hbmp);
if (ImageList_GetImageCount(_hImaLst) < 4)
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(ivalid_leaf_id));
if(hbmp == NULL)
return FALSE;
i =ImageList_Add(_hImaLst, hbmp, (HBITMAP)NULL);
DeleteObject(hbmp);
if (ImageList_GetImageCount(_hImaLst) < 5)
return FALSE;
// Set image list to the tree view
@ -146,3 +152,33 @@ void TreeView::cleanSubEntries(HTREEITEM hTreeItem)
}
}
void TreeView::collapsItemGUI(HTREEITEM hTreeItem)
{
if (getChildFrom(hTreeItem) == NULL)
{
TVITEM tvItem;
tvItem.hItem = hTreeItem;
tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvItem.iImage = INDEX_CLOSED_NODE;
tvItem.iSelectedImage = INDEX_CLOSED_NODE;
TreeView_SetItem(_hSelf, &tvItem);
}
}
void TreeView::expandItemGUI(HTREEITEM hTreeItem)
{
TVITEM tvItem;
tvItem.hItem = hTreeItem;
tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
TreeView_GetItem(_hSelf, &tvItem);
if (tvItem.iImage != INDEX_PROJECT_ROOT)
{
if (tvItem.state & TVIS_EXPANDED)
{
tvItem.iImage = INDEX_OPEN_NODE;
tvItem.iSelectedImage = INDEX_OPEN_NODE;
TreeView_SetItem(_hSelf, &tvItem);
}
}
}

@ -22,6 +22,7 @@
#define INDEX_OPEN_NODE 1
#define INDEX_CLOSED_NODE 2
#define INDEX_LEAF 3
#define INDEX_LEAF_INVALID 4
#include "window.h"
@ -42,8 +43,12 @@ public:
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);
HTREEITEM getSelection() {
return TreeView_GetSelection(_hSelf);
};
void expandItemGUI(HTREEITEM hTreeItem);
void collapsItemGUI(HTREEITEM hTreeItem);
BOOL initImageList(int project_root_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id);
protected:
HIMAGELIST _hImaLst;

Loading…
Cancel
Save