diff options
Diffstat (limited to 'indra/newview/llviewermenu.cpp')
-rw-r--r-- | indra/newview/llviewermenu.cpp | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index 9f43fa1ac2..12b15b1367 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -7342,37 +7342,70 @@ class LLAttachmentDetach : public view_listener_t { // Called when the user clicked on an object attached to them // and selected "Detach". - LLViewerObject *object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject(); + LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection(); + LLViewerObject *object = selection->getPrimaryObject(); if (!object) { LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL; return true; } - LLViewerObject *parent = (LLViewerObject*)object->getParent(); + struct f: public LLSelectedObjectFunctor + { + f() : mAvatarsInSelection(false) {} + virtual bool apply(LLViewerObject* objectp) + { + if (!objectp) + { + return false; + } + + if (objectp->isAvatar()) + { + mAvatarsInSelection = true; + return false; + } + + LLViewerObject* parent = (LLViewerObject*)objectp->getParent(); while (parent) { if(parent->isAvatar()) { break; } - object = parent; + objectp = parent; parent = (LLViewerObject*)parent->getParent(); } - if (!object) - { - LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL; + // std::set to avoid dupplicate 'roots' from linksets + mRemoveSet.insert(objectp->getAttachmentItemID()); + return true; } + bool mAvatarsInSelection; + uuid_set_t mRemoveSet; + } func; + // Probbly can run applyToRootObjects instead, + // but previous version of this code worked for any selected object + selection->applyToObjects(&func); - if (object->isAvatar()) + if (func.mAvatarsInSelection) { + // Not possible under normal circumstances + // Either avatar selection is ON or has to do with animeshes + // Better stop this than mess something LL_WARNS() << "Trying to detach avatar from avatar." << LL_ENDL; return true; } - LLAppearanceMgr::instance().removeItemFromAvatar(object->getAttachmentItemID()); + if (func.mRemoveSet.empty()) + { + LL_WARNS() << "handle_detach() - no valid attachments in selection to detach" << LL_ENDL; + return true; + } + + uuid_vec_t detach_list(func.mRemoveSet.begin(), func.mRemoveSet.end()); + LLAppearanceMgr::instance().removeItemsFromAvatar(detach_list); return true; } |