diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp index 9fd5243db..e24bc3c15 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp @@ -240,6 +240,8 @@ bool TreeView::canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem) return false; if (isDescendant(targetItem, draggedItem)) return false; + if (isParent(targetItem, draggedItem)) + return false; // candragItem, canBeDropInItems if (!canDropIn(targetItem)) return false; @@ -259,22 +261,34 @@ bool TreeView::isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem) return isDescendant(parent, draggedItem); } +bool TreeView::isParent(HTREEITEM targetItem, HTREEITEM draggedItem) +{ + HTREEITEM parent = TreeView_GetParent(_hSelf, draggedItem); + if (parent == targetItem) + return true; + return false; +} + void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem) { TCHAR textBuffer[MAX_PATH]; - TVITEM tvItem; - tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - tvItem.pszText = textBuffer; - tvItem.cchTextMax = MAX_PATH; - tvItem.hItem = draggedItem; - SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvItem); + TVITEM tvDraggingItem; + tvDraggingItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + tvDraggingItem.pszText = textBuffer; + tvDraggingItem.cchTextMax = MAX_PATH; + tvDraggingItem.hItem = draggedItem; + SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvDraggingItem); + + if (tvDraggingItem.lParam) + tvDraggingItem.lParam = (LPARAM)(new generic_string(*((generic_string *)(tvDraggingItem.lParam)))); TVINSERTSTRUCT tvInsertStruct; - tvInsertStruct.item = tvItem; + tvInsertStruct.item = tvDraggingItem; tvInsertStruct.hInsertAfter = (HTREEITEM)TVI_LAST; tvInsertStruct.hParent = targetItem; ::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertStruct); + removeItem(draggedItem); } bool TreeView::canDropIn(HTREEITEM targetItem) @@ -292,6 +306,7 @@ bool TreeView::canDropIn(HTREEITEM targetItem) return true; } + bool TreeView::canDragOut(HTREEITEM targetItem) { TVITEM tvItem; diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h index 2397ad3f5..c1b05d1d3 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h @@ -83,6 +83,7 @@ protected: std::vector _canNotDropInList; bool canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem); void moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem); + bool isParent(HTREEITEM targetItem, HTREEITEM draggedItem); bool isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem); bool canDragOut(HTREEITEM targetItem); bool canDropIn(HTREEITEM targetItem);