diff options
author | Sergei Litovchuk <slitovchuk@productengine.com> | 2010-05-13 19:31:50 +0300 |
---|---|---|
committer | Sergei Litovchuk <slitovchuk@productengine.com> | 2010-05-13 19:31:50 +0300 |
commit | a9680462828d99cb482cdb235f14d6bd3c87bc9c (patch) | |
tree | 67d6a4f5cb9ed3b7ac38b6e2f1e4137901f8d51e /indra/newview/lloutfitslist.cpp | |
parent | 90940d0b065d18b1dfaa178ee294b4d47ff96e2a (diff) |
EXT-7158 FIXED Implemented filter in "My Outfits" tab.
- Added accordion tab title highlighting setter and title getter.
- Added filtered tabs title highlighting.
- Tabs which don't pass filter are hidden.
- Added applying filter on list refresh event to avoid refreshing list on every filter change.
- Moved part of LLTextUtil to llui/lluitextutil to reuse code in llaccordionctrltab.
- Fixed passing list size to mRefreshCompleteSignal.
- Added list refresh callback to LLInventoryItemsList for checking tab visibility without re-applying filter sub-string.
Committed to proceed with dependent tasks.
If there are any comments/suggestions related to text utils this part of code may be changed without requiring much effort.
Reviewed by Mike Antipov at https://codereview.productengine.com/secondlife/r/363/
--HG--
branch : product-engine
Diffstat (limited to 'indra/newview/lloutfitslist.cpp')
-rw-r--r-- | indra/newview/lloutfitslist.cpp | 131 |
1 files changed, 103 insertions, 28 deletions
diff --git a/indra/newview/lloutfitslist.cpp b/indra/newview/lloutfitslist.cpp index 18bd610dd9..12d5203429 100644 --- a/indra/newview/lloutfitslist.cpp +++ b/indra/newview/lloutfitslist.cpp @@ -169,6 +169,9 @@ void LLOutfitsList::refreshList(const LLUUID& category_id) // Setting list commit callback to monitor currently selected wearable item. list->setCommitCallback(boost::bind(&LLOutfitsList::onSelectionChange, this, _1)); + // Setting list refresh callback to apply filter on list change. + list->setRefreshCompleteCallback(boost::bind(&LLOutfitsList::onWearableItemsListRefresh, this, _1)); + // Fetch the new outfit contents. cat->fetch(); @@ -244,35 +247,9 @@ void LLOutfitsList::performAction(std::string action) void LLOutfitsList::setFilterSubString(const std::string& string) { - mFilterSubString = string; + applyFilter(string); - for (outfits_map_t::iterator - iter = mOutfitsMap.begin(), - iter_end = mOutfitsMap.end(); - iter != iter_end; ++iter) - { - LLAccordionCtrlTab* tab = iter->second; - if (tab) - { - LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*> (tab->getAccordionView()); - if (list) - { - list->setFilterSubString(mFilterSubString); - } - - if(!mFilterSubString.empty()) - { - //store accordion tab state when filter is not empty - tab->notifyChildren(LLSD().with("action","store_state")); - tab->setDisplayChildren(true); - } - else - { - //restore accordion state after all those accodrion tab manipulations - tab->notifyChildren(LLSD().with("action","restore_state")); - } - } - } + mFilterSubString = string; } ////////////////////////////////////////////////////////////////////////// @@ -350,4 +327,102 @@ void LLOutfitsList::changeOutfitSelection(LLWearableItemsList* list, const LLUUI mSelectedOutfitUUID = category_id; } +void LLOutfitsList::onWearableItemsListRefresh(LLUICtrl* ctrl) +{ + if (!ctrl || mFilterSubString.empty()) + return; + + for (outfits_map_t::iterator + iter = mOutfitsMap.begin(), + iter_end = mOutfitsMap.end(); + iter != iter_end; ++iter) + { + LLAccordionCtrlTab* tab = iter->second; + if (tab) continue; + + LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView()); + if (list != ctrl) continue; + + std::string title = tab->getTitle(); + LLStringUtil::toUpper(title); + + std::string cur_filter = mFilterSubString; + LLStringUtil::toUpper(cur_filter); + + if (std::string::npos == title.find(cur_filter)) + { + // hide tab if its title doesn't pass filter + // and it has no visible items + tab->setVisible(list->size() != 0); + } + else + { + tab->setTitle(tab->getTitle(), cur_filter); + } + } +} + +void LLOutfitsList::applyFilter(const std::string& new_filter_substring) +{ + for (outfits_map_t::iterator + iter = mOutfitsMap.begin(), + iter_end = mOutfitsMap.end(); + iter != iter_end; ++iter) + { + LLAccordionCtrlTab* tab = iter->second; + if (!tab) continue; + + bool more_restrictive = mFilterSubString.size() < new_filter_substring.size() && !new_filter_substring.substr(0, mFilterSubString.size()).compare(mFilterSubString); + + // Restore tab visibility in case of less restrictive filter + // to compare it with updated string if it was previously hidden. + if (!more_restrictive) + { + tab->setVisible(TRUE); + } + + LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView()); + if (list) + { + list->setFilterSubString(new_filter_substring); + } + + if(mFilterSubString.empty() && !new_filter_substring.empty()) + { + //store accordion tab state when filter is not empty + tab->notifyChildren(LLSD().with("action","store_state")); + } + + if (!new_filter_substring.empty()) + { + tab->setDisplayChildren(true); + + std::string title = tab->getTitle(); + LLStringUtil::toUpper(title); + + std::string cur_filter = new_filter_substring; + LLStringUtil::toUpper(cur_filter); + + if (std::string::npos == title.find(cur_filter)) + { + // hide tab if its title doesn't pass filter + // and it has no visible items + tab->setVisible(list->size() != 0); + } + else + { + tab->setTitle(tab->getTitle(), cur_filter); + } + } + else + { + // restore tab title when filter is empty + tab->setTitle(tab->getTitle()); + + //restore accordion state after all those accodrion tab manipulations + tab->notifyChildren(LLSD().with("action","restore_state")); + } + } +} + // EOF |