void PHPWorkspaceView::OnNewClass(wxCommandEvent& e) { wxTreeItemId folderId = DoGetSingleSelection(); ItemData* data = DoGetItemData(folderId); if(!data || !data->IsFolder()) { return; } PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(data->GetProjectName()); CHECK_PTR_RET(pProject); PHPFolder::Ptr_t pFolder = pProject->Folder(data->GetFolderPath()); CHECK_PTR_RET(pFolder); NewPHPClass dlg(wxTheApp->GetTopWindow(), pFolder->GetFullPath(pProject->GetFilename().GetPath(), false)); if(dlg.ShowModal() == wxID_OK) { PHPClassDetails pcd = dlg.GetDetails(); pFolder = pProject->AddFolder(PHPFolder::GetFolderPathFromFileFullPath(pcd.GetFilepath().GetFullPath(), pProject->GetFilename().GetPath())); CHECK_PTR_RET(pFolder); folderId = EnsureFolderExists( DoGetProjectItem(pProject->GetName()), pFolder->GetPathRelativeToProject(), pProject->GetName()); DoAddFileWithContent( folderId, pcd.GetFilepath(), pcd.ToString(EditorConfigST::Get()->GetOptions()->GetEOLAsString(), " ")); } }
void PHPWorkspaceView::DoAddFolder(const wxTreeItemId& parent, PHPFolder::Ptr_t folder, PHPProject::Ptr_t project) { // add the folder itself ItemData* itemData = new ItemData(ItemData::Kind_Folder); itemData->SetFolderPath(folder->GetPathRelativeToProject()); itemData->SetProjectName(project->GetName()); itemData->SetFolderName(folder->GetName()); // display name wxTreeItemId folderItem = EnsureFolderExists( DoGetProjectItem(project->GetName()), folder->GetPathRelativeToProject(), project->GetName()); // Get list of folders const PHPFolder::List_t& children = folder->GetChildren(); PHPFolder::List_t::const_iterator iter = children.begin(); for(; iter != children.end(); ++iter) { DoAddFolder(folderItem, *iter, project); } wxArrayString folderFiles; folder->GetFiles(folderFiles, project->GetFilename().GetPath(), 0); // Add the files for(size_t i = 0; i < folderFiles.GetCount(); ++i) { ItemData* itemData = new ItemData(ItemData::Kind_File); itemData->SetFile(folderFiles.Item(i)); itemData->SetProjectName(project->GetName()); itemData->SetFolderPath(folder->GetPathRelativeToProject()); int imgId = DoGetItemImgIdx(folderFiles.Item(i)); m_treeCtrlView->AppendItem(folderItem, wxFileName(folderFiles.Item(i)).GetFullName(), imgId, imgId, itemData); } }
void PHPWorkspaceView::DoAddFilesToFolder(const wxArrayString& paths, PHPProject::Ptr_t pProject, bool notify) { if(paths.IsEmpty()) return; CHECK_PTR_RET(pProject); wxString folder_path = PHPFolder::GetFolderPathFromFileFullPath(paths.Item(0), pProject->GetFilename().GetPath()); wxTreeItemId folderItem = EnsureFolderExists(DoGetProjectItem(pProject->GetName()), folder_path, pProject->GetName()); PHPFolder::Ptr_t pFolder = pProject->AddFolder(folder_path); CHECK_PTR_RET(pFolder); wxArrayString newPaths; for(size_t i = 0; i < paths.GetCount(); i++) { if(pFolder->AddFile(paths.Item(i))) { newPaths.Add(paths.Item(i)); } } if(newPaths.IsEmpty()) return; if(notify) { DoAddFilesToTreeView(folderItem, pProject, pFolder, newPaths); // Notify the plugins clCommandEvent evtFilesAdded(wxEVT_PROJ_FILE_ADDED); evtFilesAdded.SetStrings(newPaths); EventNotifier::Get()->AddPendingEvent(evtFilesAdded); } }
void PHPWorkspaceView::DoAddFolderFiles(const wxString& project, const wxString& folder, const wxTreeItemId& folderTreeItemId, wxStringSet_t* filesAdded) { PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(project); CHECK_PTR_RET(pProject); PHPFolder::Ptr_t pFolder = pProject->Folder(folder); CHECK_PTR_RET(pFolder); wxArrayString files; pFolder->GetFiles(files, pProject->GetFilename().GetPath()); files.Sort(); for(size_t i = 0; i < files.GetCount(); ++i) { wxFileName fn(files.Item(i)); // create the user data ItemData* itemData = new ItemData(ItemData::Kind_File); itemData->SetFile(fn.GetFullPath()); itemData->SetFolderPath(folder); itemData->SetProjectName(project); int imgId = DoGetItemImgIdx(fn.GetFullName()); m_treeCtrlView->AppendItem(folderTreeItemId, fn.GetFullName(), imgId, imgId, itemData); if(filesAdded) { filesAdded->insert(fn.GetFullPath()); } } }
wxTreeItemId PHPWorkspaceView::EnsureFolderExists(const wxTreeItemId& projectItem, const wxString& path, const wxString& project) { PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(project); wxASSERT_MSG(pProject, wxString::Format("Could not locate project %s", project)); int imgId = m_mgr->GetStdIcons()->GetMimeImageId(FileExtManager::TypeFolder); wxString curpath; wxTreeItemId parent = projectItem; wxArrayString parts = ::wxStringTokenize(path, "/", wxTOKEN_STRTOK); for(size_t i = 0; i < parts.GetCount(); ++i) { if(!curpath.IsEmpty()) { curpath << "/"; } curpath << parts.Item(i); if(!HasFolderWithName(parent, parts.Item(i), parent)) { ItemData* itemData = new ItemData(ItemData::Kind_Folder); itemData->SetFolderPath(curpath); itemData->SetProjectName(project); itemData->SetFolderName(parts.Item(i)); parent = m_treeCtrlView->AppendItem(parent, parts.Item(i) == "." ? pProject->GetFilename().GetPath() : parts.Item(i), imgId, imgId, itemData); } } m_treeCtrlView->SortChildren(projectItem); return parent; }
void PHPWorkspace::FromJSON(const JSONElement& e) { m_projects.clear(); if(e.hasNamedObject("projects")) { PHPProject::Ptr_t firstProject; JSONElement projects = e.namedObject("projects"); int count = projects.arraySize(); for(int i = 0; i < count; ++i) { PHPProject::Ptr_t p(new PHPProject()); wxString project_file = projects.arrayItem(i).toString(); wxFileName fnProject(project_file); fnProject.MakeAbsolute(m_workspaceFile.GetPath()); p->Load(fnProject); m_projects.insert(std::make_pair(p->GetName(), p)); if(!firstProject) { firstProject = p; } } PHPProject::Ptr_t activeProject = GetActiveProject(); if(!activeProject && firstProject) { // No active project found, mark the first project as active activeProject = firstProject; SetProjectActive(firstProject->GetName()); } if(activeProject) { // Notify about active project been set clProjectSettingsEvent evt(wxEVT_ACTIVE_PROJECT_CHANGED); evt.SetProjectName(activeProject->GetName()); evt.SetFileName(activeProject->GetFilename().GetFullPath()); EventNotifier::Get()->AddPendingEvent(evt); } } }
wxFileName PHPWorkspace::GetProjectFileName(const wxString& projectName) const { PHPProject::Ptr_t p = GetProject(projectName); if(!p) { return wxFileName(); } return p->GetFilename(); }
void PHPWorkspaceView::OnAddFile(wxCommandEvent& e) { wxTreeItemId folderItem = DoGetSingleSelection(); CHECK_ITEM_RET(folderItem); ItemData* data = DoGetItemData(folderItem); CHECK_PTR_RET(data); if(!data->IsFolder()) return; PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(data->GetProjectName()); CHECK_PTR_RET(pProject); PHPFolder::Ptr_t pFolder = pProject->Folder(data->GetFolderPath()); CHECK_PTR_RET(pFolder); wxFileDialog dlg(wxTheApp->GetTopWindow(), _("Add file"), pFolder->GetFullPath(pProject->GetFilename().GetPath()), wxT(""), wxT("PHP Files (*.php)|*.php|PHP include files (*.inc)|*.inc|All files (*)|*"), wxFD_FILE_MUST_EXIST | wxFD_OPEN | wxFD_MULTIPLE); if(dlg.ShowModal() == wxID_OK) { wxArrayString paths; dlg.GetPaths(paths); if(paths.IsEmpty()) return; // if the file is not under the project's tree - do not add it // Use the folder taken from the file's full path and the pFolder as the base folder for adding the file if(!paths.Item(0).StartsWith(pProject->GetFilename().GetPath())) { ::wxMessageBox(_("Can not add file to project. File must be under the project directory tree"), "CodeLite", wxOK | wxCENTER | wxICON_WARNING); return; } DoAddFilesToFolder(paths, pProject, true); pProject->Save(); } }
void PHPWorkspaceView::OnNewFile(wxCommandEvent& e) { wxTreeItemId folderId = DoGetSingleSelection(); ItemData *data = DoGetItemData( folderId ); if( data->IsFolder() ) { PHPProject::Ptr_t pProj = PHPWorkspace::Get()->GetProject(data->GetProjectName()); CHECK_PTR_RET(pProj); PHPFolder::Ptr_t pFolder = pProj->Folder(data->GetFolderPath()); CHECK_PTR_RET(pFolder); NewFileDlg dlg(wxTheApp->GetTopWindow(), pFolder->GetFullPath( pProj->GetFilename().GetPath() ) ); if(dlg.ShowModal() == wxID_OK) { wxFileName filename = dlg.GetPath(); if( filename.FileExists() ) { // A file with this name already exists wxMessageBox(_("A file with same name already exists!"), wxT("CodeLite"), wxOK|wxCENTER|wxICON_WARNING); return; } DoAddFileWithContent(folderId, filename, ""); } } }
void PHPWorkspace::SetProjectActive(const wxString& project) { PHPProject::Map_t::iterator iter = m_projects.begin(); PHPProject::Ptr_t activeProject; for(; iter != m_projects.end(); ++iter) { if(iter->first == project) { activeProject = iter->second; } bool newState = (iter->first == project); if(iter->second->IsActive() != newState) { iter->second->SetIsActive(newState); // Save the change to the file system iter->second->Save(); } } // notify about this change if(activeProject) { clProjectSettingsEvent evt(wxEVT_ACTIVE_PROJECT_CHANGED); evt.SetProjectName(project); evt.SetFileName(activeProject->GetFilename().GetFullPath()); EventNotifier::Get()->AddPendingEvent(evt); } }