diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index 1a1c9f407..98837ec83 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -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: diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp index e24bc3c15..bc3eaf1f9 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp @@ -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); } diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h index c1b05d1d3..075079a0d 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h @@ -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;