ResourceVector_t OpenResourceDlg::DoGetFiles(const wxString& filter) { ResourceVector_t resources; // filter non matched entries wxString lcFilter = filter; lcFilter.MakeLower(); for(size_t i = 0; i < m_allFiles.size(); i++) { wxString filename = m_allFiles.at(i).filename.GetFullPath().Lower(); if(FileUtils::FuzzyMatch(filter, filename)) { resources.push_back(m_allFiles.at(i)); // Don't return too many matches... if(resources.size() == 300) break; } } return resources; }
void OpenResourceDlg::OnTimer(wxTimerEvent& event) { event.Skip(); wxString currentFilter = m_textCtrlFilter->GetValue(); if(currentFilter != m_lastFilter) { m_lastFilter = currentFilter; m_dvListCtrl->DeleteAllItems(); if(m_lastFilter.IsEmpty()) { m_timer->Start(500, true); return; } ResourceVector_t filesVec; ResourceVector_t allVec; // Refresh the list filesVec = DoGetFiles(m_lastFilter); DoGetResources(m_lastFilter); allVec.insert(allVec.end(), filesVec.begin(), filesVec.end()); allVec.insert(allVec.end(), m_resources.begin(), m_resources.end()); DoPopulateListCtrl(allVec); } m_timer->Start(500, true); }
ResourceVector_t OpenResourceDlg::DoGetFiles(const wxString& filter) { ResourceVector_t resources; // filter non matched entries wxString lcFilter = filter; lcFilter.MakeLower(); for(size_t i=0; i<m_allFiles.size(); i++) { wxString displayName = m_allFiles.at(i).displayName; displayName.MakeLower(); if(displayName.Contains(lcFilter)) { resources.push_back(m_allFiles.at(i)); // Don't return too many matches... if(resources.size() == 150) break; } } return resources; }
void OpenResourceDlg::DoPopulateListCtrl(const ResourceVector_t& items) { wxDataViewItem selection; for(size_t i = 0; i < items.size(); ++i) { wxVector<wxVariant> cols; cols.push_back(::MakeIconText(items.at(i).displayName, DoGetImgIdx(&items.at(i)))); cols.push_back(items.at(i).TypeAsString()); cols.push_back(items.at(i).filename.GetFullPath()); m_dvListCtrl->AppendItem(cols, (wxUIntPtr)(new ResourceItem(items.at(i)))); if(!selection.IsOk()) { selection = m_dvListCtrl->RowToItem(0); } } if(selection.IsOk()) { m_dvListCtrl->Select(selection); m_dvListCtrl->EnsureVisible(selection); } }
void OpenResourceDlg::OnTimer(wxTimerEvent& event) { event.Skip(); wxString currentFilter = m_textCtrlFilter->GetValue(); if(currentFilter != m_lastFilter) { m_lastFilter = currentFilter; m_dvListCtrl->DeleteAllItems(); if(m_lastFilter.IsEmpty()) { m_timer->Start(50, true); return; } ResourceVector_t filesVec; ResourceVector_t allVec; // Refresh the list filesVec = DoGetFiles(m_lastFilter); DoGetResources(m_lastFilter); allVec.insert(allVec.end(), filesVec.begin(), filesVec.end()); allVec.insert(allVec.end(), m_resources.begin(), m_resources.end()); // and sort the results wxString lcFilter = m_lastFilter.Lower(); ResourceVector_t v1, v2, v3, v4, v5; std::for_each(allVec.begin(), allVec.end(), [&](const ResourceItem& a) { if(a.displayName == m_lastFilter) { v1.push_back(a); // Exact match } else if(a.displayName.Lower() == lcFilter) { v2.push_back(a); // case insenstive exact match } else if(a.displayName.StartsWith(m_lastFilter)) { v3.push_back(a); // starts with } else if(a.displayName.Lower().StartsWith(lcFilter)) { v4.push_back(a); // case insenstive starts with } else { // other v5.push_back(a); } }); allVec.clear(); allVec.insert(allVec.end(), v1.begin(), v1.end()); allVec.insert(allVec.end(), v2.begin(), v2.end()); allVec.insert(allVec.end(), v3.begin(), v3.end()); allVec.insert(allVec.end(), v4.begin(), v4.end()); allVec.insert(allVec.end(), v5.begin(), v5.end()); DoPopulateListCtrl(allVec); } m_timer->Start(50, true); }