From e88ed1164adf3797f97ede40def40e0d85fc24f6 Mon Sep 17 00:00:00 2001
From: Todd Stinson <stinson@lindenlab.com>
Date: Fri, 10 Feb 2012 13:37:37 -0800
Subject: [PATCH] PATH-245: Adding functionality for returning objects to owner
 from the characters floater.

---
 .../llfloaterpathfindingcharacters.cpp        |  6 +--
 indra/newview/llviewermenu.cpp                | 49 +++++++++++++++++++
 indra/newview/llviewermenu.h                  |  2 +
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/indra/newview/llfloaterpathfindingcharacters.cpp b/indra/newview/llfloaterpathfindingcharacters.cpp
index 561ad9535bc..25642f02262 100644
--- a/indra/newview/llfloaterpathfindingcharacters.cpp
+++ b/indra/newview/llfloaterpathfindingcharacters.cpp
@@ -356,12 +356,12 @@ void LLFloaterPathfindingCharacters::onTakeCopyCharactersClicked()
 
 void LLFloaterPathfindingCharacters::onReturnCharactersClicked()
 {
-	llwarns << "functionality has not yet been implemented to return characters" << llendl;
+	handle_object_return();
 }
 
 void LLFloaterPathfindingCharacters::onDeleteCharactersClicked()
 {
-	handle_object_delete();
+	handle_object_delete();
 }
 
 void LLFloaterPathfindingCharacters::onTeleportCharacterToMeClicked()
@@ -528,7 +528,7 @@ void LLFloaterPathfindingCharacters::setEnableActionFields(BOOL pEnabled)
 	mShowBeaconCheckBox->setEnabled(pEnabled);
 	mTakeBtn->setEnabled(pEnabled && tools_visible_take_object());
 	mTakeCopyBtn->setEnabled(pEnabled && enable_object_take_copy());
-	mReturnBtn->setEnabled(false && pEnabled);
+	mReturnBtn->setEnabled(pEnabled && enable_object_return());
 	mDeleteBtn->setEnabled(pEnabled && enable_object_delete());
 	mTeleportBtn->setEnabled(pEnabled && (mCharactersScrollList->getNumSelected() == 1));
 }
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index d2c441ce737..92a01c22b31 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -5010,6 +5010,12 @@ class LLEditDelete : public view_listener_t
 	}
 };
 
+bool enable_object_return()
+{
+	return (!LLSelectMgr::getInstance()->getSelection()->isEmpty() &&
+		(gAgent.isGodlike() || can_derez(DRD_RETURN_TO_OWNER)));
+}
+
 bool enable_object_delete()
 {
 	bool new_value = 
@@ -5025,6 +5031,49 @@ bool enable_object_delete()
 	return new_value;
 }
 
+class LLObjectsReturnPackage
+{
+public:
+	LLObjectsReturnPackage() : mObjectSelection(), mReturnableObjects(), mError(),	mFirstRegion(NULL) {};
+	~LLObjectsReturnPackage()
+	{
+		mObjectSelection.clear();
+		mReturnableObjects.clear();
+		mError.clear();
+		mFirstRegion = NULL;
+	};
+
+	LLObjectSelectionHandle mObjectSelection;
+	LLDynamicArray<LLViewerObjectPtr> mReturnableObjects;
+	std::string mError;
+	LLViewerRegion *mFirstRegion;
+};
+
+static void return_objects(LLObjectsReturnPackage *objectsReturnPackage, const LLSD& notification, const LLSD& response)
+{
+	if (LLNotificationsUtil::getSelectedOption(notification, response) == 0)
+	{
+		// Ignore category ID for this derez destination.
+		derez_objects(DRD_RETURN_TO_OWNER, LLUUID::null, objectsReturnPackage->mFirstRegion, objectsReturnPackage->mError, &objectsReturnPackage->mReturnableObjects);
+	}
+
+	delete objectsReturnPackage;
+}
+
+void handle_object_return()
+{
+	if (!LLSelectMgr::getInstance()->getSelection()->isEmpty())
+	{
+		LLObjectsReturnPackage *objectsReturnPackage = new LLObjectsReturnPackage();
+		objectsReturnPackage->mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
+
+		// Save selected objects, so that we still know what to return after the confirmation dialog resets selection.
+		get_derezzable_objects(DRD_RETURN_TO_OWNER, objectsReturnPackage->mError, objectsReturnPackage->mFirstRegion, &objectsReturnPackage->mReturnableObjects);
+
+		LLNotificationsUtil::add("ReturnToOwner", LLSD(), LLSD(), boost::bind(&return_objects, objectsReturnPackage, _1, _2));
+	}
+}
+
 void handle_object_delete()
 {
 
diff --git a/indra/newview/llviewermenu.h b/indra/newview/llviewermenu.h
index 6316141e757..f10891737fd 100644
--- a/indra/newview/llviewermenu.h
+++ b/indra/newview/llviewermenu.h
@@ -96,6 +96,7 @@ void handle_object_open();
 bool visible_take_object();
 bool tools_visible_take_object();
 bool enable_object_take_copy();
+bool enable_object_return();
 bool enable_object_delete();
 
 // Buy either contents or object itself
@@ -104,6 +105,7 @@ void handle_take();
 void handle_take_copy();
 void handle_look_at_selection(const LLSD& param);
 void handle_zoom_to_object(LLUUID object_id);
+void handle_object_return();
 void handle_object_delete();
 
 void handle_buy_land();
-- 
GitLab