void SmartCompletion::OnGotoAnythingSort(clGotoEvent& event) { event.Skip(); if(!m_config.IsEnabled()) return; // Sort the entries by their weight clGotoEntry::Vec_t& entries = event.GetEntries(); WeightTable_t& T = *m_pGTAWeight; // We dont want to mess with the default sorting. We just want to place the ones with weight at the top // so we split the list into 2: entries with weight geater than 0 and 0 std::vector<std::pair<int, clGotoEntry> > importantEntries; clGotoEntry::Vec_t normalEntries; clGotoEntry::Vec_t::iterator iter = entries.begin(); std::for_each(entries.begin(), entries.end(), [&](const clGotoEntry& entry) { if(T.count(entry.GetDesc())) { // This item has weight int weight = T[entry.GetDesc()]; importantEntries.push_back({ weight, entry }); } else { normalEntries.push_back(entry); } }); // the list should now contains all the list *wihtout* weight entries.swap(normalEntries); // Step 2: sort the important entries - the sorting is DESC (lower first) std::sort( importantEntries.begin(), importantEntries.end(), [&](const std::pair<int, clGotoEntry>& a, const std::pair<int, clGotoEntry>& b) { return a.first < b.first; }); // Step 3: prepend the important entries (it actually reverse the sorting) std::for_each(importantEntries.begin(), importantEntries.end(), [&](const std::pair<int, clGotoEntry>& p) { entries.insert(entries.begin(), p.second); }); }
void clGotoAnythingManager::OnActionSelected(clGotoEvent& e) { e.Skip(); // Trigger the action const clGotoEntry& entry = e.GetEntry(); if(entry.GetResourceID() != wxID_ANY) { wxCommandEvent evtAction(wxEVT_MENU, entry.GetResourceID()); if(entry.IsCheckable()) { evtAction.SetInt(entry.IsChecked() ? 0 : 1); // Set the opposite value } EventNotifier::Get()->TopFrame()->GetEventHandler()->AddPendingEvent(evtAction); } }
void SmartCompletion::OnGotoAnythingSelectionMade(clGotoEvent& event) { event.Skip(); if(!m_config.IsEnabled()) return; // Collect info about this match WeightTable_t& T = *m_pGTAWeight; const wxString& key = event.GetEntry().GetDesc(); if(T.count(key) == 0) { T[key] = 1; } else { T[key]++; } m_config.GetUsageDb().StoreGTAUsage(key, T[key]); }