void SuggestionsSidebarBlock::UpdateSuggestionsMenu() { ClearSuggestionsMenu(); bool isRTL = m_parent->GetCurrentLanguage().IsRTL(); wxString formatMask; if (isRTL) formatMask = L"\u202b%s\u202c\tCtrl+%d"; else formatMask = L"\u202a%s\u202c\tCtrl+%d"; int index = 0; for (auto s: m_suggestions) { if (index >= SUGGESTIONS_MENU_ENTRIES) break; auto text = wxString::Format(formatMask, s.text, index+1); auto item = m_suggestionMenuItems[index]; m_suggestionsMenu->Append(item); item->SetItemLabel(text); item->SetBitmap(GetIconForSuggestion(s)); index++; } }
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: auto lang = m_parent->GetCurrentLanguage(); bool isRTL = lang.IsRTL(); for (size_t i = 0; i < m_suggestions.size(); ++i) { auto s = m_suggestions[i]; m_suggestionsWidgets[i]->SetValue((int)i, s, lang, isRTL, GetIconForSuggestion(s), GetTooltipForSuggestion(s)); } m_innerSizer->Layout(); UpdateVisibility(); m_parent->Layout(); UpdateSuggestionsMenu(); }
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(); }