FS#2593 - [Patch] Filtering for GUILists

Attached to Project: OpenTTD
Opened by Manuel Wolf (Roujin) - Sunday, 01 February 2009, 01:40 GMT
Last edited by Remko Bijker (Rubidium) - Friday, 06 February 2009, 12:00 GMT
Type Patch
Category Interface
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


This patch adds Filtering functions to the GUIList class.

You can specify different callback functions that are used to decide if an item would be filtered out or not, much like the sort functions work. The pointer to those functions is given to the GUIList with SetFilterFuncs(..) similar to SetSortFuncs(..). If no Filter functions are specified and/or filtering is disabled with e.g. "SetFilterStatus(false)", nothing will be filtered.

To filter the GUIList, you have to manually call Filter(const char *filter_string), where filter_string is an optional string you can pass through to the callback function(s) to decide on an item. It is advised to call this right after (re)building the list, before sorting.

If an item is filtered out, it is currently just erased from the list, so to get back filtered out items (if e.g. the filtering conditions have changed), you need to rebuild the list.

Attached are two files, the first one (GUIList_filtering_base.diff) contains only the changes to the GUIList class to allow for filtering.
The second one (GUIList_filtering_content.diff) is an example application of the filtering in the online content window. It allows entering a keyword that the list is compared with and only items containing this keyword are displayed.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Friday, 06 February 2009, 12:00 GMT
Reason for closing:  Implemented
Comment by Manuel Wolf (Roujin) - Sunday, 01 February 2009, 01:45 GMT
Uhm, some things I forgot to write:
1) the second .diff needs to be applied together with the first one to work
2) for the second diff, I changed the key one has to press to select the current item for download to RETURN, so it doesn't conflict with entering the filter string (where you may need space)
Comment by Manuel Wolf (Roujin) - Sunday, 01 February 2009, 03:07 GMT
The above patches seemingly did not compile with gcc due to some bad duplicate names I chose. Here are new versions for both which hopefully also compile on gcc.