summaryrefslogtreecommitdiff
path: root/indra/llui/llclipboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/llclipboard.cpp')
-rw-r--r--indra/llui/llclipboard.cpp148
1 files changed, 86 insertions, 62 deletions
diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp
index 6910b962a1..e0729366cc 100644
--- a/indra/llui/llclipboard.cpp
+++ b/indra/llui/llclipboard.cpp
@@ -34,109 +34,133 @@
#include "llview.h"
#include "llwindow.h"
-// Global singleton
-LLClipboard gClipboard;
-
-
-LLClipboard::LLClipboard()
+LLClipboard::LLClipboard() :
+ mState(0)
{
- mSourceItem = NULL;
+ reset();
}
-
LLClipboard::~LLClipboard()
{
+ reset();
}
-
-void LLClipboard::copyFromSubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
+void LLClipboard::reset()
{
- mSourceID = source_id;
- mString = src.substr(pos, len);
- LLView::getWindow()->copyTextToClipboard( mString );
+ // 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();
}
-void LLClipboard::copyFromString(const LLWString &src, const LLUUID& source_id )
+// Copy the input uuid to the LL clipboard
+bool LLClipboard::copyToClipboard(const LLUUID& src, const LLAssetType::EType type)
{
- mSourceID = source_id;
- mString = src;
- LLView::getWindow()->copyTextToClipboard( mString );
+ reset();
+ return addToClipboard(src, type);
}
-const LLWString& LLClipboard::getPasteWString( LLUUID* source_id )
+// Add the input uuid to the LL clipboard
+// Convert the uuid to string and concatenate that string to the system clipboard if legit
+bool LLClipboard::addToClipboard(const LLUUID& src, const LLAssetType::EType type)
{
- if( mSourceID.notNull() )
+ bool res = false;
+ if (src.notNull())
{
- LLWString temp_string;
- LLView::getWindow()->pasteTextFromClipboard(temp_string);
-
- if( temp_string != mString )
+ res = true;
+ if (LLAssetType::lookupIsAssetIDKnowable(type))
{
- mSourceID.setNull();
- mString = temp_string;
+ LLWString source = utf8str_to_wstring(src.asString());
+ res = addToClipboard(source, 0, source.size());
+ }
+ if (res)
+ {
+ mObjects.put(src);
+ mState++;
}
}
- else
- {
- LLView::getWindow()->pasteTextFromClipboard(mString);
- }
+ return res;
+}
- if( source_id )
+bool LLClipboard::pasteFromClipboard(LLDynamicArray<LLUUID>& inv_objects) const
+{
+ bool res = false;
+ S32 count = mObjects.count();
+ if (count > 0)
{
- *source_id = mSourceID;
+ res = true;
+ inv_objects.reset();
+ for (S32 i = 0; i < count; i++)
+ {
+ inv_objects.put(mObjects[i]);
+ }
}
-
- return mString;
+ return res;
}
-
-BOOL LLClipboard::canPasteString() const
+// Returns true if the LL Clipboard has pasteable items in it
+bool LLClipboard::hasContents() const
{
- return LLView::getWindow()->isClipboardTextAvailable();
+ return (mObjects.count() > 0);
}
-
-void LLClipboard::copyFromPrimarySubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
+// Returns true if the input uuid is in the list of clipboard objects
+bool LLClipboard::isOnClipboard(const LLUUID& object) const
{
- mSourceID = source_id;
- mString = src.substr(pos, len);
- LLView::getWindow()->copyTextToPrimary( mString );
+ return (mObjects.find(object) != LLDynamicArray<LLUUID>::FAIL);
}
+// Copy the input string to the LL and the system clipboard
+bool LLClipboard::copyToClipboard(const LLWString &src, S32 pos, S32 len, bool use_primary)
+{
+ reset();
+ return addToClipboard(src, pos, len, use_primary);
+}
-const LLWString& LLClipboard::getPastePrimaryWString( LLUUID* source_id )
+// Concatenate the input string to the LL and the system clipboard
+bool LLClipboard::addToClipboard(const LLWString &src, S32 pos, S32 len, bool use_primary)
{
- if( mSourceID.notNull() )
+ const LLWString sep(utf8str_to_wstring(std::string(", ")));
+ if (mString.length() == 0)
{
- LLWString temp_string;
- LLView::getWindow()->pasteTextFromPrimary(temp_string);
-
- if( temp_string != mString )
- {
- mSourceID.setNull();
- mString = temp_string;
- }
+ mString = src.substr(pos, len);
}
else
{
- LLView::getWindow()->pasteTextFromPrimary(mString);
+ mString = mString + sep + src.substr(pos, len);
}
+ mState++;
+ return (use_primary ? LLView::getWindow()->copyTextToPrimary(mString) : LLView::getWindow()->copyTextToClipboard(mString));
+}
- if( source_id )
+// Copy the System clipboard to the output string.
+// Manage the LL Clipboard / System clipboard consistency
+bool LLClipboard::pasteFromClipboard(LLWString &dst, bool use_primary)
+{
+ bool res = (use_primary ? LLView::getWindow()->pasteTextFromPrimary(dst) : LLView::getWindow()->pasteTextFromClipboard(dst));
+ if (res)
{
- *source_id = mSourceID;
+ if (dst != mString)
+ {
+ // Invalidate the LL clipboard if the System had a different string in it (i.e. some copy/cut was done in some other app)
+ reset();
+ }
+ mString = dst;
}
-
- return mString;
+ return res;
}
-
-BOOL LLClipboard::canPastePrimaryString() const
+// Return true if there's something on the System clipboard
+bool LLClipboard::isTextAvailable(bool use_primary) const
{
- return LLView::getWindow()->isPrimaryTextAvailable();
+ return (use_primary ? LLView::getWindow()->isPrimaryTextAvailable() : LLView::getWindow()->isClipboardTextAvailable());
}
-void LLClipboard::setSourceObject(const LLUUID& source_id, LLAssetType::EType type)
-{
- mSourceItem = new LLInventoryObject (source_id, LLUUID::null, type, "");
-}