From 335e750590bd782a9b8d03c6a0af0b20b07940f2 Mon Sep 17 00:00:00 2001 From: Nailson Date: Sat, 22 Oct 2016 11:45:23 -0300 Subject: [PATCH] Fix #126 --- source/main_menubar.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/main_menubar.cpp b/source/main_menubar.cpp index f24ff354..ca0ec178 100644 --- a/source/main_menubar.cpp +++ b/source/main_menubar.cpp @@ -927,6 +927,25 @@ namespace OnSearchForStuff return label; } + + void sort() + { + if(search_unique || search_action) + std::sort(found.begin(), found.end(), Searcher::compare); + } + + static bool compare(const std::pair& pair1, const std::pair& pair2) + { + const Item* item1 = pair1.second; + const Item* item2 = pair2.second; + + if(item1->getActionID() != 0 || item2->getActionID() != 0) + return item1->getActionID() < item2->getActionID(); + else if(item1->getUniqueID() != 0 || item2->getUniqueID() != 0) + return item1->getUniqueID() < item2->getUniqueID(); + + return false; + } }; } @@ -944,6 +963,7 @@ void MainMenuBar::OnSearchForStuff(wxCommandEvent& WXUNUSED(event)) searcher.search_writeable = true; foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher); + searcher.sort(); std::vector >& found = searcher.found; g_gui.DestroyLoadBar(); @@ -965,6 +985,7 @@ void MainMenuBar::OnSearchForUnique(wxCommandEvent& WXUNUSED(event)) OnSearchForStuff::Searcher searcher; searcher.search_unique = true; foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher); + searcher.sort(); std::vector >& found = searcher.found; g_gui.DestroyLoadBar(); @@ -985,6 +1006,7 @@ void MainMenuBar::OnSearchForAction(wxCommandEvent& WXUNUSED(event)) { OnSearchForStuff::Searcher searcher; searcher.search_action = true; foreach_ItemOnMap(g_gui.GetCurrentMap(), searcher); + searcher.sort(); std::vector >& found = searcher.found; g_gui.DestroyLoadBar();