summaryrefslogtreecommitdiff
path: root/indra/llui/llclipboard.cpp
diff options
context:
space:
mode:
authorMerov Linden <merov@lindenlab.com>2012-02-06 15:43:53 -0800
committerMerov Linden <merov@lindenlab.com>2012-02-06 15:43:53 -0800
commit9761375ac244af36635899c73e99efc46b68b589 (patch)
treefa48adfda40be0cced2c0425a09ddde99a1faf23 /indra/llui/llclipboard.cpp
parentdb824cff75696c42fff80ba29dbb60f12d10a1da (diff)
EXP-1841 : Refactoring of LLClipboard, simplify the API and make it behave like a normal clipboard.
Diffstat (limited to 'indra/llui/llclipboard.cpp')
-rw-r--r--indra/llui/llclipboard.cpp112
1 files changed, 31 insertions, 81 deletions
diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp
index 8917dc2d88..5c8db29ae4 100644
--- a/indra/llui/llclipboard.cpp
+++ b/indra/llui/llclipboard.cpp
@@ -91,112 +91,62 @@ void LLClipboard::reset()
mCutMode = false;
}
-// returns true if the clipboard has something pasteable in it.
+// Returns true if the LL Clipboard has pasteable items in it
BOOL LLClipboard::hasContents() const
{
return (mObjects.count() > 0);
}
-
-void LLClipboard::copyFromSubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
+// 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();
- if (source_id.notNull())
- {
- store(source_id);
- }
mString = src.substr(pos, len);
- llinfos << "Merov debug : copyFromSubstring, string = " << wstring_to_utf8str(mString) << ", uuid = " << (hasContents() ? mObjects[0] : LLUUID::null) << llendl;
- LLView::getWindow()->copyTextToClipboard( mString );
+ return (use_primary ? LLView::getWindow()->copyTextToPrimary(mString) : LLView::getWindow()->copyTextToClipboard(mString));
}
-void LLClipboard::copyFromString(const LLWString &src, const LLUUID& source_id )
+// Copy the input uuid to the LL clipboard
+// Convert the uuid to string and copy that string to the system clipboard if legit
+bool LLClipboard::copyToClipboard(const LLUUID& src, const LLAssetType::EType type)
{
+ bool res = false;
reset();
- if (source_id.notNull())
- {
- store(source_id);
- }
- mString = src;
- llinfos << "Merov debug : copyFromString, string = " << wstring_to_utf8str(mString) << ", uuid = " << (hasContents() ? mObjects[0] : LLUUID::null) << llendl;
- LLView::getWindow()->copyTextToClipboard( mString );
-}
-
-const LLWString& LLClipboard::getPasteWString( LLUUID* source_id )
-{
- if (hasContents())
+ if (src.notNull())
{
- LLWString temp_string;
- LLView::getWindow()->pasteTextFromClipboard(temp_string);
-
- if (temp_string != mString)
+ res = true;
+ if (LLAssetType::lookupIsAssetIDKnowable(type))
{
- reset();
- mString = temp_string;
+ LLWString source = utf8str_to_wstring(src.asString());
+ res = copyToClipboard(source, 0, source.size());
+ }
+ if (res)
+ {
+ store(src);
}
}
- else
- {
- LLView::getWindow()->pasteTextFromClipboard(mString);
- }
-
- if (source_id)
- {
- *source_id = (hasContents() ? mObjects[0] : LLUUID::null);
- }
-
- llinfos << "Merov debug : getPasteWString, string = " << wstring_to_utf8str(mString) << ", uuid = " << (hasContents() ? mObjects[0] : LLUUID::null) << llendl;
-
- return mString;
-}
-
-
-BOOL LLClipboard::canPasteString() const
-{
- return LLView::getWindow()->isClipboardTextAvailable();
-}
-
-
-void LLClipboard::copyFromPrimarySubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
-{
- reset();
- if (source_id.notNull())
- {
- store(source_id);
- }
- mString = src.substr(pos, len);
- LLView::getWindow()->copyTextToPrimary( mString );
+ return res;
}
-
-const LLWString& LLClipboard::getPastePrimaryWString( LLUUID* 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)
{
- if (hasContents())
+ bool res = (use_primary ? LLView::getWindow()->pasteTextFromPrimary(dst) : LLView::getWindow()->pasteTextFromClipboard(dst));
+ if (res)
{
- LLWString temp_string;
- LLView::getWindow()->pasteTextFromPrimary(temp_string);
-
- if (temp_string != mString)
+ 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 = temp_string;
}
+ mString = dst;
}
- else
- {
- LLView::getWindow()->pasteTextFromPrimary(mString);
- }
-
- if (source_id)
- {
- *source_id = (hasContents() ? mObjects[0] : LLUUID::null);
- }
-
- 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());
}
+