mail[Wesnoth-commits] r36899 - in /trunk: data/gui/default/window/game_load.cfg src/gui/dialogs/game_load.cpp src/gui/dialogs/game_load.hpp


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

Header


Content

Posted by joerg . hinrichs on July 14, 2009 - 21:22:
Author: jhinrichs
Date: Tue Jul 14 21:22:19 2009
New Revision: 36899

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36899&view=rev
Log:
Add the filter functionality for the savegame list of the load-game dialog.

Modified:
    trunk/data/gui/default/window/game_load.cfg
    trunk/src/gui/dialogs/game_load.cpp
    trunk/src/gui/dialogs/game_load.hpp

Modified: trunk/data/gui/default/window/game_load.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/gui/default/window/game_load.cfg?rev=36899&r1=36898&r2=36899&view=diff
==============================================================================
--- trunk/data/gui/default/window/game_load.cfg (original)
+++ trunk/data/gui/default/window/game_load.cfg Tue Jul 14 21:22:19 2009
@@ -162,11 +162,47 @@
                                                                              
          
                                                                              
          [label]
                                                                              
                  id = "lblChoose"
-                                                                             
                  definition = "choose"
+                                                                             
                  definition = "default"
 
                                                                              
                  label = _ "Choose the game to load"
                                                                              
          [/label]
 
+                                                                             
  [/column]
+                                                                       
+                                                                       [/row]
+                                                                       
+                                                                       [row]
+                                                                             
  [column]
+                                                                             
          horizontal_alignment = "left"
+                                                                             
          
+                                                                             
          [grid]
+                                                                             
          
+                                                                             
                  [row]
+                                                                             
                  
+                                                                             
                          [column]
+                                                                             
                                  [label]
+                                                                             
                                          id = "lblFilter"
+                                                                             
                                          definition = "default"
+
+                                                                             
                                          label = _ "Filter"
+                                                                             
                                  [/label]
+
+                                                                             
                          [/column]
+                                                                             
                          
+                                                                             
                          [column]
+
+                                                                             
                                  [text_box]
+                                                                             
                                          id = "txtFilter"
+                                                                             
                                          definition = "default"
+                                                                             
                                          label = ""
+                                                                             
                                  [/text_box]
+
+                                                                             
                          [/column]
+
+                                                                             
                  [/row]
+                                                                             
                  
+                                                                             
          [/grid]
+                                                                             
          
                                                                              
  [/column]
                                                                        
                                                                        [/row]
@@ -305,6 +341,38 @@
                                        [grid]
 
                                                [row]
+                                               
+                                                       [column]
+
+                                                               [spacer]
+                                                                       
definition = "default"
+                                                               [/spacer]
+
+                                                       [/column]
+
+                                                       [column]
+
+                                                               [spacer]
+                                                                       
definition = "default"
+                                                               [/spacer]
+
+                                                       [/column]
+
+                                                       [column]
+                                                               
horizontal_alignment = "right"
+                                                       
+                                                               [button]
+                                                                       id = 
"delete"
+                                                                       
definition = "default"
+
+                                                                       
size_text = _ "Delete"
+                                                                       label 
= _ "Delete"
+                                                               [/button]
+
+                                                       [/column]
+                                               [/row]
+                                               
+                                               [row]
                                                        grow_factor = 0
                                                        
                                                        [column]

Modified: trunk/src/gui/dialogs/game_load.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/game_load.cpp?rev=36899&r1=36898&r2=36899&view=diff
==============================================================================
--- trunk/src/gui/dialogs/game_load.cpp (original)
+++ trunk/src/gui/dialogs/game_load.cpp Tue Jul 14 21:22:19 2009
@@ -20,14 +20,22 @@
 #include "formula_string_utils.hpp"
 #include "gettext.hpp"
 #include "gui/auxiliary/log.hpp"
+#include "gui/dialogs/field.hpp"
+#include "gui/dialogs/game_delete.hpp"
 #include "gui/dialogs/helper.hpp"
+#include "gui/widgets/button.hpp"
 #include "gui/widgets/image.hpp"
 #include "gui/widgets/label.hpp"
 #include "gui/widgets/listbox.hpp"
 #include "gui/widgets/minimap.hpp"
+#include "gui/widgets/text_box.hpp"
 #include "gui/widgets/window.hpp"
 #include "language.hpp"
 #include "marked-up_text.hpp"
+#include "preferences_display.hpp"
+
+#include <cctype>
+#include <boost/bind.hpp>
 
 namespace gui2 {
 
@@ -45,7 +53,8 @@
  */
 
        tgame_load::tgame_load(const config& cache_config)
-               : filename_(),
+               : txtFilter_(register_text("txtFilter", false)),
+               filename_(),
                cache_config_(cache_config)
 {
 }
@@ -61,6 +70,12 @@
        VALIDATE(minimap, missing_widget("minimap"));
        minimap->set_config(&cache_config_);
 
+       assert(txtFilter_);
+       ttext_box* filter = 
dynamic_cast<ttext_box*>(window.find_widget("txtFilter", false));
+       VALIDATE(filter, missing_widget("txtFilter"));
+       window.keyboard_capture(filter);
+       
filter->set_text_changed_callback(boost::bind(&tgame_load::filter_text_changed,
 this, _1, _2));
+
        tlistbox* list = 
dynamic_cast<tlistbox*>(window.find_widget("savegame_list", false));
        VALIDATE(list, missing_widget("savegame_list"));
        window.keyboard_capture(list);
@@ -71,8 +86,20 @@
                cursor::setter cur(cursor::WAIT);
                games_ = savegame_manager::get_saves_list();
        }
-
-       foreach(const save_info game, games_) {
+       fill_game_list(window, games_);
+
+       GUI2_EASY_BUTTON_CALLBACK(delete, tgame_load);
+               
+       display_savegame(window);
+}
+
+void tgame_load::fill_game_list(twindow& window, std::vector<save_info>& 
games){
+       tlistbox* list = 
dynamic_cast<tlistbox*>(window.find_widget("savegame_list", false));
+       VALIDATE(list, missing_widget("savegame_list"));
+
+       list->clear();
+
+       foreach(const save_info game, games) {
                std::map<std::string, string_map> data;
                string_map item;
 
@@ -85,14 +112,58 @@
                list->add_row(data);
        }
 
-       display_savegame(window);
+       window.invalidate_layout();
 }
 
 void tgame_load::list_item_clicked(twindow& window){
        display_savegame(window);
 }
 
-void tgame_load::post_show(twindow& /*window*/)
+bool tgame_load::filter_text_changed(ttext_* textbox, const std::string 
text){
+       twindow& window = *textbox->get_window();
+
+       tlistbox* list = 
dynamic_cast<tlistbox*>(window.find_widget("savegame_list", false));
+       VALIDATE(list, missing_widget("savegame_list"));
+
+       const std::vector<std::string> words = utils::split(text, ' ');
+
+       if (words == last_words_)
+               return false;
+       last_words_ = words;
+
+       bool found;
+       for (unsigned int i = 0; i < list->get_item_count(); i++){
+               tgrid* row = list->get_row_grid(i);
+
+               if (text == ""){
+                       row->set_visible(twidget::VISIBLE);
+               }
+               else{
+                       tgrid::iterator it = row->begin();
+                       tlabel* filename_label = 
dynamic_cast<tlabel*>(it->find_widget("filename", false));
+
+                       foreach (const std::string& word, words){
+                               found = 
std::search(filename_label->label().str().begin(), 
filename_label->label().str().end(),
+                                                       word.begin(), 
word.end(),
+                                                       
chars_equal_insensitive) != filename_label->label().str().end();
+                               
+                               if (! found)
+                                       break; // one word doesn't match, we 
don't reach words.end()
+                       }
+
+                       if (found)
+                               row->set_visible(twidget::VISIBLE);
+                       else
+                               row->set_visible(twidget::INVISIBLE);
+               }
+       }
+
+       window.invalidate_layout();
+
+       return false;
+}
+
+void tgame_load::post_show(twindow& window)
 {
        //filename_ = txtFilename_->get_widget_value(window);
 }
@@ -185,5 +256,44 @@
        }
 }
 
+void tgame_load::delete_button_callback(twindow& window){
+       tlistbox* list = 
dynamic_cast<tlistbox*>(window.find_widget("savegame_list", false));
+       VALIDATE(list, missing_widget("savegame_list"));
+
+       const size_t index = size_t(list->get_selected_row());
+       if(index < games_.size()) {
+
+               // See if we should ask the user for deletion confirmation
+               if(preferences::ask_delete_saves()) {
+                       //gui2::tgame_delete dlg_delete;
+                       //dlg_delete.show(window, 0);
+                       
+                       /*
+                       gui::dialog dmenu(disp_,"",
+                                              _("Do you really want to 
delete this game?"),
+                                              gui::YES_NO);
+                       dmenu.add_option(_("Don't ask me again!"), false);
+                       const int res = dmenu.show();
+                       // See if the user doesn't want to be asked this again
+                       if(dmenu.option_checked()) {
+                               preferences::set_ask_delete_saves(false);
+                       }
+                       */
+
+                       //if(res != 0) {
+                       //      return gui::CONTINUE_DIALOG;
+                       //}
+               }
+
+               // Delete the file
+               //savegame_manager::delete_game(games_[index].name);
+
+               // Remove it from the list of saves
+               games_.erase(games_.begin() + index);
+               list->remove_row(index);
+
+               display_savegame(window);
+       }
+}
+
 } // namespace gui2
-

Modified: trunk/src/gui/dialogs/game_load.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/game_load.hpp?rev=36899&r1=36898&r2=36899&view=diff
==============================================================================
--- trunk/src/gui/dialogs/game_load.hpp (original)
+++ trunk/src/gui/dialogs/game_load.hpp Tue Jul 14 21:22:19 2009
@@ -17,6 +17,7 @@
 
 #include "gui/dialogs/dialog.hpp"
 #include "gui/widgets/listbox.hpp"
+#include "gui/widgets/text.hpp"
 #include "savegame.hpp"
 #include "tstring.hpp"
 
@@ -40,16 +41,22 @@
        /** Inherited from tdialog. */
        twindow* build_window(CVideo& video);
 
+       bool filter_text_changed(ttext_* textbox, const std::string text);
        void list_item_clicked(twindow& window);
+       void delete_button_callback(twindow& window);
 
        void display_savegame(twindow& window);
        void evaluate_summary_string(std::stringstream& str, const config& 
cfg_summary);
+       void fill_game_list(twindow& window, std::vector<save_info>& games);
 
-       //tfield_text* txtFilename_;
+       tfield_text* txtFilter_;
+
        std::string filename_;
 
        std::vector<save_info> games_;
        const config& cache_config_;
+
+       std::vector<std::string> last_words_;
 };
 
 }




Related Messages


Powered by MHonArc, Updated Tue Jul 14 21:40:52 2009