[NEW_FEATURE] Add "Move Up" and "Move Down" commands in Project Panel (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@850 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-12-30 15:19:36 +00:00
parent 07acbb5812
commit 5bdd0008f3
5 changed files with 148 additions and 14 deletions

View File

@ -133,7 +133,14 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
popupMenuCmd(LOWORD(wParam));
break;
}
/*
#define NPPM_INTERNAL_ISDRAGGING 40926
case NPPM_INTERNAL_ISDRAGGING:
{
setDraggingBool(true);
break;
}
*/
case WM_DESTROY:
{
_treeView.destroy();
@ -207,6 +214,8 @@ void ProjectPanel::initMenus()
edit_remove = pNativeSpeaker->getProjectPanelLangMenuStr("FolderMenu", IDM_PROJECT_DELETEFOLDER, PM_EDITREMOVE);
_hFolderMenu = ::CreatePopupMenu();
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_MOVEUP, TEXT("Move Up"));
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_MOVEDOWN, TEXT("Move Down"));
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, edit_rename.c_str());
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, edit_addfolder.c_str());
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, edit_addfiles.c_str());
@ -218,6 +227,8 @@ void ProjectPanel::initMenus()
generic_string edit_modifyfile = pNativeSpeaker->getProjectPanelLangMenuStr("FileMenu", IDM_PROJECT_MODIFYFILEPATH, PM_EDITMODIFYFILE);
_hFileMenu = ::CreatePopupMenu();
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_MOVEUP, TEXT("Move Up"));
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_MOVEDOWN, TEXT("Move Down"));
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, edit_rename.c_str());
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFILE, edit_remove.c_str());
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_MODIFYFILEPATH, edit_modifyfile.c_str());
@ -701,7 +712,7 @@ void ProjectPanel::showContextMenu(int x, int y)
if(tvHitInfo.hItem != NULL)
{
// Make item selected
TreeView_SelectItem(_treeView.getHSelf(), tvHitInfo.hItem);
_treeView.selectItem(tvHitInfo.hItem);
// get clicked item type
NodeType nodeType = getNodeType(tvHitInfo.hItem);
@ -831,6 +842,20 @@ void ProjectPanel::popupMenuCmd(int cmdID)
}
break;
case IDM_PROJECT_MOVEDOWN :
{
_treeView.moveDown(hTreeItem);
setWorkSpaceDirty(true);
}
break;
case IDM_PROJECT_MOVEUP :
{
_treeView.moveUp(hTreeItem);
setWorkSpaceDirty(true);
}
break;
case IDM_PROJECT_ADDFILES :
{
addFiles(hTreeItem);
@ -920,7 +945,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_DELETEFOLDER :
{
HTREEITEM parent = TreeView_GetParent(_treeView.getHSelf(), hTreeItem);
HTREEITEM parent = _treeView.getParent(hTreeItem);
if (_treeView.getChildFrom(hTreeItem) != NULL)
{
@ -943,7 +968,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDM_PROJECT_DELETEFILE :
{
HTREEITEM parent = TreeView_GetParent(_treeView.getHSelf(), hTreeItem);
HTREEITEM parent = _treeView.getParent(hTreeItem);
TCHAR str2display[MAX_PATH] = TEXT("Are you sure to remove this file from the project?");
if (::MessageBox(_hSelf, str2display, TEXT("Remove file from projet"), MB_YESNO) == IDYES)

View File

@ -90,7 +90,15 @@ public:
return _isDirty;
};
void checkIfNeedSave(const TCHAR *title);
/*
HWND getTreeHandle() {
return _treeView.getHSelf();
};
void setDraggingBool(bool val){
_treeView.setDraggingBool(val);
};
*/
protected:
TreeView _treeView;
HIMAGELIST _hImaLst;

View File

@ -28,6 +28,8 @@
#define IDM_PROJECT_DELETEFILE (IDD_PROJECTPANEL_MENU + 5)
#define IDM_PROJECT_MODIFYFILEPATH (IDD_PROJECTPANEL_MENU + 6)
#define IDM_PROJECT_ADDFILESRECUSIVELY (IDD_PROJECTPANEL_MENU + 7)
#define IDM_PROJECT_MOVEUP (IDD_PROJECTPANEL_MENU + 8)
#define IDM_PROJECT_MOVEDOWN (IDD_PROJECTPANEL_MENU + 9)
#define IDD_PROJECTPANEL_MENUWS (IDD_PROJECTPANEL + 20)
#define IDM_PROJECT_NEWPROJECT (IDD_PROJECTPANEL_MENUWS + 1)

View File

@ -218,13 +218,6 @@ 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);
}
@ -285,7 +278,7 @@ bool TreeView::isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem)
if (TreeView_GetRoot(_hSelf) == targetItem)
return false;
HTREEITEM parent = TreeView_GetParent(_hSelf, targetItem);
HTREEITEM parent = getParent(targetItem);
if (parent == draggedItem)
return true;
@ -294,7 +287,7 @@ bool TreeView::isDescendant(HTREEITEM targetItem, HTREEITEM draggedItem)
bool TreeView::isParent(HTREEITEM targetItem, HTREEITEM draggedItem)
{
HTREEITEM parent = TreeView_GetParent(_hSelf, draggedItem);
HTREEITEM parent = getParent(draggedItem);
if (parent == targetItem)
return true;
return false;
@ -323,6 +316,95 @@ void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem)
removeItem(draggedItem);
}
bool TreeView::moveDown(HTREEITEM itemToMove)
{
HTREEITEM hItemToUp = getNextSibling(itemToMove);
if (!hItemToUp)
return false;
return swapTreeViewItem(itemToMove, hItemToUp);
}
bool TreeView::moveUp(HTREEITEM itemToMove)
{
HTREEITEM hItemToDown = getPrevSibling(itemToMove);
if (!hItemToDown)
return false;
return swapTreeViewItem(hItemToDown, itemToMove);
}
bool TreeView::swapTreeViewItem(HTREEITEM itemGoDown, HTREEITEM itemGoUp)
{
HTREEITEM selectedItem = getSelection();
int itemSelected = selectedItem == itemGoDown?1:(selectedItem == itemGoUp?2:0);
// get previous and next for both items with () function
HTREEITEM itemTop = getPrevSibling(itemGoDown);
itemTop = itemTop?itemTop:(HTREEITEM)TVI_FIRST;
//HTREEITEM itemBottom = getNextSibling(itemGoUp);
HTREEITEM parentGoDown = getParent(itemGoDown);
HTREEITEM parentGoUp = getParent(itemGoUp);
if (parentGoUp != parentGoDown)
return false;
// get both item infos
TCHAR textBufferUp[MAX_PATH];
TCHAR textBufferDown[MAX_PATH];
TVITEM tvUpItem;
TVITEM tvDownItem;
tvUpItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvDownItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvUpItem.pszText = textBufferUp;
tvDownItem.pszText = textBufferDown;
tvUpItem.cchTextMax = MAX_PATH;
tvDownItem.cchTextMax = MAX_PATH;
tvUpItem.hItem = itemGoUp;
tvDownItem.hItem = itemGoDown;
SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvUpItem);
SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvDownItem);
// make copy recursively for both items
if (tvUpItem.lParam)
tvUpItem.lParam = (LPARAM)(new generic_string(*((generic_string *)(tvUpItem.lParam))));
if (tvDownItem.lParam)
tvDownItem.lParam = (LPARAM)(new generic_string(*((generic_string *)(tvDownItem.lParam))));
// add 2 new items
TVINSERTSTRUCT tvInsertUp;
tvInsertUp.item = tvUpItem;
tvInsertUp.hInsertAfter = itemTop;
tvInsertUp.hParent = parentGoUp;
HTREEITEM hTreeParent1stInserted = (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertUp);
dupTree(itemGoUp, hTreeParent1stInserted);
TVINSERTSTRUCT tvInsertDown;
tvInsertDown.item = tvDownItem;
tvInsertDown.hInsertAfter = hTreeParent1stInserted;
tvInsertDown.hParent = parentGoDown;
HTREEITEM hTreeParent2ndInserted = (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertDown);
dupTree(itemGoDown, hTreeParent2ndInserted);
// remove 2 old items
removeItem(itemGoUp);
removeItem(itemGoDown);
// Restore the selection if needed
if (itemSelected != 0)
{
if (itemSelected == 1)
{
selectItem(hTreeParent2ndInserted);
}
else if (itemSelected == 2)
{
selectItem(hTreeParent1stInserted);
}
}
return true;
}
bool TreeView::canDropIn(HTREEITEM targetItem)
{
TVITEM tvItem;

View File

@ -38,12 +38,21 @@ public:
HTREEITEM getSelection() const {
return TreeView_GetSelection(_hSelf);
};
bool selectItem(HTREEITEM hTreeItem2Select) const {
return TreeView_SelectItem(_hSelf, hTreeItem2Select) == TRUE;
};
HTREEITEM getRoot() const {
return TreeView_GetRoot(_hSelf);
};
HTREEITEM getParent(HTREEITEM hItem) const {
return TreeView_GetParent(_hSelf, hItem);
};
HTREEITEM getNextSibling(HTREEITEM hItem) const {
return TreeView_GetNextSibling(_hSelf, hItem);
};
HTREEITEM getPrevSibling(HTREEITEM hItem) const {
return TreeView_GetPrevSibling(_hSelf, hItem);
};
void expand(HTREEITEM hItem) const {
TreeView_Expand(_hSelf, hItem, TVE_EXPAND);
};
@ -66,6 +75,14 @@ public:
void addCanNotDragOutList(int val2set) {
_canNotDragOutList.push_back(val2set);
};
/*
void setDraggingBool(bool val){
_isItemDragged = val;
};
*/
bool moveDown(HTREEITEM itemToMove);
bool moveUp(HTREEITEM itemToMove);
bool swapTreeViewItem(HTREEITEM itemGoDown, HTREEITEM itemGoUp);
protected:
WNDPROC _defaultProc;