[NEW_FEATURE] enhance Project manager (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@818 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-09-26 18:24:22 +00:00
parent 79399432c0
commit 7c71960fda
2 changed files with 24 additions and 6 deletions

View File

@ -302,7 +302,8 @@ bool ProjectPanel::saveWorkSpace()
bool ProjectPanel::writeWorkSpace(TCHAR *projectFileName) bool ProjectPanel::writeWorkSpace(TCHAR *projectFileName)
{ {
//write <NotepadPlus>: use the default file name if new file name is not given //write <NotepadPlus>: use the default file name if new file name is not given
TiXmlDocument projDoc(projectFileName?projectFileName:_workSpaceFilePath.c_str()); const TCHAR * fn2write = projectFileName?projectFileName:_workSpaceFilePath.c_str();
TiXmlDocument projDoc(fn2write);
TiXmlNode *root = projDoc.InsertEndChild(TiXmlElement(TEXT("NotepadPlus"))); TiXmlNode *root = projDoc.InsertEndChild(TiXmlElement(TEXT("NotepadPlus")));
TCHAR textBuffer[MAX_PATH]; TCHAR textBuffer[MAX_PATH];
@ -326,13 +327,13 @@ bool ProjectPanel::writeWorkSpace(TCHAR *projectFileName)
TiXmlNode *projRoot = root->InsertEndChild(TiXmlElement(TEXT("Project"))); TiXmlNode *projRoot = root->InsertEndChild(TiXmlElement(TEXT("Project")));
projRoot->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText); projRoot->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText);
buildProjectXml(projRoot, tvProj); buildProjectXml(projRoot, tvProj, fn2write);
} }
projDoc.SaveFile(); projDoc.SaveFile();
return true; return true;
} }
void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem) void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem, const TCHAR* fn2write)
{ {
TCHAR textBuffer[MAX_PATH]; TCHAR textBuffer[MAX_PATH];
TVITEM tvItem; TVITEM tvItem;
@ -349,18 +350,34 @@ void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem)
if (tvItem.lParam != NULL) if (tvItem.lParam != NULL)
{ {
generic_string *fn = (generic_string *)tvItem.lParam; generic_string *fn = (generic_string *)tvItem.lParam;
generic_string newFn = getRelativePath(*fn, fn2write);
TiXmlNode *fileLeaf = node->InsertEndChild(TiXmlElement(TEXT("File"))); TiXmlNode *fileLeaf = node->InsertEndChild(TiXmlElement(TEXT("File")));
fileLeaf->ToElement()->SetAttribute(TEXT("name"), fn->c_str()); fileLeaf->ToElement()->SetAttribute(TEXT("name"), newFn.c_str());
} }
else else
{ {
TiXmlNode *folderNode = node->InsertEndChild(TiXmlElement(TEXT("Folder"))); TiXmlNode *folderNode = node->InsertEndChild(TiXmlElement(TEXT("Folder")));
folderNode->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText); folderNode->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText);
buildProjectXml(folderNode, hItemNode); buildProjectXml(folderNode, hItemNode, fn2write);
} }
} }
} }
generic_string ProjectPanel::getRelativePath(const generic_string & filePath, const TCHAR *workSpaceFileName)
{
TCHAR wsfn[MAX_PATH];
lstrcpy(wsfn, workSpaceFileName);
::PathRemoveFileSpec(wsfn);
size_t pos_found = filePath.find(wsfn);
if (pos_found == generic_string::npos)
return filePath;
const TCHAR *relativeFile = filePath.c_str() + lstrlen(wsfn) + 1;
//printStr(relativeFile);
return relativeFile;
}
bool ProjectPanel::buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem) bool ProjectPanel::buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem)
{ {
for (TiXmlNode *childNode = projectRoot->FirstChildElement(); for (TiXmlNode *childNode = projectRoot->FirstChildElement();

View File

@ -80,7 +80,8 @@ protected:
BOOL setImageList(int root_clean_id, int root_dirty_id, int project_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id); BOOL setImageList(int root_clean_id, int root_dirty_id, int project_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id);
void addFiles(HTREEITEM hTreeItem); void addFiles(HTREEITEM hTreeItem);
bool writeWorkSpace(TCHAR *projectFileName = NULL); bool writeWorkSpace(TCHAR *projectFileName = NULL);
void buildProjectXml(TiXmlNode *root, HTREEITEM hItem); generic_string getRelativePath(const generic_string & fn, const TCHAR *workSpaceFileName);
void buildProjectXml(TiXmlNode *root, HTREEITEM hItem, const TCHAR* fn2write);
NodeType getNodeType(HTREEITEM hItem); NodeType getNodeType(HTREEITEM hItem);
void setWorkSpaceDirty(bool isDirty); void setWorkSpaceDirty(bool isDirty);
void popupMenuCmd(int cmdID); void popupMenuCmd(int cmdID);