Esempio n. 1
0
void SuggestionsSidebarBlock::UpdateSuggestions(const SuggestionsList& hits)
{
    wxWindowUpdateLocker lock(m_parent);

    m_suggestions.insert(m_suggestions.end(), hits.begin(), hits.end());
    std::stable_sort(m_suggestions.begin(), m_suggestions.end(),
                     [](const Suggestion& a, const Suggestion& b){
                        if (std::fabs(a.score - b.score) <= std::numeric_limits<double>::epsilon())
                            return a.timestamp > b.timestamp;
                        else
                            return a.score > b.score;
                     });

    // create any necessary controls:
    while (m_suggestions.size() > m_suggestionsWidgets.size())
    {
        auto w = new SuggestionWidget(m_parent);
        m_suggestionsSizer->Add(w, wxSizerFlags().Expand());
        m_suggestionsWidgets.push_back(w);
    }
    m_innerSizer->Layout();

    // update shown suggestions:
    bool isRTL = m_parent->GetCurrentLanguage().IsRTL();
    for (size_t i = 0; i < m_suggestions.size(); ++i)
    {
        auto s = m_suggestions[i];
        m_suggestionsWidgets[i]->SetValue((int)i, s, isRTL, GetIconForSuggestion(s), GetTooltipForSuggestion(s));
    }

    m_innerSizer->Layout();
    UpdateVisibility();
    m_parent->Layout();

    UpdateSuggestionsMenu();
}
Esempio n. 2
0
void SuggestionsSidebarBlock::UpdateSuggestions(const SuggestionsList& hits)
{
    wxWindowUpdateLocker lock(m_parent);

    for (auto& h: hits)
    {
        // empty entries screw up menus (treated as stock items), don't use them:
        if (!h.text.empty())
            m_suggestions.push_back(h);
    }

    std::stable_sort(m_suggestions.begin(), m_suggestions.end());

    // create any necessary controls:
    while (m_suggestions.size() > m_suggestionsWidgets.size())
    {
        auto w = new SuggestionWidget(m_parent);
        m_suggestionsSizer->Add(w, wxSizerFlags().Expand());
        m_suggestionsWidgets.push_back(w);
    }
    m_innerSizer->Layout();

    // update shown suggestions:
    bool isRTL = m_parent->GetCurrentLanguage().IsRTL();
    for (size_t i = 0; i < m_suggestions.size(); ++i)
    {
        auto s = m_suggestions[i];
        m_suggestionsWidgets[i]->SetValue((int)i, s, isRTL, GetIconForSuggestion(s), GetTooltipForSuggestion(s));
    }

    m_innerSizer->Layout();
    UpdateVisibility();
    m_parent->Layout();

    UpdateSuggestionsMenu();
}