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();
    }
}
void ThreadSearchLoggerTree::OnThreadSearchEvent(const ThreadSearchEvent& event)
{
	// A search event has been sent by the worker thread.
	// Tree log upddate
	const wxArrayString& words  = event.GetLineTextArray();
	const wxFileName&    filename(event.GetString());
	bool                 setFocus(false);
	wxTreeItemId         rootItemId(m_pTreeLog->GetRootItem());
	wxTreeItemId         fileItemId;
	long                 index    = m_IndexManager.GetInsertionIndex(filename.GetFullPath());
	long                 nb_items = m_pTreeLog->GetChildrenCount(rootItemId, false);

	wxASSERT(index != wxNOT_FOUND);
	wxASSERT((words.GetCount() % 2) == 0);

	// Use of Freeze Thaw to enhance speed and limit blink effect
	m_pTreeLog->Freeze();
	wxTreeItemId lineItemId;

	if ( index == nb_items )
	{
		fileItemId = m_pTreeLog->AppendItem(rootItemId,
													 wxString::Format(wxT("%s (%s)"),
																	  filename.GetFullName().c_str(),
																	  filename.GetPath().c_str()));
	}
	else
	{
		fileItemId = m_pTreeLog->InsertItem(rootItemId, index,
											wxString::Format(wxT("%s (%s)"),
															 filename.GetFullName().c_str(),
															 filename.GetPath().c_str()));
	}

	for (size_t i = 0; i < words.GetCount(); i += 2)
	{
		lineItemId = m_pTreeLog->AppendItem(fileItemId, wxString::Format(wxT("%s: %s"),
																		 words[i].c_str(),     // Line index starting from 1
																		 words[i+1].c_str())); // File line matching search expression

        //(pecan 2008/7/31) Dont do the following, else Ctrl-MouseWheel cannot change fonts
		//-m_pTreeLog->SetItemFont(fileItemId, m_ThreadSearchPlugin.m_Conf_font);          //(pecan 2008/3/06)
		//-m_pTreeLog->SetItemFont(lineItemId, m_ThreadSearchPlugin.m_Conf_font);          //(pecan 2008/3/06)

		// We update preview log for first list item
		if ( (m_FirstItemProcessed == false)                        &&
			 (m_pTreeLog->GetChildrenCount(fileItemId, false) == 1) &&
			 (m_pTreeLog->GetChildrenCount(rootItemId, false) == 1) )
		{
			// Expand first file item
			m_pTreeLog->Expand(fileItemId);

			// Select first item (generates selection event to update ThreadSearchView code preview)
			m_pTreeLog->SelectItem(lineItemId);

			// to avoid lots of preview that freezes app
			m_FirstItemProcessed = true;

			// It is useful to give focus to tree to navigate in results
			// just after running a search
			setFocus = true;
		}
	}
	m_pTreeLog->Thaw();

	if ( setFocus == true )
	{
		// On Linux, executing SetFocus just after SelectItem
		// does not work. Probbly because of Thaw...
		m_pTreeLog->SetFocus();
	}
}
Ejemplo n.º 3
0
void ThreadSearchView::OnThreadSearchErrorEvent(const ThreadSearchEvent& event)
{
    Manager::Get()->GetLogManager()->Log(F(_T("ThreadSearch: %s"), event.GetString().wx_str()));
    InfoWindow::Display(_("Thread Search Error"), event.GetString());
}