[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.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(); _treeView.display();
openProject(TEXT("D:\\source\\notepad++\\trunk\\PowerEditor\\src\\WinControls\\ProjectPanel\\demo.xml")); openProject(TEXT("D:\\source\\notepad++\\trunk\\PowerEditor\\src\\WinControls\\ProjectPanel\\demo.xml"));
return TRUE; return TRUE;
@ -143,8 +143,8 @@ bool ProjectPanel::buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem)
{ {
const TCHAR *strValue = (childNode->ToElement())->Attribute(TEXT("name")); const TCHAR *strValue = (childNode->ToElement())->Attribute(TEXT("name"));
TCHAR *strValueLabel = ::PathFindFileName(strValue); TCHAR *strValueLabel = ::PathFindFileName(strValue);
_treeView.addItem(strValueLabel, hParentItem, INDEX_LEAF, strValue); int iImage = ::PathFileExists(strValue)?INDEX_LEAF:INDEX_LEAF_INVALID;
//::MessageBox(NULL, (childNode->ToElement())->Attribute(TEXT("name")), TEXT("File"), MB_OK); _treeView.addItem(strValueLabel, hParentItem, iImage, strValue);
} }
} }
return true; return true;
@ -164,11 +164,25 @@ void ProjectPanel::notified(LPNMHDR notification)
{ {
case NM_DBLCLK: case NM_DBLCLK:
{ {
tvItem.hItem = TreeView_GetSelection(_treeView.getHSelf()); tvItem.hItem = _treeView.getSelection();
::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); ::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
generic_string *fn = (generic_string *)tvItem.lParam; generic_string *fn = (generic_string *)tvItem.lParam;
if (fn) 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; break;
@ -182,7 +196,7 @@ void ProjectPanel::notified(LPNMHDR notification)
if (tvnotif->item.lParam) if (tvnotif->item.lParam)
{ {
// Get the old label // Get the old label
tvItem.hItem = TreeView_GetSelection(_treeView.getHSelf()); tvItem.hItem = _treeView.getSelection();
::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); ::SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
size_t len = lstrlen(tvItem.pszText); size_t len = lstrlen(tvItem.pszText);
@ -194,6 +208,19 @@ void ProjectPanel::notified(LPNMHDR notification)
if (found != generic_string::npos) if (found != generic_string::npos)
filePath->replace(found, len, tvnotif->item.pszText); 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 // For File, Folder and Project
@ -285,7 +312,7 @@ void ProjectPanel::showContextMenu(int x, int y)
void ProjectPanel::popupMenuCmd(int cmdID) void ProjectPanel::popupMenuCmd(int cmdID)
{ {
// get selected item handle // get selected item handle
HTREEITEM hTreeItem = TreeView_GetSelection(_treeView.getHSelf()); HTREEITEM hTreeItem = _treeView.getSelection();
if (!hTreeItem) if (!hTreeItem)
return; return;
@ -298,15 +325,16 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_NEWFOLDER : case IDM_PROJECT_NEWFOLDER :
{ {
HTREEITEM addedItem = _treeView.addItem(TEXT("Folder Name"), hTreeItem, INDEX_CLOSED_NODE); HTREEITEM addedItem = _treeView.addItem(TEXT("Folder Name"), hTreeItem, INDEX_CLOSED_NODE);
//TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND); TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
::SendMessage(_treeView.getHSelf(), TVM_EXPAND, TVE_EXPAND, (LPARAM)hTreeItem);
TreeView_EditLabel(_treeView.getHSelf(), addedItem); TreeView_EditLabel(_treeView.getHSelf(), addedItem);
_treeView.expandItemGUI(hTreeItem);
} }
break; break;
case IDM_PROJECT_ADDFILES : case IDM_PROJECT_ADDFILES :
{ {
addFiles(hTreeItem); addFiles(hTreeItem);
_treeView.expandItemGUI(hTreeItem);
} }
break; break;
case IDM_PROJECT_DELETEFOLDER : case IDM_PROJECT_DELETEFOLDER :
@ -325,16 +353,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
{ {
_treeView.removeItem(hTreeItem); _treeView.removeItem(hTreeItem);
} }
_treeView.collapsItemGUI(parent);
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; break;
@ -346,16 +365,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
if (::MessageBox(_hSelf, str2display, TEXT("Remove file from projet"), MB_YESNO) == IDYES) if (::MessageBox(_hSelf, str2display, TEXT("Remove file from projet"), MB_YESNO) == IDYES)
{ {
_treeView.removeItem(hTreeItem); _treeView.removeItem(hTreeItem);
_treeView.collapsItemGUI(parent);
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; break;

@ -32,7 +32,7 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID)
TreeView_SetItemHeight(_hSelf, CY_ITEMHEIGHT); 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; int i;
HBITMAP hbmp; 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); i =ImageList_Add(_hImaLst, hbmp, (HBITMAP)NULL);
DeleteObject(hbmp); 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; return FALSE;
// Set image list to the tree view // 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_OPEN_NODE 1
#define INDEX_CLOSED_NODE 2 #define INDEX_CLOSED_NODE 2
#define INDEX_LEAF 3 #define INDEX_LEAF 3
#define INDEX_LEAF_INVALID 4
#include "window.h" #include "window.h"
@ -42,8 +43,12 @@ public:
HTREEITEM getNextSibling(HTREEITEM hTreeItem){ HTREEITEM getNextSibling(HTREEITEM hTreeItem){
return TreeView_GetNextSibling(_hSelf ,hTreeItem); return TreeView_GetNextSibling(_hSelf ,hTreeItem);
}; };
HTREEITEM getSelection() {
BOOL initImageList(int project_root_id, int open_node_id, int closed_node_id, int leaf_id); 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: protected:
HIMAGELIST _hImaLst; HIMAGELIST _hImaLst;

Loading…
Cancel
Save