void *ThreadSearchThread::Entry() { // Tests if we have a working searcher object. // Cancel search if it is not the case if ( m_pTextFileSearcher == NULL ) return 0; size_t i = 0; // For now, we look for all paths for the different search scopes // and store them in a sorted array to avoid pasing several times // the same file. // This will be changed to avoid consuming a lot of memory (parsing // form C:\ and storing all paths...). Aim is to avoid the use of the // array for storing items. // Search in directory files ? if ( m_FindData.MustSearchInDirectory() == true ) { int flags = wxDIR_FILES | wxDIR_DIRS | wxDIR_DOTDOT; flags |= m_FindData.GetHiddenSearch() ? wxDIR_HIDDEN : 0; const wxString &path = m_FindData.GetSearchPath(true); if (!wxDir::Exists(path)) { ThreadSearchEvent event(wxEVT_THREAD_SEARCH_ERROR, -1); event.SetString(_("Cannot open folder ") + path); // Using wxPostEvent, we avoid multi-threaded memory violation. wxPostEvent(m_pThreadSearchView,event); return 0; } else { wxDir Dir(path); Dir.Traverse(*(static_cast<wxDirTraverser*>(this)), wxEmptyString, flags); } // Tests thread stop (cancel search, app shutdown) if ( TestDestroy() == true ) return 0; } // Search in workspace files ? if ( m_FindData.MustSearchInWorkspace() == true ) { ProjectsArray* pProjectsArray = Manager::Get()->GetProjectManager()->GetProjects(); for ( size_t j=0; j < pProjectsArray->GetCount(); ++j ) { AddProjectFiles(m_FilePaths, *pProjectsArray->Item(j)); if ( TestDestroy() == true ) return 0; } } else if ( m_FindData.MustSearchInProject() == true ) { // Search in project files ? // Necessary only if not already parsed in worspace part cbProject* pProject = Manager::Get()->GetProjectManager()->GetActiveProject(); if ( pProject != NULL ) { AddProjectFiles(m_FilePaths, *pProject); if ( TestDestroy() == true ) return 0; } } else if ( m_FindData.MustSearchInTarget() == true ) { // Search in target files ? // Necessary only if not already parsed in project part cbProject* pProject = Manager::Get()->GetProjectManager()->GetActiveProject(); if ( pProject != NULL ) { ProjectBuildTarget *pTarget = pProject->GetBuildTarget(pProject->GetActiveBuildTarget()); if ( pTarget != 0 ) { AddTargetFiles(m_FilePaths, *pTarget); if ( TestDestroy() == true ) return 0; } } } // Tests thread stop (cancel search, app shutdown) if ( TestDestroy() == true ) return 0; // Open files if ( m_FindData.MustSearchInOpenFiles() == true ) { EditorManager* pEdManager = Manager::Get()->GetEditorManager(); for (i = 0; i < (size_t)pEdManager->GetNotebook()->GetPageCount(); ++i) { cbEditor* pEditor = pEdManager->GetBuiltinEditor(i); if ( pEditor != NULL ) { AddNewItem(m_FilePaths, pEditor->GetFilename(), m_Masks); } } } // Tests thread stop (cancel search, app shutdown) if ( TestDestroy() == true ) return 0; // if the list is empty, leave if (m_FilePaths.GetCount() == 0) { //-cbMessageBox(wxT("No files to search in!"), wxT("Error"), wxICON_WARNING); ////(pecan 2008/4/26) // DO NOT issue graphics calls from this thread !!!!!! ThreadSearchEvent event(wxEVT_THREAD_SEARCH_ERROR, -1); event.SetString(_("No files to search.\nCheck options ")); // Using wxPostEvent, we avoid multi-threaded memory violation. wxPostEvent(m_pThreadSearchView,event); return 0; } for ( i = 0; i < m_FilePaths.GetCount(); ++i ) { FindInFile(m_FilePaths[i]); // Tests thread stop (cancel search, app shutdown) if ( TestDestroy() == true ) return 0; } return 0; }