mail[Wesnoth-commits] r27185 - in /trunk/src: construct_dialog.cpp construct_dialog.hpp dialogs.cpp game.cpp menu_events.cpp


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

Header


Content

Posted by alinktomine on June 15, 2008 - 02:28:
Author: alink
Date: Sun Jun 15 02:28:33 2008
New Revision: 27185

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27185&view=rev
Log:
- Fix a bug introduced by r27043, savegames after a deleted one were shifted
(even without using any filter, so bug #11779 was not fixed. It is now)
- Fix an inaccuracy with the new filter from the addon manager (always show 
the
first one: the accuracy era) spotted by Shadow_Master.

Modified:
    trunk/src/construct_dialog.cpp
    trunk/src/construct_dialog.hpp
    trunk/src/dialogs.cpp
    trunk/src/game.cpp
    trunk/src/menu_events.cpp

Modified: trunk/src/construct_dialog.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.cpp?rev=27185&r1=27184&r2=27185&view=diff
==============================================================================
--- trunk/src/construct_dialog.cpp (original)
+++ trunk/src/construct_dialog.cpp Sun Jun 15 02:28:33 2008
@@ -855,24 +855,42 @@
        if(selection < 0) {
                return selection;
        }
-       //we must add one to the index to ignore the header row, and
-       //then subtract one from the result to return the index not including
-       //the header row.
-
-       size_t header = 1; // for now, just assume there's a header row
-
-       if (size_t(selection+header) >= index_map_.size()) {
+       //we must the header row value to the index to ignore this row and
+       //then subtract it from the result to return the index not including
+       //the possible header row.
+
+       if (size_t(selection+header_row_) >= index_map_.size()) {
                return -1; // bad index, cancel
        }
 
-       return index_map_[selection+header]-header;
+       return index_map_[selection+header_row_]-header_row_;
 }
 
 void filter_textbox::delete_item(int selection) {
-       size_t header = 1; // for now, just assume there's a header row
-       filtered_items_.erase(filtered_items_.begin() + selection+header);
-       items_.erase(items_.begin() + index_map_[selection+header]);
-       index_map_.erase(index_map_.begin() + selection+header);
+       // use the real selection
+       selection += header_row_;
+
+       const size_t size = index_map_.size();
+       assert(size == filtered_items_.size());
+       if (selection >= size)
+               return;
+       int selection_index = index_map_[selection];
+
+       // we erase the selected element by shifting the following others
+       for(size_t i = selection; i < size-1; ++i) {
+               filtered_items_[i] = filtered_items_[i+1];
+               // don't forget to also shift the next index values
+               index_map_[i] = index_map_[i+1] - 1;
+       }
+       // same operation for item, but starting from the index of selection
+       for(size_t i = selection_index; i < items_.size()-1; ++i) {
+               items_[i] = items_[i+1];
+       }
+
+       // finally, we resize to remove the last doubled element
+       filtered_items_.resize(size - 1);
+       index_map_.resize(size - 1);
+       items_.resize(items_.size() - 1);
 
        //for now, assume the dialog menu item is deleted using DELETE_ITEM
        /* dialog_.set_menu_items(filtered_items_); */
@@ -883,7 +901,7 @@
        index_map_.clear();
        const std::string t = utils::wstring_to_string(text);
        for(size_t n = 0; n != items_.size(); ++n) {
-               if(n == 0 || std::search(items_[n].begin(), items_[n].end(),
+               if(n < header_row_ || std::search(items_[n].begin(), 
items_[n].end(),
                                                                 t.begin(), 
t.end(),
                                                                 
chars_equal_insensitive) != items_[n].end())
                {

Modified: trunk/src/construct_dialog.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.hpp?rev=27185&r1=27184&r2=27185&view=diff
==============================================================================
--- trunk/src/construct_dialog.hpp (original)
+++ trunk/src/construct_dialog.hpp Sun Jun 15 02:28:33 2008
@@ -122,10 +122,11 @@
 class filter_textbox : public gui::dialog_textbox {
 public:
        filter_textbox(CVideo& video, const std::string& header,
-               const std::vector<std::string>& items,
+               const std::vector<std::string>& items, size_t header_row,
                dialog& dialog, int width = 250)
                : dialog_textbox(new label(video, header), video, width),
                items_(items),
+               header_row_(header_row),
                dialog_(dialog),
                first_time_(true)
        {
@@ -140,6 +141,7 @@
 private:
        std::vector<std::string> items_, filtered_items_;
        std::vector<int> index_map_;
+       size_t header_row_;
        gui::dialog& dialog_;
        bool first_time_;
        virtual void handle_text_changed(const wide_string& text);

Modified: trunk/src/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/dialogs.cpp?rev=27185&r1=27184&r2=27185&view=diff
==============================================================================
--- trunk/src/dialogs.cpp (original)
+++ trunk/src/dialogs.cpp Sun Jun 15 02:28:33 2008
@@ -664,7 +664,7 @@
        sorter.set_alpha_sort(0).set_id_sort(1);
        lmenu.set_menu(items, &sorter);
 
-       gui::filter_textbox* filter = new gui::filter_textbox(disp.video(), 
_("Filter: "), items, lmenu);
+       gui::filter_textbox* filter = new gui::filter_textbox(disp.video(), 
_("Filter: "), items, 1, lmenu);
        lmenu.set_textbox(filter);
 
        save_preview_pane 
save_preview(disp.video(),game_config,&map_obj,games,summaries,*filter);

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=27185&r1=27184&r2=27185&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Sun Jun 15 02:28:33 2008
@@ -1421,7 +1421,7 @@
                addon_dialog.set_menu(addon_menu);
 
                gui::filter_textbox* filter = new 
gui::filter_textbox(disp().video(),
-                       _("Filter: "), options, addon_dialog, 300);
+                       _("Filter: "), options, 0, addon_dialog, 300);
                addon_dialog.set_textbox(filter);
 
                const int index = addon_dialog.show();

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=27185&r1=27184&r2=27185&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Sun Jun 15 02:28:33 2008
@@ -1660,7 +1660,7 @@
                        umenu.set_menu(options, &sorter);
 
                        gui::filter_textbox* filter = new 
gui::filter_textbox(gui_->video(),
-                               _("Filter: "), options, umenu, 200);
+                               _("Filter: "), options, 1, umenu, 200);
                        umenu.set_textbox(filter);
 
                        //sort by race then by type name




Related Messages


Powered by MHonArc, Updated Sun Jun 15 03:01:47 2008