[ENHANCE] Drag and drop feature in Project Manager.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@849 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-12-19 22:47:31 +00:00
parent ab2836f716
commit 07acbb5812
3 changed files with 42 additions and 7 deletions

View File

@ -99,7 +99,8 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
break;
case WM_LBUTTONUP:
if (_treeView.isDragging())
_treeView.dropItem();
if (_treeView.dropItem())
setWorkSpaceDirty(true);
break;
case WM_NOTIFY:

View File

@ -119,6 +119,33 @@ void TreeView::removeAllItems()
TreeView_DeleteAllItems(_hSelf);
}
void TreeView::dupTree(HTREEITEM hTree2Dup, HTREEITEM hParentItem)
{
for (HTREEITEM hItem = getChildFrom(hTree2Dup); hItem != NULL; hItem = getNextSibling(hItem))
{
TCHAR textBuffer[MAX_PATH];
TVITEM tvItem;
tvItem.hItem = hItem;
tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH;
tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvItem);
if (tvItem.lParam)
{
tvItem.lParam = (LPARAM)(new generic_string(*((generic_string *)(tvItem.lParam))));
}
TVINSERTSTRUCT tvInsertStruct;
tvInsertStruct.item = tvItem;
tvInsertStruct.hInsertAfter = (HTREEITEM)TVI_LAST;
tvInsertStruct.hParent = hParentItem;
HTREEITEM hTreeParent = (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertStruct);
dupTree(hItem, hTreeParent);
}
}
void TreeView::cleanSubEntries(HTREEITEM hTreeItem)
{
for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem))
@ -205,8 +232,9 @@ void TreeView::dragItem(HWND parentHandle, int x, int y)
::ImageList_DragShowNolock(true);
}
void TreeView::dropItem()
bool TreeView::dropItem()
{
bool isFilesMoved = false;
// get the target item
HTREEITEM targetItem = (HTREEITEM)::SendMessage(_hSelf, TVM_GETNEXTITEM, (WPARAM)TVGN_DROPHILITE, (LPARAM)0);
@ -215,8 +243,10 @@ void TreeView::dropItem()
// Note that the dragged item may have children. In this case,
// you have to move (copy and delete) for every child items, too.
if (canBeDropped(_draggedItem, targetItem))
{
moveTreeViewItem(_draggedItem, targetItem);
isFilesMoved = true;
}
// finish drag-and-drop operation
::ImageList_EndDrag();
::ImageList_Destroy(_draggedImageList);
@ -230,6 +260,7 @@ void TreeView::dropItem()
_draggedItem = 0;
_draggedImageList = 0;
_isItemDragged = false;
return isFilesMoved;
}
bool TreeView::canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem)
@ -283,11 +314,12 @@ void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem)
tvDraggingItem.lParam = (LPARAM)(new generic_string(*((generic_string *)(tvDraggingItem.lParam))));
TVINSERTSTRUCT tvInsertStruct;
tvInsertStruct.item = tvDraggingItem;
tvInsertStruct.item = tvDraggingItem;
tvInsertStruct.hInsertAfter = (HTREEITEM)TVI_LAST;
tvInsertStruct.hParent = targetItem;
::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertStruct);
HTREEITEM hTreeParent = (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertStruct);
dupTree(draggedItem, hTreeParent);
removeItem(draggedItem);
}

View File

@ -31,7 +31,7 @@ public:
HTREEITEM addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iImage, const TCHAR *filePath = NULL);
void removeItem(HTREEITEM hTreeItem);
void removeAllItems();
void cleanSubEntries(HTREEITEM hTreeItem);
HTREEITEM getChildFrom(HTREEITEM hTreeItem) const {
return TreeView_GetChild(_hSelf, hTreeItem);
};
@ -58,7 +58,7 @@ public:
bool isDragging() const {
return _isItemDragged;
};
void dropItem();
bool dropItem();
void addCanNotDropInList(int val2set) {
_canNotDropInList.push_back(val2set);
};
@ -74,6 +74,8 @@ protected:
static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
return (((TreeView *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(hwnd, Message, wParam, lParam));
};
void cleanSubEntries(HTREEITEM hTreeItem);
void dupTree(HTREEITEM hTree2Dup, HTREEITEM hParentItem);
// Drag and Drop operations
HTREEITEM _draggedItem;