void ThreadSearchLoggerList::OnThreadSearchEvent(const ThreadSearchEvent& event) { // A search event has been sent by the worker thread. // List log upddate const wxArrayString& words = event.GetLineTextArray(); const wxFileName& filename(event.GetString()); bool setFocus(false); m_TotalLinesFound += event.GetNumberOfMatches(); wxASSERT((words.GetCount() % 2) == 0); // Use of Freeze Thaw to enhance speed and limit blink effect m_pListLog->Freeze(); long index = m_IndexManager.GetInsertionIndex(filename.GetFullPath(), words.GetCount()/2); index += m_IndexOffset; for (size_t i = 0; i + 1 < words.GetCount(); i += 2) { m_pListLog->InsertItem(index, filename.GetPath()); // Directory m_pListLog->SetItem(index, 1, filename.GetFullName()); // File name m_pListLog->SetItem(index, 2, words[i]); // Line index starting from 1 m_pListLog->SetItem(index, 3, words[i+1]); // File line matching search expression m_pListLog->SetItemData(index, 0); // We update preview log for first list item if ( m_pListLog->GetItemCount() == 1 ) { // Gets line index long line = 0; if ( words[i].ToLong(&line) == false ) { cbMessageBox(_("Failed to convert line number from %s") + words[i], _("Error"), wxICON_ERROR); } else { m_ThreadSearchView.UpdatePreview(filename.GetFullPath(), line); // It is useful to give focus to list to navigate in results // just after running a search setFocus = true; } } index++; } size_t count = m_pListLog->GetItemCount(); size_t countPerPage = std::max<size_t>(m_pListLog->GetCountPerPage() - 1, 0); if (count > countPerPage && m_IndexOffset > 0) { size_t markerLine = m_IndexOffset - 1; if (m_TotalLinesFound <= countPerPage) { m_pListLog->EnsureVisible(markerLine + m_TotalLinesFound); } else if (m_TotalLinesFound > countPerPage && !m_MadeVisible) { m_pListLog->EnsureVisible(markerLine + countPerPage); if (static_cast<size_t>(m_pListLog->GetTopItem()) != markerLine) m_pListLog->EnsureVisible(markerLine); m_MadeVisible = true; } } m_pListLog->Thaw(); if ( setFocus == true ) { // On Linux, executing SetFocus just after UpdatePreview(0) // does not work. Probbly because of Thaw... m_pListLog->SetFocus(); } }