void ProjectPanel::newWorkSpace() { NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string workspace = pNativeSpeaker->getProjectPanelLangStr("WorkspaceRootName", PM_WORKSPACEROOTNAME); _treeView.addItem(workspace.c_str(), TVI_ROOT, INDEX_CLEAN_ROOT); setWorkSpaceDirty(false); _workSpaceFilePath = TEXT(""); }
bool ProjectPanel::openWorkSpace(const TCHAR *projectFileName) { TiXmlDocument *pXmlDocProject = new TiXmlDocument(projectFileName); bool loadOkay = pXmlDocProject->LoadFile(); if (!loadOkay) return false; TiXmlNode *root = pXmlDocProject->FirstChild(TEXT("NotepadPlus")); if (!root) return false; TiXmlNode *childNode = root->FirstChildElement(TEXT("Project")); if (!childNode) return false; if (!::PathFileExists(projectFileName)) return false; _treeView.removeAllItems(); _workSpaceFilePath = projectFileName; NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string workspace = pNativeSpeaker->getProjectPanelLangStr("WorkspaceRootName", PM_WORKSPACEROOTNAME); HTREEITEM rootItem = _treeView.addItem(workspace.c_str(), TVI_ROOT, INDEX_CLEAN_ROOT); for ( ; childNode ; childNode = childNode->NextSibling(TEXT("Project"))) { HTREEITEM projectItem = _treeView.addItem((childNode->ToElement())->Attribute(TEXT("name")), rootItem, INDEX_PROJECT); buildTreeFrom(childNode, projectItem); } setWorkSpaceDirty(false); _treeView.expand(rootItem); delete pXmlDocProject; return loadOkay; }
void ProjectPanel::popupMenuCmd(int cmdID) { // get selected item handle HTREEITEM hTreeItem = _treeView.getSelection(); if (!hTreeItem) return; switch (cmdID) { // // Toolbar menu buttons // case IDB_PROJECT_BTN: { POINT p = getMenuDisplyPoint(0); TrackPopupMenu(_hWorkSpaceMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL); } break; case IDB_EDIT_BTN: { POINT p = getMenuDisplyPoint(1); HMENU hMenu = NULL; NodeType nodeType = getNodeType(hTreeItem); if (nodeType == nodeType_project) hMenu = _hProjectMenu; else if (nodeType == nodeType_folder) hMenu = _hFolderMenu; else if (nodeType == nodeType_file) hMenu = _hFileMenu; if (hMenu) TrackPopupMenu(hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL); } break; // // Toolbar menu commands // case IDM_PROJECT_NEWPROJECT : { HTREEITEM root = _treeView.getRoot(); NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string newProjectLabel = pNativeSpeaker->getProjectPanelLangStr("NewProjectName", PM_NEWPROJECTNAME); HTREEITEM addedItem = _treeView.addItem(newProjectLabel.c_str(), root, INDEX_PROJECT); setWorkSpaceDirty(true); _treeView.expand(hTreeItem); TreeView_EditLabel(_treeView.getHSelf(), addedItem); } break; case IDM_PROJECT_NEWWS : { if (_isDirty) { int res = ::MessageBox(_hSelf, TEXT("The current workspace was modified. Do you want to save the current project?"), TEXT(""), MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL); if (res == IDYES) { if (!saveWorkSpace()) return; } else if (res == IDNO) { // Don't save so do nothing here } else if (res == IDCANCEL) { // User cancels action "New Workspace" so we interrupt here return; } } _treeView.removeAllItems(); newWorkSpace(); } break; case IDM_PROJECT_RENAME : TreeView_EditLabel(_treeView.getHSelf(), hTreeItem); break; case IDM_PROJECT_NEWFOLDER : { NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string newFolderLabel = pNativeSpeaker->getProjectPanelLangStr("NewFolderName", PM_NEWFOLDERNAME); addFolder(hTreeItem, newFolderLabel.c_str()); setWorkSpaceDirty(true); } break; case IDM_PROJECT_MOVEDOWN : { if (_treeView.moveDown(hTreeItem)) setWorkSpaceDirty(true); } break; case IDM_PROJECT_MOVEUP : { if (_treeView.moveUp(hTreeItem)) setWorkSpaceDirty(true); } break; case IDM_PROJECT_ADDFILES : { addFiles(hTreeItem); if (getNodeType(hTreeItem) == nodeType_folder) _treeView.setItemImage(hTreeItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE); } break; case IDM_PROJECT_ADDFILESRECUSIVELY : { addFilesFromDirectory(hTreeItem); if (getNodeType(hTreeItem) == nodeType_folder) _treeView.setItemImage(hTreeItem, INDEX_OPEN_NODE, INDEX_OPEN_NODE); } break; case IDM_PROJECT_OPENWS: { if (_isDirty) { int res = ::MessageBox(_hSelf, TEXT("The current workspace was modified. Do you want to save the current project?"), TEXT(""), MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL); if (res == IDYES) { if (!saveWorkSpace()) return; } else if (res == IDNO) { // Don't save so do nothing here } else if (res == IDCANCEL) { // User cancels action "New Workspace" so we interrupt here return; } } FileDialog fDlg(_hSelf, ::GetModuleHandle(NULL)); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); if (TCHAR *fn = fDlg.doOpenSingleFileDlg()) { if (!openWorkSpace(fn)) { ::MessageBox(_hSelf, TEXT("Opening Workspace failed.\rIt seems the file to open is not valid project file."), TEXT("Open Workspace"), MB_OK); return; } } } break; case IDM_PROJECT_RELOADWS: { if (_isDirty) { int res = ::MessageBox(_hSelf, TEXT("The current workspace was modified. Reload will discard all modification.\rDo you want to continue?"), TEXT(""), MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); if (res == IDYES) { // Do nothing } else if (res == IDNO) { return; } } if (::PathFileExists(_workSpaceFilePath.c_str())) { openWorkSpace(_workSpaceFilePath.c_str()); } else { ::MessageBox(_hSelf, TEXT("Can not find file to reload"), TEXT(""), MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL); } } break; case IDM_PROJECT_SAVEWS: saveWorkSpace(); break; case IDM_PROJECT_SAVEACOPYASWS: case IDM_PROJECT_SAVEASWS: { saveWorkSpaceAs(cmdID == IDM_PROJECT_SAVEACOPYASWS); } break; case IDM_PROJECT_DELETEFOLDER : { HTREEITEM parent = _treeView.getParent(hTreeItem); if (_treeView.getChildFrom(hTreeItem) != NULL) { TCHAR str2display[MAX_PATH] = TEXT("All the sub-items will be removed.\rAre you sure to remove this folder from the project?"); if (::MessageBox(_hSelf, str2display, TEXT("Remove folder from projet"), MB_YESNO) == IDYES) { _treeView.removeItem(hTreeItem); setWorkSpaceDirty(true); } } else { _treeView.removeItem(hTreeItem); setWorkSpaceDirty(true); } if (getNodeType(parent) == nodeType_folder) _treeView.setItemImage(parent, INDEX_CLOSED_NODE, INDEX_CLOSED_NODE); } break; case IDM_PROJECT_DELETEFILE : { HTREEITEM parent = _treeView.getParent(hTreeItem); TCHAR str2display[MAX_PATH] = TEXT("Are you sure to remove this file from the project?"); if (::MessageBox(_hSelf, str2display, TEXT("Remove file from projet"), MB_YESNO) == IDYES) { _treeView.removeItem(hTreeItem); setWorkSpaceDirty(true); if (getNodeType(parent) == nodeType_folder) _treeView.setItemImage(parent, INDEX_CLOSED_NODE, INDEX_CLOSED_NODE); } } break; case IDM_PROJECT_MODIFYFILEPATH : { FileRelocalizerDlg fileRelocalizerDlg; fileRelocalizerDlg.init(_hInst, _hParent); TCHAR textBuffer[MAX_PATH]; TVITEM tvItem; tvItem.hItem = hTreeItem; tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvItem.pszText = textBuffer; tvItem.cchTextMax = MAX_PATH; SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0,(LPARAM)&tvItem); if (!tvItem.lParam) return; generic_string * fn = (generic_string *)tvItem.lParam; if (fileRelocalizerDlg.doDialog(fn->c_str()) == 0) { generic_string newValue = fileRelocalizerDlg.getFullFilePath(); if (*fn == newValue) return; *fn = newValue; TCHAR *strValueLabel = ::PathFindFileName(fn->c_str()); lstrcpy(textBuffer, strValueLabel); int iImage = ::PathFileExists(fn->c_str())?INDEX_LEAF:INDEX_LEAF_INVALID; tvItem.iImage = tvItem.iSelectedImage = iImage; SendMessage(_treeView.getHSelf(), TVM_SETITEM, 0,(LPARAM)&tvItem); setWorkSpaceDirty(true); } } break; } }