From 3eb16193b448ab03dbcd3db32ad17b48dc8e3688 Mon Sep 17 00:00:00 2001 From: Arrehn Date: Sat, 29 Oct 2011 01:20:43 -0400 Subject: [PATCH] FIRE-3690, inventory filter accepts multiple terms with '+', by Dawa Gurbux --- indra/newview/llfolderviewitem.cpp | 62 +++++++++---- indra/newview/llfolderviewitem.h | 6 ++ indra/newview/llinventoryfilter.cpp | 92 +++++++++++++++++-- indra/newview/llinventoryfilter.h | 17 ++++ .../default/xui/en/panel_main_inventory.xml | 1 + 5 files changed, 154 insertions(+), 24 deletions(-) diff --git a/indra/newview/llfolderviewitem.cpp b/indra/newview/llfolderviewitem.cpp index 7e5ae00e73..38fe8914fb 100644 --- a/indra/newview/llfolderviewitem.cpp +++ b/indra/newview/llfolderviewitem.cpp @@ -472,6 +472,17 @@ void LLFolderViewItem::filter( LLInventoryFilter& filter) setFiltered(passed_filter, filter.getCurrentGeneration()); mStringMatchOffset = filter.getStringMatchOffset(); + + // Begin Multi-substring inventory search + mStringMatchOffsets.clear(); + mStringMatchSizes.clear(); + for (U32 index = 0, max = filter.getFilterSubStringCount(); index < max; index++) + { + mStringMatchOffsets.push_back(filter.getFilterSubStringPos(index)); + mStringMatchSizes.push_back(filter.getFilterSubStringLen(index)); + } + // End Multi-substring inventory search + filter.decrementFilterCount(); if (getRoot()->getDebugFilters()) @@ -1116,28 +1127,43 @@ void LLFolderViewItem::draw() //--------------------------------------------------------------------------------// // Highlight string match // - if (mStringMatchOffset != std::string::npos) + + // Begin Multi-substring inventory search + if (mStringMatchOffsets.size()) { - // don't draw backgrounds for zero-length strings - S32 filter_string_length = getRoot()->getFilterSubString().size(); - if (filter_string_length > 0) - { - std::string combined_string = mLabel + mLabelSuffix; - S32 left = llround(text_left) + font->getWidth(combined_string, 0, mStringMatchOffset) - 1; - S32 right = left + font->getWidth(combined_string, mStringMatchOffset, filter_string_length) + 2; - S32 bottom = llfloor(getRect().getHeight() - font->getLineHeight() - 3 - TOP_PAD); - S32 top = getRect().getHeight() - TOP_PAD; + //std::vector mStringMatchOffsets; + //std::vector mStringMatchSizes; + std::vector::iterator offset_iter = mStringMatchOffsets.begin(); + std::vector::iterator size_iter = mStringMatchSizes.begin(); - LLUIImage* box_image = default_params.selection_image; - LLRect box_rect(left, top, right, bottom); - box_image->draw(box_rect, sFilterBGColor); - F32 match_string_left = text_left + font->getWidthF32(combined_string, 0, mStringMatchOffset); - F32 yy = (F32)getRect().getHeight() - font->getLineHeight() - (F32)TEXT_PAD - (F32)TOP_PAD; - font->renderUTF8( combined_string, mStringMatchOffset, match_string_left, yy, - sFilterTextColor, LLFontGL::LEFT, LLFontGL::BOTTOM, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, - filter_string_length, S32_MAX, &right_x, FALSE ); + LLUIImage* box_image = default_params.selection_image; + + while (offset_iter < mStringMatchOffsets.end() && size_iter < mStringMatchSizes.end()) + { + // don't draw backgrounds for zero-length strings + S32 filter_string_length = *size_iter; + S32 filter_string_offset = *offset_iter; + if (filter_string_length > 0 && filter_string_offset != std::string::npos) + { + std::string combined_string = mLabel + mLabelSuffix; + S32 left = llround(text_left) + font->getWidth(combined_string, 0, filter_string_offset) - 1; + S32 right = left + font->getWidth(combined_string, filter_string_offset, filter_string_length) + 2; + S32 bottom = llfloor(getRect().getHeight() - font->getLineHeight() - 3 - TOP_PAD); + S32 top = getRect().getHeight() - TOP_PAD; + + LLRect box_rect(left, top, right, bottom); + box_image->draw(box_rect, sFilterBGColor); + F32 match_string_left = text_left + font->getWidthF32(combined_string, 0, filter_string_offset); + F32 yy = (F32)getRect().getHeight() - font->getLineHeight() - (F32)TEXT_PAD - (F32)TOP_PAD; + font->renderUTF8( combined_string, filter_string_offset, match_string_left, yy, + sFilterTextColor, LLFontGL::LEFT, LLFontGL::BOTTOM, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, + filter_string_length, S32_MAX, &right_x, FALSE ); + } + offset_iter++; + size_iter++; } } + // End Multi-substring inventory search } diff --git a/indra/newview/llfolderviewitem.h b/indra/newview/llfolderviewitem.h index 914ef02df0..0e68800257 100644 --- a/indra/newview/llfolderviewitem.h +++ b/indra/newview/llfolderviewitem.h @@ -153,6 +153,12 @@ protected: BOOL mPassedFilter; S32 mLastFilterGeneration; std::string::size_type mStringMatchOffset; + + // Begin Multi-substring inventory search + std::vector mStringMatchOffsets; + std::vector mStringMatchSizes; + // End Multi-substring inventory search + F32 mControlLabelRotation; LLFolderView* mRoot; BOOL mDragAndDropTarget; diff --git a/indra/newview/llinventoryfilter.cpp b/indra/newview/llinventoryfilter.cpp index 252eac1b60..e9722a5ebd 100644 --- a/indra/newview/llinventoryfilter.cpp +++ b/indra/newview/llinventoryfilter.cpp @@ -70,6 +70,12 @@ LLInventoryFilter::LLInventoryFilter(const std::string& name) mSubStringMatchOffset = 0; mFilterSubString.clear(); + + // Begin Multi-substring inventory search + mSubStringMatchOffsets.clear(); + mFilterSubStrings.clear(); + // End Multi-substring inventory search + mFilterGeneration = 0; mMustPassGeneration = S32_MAX; mMinRequiredGeneration = 0; @@ -95,8 +101,38 @@ BOOL LLInventoryFilter::check(const LLFolderViewItem* item) { return TRUE; } + + // Begin Multi-substring inventory search + mSubStringMatchOffset = std::string::npos; + if (mFilterSubStrings.size()) + { + const std::string& searchLabel = item->getSearchableLabel(); + + U32 index = 0; + for (std::vector::iterator it=mFilterSubStrings.begin(); + itgetSearchableLabel().find(mFilterSubString) : std::string::npos; + mSubStringMatchOffsets[index] = sub_string_offset; + + if (sub_string_offset == std::string::npos) + { + mSubStringMatchOffset = std::string::npos; + for (std::vector::iterator it=mSubStringMatchOffsets.begin(); + it= filter_sub_string_new.size() && !mFilterSubString.substr(0, filter_sub_string_new.size()).compare(filter_sub_string_new); @@ -394,6 +450,7 @@ void LLInventoryFilter::setFilterSubString(const std::string& string) && !filter_sub_string_new.substr(0, mFilterSubString.size()).compare(mFilterSubString); mFilterSubString = filter_sub_string_new; + if (less_restrictive) { setModified(FILTER_LESS_RESTRICTIVE); @@ -420,6 +477,7 @@ void LLInventoryFilter::setFilterSubString(const std::string& string) mFilterOps.mFilterLinks = FILTERLINK_INCLUDE_LINKS; } } + // End Multi-substring inventory search } void LLInventoryFilter::setFilterPermissions(PermissionMask perms) @@ -978,3 +1036,25 @@ const std::string& LLInventoryFilter::getEmptyLookupMessage() const return mEmptyLookupMessage; } + +// Begin Multi-substring inventory search + +// For use by LLFolderViewItem for highlighting + +U32 LLInventoryFilter::getFilterSubStringCount() const +{ + return mFilterSubStrings.size(); +} + +std::string::size_type LLInventoryFilter::getFilterSubStringPos(U32 index) const +{ + if (index < 0 || index >= mSubStringMatchOffsets.size()) return std::string::npos; + return mSubStringMatchOffsets[index]; +} + +std::string::size_type LLInventoryFilter::getFilterSubStringLen(U32 index) const +{ + if (index < 0 || index >= mFilterSubStrings.size()) return 0; + return mFilterSubStrings[index].size(); +} +// End Multi-substring inventory search \ No newline at end of file diff --git a/indra/newview/llinventoryfilter.h b/indra/newview/llinventoryfilter.h index 7d38d468b1..47e74d5490 100644 --- a/indra/newview/llinventoryfilter.h +++ b/indra/newview/llinventoryfilter.h @@ -30,6 +30,10 @@ #include "llinventorytype.h" #include "llpermissionsflags.h" +// Begin Multi-substring inventory search +#include +// End Multi-substring inventory search + class LLFolderViewItem; class LLFolderViewFolder; @@ -95,6 +99,13 @@ public: const std::string& getFilterSubString(BOOL trim = FALSE) const; const std::string& getFilterSubStringOrig() const { return mFilterSubStringOrig; } BOOL hasFilterString() const; + + // Begin Multi-substring inventory search + // For use by LLFolderViewItem for highlighting + U32 getFilterSubStringCount() const; + std::string::size_type getFilterSubStringPos(U32 index) const; + std::string::size_type getFilterSubStringLen(U32 index) const; + // End Multi-substring inventory search void setFilterPermissions(PermissionMask perms); PermissionMask getFilterPermissions() const; @@ -203,6 +214,12 @@ private: std::string::size_type mSubStringMatchOffset; std::string mFilterSubString; + + // Begin Multi-substring inventory search + std::vector mSubStringMatchOffsets; + std::vector mFilterSubStrings; + // End Multi-substring inventory search + std::string mFilterSubStringOrig; const std::string mName; diff --git a/indra/newview/skins/default/xui/en/panel_main_inventory.xml b/indra/newview/skins/default/xui/en/panel_main_inventory.xml index 3eb3b31eb7..7346804460 100644 --- a/indra/newview/skins/default/xui/en/panel_main_inventory.xml +++ b/indra/newview/skins/default/xui/en/panel_main_inventory.xml @@ -34,6 +34,7 @@ left="10" max_length_chars="300" name="inventory search editor" + tool_tip="Type in one or more words to search for, separated by '+' " top_pad="4" width="322" />