diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 6a9f3fe18..05101b136 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -345,8 +345,9 @@ LRESULT Notepad_plus::init(HWND hwnd) // Load plugins firstly from "%APPDATA%/Notepad++/plugins" // if Notepad++ is not in localConf mode. // All the dll loaded are marked. + bool isLoadFromAppDataAllow = true; const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); - if (appDataNpp[0]) + if (appDataNpp[0] && isLoadFromAppDataAllow) _pluginsManager.loadPlugins(appDataNpp); // Load plugins from its installation directory. diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index 13245ab69..1a1c9f407 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -78,6 +78,13 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar _treeView.init(_hInst, _hSelf, ID_PROJECTTREEVIEW); setImageList(IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID); + _treeView.addCanNotDropInList(INDEX_LEAF); + _treeView.addCanNotDropInList(INDEX_LEAF_INVALID); + + _treeView.addCanNotDragOutList(INDEX_CLEAN_ROOT); + _treeView.addCanNotDragOutList(INDEX_DIRTY_ROOT); + _treeView.addCanNotDragOutList(INDEX_PROJECT); + _treeView.display(); if (!openWorkSpace(_workSpaceFilePath.c_str())) newWorkSpace(); diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp index 2bf14f266..9fd5243db 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp @@ -29,7 +29,7 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID) WC_TREEVIEW, TEXT("Tree View"), WS_CHILD | WS_BORDER | WS_HSCROLL | WS_TABSTOP | TVS_LINESATROOT | TVS_HASLINES | - TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_EDITLABELS | TVS_INFOTIP, + /*TVS_DISABLEDRAGDROP |*/ TVS_HASBUTTONS | TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_EDITLABELS | TVS_INFOTIP, 0, 0, 0, 0, _hParent, NULL, @@ -148,6 +148,9 @@ void TreeView::setItemImage(HTREEITEM hTreeItem, int iImage, int iSelectedImage) // pass LPARAM of WM_NOTIFY here after casted to NMTREEVIEW* void TreeView::beginDrag(NMTREEVIEW* tv) { + if (!canDragOut(tv->itemNew.hItem)) + return; + // create dragging image for you using TVM_CREATEDRAGIMAGE // You have to delete it after drop operation, so remember it. _draggedItem = tv->itemNew.hItem; @@ -188,9 +191,14 @@ void TreeView::dragItem(HWND parentHandle, int x, int y) HTREEITEM targetItem = (HTREEITEM)::SendMessage(_hSelf, TVM_HITTEST, (WPARAM)0, (LPARAM)&hitTestInfo); if(targetItem) { + /* if (canBeDropped(_draggedItem, targetItem)) // highlight the target of drag-and-drop operation ::SendMessage(_hSelf, TVM_SELECTITEM, (WPARAM)(TVGN_DROPHILITE), (LPARAM)targetItem); + else + SendMessage(_hSelf,TVM_SELECTITEM,TVGN_CARET,(LPARAM)targetItem); + */ + ::SendMessage(_hSelf, TVM_SELECTITEM, (WPARAM)(TVGN_DROPHILITE), (LPARAM)targetItem); } // show the dragged image @@ -206,7 +214,8 @@ void TreeView::dropItem() // the target item, then, delete the original dragged item // Note that the dragged item may have children. In this case, // you have to move (copy and delete) for every child items, too. - moveTreeViewItem(_draggedItem, targetItem); + if (canBeDropped(_draggedItem, targetItem)) + moveTreeViewItem(_draggedItem, targetItem); // finish drag-and-drop operation ::ImageList_EndDrag(); @@ -231,6 +240,10 @@ bool TreeView::canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem) return false; if (isDescendant(targetItem, draggedItem)) return false; + // candragItem, canBeDropInItems + if (!canDropIn(targetItem)) + return false; + return true; } @@ -248,7 +261,6 @@ bool TreeView::isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem) void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem) { - TCHAR textBuffer[MAX_PATH]; TVITEM tvItem; tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; @@ -263,5 +275,34 @@ void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem) tvInsertStruct.hParent = targetItem; ::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertStruct); - -} \ No newline at end of file +} + +bool TreeView::canDropIn(HTREEITEM targetItem) +{ + TVITEM tvItem; + tvItem.mask = TVIF_IMAGE; + tvItem.hItem = targetItem; + SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvItem); + + for (size_t i = 0; i < _canNotDropInList.size(); i++) + { + if (tvItem.iImage == _canNotDropInList[i]) + return false; + } + return true; +} + +bool TreeView::canDragOut(HTREEITEM targetItem) +{ + TVITEM tvItem; + tvItem.mask = TVIF_IMAGE; + tvItem.hItem = targetItem; + SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvItem); + + for (size_t i = 0; i < _canNotDragOutList.size(); i++) + { + if (tvItem.iImage == _canNotDragOutList[i]) + return false; + } + return true; +} diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h index cdbf5f0d8..2397ad3f5 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.h +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.h @@ -59,6 +59,13 @@ public: return _isItemDragged; }; void dropItem(); + void addCanNotDropInList(int val2set) { + _canNotDropInList.push_back(val2set); + }; + + void addCanNotDragOutList(int val2set) { + _canNotDragOutList.push_back(val2set); + }; protected: WNDPROC _defaultProc; @@ -69,16 +76,16 @@ protected: }; // Drag and Drop operations + HTREEITEM _draggedItem; + HIMAGELIST _draggedImageList; + bool _isItemDragged; + std::vector _canNotDragOutList; + std::vector _canNotDropInList; bool canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem); void moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem); bool isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem); - -private: - // Drag and drop - HTREEITEM _draggedItem; - HIMAGELIST _draggedImageList; - bool _isItemDragged; - + bool canDragOut(HTREEITEM targetItem); + bool canDropIn(HTREEITEM targetItem); };