[ENHANCE] Project Manager Drag and Drop feature (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@845 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 13 years ago
parent 6c4eef8cb7
commit 24a25a0b49

@ -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.

@ -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();

@ -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,6 +214,7 @@ 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.
if (canBeDropped(_draggedItem, targetItem))
moveTreeViewItem(_draggedItem, targetItem);
// finish drag-and-drop operation
@ -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);
}
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;
}

@ -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
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;
std::vector<int> _canNotDragOutList;
std::vector<int> _canNotDropInList;
bool canBeDropped(HTREEITEM draggedItem, HTREEITEM targetItem);
void moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem);
bool isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem);
bool canDragOut(HTREEITEM targetItem);
bool canDropIn(HTREEITEM targetItem);
};

Loading…
Cancel
Save