summaryrefslogtreecommitdiff
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
parentdb824cff75696c42fff80ba29dbb60f12d10a1da (diff)
EXP-1841 : Refactoring of LLClipboard, simplify the API and make it behave like a normal clipboard.
-rw-r--r--indra/llui/llclipboard.cpp112
-rw-r--r--indra/llui/llclipboard.h23
-rw-r--r--indra/llui/lllineeditor.cpp19
-rw-r--r--indra/llui/llscrolllistctrl.cpp2
-rw-r--r--indra/llui/lltexteditor.cpp20
-rw-r--r--indra/newview/llfavoritesbar.cpp2
-rw-r--r--indra/newview/llfloatergesture.cpp2
-rw-r--r--indra/newview/llinventorybridge.cpp3
-rw-r--r--indra/newview/llpanelteleporthistory.cpp2
-rw-r--r--indra/newview/llpaneltopinfobar.cpp2
-rw-r--r--indra/newview/llpanelwearing.cpp2
-rw-r--r--indra/newview/llurllineeditorctrl.cpp2
12 files changed, 60 insertions, 131 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());
}
+
diff --git a/indra/llui/llclipboard.h b/indra/llui/llclipboard.h
index 2cb857145e..bb2d003703 100644
--- a/indra/llui/llclipboard.h
+++ b/indra/llui/llclipboard.h
@@ -32,6 +32,7 @@
#include "lluuid.h"
#include "stdenums.h"
#include "llsingleton.h"
+#include "llassettype.h"
#include "llinventory.h"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -52,19 +53,11 @@ public:
which is implicitly copied upon selection on platforms which expect this
(i.e. X11/Linux). */
- // Text strings management
- void copyFromSubstring(const LLWString &copy_from, S32 pos, S32 len, const LLUUID& source_id = LLUUID::null );
- void copyFromString(const LLWString &copy_from, const LLUUID& source_id = LLUUID::null );
- BOOL canPasteString() const;
- const LLWString& getPasteWString(LLUUID* source_id = NULL);
-
- // Primary text string management (Linux gtk implementation)
- void copyFromPrimarySubstring(const LLWString &copy_from, S32 pos, S32 len, const LLUUID& source_id = LLUUID::null );
- BOOL canPastePrimaryString() const;
- const LLWString& getPastePrimaryWString(LLUUID* source_id = NULL);
-
- // Support clipboard for object known only by their uuid
- //void setSourceObject(const LLUUID& source_id) { mSourceID = source_id; }
+ // Text strings and single item management
+ bool copyToClipboard(const LLWString& src, S32 pos, S32 len, bool use_primary = false);
+ bool copyToClipboard(const LLUUID& src, const LLAssetType::EType type = LLAssetType::AT_NONE);
+ bool pasteFromClipboard(LLWString& dst, bool use_primary = false);
+ bool isTextAvailable(bool use_primary = false) const;
// Object list management
void add(const LLUUID& object); // Adds to the current list of objects on the clipboard
@@ -78,11 +71,9 @@ public:
bool isCutMode() const { return mCutMode; }
private:
- // *TODO: To know if an asset ID can be serialized, check out LLAssetType::lookupIsAssetIDKnowable(EType asset_type)
LLDynamicArray<LLUUID> mObjects;
bool mCutMode;
-
- LLWString mString;
+ LLWString mString;
};
#endif // LL_LLCLIPBOARD_H
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp
index 9292158b7c..e961cfb14f 100644
--- a/indra/llui/lllineeditor.cpp
+++ b/indra/llui/lllineeditor.cpp
@@ -1047,7 +1047,7 @@ void LLLineEditor::cut()
// Prepare for possible rollback
LLLineEditorRollback rollback( this );
- LLClipboard::getInstance()->copyFromSubstring( mText.getWString(), left_pos, length );
+ LLClipboard::getInstance()->copyToClipboard( mText.getWString(), left_pos, length );
deleteSelection();
// Validate new string and rollback the if needed.
@@ -1078,13 +1078,13 @@ void LLLineEditor::copy()
{
S32 left_pos = llmin( mSelectionStart, mSelectionEnd );
S32 length = llabs( mSelectionStart - mSelectionEnd );
- LLClipboard::getInstance()->copyFromSubstring( mText.getWString(), left_pos, length );
+ LLClipboard::getInstance()->copyToClipboard( mText.getWString(), left_pos, length );
}
}
BOOL LLLineEditor::canPaste() const
{
- return !mReadOnly && LLClipboard::getInstance()->canPasteString();
+ return !mReadOnly && LLClipboard::getInstance()->isTextAvailable();
}
void LLLineEditor::paste()
@@ -1115,14 +1115,7 @@ void LLLineEditor::pasteHelper(bool is_primary)
if (can_paste_it)
{
LLWString paste;
- if (is_primary)
- {
- paste = LLClipboard::getInstance()->getPastePrimaryWString();
- }
- else
- {
- paste = LLClipboard::getInstance()->getPasteWString();
- }
+ LLClipboard::getInstance()->pasteFromClipboard(paste, is_primary);
if (!paste.empty())
{
@@ -1209,13 +1202,13 @@ void LLLineEditor::copyPrimary()
{
S32 left_pos = llmin( mSelectionStart, mSelectionEnd );
S32 length = llabs( mSelectionStart - mSelectionEnd );
- LLClipboard::getInstance()->copyFromPrimarySubstring( mText.getWString(), left_pos, length );
+ LLClipboard::getInstance()->copyToClipboard( mText.getWString(), left_pos, length, true);
}
}
BOOL LLLineEditor::canPastePrimary() const
{
- return !mReadOnly && LLClipboard::getInstance()->canPastePrimaryString();
+ return !mReadOnly && LLClipboard::getInstance()->isTextAvailable(true);
}
void LLLineEditor::updatePrimary()
diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp
index 8cbc2a8f99..0a9d862b66 100644
--- a/indra/llui/llscrolllistctrl.cpp
+++ b/indra/llui/llscrolllistctrl.cpp
@@ -2504,7 +2504,7 @@ void LLScrollListCtrl::copy()
{
buffer += (*itor)->getContentsCSV() + "\n";
}
- LLClipboard::getInstance()->copyFromSubstring(utf8str_to_wstring(buffer), 0, buffer.length());
+ LLClipboard::getInstance()->copyToClipboard(utf8str_to_wstring(buffer), 0, buffer.length());
}
// virtual
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 22a577cda8..ffe012c110 100644
--- a/indra/llui/lltexteditor.cpp
+++ b/indra/llui/lltexteditor.cpp
@@ -1332,7 +1332,7 @@ void LLTextEditor::cut()
}
S32 left_pos = llmin( mSelectionStart, mSelectionEnd );
S32 length = llabs( mSelectionStart - mSelectionEnd );
- LLClipboard::getInstance()->copyFromSubstring( getWText(), left_pos, length, mSourceID );
+ LLClipboard::getInstance()->copyToClipboard( getWText(), left_pos, length);
deleteSelection( FALSE );
onKeyStroke();
@@ -1352,12 +1352,12 @@ void LLTextEditor::copy()
}
S32 left_pos = llmin( mSelectionStart, mSelectionEnd );
S32 length = llabs( mSelectionStart - mSelectionEnd );
- LLClipboard::getInstance()->copyFromSubstring(getWText(), left_pos, length, mSourceID);
+ LLClipboard::getInstance()->copyToClipboard(getWText(), left_pos, length);
}
BOOL LLTextEditor::canPaste() const
{
- return !mReadOnly && LLClipboard::getInstance()->canPasteString();
+ return !mReadOnly && LLClipboard::getInstance()->isTextAvailable();
}
// paste from clipboard
@@ -1393,16 +1393,8 @@ void LLTextEditor::pasteHelper(bool is_primary)
return;
}
- LLUUID source_id;
LLWString paste;
- if (is_primary)
- {
- paste = LLClipboard::getInstance()->getPastePrimaryWString(&source_id);
- }
- else
- {
- paste = LLClipboard::getInstance()->getPasteWString(&source_id);
- }
+ LLClipboard::getInstance()->pasteFromClipboard(paste, is_primary);
if (paste.empty())
{
@@ -1475,12 +1467,12 @@ void LLTextEditor::copyPrimary()
}
S32 left_pos = llmin( mSelectionStart, mSelectionEnd );
S32 length = llabs( mSelectionStart - mSelectionEnd );
- LLClipboard::getInstance()->copyFromPrimarySubstring(getWText(), left_pos, length, mSourceID);
+ LLClipboard::getInstance()->copyToClipboard(getWText(), left_pos, length, true);
}
BOOL LLTextEditor::canPastePrimary() const
{
- return !mReadOnly && LLClipboard::getInstance()->canPastePrimaryString();
+ return !mReadOnly && LLClipboard::getInstance()->isTextAvailable(true);
}
void LLTextEditor::updatePrimary()
diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp
index c81bff4b5d..4308bf2d3c 100644
--- a/indra/newview/llfavoritesbar.cpp
+++ b/indra/newview/llfavoritesbar.cpp
@@ -1118,7 +1118,7 @@ BOOL LLFavoritesBarCtrl::handleRightMouseDown(S32 x, S32 y, MASK mask)
}
void copy_slurl_to_clipboard_cb(std::string& slurl)
{
- LLClipboard::getInstance()->copyFromString(utf8str_to_wstring(slurl));
+ LLClipboard::getInstance()->copyToClipboard(utf8str_to_wstring(slurl),0,slurl.size());
LLSD args;
args["SLURL"] = slurl;
diff --git a/indra/newview/llfloatergesture.cpp b/indra/newview/llfloatergesture.cpp
index 281cafa90d..3c647284f6 100644
--- a/indra/newview/llfloatergesture.cpp
+++ b/indra/newview/llfloatergesture.cpp
@@ -533,7 +533,7 @@ void LLFloaterGesture::onCopyPasteAction(const LLSD& command)
}
else if ("copy_uuid" == command_name)
{
- LLClipboard::getInstance()->copyFromString(utf8str_to_wstring(mGestureList->getCurrentID().asString()), mGestureList->getCurrentID());
+ LLClipboard::getInstance()->copyToClipboard(mGestureList->getCurrentID(),LLAssetType::AT_GESTURE);
}
}
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index 420b834933..14f1bb9d41 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -409,6 +409,9 @@ BOOL LLInvFVBridge::isClipboardPasteable() const
const LLUUID &agent_id = gAgent.getID();
+ // Merov : This should be suppressed for 2 reasons:
+ // 1. folders should be pastable
+ // 2. when pasting, we should paste what is authorized and let the rest not pasted
LLDynamicArray<LLUUID> objects;
LLClipboard::getInstance()->retrieve(objects);
S32 count = objects.count();
diff --git a/indra/newview/llpanelteleporthistory.cpp b/indra/newview/llpanelteleporthistory.cpp
index a4c9af3fad..f92fbf3220 100644
--- a/indra/newview/llpanelteleporthistory.cpp
+++ b/indra/newview/llpanelteleporthistory.cpp
@@ -358,7 +358,7 @@ void LLTeleportHistoryPanel::ContextMenu::onInfo()
//static
void LLTeleportHistoryPanel::ContextMenu::gotSLURLCallback(const std::string& slurl)
{
- LLClipboard::getInstance()->copyFromString(utf8str_to_wstring(slurl));
+ LLClipboard::getInstance()->copyToClipboard(utf8str_to_wstring(slurl),0,slurl.size());
}
void LLTeleportHistoryPanel::ContextMenu::onCopyToClipboard()
diff --git a/indra/newview/llpaneltopinfobar.cpp b/indra/newview/llpaneltopinfobar.cpp
index 0e3ff99066..0ad207ef00 100644
--- a/indra/newview/llpaneltopinfobar.cpp
+++ b/indra/newview/llpaneltopinfobar.cpp
@@ -467,7 +467,7 @@ void LLPanelTopInfoBar::onContextMenuItemClicked(const LLSD::String& item)
LLAgentUI::buildSLURL(slurl, false);
LLUIString location_str(slurl.getSLURLString());
- LLClipboard::getInstance()->copyFromString(location_str);
+ LLClipboard::getInstance()->copyToClipboard(location_str,0,location_str.length());
}
}
diff --git a/indra/newview/llpanelwearing.cpp b/indra/newview/llpanelwearing.cpp
index 1286756693..5199bcb6b1 100644
--- a/indra/newview/llpanelwearing.cpp
+++ b/indra/newview/llpanelwearing.cpp
@@ -302,6 +302,6 @@ void LLPanelWearing::copyToClipboard()
}
}
- LLClipboard::getInstance()->copyFromString(utf8str_to_wstring(text));
+ LLClipboard::getInstance()->copyToClipboard(utf8str_to_wstring(text),0,text.size());
}
// EOF
diff --git a/indra/newview/llurllineeditorctrl.cpp b/indra/newview/llurllineeditorctrl.cpp
index 9d7e26d41c..3efebcade9 100644
--- a/indra/newview/llurllineeditorctrl.cpp
+++ b/indra/newview/llurllineeditorctrl.cpp
@@ -89,5 +89,5 @@ void LLURLLineEditor::copyEscapedURLToClipboard()
else // human-readable location
text_to_copy = utf8str_to_wstring(unescaped_text);
- LLClipboard::getInstance()->copyFromString( text_to_copy );
+ LLClipboard::getInstance()->copyToClipboard(text_to_copy, 0, text_to_copy.size());
}