mail[Wesnoth-commits] r27210 - in /trunk/src: construct_dialog.cpp construct_dialog.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on June 15, 2008 - 20:57:
Author: alink
Date: Sun Jun 15 20:57:51 2008
New Revision: 27210

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27210&view=rev
Log:
- Optimize text filter: don't update after simple cursor move.
- reset selection between filter change (prevent random selection).
- Allow multi words filter, separated by space and must all match somewhere
examples: create unit "hum bow" match "Human | Bowman" only,
or you can directly search savegame like "HttT replay"

Modified:
    trunk/src/construct_dialog.cpp
    trunk/src/construct_dialog.hpp

Modified: trunk/src/construct_dialog.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.cpp?rev=27210&r1=27209&r2=27210&view=diff
==============================================================================
--- trunk/src/construct_dialog.cpp (original)
+++ trunk/src/construct_dialog.cpp Sun Jun 15 20:57:51 2008
@@ -889,20 +889,38 @@
 }
 
 void filter_textbox::handle_text_changed(const wide_string& text) {
+       const std::vector<std::string> words = 
utils::split(utils::wstring_to_string(text),' ');
+       if (words == last_words)
+               return;
+       last_words = words;
+
        filtered_items_.clear();
        index_map_.clear();
-       const std::string t = utils::wstring_to_string(text);
-       for(size_t n = 0; n != items_to_filter_.size(); ++n) {
-               if(n < header_row_ || 
std::search(items_to_filter_[n].begin(), items_to_filter_[n].end(),
-                                                                t.begin(), 
t.end(),
-                                                                
chars_equal_insensitive) != items_to_filter_[n].end())
+
+       if(header_row_ == 1) {
+                       filtered_items_.push_back(items_[0]);
+                       index_map_.push_back(0);
+       }
+
+       // we keep all items containing each word
+       for(size_t n = header_row_; n < items_to_filter_.size(); ++n) {
+               std::vector<std::string>::const_iterator w = words.begin();
+               for(; w != words.end(); ++w)
                {
+                       if (std::search(items_to_filter_[n].begin(), 
items_to_filter_[n].end(),
+                                               w->begin(), w->end(),
+                                               chars_equal_insensitive) == 
items_to_filter_[n].end())
+                               break; // one word doesn't match, we don't 
reach words.end()
+               }
+               if (w == words.end()) {
+                       // all words have matched, keep the item
                        filtered_items_.push_back(items_[n]);
                        index_map_.push_back(n);
                }
        }
 
        dialog_.set_menu_items(filtered_items_);
+       dialog_.get_menu().reset_selection();
 }
 
 int message_dialog::show(msecs minimum_lifetime)

Modified: trunk/src/construct_dialog.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.hpp?rev=27210&r1=27209&r2=27210&view=diff
==============================================================================
--- trunk/src/construct_dialog.hpp (original)
+++ trunk/src/construct_dialog.hpp Sun Jun 15 20:57:51 2008
@@ -123,7 +123,7 @@
 public:
        filter_textbox(CVideo& video, const std::string& header,
                const std::vector<std::string>& items, const 
std::vector<std::string>& items_to_filter,
-                size_t header_row,
+               size_t header_row,
                dialog& dialog, int width = 250)
                : dialog_textbox(new label(video, header), video, width),
                items_(items),
@@ -131,6 +131,7 @@
                header_row_(header_row),
                dialog_(dialog)
        {
+               last_words.push_back(""); // dummy word to trigger an update
                set_text("");
        }
 
@@ -142,6 +143,7 @@
 private:
        std::vector<std::string> items_, items_to_filter_, filtered_items_;
        std::vector<int> index_map_;
+       std::vector<std::string> last_words;
        size_t header_row_;
        gui::dialog& dialog_;
        virtual void handle_text_changed(const wide_string& text);




Related Messages


Powered by MHonArc, Updated Mon Jun 16 00:01:39 2008