Exemple #1
0
void SymbolList::ActionList::Find(const wxString& searchtext, bool refresh) {
	m_searchText = searchtext; // cache for later updates

	if (searchtext.empty()) {
		SetAllItems();
		return;
	}

	// Convert to upper case for case insensitive search
	const wxString text = searchtext.Upper();

	m_items.clear();
	vector<unsigned int> hlChars;
	for (unsigned int i = 0; i < m_actions.GetCount(); ++i) {
		const wxString& name = m_actions[i];
		unsigned int charpos = 0;
		wxChar c = text[charpos];
		hlChars.clear();

		for (unsigned int textpos = 0; textpos < name.size(); ++textpos) {
			if ((wxChar)wxToupper(name[textpos]) == c) {
				hlChars.push_back(textpos);
				++charpos;
				if (charpos == text.size()) {
					// All chars found.
					m_items.push_back(aItem(i, &m_actions[i], hlChars));
					break;
				}
				else c = text[charpos];
			}
		}
	}

	sort(m_items.begin(), m_items.end());

	Freeze();
	SetItemCount(m_items.size());
	if (refresh) {
		if (m_items.empty()) SetSelection(-1); // deselect
		else SetSelection(0);

		RefreshAll();
	}
	Thaw();
}
Exemple #2
0
void GotoFileList::AddFileIfMatching(const wxString& text, FileEntry* file_entry) {
	wxASSERT(!text.empty());

	const wxString& name = file_entry->nameLower;

	// The string positions of the characters to highlight. (Note, variable is static!)
	static std::vector<unsigned int> hlChars;
	hlChars.clear();

	unsigned int charpos = 0;
	wxChar c = text[charpos];
	for (unsigned int textpos = 0; textpos < name.size(); ++textpos) {
		if (name[textpos] != c) continue;

		hlChars.push_back(textpos);
		++charpos;
		if (charpos == text.size()) {
			// All chars found.
			m_items.push_back(aItem(file_entry, hlChars));
			break;
		}
		else c = text[charpos];
	}
}