[ENHANCE] Enhance Project Manager.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@809 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-09-16 00:51:02 +00:00
parent 489f63cd6b
commit 0fd460401a
4 changed files with 140 additions and 35 deletions

View File

@ -33,6 +33,31 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
{
case WM_INITDIALOG :
{
// Create toolbar menu
int style = WS_CHILD | WS_VISIBLE | CCS_ADJUSTABLE | TBSTYLE_AUTOSIZE | TBSTYLE_FLAT;
_hToolbarMenu = CreateWindowEx(0,TOOLBARCLASSNAME,NULL, style,
0,0,0,0,_hSelf,(HMENU)0, _hInst, NULL);
TBBUTTON tbButtons[2];
static TCHAR *projectMenuStr = TEXT("Project");
tbButtons[0].idCommand = IDB_PROJECT_BTN;
tbButtons[0].iBitmap = I_IMAGENONE;
tbButtons[0].fsState = TBSTATE_ENABLED;
tbButtons[0].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE;
tbButtons[0].iString = (INT_PTR)projectMenuStr;
static TCHAR *editMenuStr = TEXT("Edit");
tbButtons[1].idCommand = IDB_EDIT_BTN;
tbButtons[1].iBitmap = I_IMAGENONE;
tbButtons[1].fsState = TBSTATE_ENABLED;
tbButtons[1].fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE;
tbButtons[1].iString = (INT_PTR)editMenuStr;
SendMessage(_hToolbarMenu, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(_hToolbarMenu, TB_ADDBUTTONS, (WPARAM)sizeof(tbButtons) / sizeof(TBBUTTON), (LPARAM)&tbButtons);
SendMessage(_hToolbarMenu, TB_AUTOSIZE, 0, 0);
ShowWindow(_hToolbarMenu, SW_SHOW);
_treeView.init(_hInst, _hSelf, ID_PROJECTTREEVIEW);
_treeView.initImageList(IDI_PROJECT_ROOT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID);
@ -51,9 +76,14 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
RECT toolbarMenuRect;
::GetClientRect(_hToolbarMenu, &toolbarMenuRect);
::MoveWindow(_hToolbarMenu, 0, 0, width, toolbarMenuRect.bottom, TRUE);
HWND hwnd = _treeView.getHSelf();
if (hwnd)
::MoveWindow(hwnd, 0, 0, width, height, TRUE);
::MoveWindow(hwnd, 0, toolbarMenuRect.bottom + 2, width, height - toolbarMenuRect.bottom - 2, TRUE);
break;
}
@ -83,20 +113,27 @@ void ProjectPanel::init(HINSTANCE hInst, HWND hPere)
{
DockingDlgInterface::init(hInst, hPere);
_hProjectMenu = ::CreatePopupMenu();
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWPROJ, TEXT("New Project"));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_OPENPROJ, TEXT("Open Project File"));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_SAVEPROJ, TEXT("Save"));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_SAVEASPROJ, TEXT("Save As..."));
_hRootMenu = ::CreatePopupMenu();
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("New Folder..."));
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("Add Folder"));
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, TEXT("Add Files..."));
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFOLDER, TEXT("Remove"));
_hFolderMenu = ::CreatePopupMenu();
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("New Folder..."));
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFOLDER, TEXT("Delete"));
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWFOLDER, TEXT("Add Folder"));
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_ADDFILES, TEXT("Add Files..."));
::InsertMenu(_hFolderMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFOLDER, TEXT("Remove"));
_hFileMenu = ::CreatePopupMenu();
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFILE, TEXT("Delete"));
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFILE, TEXT("Remove"));
}
bool ProjectPanel::openProject(TCHAR *projectFileName)
@ -266,6 +303,31 @@ void ProjectPanel::notified(LPNMHDR notification)
}
}
NodeType ProjectPanel::getNodeType(HTREEITEM hItem)
{
TVITEM tvItem;
tvItem.hItem = hItem;
tvItem.mask = TVIF_IMAGE | TVIF_PARAM;
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
// Root
if (tvItem.iImage == INDEX_PROJECT_ROOT)
{
return nodeType_root;
}
// Folder
else if (tvItem.lParam == NULL)
{
return nodeType_node;
}
// File
else
{
return nodeType_leaf;
}
}
void ProjectPanel::showContextMenu(int x, int y)
{
TVHITTESTINFO tvHitInfo;
@ -283,32 +345,31 @@ void ProjectPanel::showContextMenu(int x, int y)
// Make item selected
TreeView_SelectItem(_treeView.getHSelf(), tvHitInfo.hItem);
// get clicked item info
TVITEM tvItem;
tvItem.hItem = tvHitInfo.hItem;
tvItem.mask = TVIF_IMAGE;
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
// get clicked item type
NodeType nodeType = getNodeType(tvHitInfo.hItem);
HMENU hMenu = NULL;
// Root
if (tvItem.iImage == INDEX_PROJECT_ROOT)
{
if (nodeType == nodeType_root)
hMenu = _hRootMenu;
}
// Folder
else if (tvItem.lParam == NULL)
{
else if (nodeType == nodeType_node)
hMenu = _hFolderMenu;
}
// File
else
{
else //nodeType_leaf
hMenu = _hFileMenu;
}
TrackPopupMenu(hMenu, TPM_LEFTALIGN, x, y, 0, _hSelf, NULL);
}
}
POINT ProjectPanel::getMenuDisplyPoint(int iButton)
{
POINT p;
RECT btnRect;
SendMessage(_hToolbarMenu, TB_GETITEMRECT, iButton, (LPARAM)&btnRect);
p.x = btnRect.left;
p.y = btnRect.top + btnRect.bottom;
ClientToScreen(_hToolbarMenu, &p);
return p;
}
void ProjectPanel::popupMenuCmd(int cmdID)
{
// get selected item handle
@ -318,6 +379,28 @@ void ProjectPanel::popupMenuCmd(int cmdID)
switch (cmdID)
{
case IDB_PROJECT_BTN:
{
POINT p = getMenuDisplyPoint(0);
TrackPopupMenu(_hProjectMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL);
}
break;
case IDB_EDIT_BTN:
{
POINT p = getMenuDisplyPoint(0);
HMENU hMenu = NULL;
NodeType nodeType = getNodeType(hTreeItem);
if (nodeType == nodeType_root)
hMenu = _hRootMenu;
else if (nodeType == nodeType_node)
hMenu = _hFolderMenu;
else //nodeType_leaf
hMenu = _hFileMenu;
TrackPopupMenu(hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL);
}
break;
case IDM_PROJECT_RENAME :
TreeView_EditLabel(_treeView.getHSelf(), hTreeItem);
break;
@ -327,14 +410,14 @@ void ProjectPanel::popupMenuCmd(int cmdID)
HTREEITEM addedItem = _treeView.addItem(TEXT("Folder Name"), hTreeItem, INDEX_CLOSED_NODE);
TreeView_Expand(_treeView.getHSelf(), hTreeItem, TVE_EXPAND);
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
_treeView.expandItemGUI(hTreeItem);
_treeView.expandItemGUI(hTreeItem);
}
break;
case IDM_PROJECT_ADDFILES :
{
addFiles(hTreeItem);
_treeView.expandItemGUI(hTreeItem);
_treeView.expandItemGUI(hTreeItem);
}
break;
case IDM_PROJECT_DELETEFOLDER :
@ -365,7 +448,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
if (::MessageBox(_hSelf, str2display, TEXT("Remove file from projet"), MB_YESNO) == IDYES)
{
_treeView.removeItem(hTreeItem);
_treeView.collapsItemGUI(parent);
_treeView.collapsItemGUI(parent);
}
}
break;

View File

@ -28,23 +28,21 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "TreeView.h"
#include "ProjectPanel_rc.h"
#define IDM_PROJECT_RENAME 2560
#define IDM_PROJECT_NEWFOLDER 2561
#define IDM_PROJECT_ADDFILES 2562
#define IDM_PROJECT_DELETEFOLDER 2563
#define IDM_PROJECT_DELETEFILE 2564
enum NodeType {
nodeType_root = 0, nodeType_node = 1, nodeType_leaf = 2
};
class TiXmlNode;
class ProjectPanel : public DockingDlgInterface {
public:
ProjectPanel(): DockingDlgInterface(IDD_PROJECTPANEL),\
_hRootMenu(NULL), _hFolderMenu(NULL), _hFileMenu(NULL){};
_hToolbarMenu(NULL), _hProjectMenu(NULL), _hRootMenu(NULL), _hFolderMenu(NULL), _hFileMenu(NULL){};
void init(HINSTANCE hInst, HWND hPere);
void destroy() {
::DestroyMenu(_hProjectMenu);
::DestroyMenu(_hRootMenu);
::DestroyMenu(_hFolderMenu);
::DestroyMenu(_hFileMenu);
@ -63,12 +61,15 @@ public:
protected:
TreeView _treeView;
HMENU _hRootMenu, _hFolderMenu, _hFileMenu;
HWND _hToolbarMenu;
HMENU _hProjectMenu, _hRootMenu, _hFolderMenu, _hFileMenu;
void popupMenuCmd(int cmdID);
POINT getMenuDisplyPoint(int iButton);
virtual BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
bool buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem);
void notified(LPNMHDR notification);
void showContextMenu(int x, int y);
NodeType getNodeType(HTREEITEM hItem);
};
#endif // PROJECTPANEL_H

View File

@ -19,7 +19,25 @@
#define PROJECTPANEL_RC_H
#define IDD_PROJECTPANEL 3100
#define ID_PROJECTTREEVIEW (IDD_PROJECTPANEL + 1)
#define IDD_PROJECTPANEL_MENU (IDD_PROJECTPANEL + 10)
#define IDM_PROJECT_RENAME (IDD_PROJECTPANEL_MENU + 1)
#define IDM_PROJECT_NEWFOLDER (IDD_PROJECTPANEL_MENU + 2)
#define IDM_PROJECT_ADDFILES (IDD_PROJECTPANEL_MENU + 3)
#define IDM_PROJECT_DELETEFOLDER (IDD_PROJECTPANEL_MENU + 4)
#define IDM_PROJECT_DELETEFILE (IDD_PROJECTPANEL_MENU + 5)
#define IDD_PROJECTPANEL_MENUPROJ (IDD_PROJECTPANEL + 20)
#define IDM_PROJECT_NEWPROJ (IDD_PROJECTPANEL_MENUPROJ + 1)
#define IDM_PROJECT_OPENPROJ (IDD_PROJECTPANEL_MENUPROJ + 2)
#define IDM_PROJECT_SAVEPROJ (IDD_PROJECTPANEL_MENUPROJ + 3)
#define IDM_PROJECT_SAVEASPROJ (IDD_PROJECTPANEL_MENUPROJ + 4)
#define IDD_PROJECTPANEL_CTRL (IDD_PROJECTPANEL + 30)
#define ID_PROJECTTREEVIEW (IDD_PROJECTPANEL_CTRL + 1)
#define IDB_PROJECT_BTN (IDD_PROJECTPANEL_CTRL + 2)
#define IDB_EDIT_BTN (IDD_PROJECTPANEL_CTRL + 3)
#endif // PROJECTPANEL_RC_H

View File

@ -154,6 +154,9 @@ void TreeView::cleanSubEntries(HTREEITEM hTreeItem)
void TreeView::collapsItemGUI(HTREEITEM hTreeItem)
{
if (TreeView_GetRoot(_hSelf) == hTreeItem)
return;
if (getChildFrom(hTreeItem) == NULL)
{
TVITEM tvItem;