From e233e4fb50e513b58f4452086182b60b25440fac Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Tue, 17 Oct 2023 01:35:47 +0300
Subject: [PATCH] SL-20232 Allow deletion of worn items #5

---
 indra/newview/llinventorybridge.cpp    |  2 +-
 indra/newview/llinventoryfunctions.cpp | 15 ++++++++++-----
 indra/newview/llinventorygallery.cpp   | 15 ++++++++++-----
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index 02ca331bffa..a12c4f7f762 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -4504,7 +4504,7 @@ void LLFolderBridge::buildContextMenuFolderOptions(U32 flags,   menuentry_vec_t&
         return;
     }
 
-	if (!isItemRemovable())
+	if (!isItemRemovable(false))
 	{
 		disabled_items.push_back(std::string("Delete"));
 	}
diff --git a/indra/newview/llinventoryfunctions.cpp b/indra/newview/llinventoryfunctions.cpp
index 849f6417580..c2cbf4b8ac2 100644
--- a/indra/newview/llinventoryfunctions.cpp
+++ b/indra/newview/llinventoryfunctions.cpp
@@ -3441,7 +3441,8 @@ void LLInventoryAction::onItemsRemovalConfirmation(const LLSD& notification, con
 
         // removeSelectedItems will change selection, collect worn items beforehand
         uuid_vec_t worn;
-        uuid_vec_t deletion_list;
+        uuid_vec_t item_deletion_list;
+        uuid_vec_t cat_deletion_list;
         if (has_worn)
         {
             //Get selected items
@@ -3473,14 +3474,14 @@ void LLInventoryAction::onItemsRemovalConfirmation(const LLSD& notification, con
                     }
                     if (cat_has_worn)
                     {
-                        deletion_list.push_back(obj_id);
+                        cat_deletion_list.push_back(obj_id);
                     }
                 }
                 LLViewerInventoryItem* item = gInventory.getItem(obj_id);
                 if (item && get_is_item_worn(item))
                 {
                     worn.push_back(obj_id);
-                    deletion_list.push_back(obj_id);
+                    item_deletion_list.push_back(obj_id);
                 }
             }
         }
@@ -3495,12 +3496,16 @@ void LLInventoryAction::onItemsRemovalConfirmation(const LLSD& notification, con
         {
             // should fire once after every item gets detached
             LLAppearanceMgr::instance().removeItemsFromAvatar(worn,
-                                                              [deletion_list]()
+                                                              [item_deletion_list, cat_deletion_list]()
                                                               {
-                                                                  for (const LLUUID& id : deletion_list)
+                                                                  for (const LLUUID& id : item_deletion_list)
                                                                   {
                                                                       remove_inventory_item(id, NULL);
                                                                   }
+                                                                  for (const LLUUID& id : cat_deletion_list)
+                                                                  {
+                                                                      remove_inventory_category(id, NULL);
+                                                                  }
                                                               });
         }
 
diff --git a/indra/newview/llinventorygallery.cpp b/indra/newview/llinventorygallery.cpp
index 058bbde8b9e..d5fce2cda76 100644
--- a/indra/newview/llinventorygallery.cpp
+++ b/indra/newview/llinventorygallery.cpp
@@ -1866,7 +1866,8 @@ void LLInventoryGallery::onDelete(const LLSD& notification, const LLSD& response
     {
         bool has_worn = notification["payload"]["has_worn"].asBoolean();
         uuid_vec_t worn;
-        uuid_vec_t deletion_list;
+        uuid_vec_t item_deletion_list;
+        uuid_vec_t cat_deletion_list;
         for (const LLUUID& obj_id : selected_ids)
         {
             LLViewerInventoryCategory* cat = gInventory.getCategory(obj_id);
@@ -1891,7 +1892,7 @@ void LLInventoryGallery::onDelete(const LLSD& notification, const LLSD& response
                 }
                 if (cat_has_worn)
                 {
-                    deletion_list.push_back(obj_id);
+                    cat_deletion_list.push_back(obj_id);
                 }
                 else
                 {
@@ -1904,7 +1905,7 @@ void LLInventoryGallery::onDelete(const LLSD& notification, const LLSD& response
                 if (has_worn && get_is_item_worn(item))
                 {
                     worn.push_back(item->getUUID());
-                    deletion_list.push_back(item->getUUID());
+                    item_deletion_list.push_back(item->getUUID());
                 }
                 else
                 {
@@ -1917,12 +1918,16 @@ void LLInventoryGallery::onDelete(const LLSD& notification, const LLSD& response
         {
             // should fire once after every item gets detached
             LLAppearanceMgr::instance().removeItemsFromAvatar(worn,
-                                                              [deletion_list]()
+                                                              [item_deletion_list, cat_deletion_list]()
                                                               {
-                                                                  for (const LLUUID& id : deletion_list)
+                                                                  for (const LLUUID& id : item_deletion_list)
                                                                   {
                                                                       remove_inventory_item(id, NULL);
                                                                   }
+                                                                  for (const LLUUID& id : cat_deletion_list)
+                                                                  {
+                                                                      remove_inventory_category(id, NULL);
+                                                                  }
                                                               });
         }
     }
-- 
GitLab