void CCDebugInfo::OnGoParentClick(wxCommandEvent& /*event*/)
{
    if (!m_Token || m_Token->m_ParentIndex == -1)
        return;

    m_Token = m_Parser->GetTokensTree()->at(m_Token->m_ParentIndex);
    DisplayTokenInfo();
}
void CCDebugInfo::OnFindClick(wxCommandEvent& /*event*/)
{
    TokensTree* tokens = m_Parser->GetTokensTree();
    wxString search = txtFilter->GetValue();

    m_Token = 0;

    // first determine if the user entered an ID or a search mask
    long unsigned id;
    if (search.ToULong(&id, 10))
    {
        // easy; ID
        m_Token = tokens->at(id);
    }
    else
    {
        // find all matching tokens
        TokenIdxSet result;
        for (size_t i = 0; i < tokens->size(); ++i)
        {
            Token* token = tokens->at(i);
            if (token && token->m_Name.Matches(search))
                result.insert(i);
        }

        // a single result?
        if (result.size() == 1)
        {
            m_Token = tokens->at(*(result.begin()));
        }
        else
        {
            // fill a list and ask the user which token to display
            wxArrayString arr;
            wxArrayInt intarr;
            for (TokenIdxSet::iterator it = result.begin(); it != result.end(); ++it)
            {
                Token* token = tokens->at(*it);
                arr.Add(token->DisplayName());
                intarr.Add(*it);
            }
            int sel = wxGetSingleChoiceIndex(_("Please make a selection:"), _("Multiple matches"), arr, this);
            if (sel == -1)
                return;

            m_Token = tokens->at(intarr[sel]);
        }
    }

    DisplayTokenInfo();
}
void CCDebugInfo::OnInit(wxInitDialogEvent& /*event*/)
{
    if (!m_Parser)
        return;

    lblInfo->SetLabel(wxString::Format(_("The parser contains %d tokens, found in %d files"),
                                       m_Parser->GetTokensTree()->size(),
                                       m_Parser->GetTokensTree()->m_FilesMap.size()));

    DisplayTokenInfo();
    FillFiles();
    FillDirs();

    txtFilter->SetFocus();
}
void CCDebugInfo::OnInit(cb_unused wxInitDialogEvent& event)
{
    if (!m_Parser || !m_Parser->GetTokenTree())
        return;

    txtInfo->SetLabel(wxString::Format(_("The parser contains %lu tokens, found in %lu files"),
                                       static_cast<unsigned long>(m_Parser->GetTokenTree()->size()),
                                       static_cast<unsigned long>(m_Parser->GetTokenTree()->m_FileMap.size())));

    DisplayTokenInfo();
    FillFiles();
    FillDirs();

    txtFilter->SetFocus();
}
void CCDebugInfo::OnGoChildrenClick(wxCommandEvent& /*event*/)
{
    int idx = cmbChildren->GetSelection();
    if (!m_Token || idx == -1)
        return;

    int count = 0;
    for (TokenIdxSet::iterator it = m_Token->m_Children.begin(); it != m_Token->m_Children.end(); ++it)
    {
        if (count == idx)
        {
            m_Token = m_Parser->GetTokensTree()->at(*it);
            DisplayTokenInfo();
            break;
        }
        ++count;
    }
}
void CCDebugInfo::OnGoDescClick(cb_unused wxCommandEvent& event)
{
    int idx = cmbDescendants->GetSelection();
    if (!m_Token || idx == -1)
        return;

    int count = 0;
    for (TokenIdxSet::const_iterator it = m_Token->m_Descendants.begin(); it != m_Token->m_Descendants.end(); ++it)
    {
        if (count == idx)
        {
            m_Token = m_Parser->GetTokenTree()->at(*it);
            DisplayTokenInfo();
            break;
        }
        ++count;
    }
}