Skip to content

Commit

Permalink
[NEW_FEATURE] enhance Project manager (in progress).
Browse files Browse the repository at this point in the history
- Notepad-plus svn trunk @ 818
  • Loading branch information
donho committed Sep 26, 2011
1 parent 22cf186 commit 59527df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
27 changes: 22 additions & 5 deletions PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ bool ProjectPanel::saveWorkSpace()
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());
const TCHAR * fn2write = projectFileName?projectFileName:_workSpaceFilePath.c_str();
TiXmlDocument projDoc(fn2write);
TiXmlNode *root = projDoc.InsertEndChild(TiXmlElement(TEXT("NotepadPlus")));

TCHAR textBuffer[MAX_PATH];
Expand All @@ -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;
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class ProjectPanel : public DockingDlgInterface {
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);
Expand Down

0 comments on commit 59527df

Please sign in to comment.