diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index e9e3ad14..21e50401 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -302,7 +302,8 @@ bool ProjectPanel::saveWorkSpace() bool ProjectPanel::writeWorkSpace(TCHAR *projectFileName) { //write : 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"))); TCHAR textBuffer[MAX_PATH]; @@ -326,13 +327,13 @@ bool ProjectPanel::writeWorkSpace(TCHAR *projectFileName) TiXmlNode *projRoot = root->InsertEndChild(TiXmlElement(TEXT("Project"))); projRoot->ToElement()->SetAttribute(TEXT("name"), tvItem.pszText); - buildProjectXml(projRoot, tvProj); + buildProjectXml(projRoot, tvProj, fn2write); } projDoc.SaveFile(); return true; } -void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem) +void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem, const TCHAR* fn2write) { TCHAR textBuffer[MAX_PATH]; TVITEM tvItem; @@ -349,18 +350,34 @@ void ProjectPanel::buildProjectXml(TiXmlNode *node, HTREEITEM hItem) if (tvItem.lParam != NULL) { generic_string *fn = (generic_string *)tvItem.lParam; + generic_string newFn = getRelativePath(*fn, fn2write); TiXmlNode *fileLeaf = node->InsertEndChild(TiXmlElement(TEXT("File"))); - fileLeaf->ToElement()->SetAttribute(TEXT("name"), fn->c_str()); + fileLeaf->ToElement()->SetAttribute(TEXT("name"), newFn.c_str()); } else { TiXmlNode *folderNode = node->InsertEndChild(TiXmlElement(TEXT("Folder"))); 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) { for (TiXmlNode *childNode = projectRoot->FirstChildElement(); diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h index ac7b9e0f..38fb317c 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h @@ -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); void addFiles(HTREEITEM hTreeItem); 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); void setWorkSpaceDirty(bool isDirty); void popupMenuCmd(int cmdID);