diff options
author | frosch <frosch@openttd.org> | 2012-06-09 19:54:16 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-06-09 19:54:16 +0000 |
commit | 03046f614f4fb8c88d1a8ee05e0caee2bde887bc (patch) | |
tree | 8ee6fcb2c3c316b89bb884e10a52e42136674b94 /src/newgrf_gui.cpp | |
parent | db709aff32244d45e613d53dbf9f0ffbc3aa5cb1 (diff) | |
download | openttd-03046f614f4fb8c88d1a8ee05e0caee2bde887bc.tar.xz |
(svn r24337) -Feature: Allow filtering for multiple words (separated by whitespace resp. quoted) in the sign list, content- and NewGRF-guis.
Diffstat (limited to 'src/newgrf_gui.cpp')
-rw-r--r-- | src/newgrf_gui.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index a62003c8d..f832454e6 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -23,6 +23,7 @@ #include "network/network.h" #include "network/network_content.h" #include "sortlist_type.h" +#include "stringfilter_type.h" #include "querystring_gui.h" #include "core/geometry_func.hpp" #include "newgrf_text.h" @@ -587,7 +588,7 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed); * Window for showing NewGRF files */ struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback { - typedef GUIList<const GRFConfig *> GUIGRFConfigList; + typedef GUIList<const GRFConfig *, StringFilter &> GUIGRFConfigList; static const uint EDITBOX_MAX_SIZE = 50; @@ -599,6 +600,7 @@ struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback { GUIGRFConfigList avails; ///< Available (non-active) grfs. const GRFConfig *avail_sel; ///< Currently selected available grf. \c NULL is none is selected. int avail_pos; ///< Index of #avail_sel if existing, else \c -1. + StringFilter string_filter; ///< Filter for available grf. GRFConfig *actives; ///< Temporary active grf list to which changes are made. GRFConfig *active_sel; ///< Selected active grf item. @@ -1297,7 +1299,8 @@ struct NewGRFWindow : public QueryStringBaseWindow, NewGRFScanCallback { { if (!this->editable) return; - this->avails.SetFilterState(!StrEmpty(this->edit_str_buf)); + string_filter.SetFilterTerm(this->edit_str_buf); + this->avails.SetFilterState(!string_filter.IsEmpty()); this->avails.ForceRebuild(); this->InvalidateData(0); } @@ -1387,12 +1390,13 @@ private: } /** Filter grfs by tags/name */ - static bool CDECL TagNameFilter(const GRFConfig * const *a, const char *filter_string) + static bool CDECL TagNameFilter(const GRFConfig * const *a, StringFilter &filter) { - if (strcasestr((*a)->GetName(), filter_string) != NULL) return true; - if ((*a)->filename != NULL && strcasestr((*a)->filename, filter_string) != NULL) return true; - if ((*a)->GetDescription() != NULL && strcasestr((*a)->GetDescription(), filter_string) != NULL) return true; - return false; + filter.ResetState(); + filter.AddLine((*a)->GetName()); + filter.AddLine((*a)->filename); + filter.AddLine((*a)->GetDescription()); + return filter.GetState();; } void BuildAvailables() @@ -1423,7 +1427,7 @@ private: } } - this->avails.Filter(this->edit_str_buf); + this->avails.Filter(this->string_filter); this->avails.Compact(); this->avails.RebuildDone(); this->avails.Sort(); |