From bb6ace0672fa5e1c47c534ba74396ef04daa408b Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Fri, 17 Feb 2012 14:42:12 -0800
Subject: EXP-1902, EXP-1903 : Move items cut to the trash when clipboard
 reset.

---
 indra/llui/llclipboard.cpp          | 8 ++++++++
 indra/llui/llclipboard.h            | 9 +++++++--
 indra/newview/llfolderview.cpp      | 5 +----
 indra/newview/llfolderview.h        | 2 +-
 indra/newview/llinventorybridge.cpp | 2 +-
 5 files changed, 18 insertions(+), 8 deletions(-)

(limited to 'indra')

diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp
index ee1f1aa816..e0729366cc 100644
--- a/indra/llui/llclipboard.cpp
+++ b/indra/llui/llclipboard.cpp
@@ -47,9 +47,17 @@ LLClipboard::~LLClipboard()
 
 void LLClipboard::reset()
 {
+	// Increment the clipboard state
 	mState++;
+	// Call the cleanup function (if any) before releasing the object list
+	if (mCutMode && mCleanupCallback)
+	{
+		mCleanupCallback();
+	}
+	// Clear the clipboard
 	mObjects.reset();
 	mCutMode = false;
+	mCleanupCallback = NULL;
 	mString = LLWString();
 }
 
diff --git a/indra/llui/llclipboard.h b/indra/llui/llclipboard.h
index 0231169748..3947fa0229 100644
--- a/indra/llui/llclipboard.h
+++ b/indra/llui/llclipboard.h
@@ -27,6 +27,7 @@
 #ifndef LL_LLCLIPBOARD_H
 #define LL_LLCLIPBOARD_H
 
+#include <boost/function.hpp>
 
 #include "llstring.h"
 #include "lluuid.h"
@@ -35,6 +36,8 @@
 #include "llassettype.h"
 #include "llinventory.h"
 
+typedef boost::function<void ()> cleanup_callback_t;
+
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // Class LLClipboard
 //
@@ -77,13 +80,15 @@ public:
 	bool isOnClipboard(const LLUUID& object) const;					// True if the input object uuid is on the clipboard
 
 	bool isCutMode() const { return mCutMode; }
-	void setCutMode(bool mode) { mCutMode = mode; mState++; }
+	void setCutMode(bool mode, cleanup_callback_t cb = NULL) { mCutMode = mode; mCleanupCallback = cb; mState++; }
 
 private:
 	LLDynamicArray<LLUUID> mObjects;	// Objects on the clipboard. Can be empty while mString contains something licit (e.g. text from chat)
 	LLWString mString;					// The text string. If mObjects is not empty, this string is reflecting them (UUIDs for the moment).
-	bool mCutMode;						// This is a convenience flag for the viewer. It has no influence on the cliboard management.
+	bool mCutMode;						// This is a convenience flag for the viewer. Will determine if mCleanupCallback() needs to be called.
+	cleanup_callback_t mCleanupCallback;// Function to call when the cut clipboard is being wiped out. Can be set to NULL (nothing done then).
 	int mState;							// Incremented when the clipboard change so that interested parties can check its state.
+	
 };
 
 #endif  // LL_LLCLIPBOARD_H
diff --git a/indra/newview/llfolderview.cpp b/indra/newview/llfolderview.cpp
index 0abfa9db8e..52cc70aee7 100644
--- a/indra/newview/llfolderview.cpp
+++ b/indra/newview/llfolderview.cpp
@@ -1014,6 +1014,7 @@ bool isDescendantOfASelectedItem(LLFolderViewItem* item, const std::vector<LLFol
 	return false;
 }
 
+// static
 void LLFolderView::removeCutItems()
 {
 	// There's no item in "cut" mode on the clipboard -> exit
@@ -2139,10 +2140,6 @@ bool LLFolderView::doToSelected(LLInventoryModel* model, const LLSD& userdata)
 	}
 	if (("copy" == action) || ("cut" == action))
 	{
-		// If there are things on the clipboard that have not been pasted but 
-		// already disappeared from view, we need to move them to the trash
-		removeCutItems();
-		
 		// Clear the clipboard before we start adding things on it
 		LLClipboard::getInstance()->reset();
 	}
diff --git a/indra/newview/llfolderview.h b/indra/newview/llfolderview.h
index 2f148d4e25..9a1df5a142 100644
--- a/indra/newview/llfolderview.h
+++ b/indra/newview/llfolderview.h
@@ -159,7 +159,7 @@ public:
 
 	// deletion functionality
  	void removeSelectedItems();
- 	void removeCutItems();
+ 	static void removeCutItems();
 
 	// open the selected item.
 	void openSelectedItems( void );
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index eb0f9803b0..54d195a2e6 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -213,7 +213,7 @@ BOOL LLInvFVBridge::cutToClipboard() const
 	const LLInventoryObject* obj = gInventory.getObject(mUUID);
 	if (obj && isItemMovable() && isItemRemovable())
 	{
-		LLClipboard::getInstance()->setCutMode(true);
+		LLClipboard::getInstance()->setCutMode(true, boost::bind(LLFolderView::removeCutItems));
 		return LLClipboard::getInstance()->addToClipboard(mUUID,obj->getType());
 	}
 	return FALSE;
-- 
cgit v1.2.3