//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ ProjectService::pProject_type ProjectService::createProject(Zen::Studio::Workbench::I_ProjectExplorerController& _controller, const std::string& _projectName) { pProject_type pProject( new Project(_controller, _projectName), boost::bind(destroyProject, _1) ); // TODO If there's any additional data associated with the Project, // it needs to be saved in the TerrainBuilderProject table here. return pProject; }
void PHPWorkspaceView::OnEditorChanged(wxCommandEvent& e) { e.Skip(); IEditor* editor = reinterpret_cast<IEditor*>(e.GetClientData()); wxUnusedVar(editor); CHECK_PTR_RET(editor); wxFileName filename = editor->GetFileName(); // FIXME : Load all breakpoints for this file and apply them to the UI // Locate the editor for this file PHPProject::Ptr_t pProject(NULL); const PHPProject::Map_t& projects = PHPWorkspace::Get()->GetProjects(); PHPProject::Map_t::const_iterator iter = projects.begin(); for(; iter != projects.end(); ++iter) { if(filename.GetPath().StartsWith(iter->second->GetFilename().GetPath())) { // found our project pProject = iter->second; break; } } CHECK_PTR_RET(pProject); PHPFolder::Ptr_t pFolder = pProject->FolderByFileFullPath(filename.GetFullPath()); CHECK_PTR_RET(pFolder); wxTreeItemId projectItem = DoGetProjectItem(pProject->GetName()); CHECK_ITEM_RET(projectItem); wxTreeItemId folderItem = DoGetFolderItem(projectItem, pFolder); CHECK_ITEM_RET(folderItem); wxTreeItemId fileItem = DoGetFileItem(folderItem, filename.GetFullPath()); CHECK_ITEM_RET(fileItem); m_treeCtrlView->SelectItem(fileItem); m_treeCtrlView->EnsureVisible(fileItem); }
intrusive_ptr<DocumentSource> DocumentSourceProject::createFromBson( BSONElement elem, const intrusive_ptr<ExpressionContext> &pExpCtx) { /* validate */ uassert(15969, str::stream() << projectName << " specification must be an object", elem.type() == Object); Expression::ObjectCtx objectCtx( Expression::ObjectCtx::DOCUMENT_OK | Expression::ObjectCtx::TOP_LEVEL | Expression::ObjectCtx::INCLUSION_OK ); VariablesIdGenerator idGenerator; VariablesParseState vps(&idGenerator); intrusive_ptr<Expression> parsed = Expression::parseObject(elem.Obj(), &objectCtx, vps); ExpressionObject* exprObj = dynamic_cast<ExpressionObject*>(parsed.get()); massert(16402, "parseObject() returned wrong type of Expression", exprObj); uassert(16403, "$projection requires at least one output field", exprObj->getFieldCount()); intrusive_ptr<DocumentSourceProject> pProject(new DocumentSourceProject(pExpCtx, exprObj)); pProject->_variables.reset(new Variables(idGenerator.getIdCount())); BSONObj projectObj = elem.Obj(); pProject->_raw = projectObj.getOwned(); #if defined(_DEBUG) if (exprObj->isSimple()) { DepsTracker deps; vector<string> path; exprObj->addDependencies(&deps, &path); pProject->_simpleProjection.init(deps.toProjection()); } #endif return pProject; }
intrusive_ptr<DocumentSource> DocumentSourceProject::createFromBson( BSONElement *pBsonElement, const intrusive_ptr<ExpressionContext> &pExpCtx) { /* validate */ uassert(15969, str::stream() << projectName << " specification must be an object", pBsonElement->type() == Object); intrusive_ptr<DocumentSourceProject> pProject(new DocumentSourceProject(pExpCtx)); BSONObj projectObj(pBsonElement->Obj()); pProject->_raw = projectObj.getOwned(); // probably not necessary, but better to be safe Expression::ObjectCtx objectCtx( Expression::ObjectCtx::DOCUMENT_OK | Expression::ObjectCtx::TOP_LEVEL | Expression::ObjectCtx::INCLUSION_OK ); intrusive_ptr<Expression> parsed = Expression::parseObject(pBsonElement, &objectCtx); ExpressionObject* exprObj = dynamic_cast<ExpressionObject*>(parsed.get()); massert(16402, "parseObject() returned wrong type of Expression", exprObj); uassert(16403, "$projection requires at least one output field", exprObj->getFieldCount()); pProject->pEO = exprObj; #if defined(_DEBUG) if (exprObj->isSimple()) { set<string> deps; vector<string> path; exprObj->addDependencies(deps, &path); pProject->_simpleProjection.init(depsToProjection(deps)); } #endif return pProject; }
intrusive_ptr<DocumentSource> DocumentSourceProject::createFromBson( BSONElement *pBsonElement, const intrusive_ptr<ExpressionContext> &pExpCtx) { /* validate */ uassert(15969, str::stream() << projectName << " specification must be an object", pBsonElement->type() == Object); /* chain the projection onto the original source */ intrusive_ptr<DocumentSourceProject> pProject( DocumentSourceProject::create(pExpCtx)); /* Pull out the $project object. This should just be a list of field inclusion or exclusion specifications. Note you can't do both, except for the case of _id. */ BSONObj projectObj(pBsonElement->Obj()); BSONObjIterator fieldIterator(projectObj); Expression::ObjectCtx objectCtx( Expression::ObjectCtx::DOCUMENT_OK); while(fieldIterator.more()) { BSONElement outFieldElement(fieldIterator.next()); string outFieldPath(outFieldElement.fieldName()); string inFieldName(outFieldPath); BSONType specType = outFieldElement.type(); int fieldInclusion = -1; switch(specType) { case NumberDouble: { double inclusion = outFieldElement.numberDouble(); fieldInclusion = static_cast<int>(inclusion); goto IncludeExclude; } case NumberLong: { long long inclusion = outFieldElement.numberLong(); fieldInclusion = static_cast<int>(inclusion); goto IncludeExclude; } case NumberInt: /* just a plain integer include/exclude specification */ fieldInclusion = outFieldElement.numberInt(); IncludeExclude: uassert(15970, str::stream() << "field inclusion or exclusion specification for \"" << outFieldPath << "\" must be true, 1, false, or zero", ((fieldInclusion == 0) || (fieldInclusion == 1))); if (fieldInclusion == 0) pProject->excludePath(outFieldPath); else pProject->includePath(outFieldPath); break; case Bool: /* just a plain boolean include/exclude specification */ fieldInclusion = (outFieldElement.Bool() ? 1 : 0); goto IncludeExclude; case String: /* include a field, with rename */ fieldInclusion = 1; inFieldName = outFieldElement.String(); pProject->addField( outFieldPath, ExpressionFieldPath::create( Expression::removeFieldPrefix(inFieldName))); break; case Object: { intrusive_ptr<Expression> pDocument( Expression::parseObject(&outFieldElement, &objectCtx)); /* add The document expression to the projection */ pProject->addField(outFieldPath, pDocument); break; } default: uassert(15971, str::stream() << "invalid BSON type (" << specType << ") for " << projectName << " field " << outFieldPath, false); } } return pProject; }
intrusive_ptr<DocumentSource> DocumentSourceProject::createFromBson( BSONElement *pBsonElement, const intrusive_ptr<ExpressionContext> &pCtx) { /* validate */ assert(pBsonElement->type() == Object); // CW TODO user error /* chain the projection onto the original source */ intrusive_ptr<DocumentSourceProject> pProject( DocumentSourceProject::create()); /* Pull out the $project object. This should just be a list of field inclusion or exclusion specifications. Note you can't do both, except for the case of _id. */ BSONObj projectObj(pBsonElement->Obj()); BSONObjIterator fieldIterator(projectObj); Expression::ObjectCtx objectCtx( Expression::ObjectCtx::DOCUMENT_OK); while(fieldIterator.more()) { BSONElement outFieldElement(fieldIterator.next()); string outFieldPath(outFieldElement.fieldName()); string inFieldName(outFieldPath); BSONType specType = outFieldElement.type(); int fieldInclusion = -1; switch(specType) { case NumberDouble: { double inclusion = outFieldElement.numberDouble(); if ((inclusion == 0) || (inclusion == 1)) fieldInclusion = (int)inclusion; else { assert(false); // CW TODO unimplemented constant expression } goto IncludeExclude; } case NumberInt: /* just a plain integer include/exclude specification */ fieldInclusion = outFieldElement.numberInt(); assert((fieldInclusion >= 0) && (fieldInclusion <= 1)); // CW TODO invalid field projection specification IncludeExclude: if (fieldInclusion == 0) pProject->excludePath(outFieldPath); else pProject->includePath(outFieldPath); break; case Bool: /* just a plain boolean include/exclude specification */ fieldInclusion = outFieldElement.Bool() ? 1 : 0; goto IncludeExclude; case String: /* include a field, with rename */ fieldInclusion = 1; inFieldName = outFieldElement.String(); pProject->addField( outFieldPath, ExpressionFieldPath::create( Expression::removeFieldPrefix(inFieldName))); break; case Object: { intrusive_ptr<Expression> pDocument( Expression::parseObject(&outFieldElement, &objectCtx)); /* add The document expression to the projection */ pProject->addField(outFieldPath, pDocument); break; } default: assert(false); // CW TODO invalid field projection specification } } return pProject; }
// Refresh the projects list. bool WorkspaceInfo::Refresh(void) { // If the internal project integrity is good, then no refresh is needed. if (CheckIntegrity()) return true; // Delete everything. RemoveAll(); // First, get a pointer to the dispatch for the Projects collection CComPtr<IDispatch> pDispProjects; VERIFY_OK(m_pApplication->get_Projects(&pDispProjects)); CComQIPtr<IProjects, &IID_IProjects> pProjects(pDispProjects); // Get the number of projects in the collection long projectCount; VERIFY_OK(pProjects->get_Count(&projectCount)); // Iterate all the projects. for (long i = 1; i < projectCount + 1; i++) { CComVariant Vari = i; // Get the next project CComPtr<IGenericProject> pGenProject; VERIFY_OK(pProjects->Item(Vari, &pGenProject)); CComQIPtr<IGenericProject, &IID_IGenericProject> pProject(pGenProject); // Get the project name. CComBSTR bszStr; VERIFY_OK(pProject->get_FullName(&bszStr)); CString projectName = bszStr; Add(projectName); } // Rename a misnamed add-on file. CString oldFilename = m_workspaceLocation + "ExtraFiles.PFO"; CString wuFilename = GetExtraFilename(); rename(oldFilename, wuFilename); // Is there an add-on file? CStdioFile file; if (file.Open(wuFilename, CFile::modeRead) == TRUE) { CString line; // Count the number of extra projects. while (1) { // Read in a project name. if (!file.ReadString(line)) break; // Check the integrity. Add(line); } // Close the file. file.Close(); } // Build the file array. m_fileList.Sort(); // Rebuilt stuff. return false; }
// CheckIntegrity() returns false if the internally stored projects // don't match the Visual Studio projects. bool WorkspaceInfo::CheckIntegrity(void) { // If there are no projects to compare against, then fail the integrity check. if (m_projects.GetCount() == 0) { // AfxMessageBox("Refresh: No projects."); return false; } // Is there an add-on file? int numAddOnProjects = 0; CStdioFile file; if (file.Open(GetExtraFilename(), CFile::modeRead) == TRUE) { CString line; // Count the number of extra projects. while (1) { // Read in a project name. if (!file.ReadString(line)) break; // Check the integrity. if (!CheckProjectIntegrity(line)) return false; // Increment the number of add-on projects. numAddOnProjects++; } // Close the file. file.Close(); } // Now run all projects with workspace parents (which means they were added // indirectly through a .dsw file). POSITION pos = m_projects.GetHeadPosition(); while (pos != NULL) { // Get the project. Project& prj = m_projects.GetNext(pos); // Does it have a parent? if (prj.m_parent) { // Yes, so it is a project added indirectly from a .dsw file. if (!CheckProjectIntegrity(prj.GetName())) return false; // Add it to the number of add-on projects. numAddOnProjects++; } } // First, get a pointer to the dispatch for the Projects collection CComPtr<IDispatch> pDispProjects; VERIFY_OK(m_pApplication->get_Projects(&pDispProjects)); CComQIPtr<IProjects, &IID_IProjects> pProjects(pDispProjects); // Get the number of projects in the collection long workspaceProjectCount; VERIFY_OK(pProjects->get_Count(&workspaceProjectCount)); // If the number of projects reported by Visual Studio is not the same // number as our local project list, then refresh everything. if (workspaceProjectCount + numAddOnProjects != m_projects.GetCount()) { // AfxMessageBox("Refresh: Project counts differ."); return false; } // Check for non-matching project names. for (long i = 1; i < workspaceProjectCount + 1; i++) { CComVariant Vari = i; // Get the next project CComPtr<IGenericProject> pGenProject; VERIFY_OK(pProjects->Item(Vari, &pGenProject)); CComQIPtr<IGenericProject, &IID_IGenericProject> pProject(pGenProject); CComBSTR bszStr; VERIFY_OK(pProject->get_FullName(&bszStr)); CString projectName = bszStr; // Check the project integrity. if (!CheckProjectIntegrity(projectName)) return false; } // end for [1..workspaceProjectCount] return true; }