[ENHANCE] Enhance Project Manager.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@810 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-09-18 23:47:16 +00:00
parent 0fd460401a
commit 647748824a
8 changed files with 221 additions and 65 deletions

View File

@ -160,7 +160,6 @@ Notepad_plus::~Notepad_plus()
if (_pProjectPanel)
{
_pProjectPanel->destroy();
delete _pProjectPanel;
}
}

View File

@ -33,36 +33,38 @@ 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];
ProjectPanel::initMenus();
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;
// 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 *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;
static TCHAR *projectMenuStr = TEXT("WorkSpace");
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;
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);
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);
_treeView.display();
openProject(TEXT("D:\\source\\notepad++\\trunk\\PowerEditor\\src\\WinControls\\ProjectPanel\\demo.xml"));
openWorkSpace(TEXT("D:\\source\\notepad++\\trunk\\PowerEditor\\src\\WinControls\\ProjectPanel\\demo.xml"));
return TRUE;
}
@ -83,7 +85,7 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
HWND hwnd = _treeView.getHSelf();
if (hwnd)
::MoveWindow(hwnd, 0, toolbarMenuRect.bottom + 2, width, height - toolbarMenuRect.bottom - 2, TRUE);
::MoveWindow(hwnd, 0, toolbarMenuRect.bottom + 2, width, height - toolbarMenuRect.bottom - 2, TRUE);
break;
}
@ -100,6 +102,8 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
case WM_DESTROY:
{
_treeView.destroy();
destroyMenus();
::DestroyWindow(_hToolbarMenu);
break;
}
@ -109,15 +113,15 @@ BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}
void ProjectPanel::init(HINSTANCE hInst, HWND hPere)
void ProjectPanel::initMenus()
{
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..."));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_NEWPROJECT, TEXT("Add New Project"));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_OPENWS, TEXT("Open WorkSpace"));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RELOADWS, TEXT("Reload WorkSpace"));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_SAVEWS, TEXT("Save"));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_SAVEASWS, TEXT("Save As..."));
::InsertMenu(_hProjectMenu, 0, MF_BYCOMMAND, IDM_PROJECT_SAVEACOPYASWS, TEXT("Save a Copy As..."));
_hRootMenu = ::CreatePopupMenu();
::InsertMenu(_hRootMenu, 0, MF_BYCOMMAND, IDM_PROJECT_RENAME, TEXT("Rename"));
@ -136,7 +140,15 @@ void ProjectPanel::init(HINSTANCE hInst, HWND hPere)
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_DELETEFILE, TEXT("Remove"));
}
bool ProjectPanel::openProject(TCHAR *projectFileName)
void ProjectPanel::destroyMenus()
{
::DestroyMenu(_hProjectMenu);
::DestroyMenu(_hRootMenu);
::DestroyMenu(_hFolderMenu);
::DestroyMenu(_hFileMenu);
}
bool ProjectPanel::openWorkSpace(const TCHAR *projectFileName)
{
TiXmlDocument *pXmlDocProject = new TiXmlDocument(projectFileName);
bool loadOkay = pXmlDocProject->LoadFile();
@ -147,17 +159,78 @@ bool ProjectPanel::openProject(TCHAR *projectFileName)
if (!root)
return false;
root = root->FirstChild(TEXT("Project"));
if (!root)
TiXmlNode *childNode = root->FirstChildElement(TEXT("Project"));
if (!childNode)
return false;
HTREEITEM rootItem = _treeView.addItem((root->ToElement())->Attribute(TEXT("name")), TVI_ROOT, INDEX_PROJECT_ROOT);
buildTreeFrom(root, rootItem);
for ( ; childNode ; childNode = childNode->NextSibling(TEXT("Project")))
{
HTREEITEM rootItem = _treeView.addItem((childNode->ToElement())->Attribute(TEXT("name")), TVI_ROOT, INDEX_PROJECT_ROOT);
buildTreeFrom(childNode, rootItem);
}
delete pXmlDocProject;
return loadOkay;
}
bool ProjectPanel::writeWorkSpace(TCHAR *projectFileName)
{
//write <NotepadPlus>: use the default file name if new file name is not given
TiXmlDocument projDoc(projectFileName?projectFileName:_workSpaceFilePath.c_str());
TiXmlNode *root = projDoc.InsertEndChild(TiXmlElement(TEXT("NotepadPlus")));
TCHAR textBuffer[MAX_PATH];
TVITEM tvItem;
tvItem.mask = TVIF_TEXT;
tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH;
//for each project, write <Project>
for (HTREEITEM tvProj = _treeView.getRoot();
tvProj != NULL;
tvProj = _treeView.getNextSibling(tvProj))
{
tvItem.hItem = tvProj;
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
//printStr(tvItem.pszText);
TiXmlNode *projRoot = root->InsertEndChild(TiXmlElement(TEXT("Project")));
projRoot->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText);
buildProjectXml(projRoot, tvProj);
}
projDoc.SaveFile();
return true;
}
void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem)
{
TCHAR textBuffer[MAX_PATH];
TVITEM tvItem;
tvItem.mask = TVIF_TEXT | TVIF_PARAM;
tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH;
for (HTREEITEM hItemNode = _treeView.getChildFrom(hItem);
hItemNode != NULL;
hItemNode = _treeView.getNextSibling(hItemNode))
{
tvItem.hItem = hItemNode;
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
if (tvItem.lParam != NULL)
{
generic_string *fn = (generic_string *)tvItem.lParam;
TiXmlNode *fileLeaf = node->InsertEndChild(TiXmlElement(TEXT("File")));
fileLeaf->ToElement()->SetAttribute(TEXT("name"), fn->c_str());
}
else
{
TiXmlNode *folderNode = node->InsertEndChild(TiXmlElement(TEXT("Folder")));
folderNode->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText);
buildProjectXml(folderNode, hItemNode);
}
}
}
bool ProjectPanel::buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem)
{
for (TiXmlNode *childNode = projectRoot->FirstChildElement();
@ -180,8 +253,8 @@ bool ProjectPanel::buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem)
{
const TCHAR *strValue = (childNode->ToElement())->Attribute(TEXT("name"));
TCHAR *strValueLabel = ::PathFindFileName(strValue);
int iImage = ::PathFileExists(strValue)?INDEX_LEAF:INDEX_LEAF_INVALID;
_treeView.addItem(strValueLabel, hParentItem, iImage, strValue);
int iImage = ::PathFileExists(strValue)?INDEX_LEAF:INDEX_LEAF_INVALID;
_treeView.addItem(strValueLabel, hParentItem, iImage, strValue);
}
}
return true;
@ -310,7 +383,6 @@ NodeType ProjectPanel::getNodeType(HTREEITEM hItem)
tvItem.mask = TVIF_IMAGE | TVIF_PARAM;
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem);
// Root
if (tvItem.iImage == INDEX_PROJECT_ROOT)
{
@ -379,6 +451,9 @@ void ProjectPanel::popupMenuCmd(int cmdID)
switch (cmdID)
{
//
// Toolbar menu buttons
//
case IDB_PROJECT_BTN:
{
POINT p = getMenuDisplyPoint(0);
@ -388,7 +463,7 @@ void ProjectPanel::popupMenuCmd(int cmdID)
case IDB_EDIT_BTN:
{
POINT p = getMenuDisplyPoint(0);
POINT p = getMenuDisplyPoint(1);
HMENU hMenu = NULL;
NodeType nodeType = getNodeType(hTreeItem);
if (nodeType == nodeType_root)
@ -401,6 +476,16 @@ void ProjectPanel::popupMenuCmd(int cmdID)
}
break;
//
// Toolbar menu commands
//
case IDM_PROJECT_NEWPROJECT :
{
HTREEITEM addedItem = _treeView.addItem(TEXT("Project Name"), TVI_ROOT, INDEX_PROJECT_ROOT);
TreeView_EditLabel(_treeView.getHSelf(), addedItem);
}
break;
case IDM_PROJECT_RENAME :
TreeView_EditLabel(_treeView.getHSelf(), hTreeItem);
break;
@ -420,6 +505,56 @@ void ProjectPanel::popupMenuCmd(int cmdID)
_treeView.expandItemGUI(hTreeItem);
}
break;
case IDM_PROJECT_OPENWS:
{
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
if (TCHAR *fn = fDlg.doOpenSingleFileDlg())
{
_treeView.removeAllItems();
openWorkSpace(fn);
_workSpaceFilePath = fn;
_isDirty = false;
}
}
break;
case IDM_PROJECT_RELOADWS:
{
if (::PathFileExists(_workSpaceFilePath.c_str()))
{
_treeView.removeAllItems();
openWorkSpace(_workSpaceFilePath.c_str());
_isDirty = false;
}
}
break;
case IDM_PROJECT_SAVEWS:
writeWorkSpace();
_isDirty = false;
break;
case IDM_PROJECT_SAVEACOPYASWS:
case IDM_PROJECT_SAVEASWS:
{
FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL));
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL);
if (TCHAR *fn = fDlg.doSaveDlg())
{
writeWorkSpace(fn);
if (cmdID == IDM_PROJECT_SAVEASWS)
{
_workSpaceFilePath = fn;
_isDirty = false;
}
}
}
break;
case IDM_PROJECT_DELETEFOLDER :
{
HTREEITEM parent = TreeView_GetParent(_treeView.getHSelf(), hTreeItem);

View File

@ -39,14 +39,10 @@ public:
ProjectPanel(): DockingDlgInterface(IDD_PROJECTPANEL),\
_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);
};
void init(HINSTANCE hInst, HWND hPere) {
DockingDlgInterface::init(hInst, hPere);
}
virtual void display(bool toShow = true) const {
DockingDlgInterface::display(toShow);
@ -56,20 +52,28 @@ public:
_hParent = parent2set;
};
bool openProject(TCHAR *projectFileName);
void destroyMenus();
void initMenus();
bool openWorkSpace(const TCHAR *projectFileName);
void addFiles(HTREEITEM hTreeItem);
bool writeWorkSpace(TCHAR *projectFileName = NULL);
void buildProjectXml(TiXmlNode *root, HTREEITEM hItem);
NodeType getNodeType(HTREEITEM hItem);
protected:
TreeView _treeView;
HWND _hToolbarMenu;
HMENU _hProjectMenu, _hRootMenu, _hFolderMenu, _hFileMenu;
generic_string _workSpaceFilePath;
bool _isDirty;
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

@ -27,12 +27,13 @@
#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_MENUWS (IDD_PROJECTPANEL + 20)
#define IDM_PROJECT_NEWPROJECT (IDD_PROJECTPANEL_MENUWS + 1)
#define IDM_PROJECT_OPENWS (IDD_PROJECTPANEL_MENUWS + 2)
#define IDM_PROJECT_RELOADWS (IDD_PROJECTPANEL_MENUWS + 3)
#define IDM_PROJECT_SAVEWS (IDD_PROJECTPANEL_MENUWS + 4)
#define IDM_PROJECT_SAVEASWS (IDD_PROJECTPANEL_MENUWS + 5)
#define IDM_PROJECT_SAVEACOPYASWS (IDD_PROJECTPANEL_MENUWS + 6)
#define IDD_PROJECTPANEL_CTRL (IDD_PROJECTPANEL + 30)
#define ID_PROJECTTREEVIEW (IDD_PROJECTPANEL_CTRL + 1)

View File

@ -136,6 +136,17 @@ void TreeView::removeItem(HTREEITEM hTreeItem)
TreeView_DeleteItem(_hSelf, hTreeItem);
}
void TreeView::removeAllItems()
{
for (HTREEITEM tvProj = getRoot();
tvProj != NULL;
tvProj = getNextSibling(tvProj))
{
cleanSubEntries(tvProj);
}
TreeView_DeleteAllItems(_hSelf);
}
void TreeView::cleanSubEntries(HTREEITEM hTreeItem)
{
for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem))

View File

@ -36,16 +36,20 @@ public:
virtual void destroy();
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) {
HTREEITEM getChildFrom(HTREEITEM hTreeItem) const {
return TreeView_GetChild(_hSelf, hTreeItem);
};
HTREEITEM getNextSibling(HTREEITEM hTreeItem){
return TreeView_GetNextSibling(_hSelf ,hTreeItem);
};
HTREEITEM getSelection() {
HTREEITEM getSelection() const {
return TreeView_GetSelection(_hSelf);
};
HTREEITEM getRoot() const {
return TreeView_GetRoot(_hSelf);
};
HTREEITEM getNextSibling(HTREEITEM hItem) const {
return TreeView_GetNextSibling(_hSelf, hItem);
};
void expandItemGUI(HTREEITEM hTreeItem);
void collapsItemGUI(HTREEITEM hTreeItem);
BOOL initImageList(int project_root_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id);

View File

@ -26,4 +26,6 @@
<Folder name="Scintilla">
</Folder>
</Project>
<Project name="Win32 GUP" >
</Project>
</NotepadPlus>

View File

@ -1611,11 +1611,11 @@
>
</File>
<File
RelativePath="..\src\resource.h"
RelativePath="..\src\WinControls\Preference\resource.h"
>
</File>
<File
RelativePath="..\src\WinControls\Preference\resource.h"
RelativePath="..\src\resource.h"
>
</File>
<File