Exemplo n.º 1
0
	void SetFilter(wxString const& new_filter) {
		std::set<HotkeyModelCombo*> old_visible;
		for (auto item : visible_items)
			old_visible.insert(static_cast<HotkeyModelCombo*>(item.GetID()));

		visible_items.clear();

		wxDataViewItemArray added;
		wxDataViewItemArray removed;

		for (auto& combo : children) {
			bool was_visible = old_visible.count(&combo) > 0;
			bool is_visible = combo.IsVisible(new_filter);

			if (is_visible)
				visible_items.push_back(wxDataViewItem(&combo));
			if (was_visible && !is_visible)
				removed.push_back(wxDataViewItem(&combo));
			if (is_visible && !was_visible)
				added.push_back(wxDataViewItem(&combo));
		}

		if (!added.empty())
			model->ItemsAdded(wxDataViewItem(this), added);
		if (!removed.empty())
			model->ItemsDeleted(wxDataViewItem(this), removed);
	}
	void SetFilter(wxRegEx const& new_filter) {
		std::set<HotkeyModelCombo*> old_visible;
		for (size_t i = 0; i < visible_items.size(); ++i)
			old_visible.insert(static_cast<HotkeyModelCombo*>(visible_items[i].GetID()));

		visible_items.clear();

		wxDataViewItemArray added;
		wxDataViewItemArray removed;

		for (std::list<HotkeyModelCombo>::iterator it = children.begin(); it != children.end(); ++it) {
			bool was_visible = old_visible.count(&*it) > 0;
			bool is_visible = it->IsVisible(new_filter);

			if (is_visible)
				visible_items.push_back(wxDataViewItem(&*it));
			if (was_visible && !is_visible)
				removed.push_back(wxDataViewItem(&*it));
			if (is_visible && !was_visible)
				added.push_back(wxDataViewItem(&*it));
		}

		if (!added.empty())
			model->ItemsAdded(wxDataViewItem(this), added);
		if (!removed.empty())
			model->ItemsDeleted(wxDataViewItem(this), removed);
	}