From 2e9671a8a8ec0a8897945c96aa62c77ad245abac Mon Sep 17 00:00:00 2001
From: Alexei Arabadji <aarabadji@productengine.com>
Date: Mon, 26 Jul 2010 10:33:43 +0300
Subject: [PATCH] EXT-8329 FIXED Provided disabling 'Wear Item' button after
 item was worn.

Details:
1 Updated condition is item can be worn considering situation when item is copied in COF but is not worn.
2 Avoided code duplication in method LLOutfitsList::canWearSelected()

reviewed by Vadim Savchuk and Neal Orman at https://codereview.productengine.com/secondlife/r/785/

--HG--
branch : product-engine
---
 indra/newview/llappearancemgr.cpp   | 15 +++++++++++++++
 indra/newview/llappearancemgr.h     |  5 +++++
 indra/newview/lloutfitslist.cpp     | 12 +-----------
 indra/newview/llpaneloutfitedit.cpp |  4 +++-
 4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp
index 5e0d49ac12b..ee0c77ef532 100644
--- a/indra/newview/llappearancemgr.cpp
+++ b/indra/newview/llappearancemgr.cpp
@@ -2699,6 +2699,21 @@ BOOL LLAppearanceMgr::getIsInCOF(const LLUUID& obj_id) const
 	return gInventory.isObjectDescendentOf(obj_id, getCOF());
 }
 
+// static
+bool LLAppearanceMgr::isLinkInCOF(const LLUUID& obj_id)
+{
+	 LLInventoryModel::cat_array_t cats;
+	 LLInventoryModel::item_array_t items;
+	 LLLinkedItemIDMatches find_links(gInventory.getLinkedItemID(obj_id));
+	 gInventory.collectDescendentsIf(LLAppearanceMgr::instance().getCOF(),
+	 cats,
+	 items,
+	 LLInventoryModel::EXCLUDE_TRASH,
+	 find_links);
+
+	 return !items.empty();
+}
+
 BOOL LLAppearanceMgr::getIsProtectedCOFItem(const LLUUID& obj_id) const
 {
 	if (!getIsInCOF(obj_id)) return FALSE;
diff --git a/indra/newview/llappearancemgr.h b/indra/newview/llappearancemgr.h
index a6cd129306d..e8df69b1794 100644
--- a/indra/newview/llappearancemgr.h
+++ b/indra/newview/llappearancemgr.h
@@ -223,6 +223,11 @@ class LLAppearanceMgr: public LLSingleton<LLAppearanceMgr>
 	BOOL getIsInCOF(const LLUUID& obj_id) const;
 	// Is this in the COF and can the user delete it from the COF?
 	BOOL getIsProtectedCOFItem(const LLUUID& obj_id) const;
+
+	/**
+	 * Checks if COF contains link to specified object.
+	 */
+	static bool isLinkInCOF(const LLUUID& obj_id);
 };
 
 class LLUpdateAppearanceOnDestroy: public LLInventoryCallback
diff --git a/indra/newview/lloutfitslist.cpp b/indra/newview/lloutfitslist.cpp
index 146684288b8..c3eee1d1ad8 100644
--- a/indra/newview/lloutfitslist.cpp
+++ b/indra/newview/lloutfitslist.cpp
@@ -1005,17 +1005,7 @@ bool LLOutfitsList::canWearSelected()
 	{
 		const LLUUID& id = *it;
 
-		// Find links to the current item in COF.
-		// *TODO: share this?
-		LLInventoryModel::cat_array_t cats;
-		LLInventoryModel::item_array_t items;
-		LLLinkedItemIDMatches find_links(gInventory.getLinkedItemID(id));
-		gInventory.collectDescendentsIf(LLAppearanceMgr::instance().getCOF(),
-										cats,
-										items,
-										LLInventoryModel::EXCLUDE_TRASH,
-										find_links);
-		if (!items.empty())
+		if (LLAppearanceMgr::isLinkInCOF(id))
 		{
 			return false;
 		}
diff --git a/indra/newview/llpaneloutfitedit.cpp b/indra/newview/llpaneloutfitedit.cpp
index c09aff44dae..38f637cabf3 100644
--- a/indra/newview/llpaneloutfitedit.cpp
+++ b/indra/newview/llpaneloutfitedit.cpp
@@ -779,7 +779,9 @@ void LLPanelOutfitEdit::updatePlusButton()
 	}
 
 	// If any of the selected items are not wearable (due to already being worn OR being of the wrong type), disable the add button.
-	uuid_vec_t::iterator unwearable_item = std::find_if(selected_items.begin(), selected_items.end(), !boost::bind(& get_can_item_be_worn, _1));
+	uuid_vec_t::iterator unwearable_item = std::find_if(selected_items.begin(), selected_items.end(), !boost::bind(& get_can_item_be_worn, _1)
+		// since item can be not worn but in wearing process at that time - we need to check is link to item presents in COF
+		|| boost::bind(&LLAppearanceMgr::isLinkInCOF, _1));
 	bool can_add = ( unwearable_item == selected_items.end() );
 
 	mPlusBtn->setEnabled(can_add);
-- 
GitLab