void PHPWorkspace::CreateProject(const PHPProject::CreateData& createData) { wxString projectName; wxFileName fnProjectFileName(createData.path, ""); projectName << createData.name << ".phprj"; fnProjectFileName.SetFullName(projectName); if(HasProject(projectName)) return; // Ensure that the path to the file exists fnProjectFileName.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); // Create an empty project and initialize it with the global settings PHPProject::Ptr_t proj(new PHPProject()); // Setup the file path + name proj->Create(fnProjectFileName, createData.name); proj->GetSettings().MergeWithGlobalSettings(); if(!createData.phpExe.IsEmpty() && wxFileName::Exists(createData.phpExe)) { proj->GetSettings().SetPhpExe(createData.phpExe); } proj->GetSettings().SetRunAs(createData.projectType); proj->GetSettings().SetCcIncludePath(createData.ccPaths); m_projects.insert(std::make_pair(proj->GetName(), proj)); if(m_projects.size() == 1) { SetProjectActive(proj->GetName()); } Save(); proj->Save(); // Retag the workspace (there could be new files that were added to the workspace) ParseWorkspace(false); }
bool Parser::ParseWorkspace(const filesystem::path& filePath) { if (filePath.str().empty()) { std::cout << "invalid workspace filename" << std::endl; return false; } WorkingDirectory::SetCurrent(filePath.make_absolute().parent_path().str()); std::cout << "{ cwd : " << WorkingDirectory::GetCurrent() << " }" << std::endl; internal::EnsureDirectoryExists(outputDirectory_); auto workspace = JsonImporter::ImportWorkspace(pimpl_->GetFileManager(), filePath.filename()); return ParseWorkspace(workspace.get()); }
bool PHPWorkspace::AddProject(const wxFileName& projectFile, wxString& errmsg) { if(!CanCreateProjectAtPath(projectFile, true)) { return false; } PHPProject::Ptr_t proj(new PHPProject()); proj->Load(projectFile); if(proj->IsOk()) { if(HasProject(proj->GetName())) { errmsg = _("A project with similar name already exists in the workspace"); return false; } // Keep the active project name _before_ we add the new project wxString activeProjectName = GetActiveProjectName(); proj->GetSettings().MergeWithGlobalSettings(); m_projects.insert(std::make_pair(proj->GetName(), proj)); if(m_projects.size() == 1) { // if we have a single project in the workspace, make it the active SetProjectActive(proj->GetName()); } else { // Restore the active project name. This also removes the "Active project" flag (if any) // from the newly added project SetProjectActive(activeProjectName); } Save(); proj->Save(); // Retag the workspace (there could be new files that were added to the workspace) ParseWorkspace(false); return true; } return false; }
bool PHPWorkspace::Open(const wxString& filename, wxEvtHandler* view, bool createIfMissing) { // Close the currently opened workspace if(IsOpen()) { Close(true, true); } m_workspaceFile = filename; wxFileName fnNewWspFile = m_workspaceFile; fnNewWspFile.SetExt("workspace"); if(!fnNewWspFile.Exists()) { wxLogNull nolog; if(::wxCopyFile(m_workspaceFile.GetFullPath(), fnNewWspFile.GetFullPath())) { m_workspaceFile = fnNewWspFile; } } // Ensure that the workspace file is renamed to .workspace { // Create the private folder if needed wxFileName fn(m_workspaceFile); fn.AppendDir(".codelite"); wxLogNull nolog; ::wxMkdir(fn.GetPath()); } if(!m_workspaceFile.FileExists()) { if(createIfMissing) { if(!Create(filename)) { return false; } } else { m_workspaceFile.Clear(); return false; } } // point the tags storage to the correct db file wxFileName tagsfile(filename); tagsfile.SetExt(wxT("phptags")); // set the working directory to the workspace path ::wxSetWorkingDirectory(m_workspaceFile.GetPath()); JSONRoot root(m_workspaceFile); FromJSON(root.toElement()); // We open the symbols database manually here and _not_ via an event // since the parser thread might open it first and leave us with a lock PHPCodeCompletion::Instance()->Open(m_workspaceFile); // Notify internally that the workspace is loaded PHPEvent phpEvent(wxEVT_PHP_WORKSPACE_LOADED); phpEvent.SetFileName(m_workspaceFile.GetFullPath()); EventNotifier::Get()->AddPendingEvent(phpEvent); // Notify that the a new workspace is loaded // This time send the standard codelite event // this is important so other plugins such as Svn, Git // want to adjust their paths according to the new workspace { wxCommandEvent event(wxEVT_WORKSPACE_LOADED); event.SetString(GetFilename().GetFullPath()); EventNotifier::Get()->AddPendingEvent(event); } // wxBusyInfo busy(_("Scanning for workspace files..."), EventNotifier::Get()->TopFrame()); // wxYieldIfNeeded(); wxBusyCursor bc; SyncWithFileSystemAsync(view); // Perform a quick re-parse of the workspace ParseWorkspace(false); // set this workspace as the active one clWorkspaceManager::Get().SetWorkspace(this); // and finally, request codelite to keep this workspace in the recently opened workspace list clGetManager()->AddWorkspaceToRecentlyUsedList(GetFilename()); CallAfter(&PHPWorkspace::RestoreWorkspaceSession); // Change the workspace extension return true; }