From f80a41cf36f023aa0b5a7368d81dd237dafc8d4a Mon Sep 17 00:00:00 2001 From: Cho Date: Fri, 27 Jun 2014 01:02:44 +0100 Subject: Sort experiences in list alphabetically by name for ACME-1537 --- indra/newview/llpanelexperiences.cpp | 43 ++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpanelexperiences.cpp') diff --git a/indra/newview/llpanelexperiences.cpp b/indra/newview/llpanelexperiences.cpp index 0d67dbf916..2885ef9305 100644 --- a/indra/newview/llpanelexperiences.cpp +++ b/indra/newview/llpanelexperiences.cpp @@ -38,9 +38,13 @@ #include "lllayoutstack.h" + static LLPanelInjector register_experiences_panel("experiences_panel"); +//comparators +static const LLExperienceItemComparator NAME_COMPARATOR; + LLPanelExperiences::LLPanelExperiences( ) : mExperiencesList(NULL) { @@ -54,6 +58,7 @@ BOOL LLPanelExperiences::postBuild( void ) { mExperiencesList->setNoItemsCommentText(getString("no_experiences")); } + mExperiencesList->setComparator(&NAME_COMPARATOR); return TRUE; } @@ -81,6 +86,8 @@ void LLPanelExperiences::setExperienceList( const LLSD& experiences ) item->init(public_key); mExperiencesList->addItem(item, public_key); } + + mExperiencesList->sort(); } LLPanelExperiences* LLPanelExperiences::create(const std::string& name) @@ -112,6 +119,7 @@ void LLPanelExperiences::addExperience( const LLUUID& id ) item->init(id); mExperiencesList->addItem(item, id); + mExperiencesList->sort(); } } @@ -137,21 +145,32 @@ void LLPanelExperiences::enableButton( bool enable ) LLExperienceItem::LLExperienceItem() + : mName(NULL) { buildFromFile("panel_experience_list_item.xml"); } void LLExperienceItem::init( const LLUUID& id) { - getChild("experience_name")->setValue(LLSLURL("experience", id, "profile").getSLURLString()); + mName = getChild("experience_name"); + mName->setValue(LLSLURL("experience", id, "profile").getSLURLString()); } - LLExperienceItem::~LLExperienceItem() { } +std::string LLExperienceItem::getExperienceName() const +{ + if (mName) + { + return mName->getValue(); + } + + return ""; +} + void LLPanelSearchExperiences::doSearch() { @@ -169,3 +188,23 @@ BOOL LLPanelSearchExperiences::postBuild( void ) childSetAction("search_button", boost::bind(&LLPanelSearchExperiences::doSearch, this)); return TRUE; } + +bool LLExperienceItemComparator::compare(const LLPanel* item1, const LLPanel* item2) const +{ + const LLExperienceItem* experience_item1 = dynamic_cast(item1); + const LLExperienceItem* experience_item2 = dynamic_cast(item2); + + if (!experience_item1 || !experience_item2) + { + LL_ERRS() << "item1 and item2 cannot be null" << LL_ENDL; + return true; + } + + std::string name1 = experience_item1->getExperienceName(); + std::string name2 = experience_item2->getExperienceName(); + + LLStringUtil::toUpper(name1); + LLStringUtil::toUpper(name2); + + return name1 < name2; +} -- cgit v1.2.3