summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llclipboard.cpp136
-rw-r--r--indra/llui/llclipboard.h72
-rw-r--r--indra/llui/lllineeditor.cpp19
-rw-r--r--indra/llui/llscrolllistctrl.cpp2
-rw-r--r--indra/llui/lltexteditor.cpp20
5 files changed, 130 insertions, 119 deletions
diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp
index 6910b962a1..14173fdbb0 100644
--- a/indra/llui/llclipboard.cpp
+++ b/indra/llui/llclipboard.cpp
@@ -34,109 +34,113 @@
#include "llview.h"
#include "llwindow.h"
-// Global singleton
-LLClipboard gClipboard;
-
-
-LLClipboard::LLClipboard()
+LLClipboard::LLClipboard() :
+ mGeneration(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 count
+ mGeneration++;
+ // Clear the clipboard
+ mObjects.clear();
+ mCutMode = false;
+ 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.push_back(src);
+ mGeneration++;
}
}
- else
- {
- LLView::getWindow()->pasteTextFromClipboard(mString);
- }
+ return res;
+}
- if( source_id )
+bool LLClipboard::pasteFromClipboard(std::vector<LLUUID>& inv_objects) const
+{
+ bool res = false;
+ S32 count = mObjects.size();
+ if (count > 0)
{
- *source_id = mSourceID;
+ res = true;
+ inv_objects.clear();
+ for (S32 i = 0; i < count; i++)
+ {
+ inv_objects.push_back(mObjects[i]);
+ }
}
-
- return mString;
+ return res;
}
+// Returns true if the LL Clipboard has pasteable items in it
+bool LLClipboard::hasContents() const
+{
+ return (mObjects.size() > 0);
+}
-BOOL LLClipboard::canPasteString() const
+// Returns true if the input uuid is in the list of clipboard objects
+bool LLClipboard::isOnClipboard(const LLUUID& object) const
{
- return LLView::getWindow()->isClipboardTextAvailable();
+ std::vector<LLUUID>::const_iterator iter = std::find(mObjects.begin(), mObjects.end(), object);
+ return (iter != mObjects.end());
}
+// Copy the input string to the LL and the system clipboard
+bool LLClipboard::copyToClipboard(const LLWString &src, S32 pos, S32 len, bool use_primary)
+{
+ return addToClipboard(src, pos, len, use_primary);
+}
-void LLClipboard::copyFromPrimarySubstring(const LLWString &src, S32 pos, S32 len, const 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)
{
- mSourceID = source_id;
mString = src.substr(pos, len);
- LLView::getWindow()->copyTextToPrimary( mString );
+ return (use_primary ? LLView::getWindow()->copyTextToPrimary(mString) : LLView::getWindow()->copyTextToClipboard(mString));
}
-
-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( mSourceID.notNull() )
- {
- LLWString temp_string;
- LLView::getWindow()->pasteTextFromPrimary(temp_string);
-
- if( temp_string != mString )
- {
- mSourceID.setNull();
- mString = temp_string;
- }
- }
- else
- {
- LLView::getWindow()->pasteTextFromPrimary(mString);
- }
-
- if( source_id )
+ bool res = (use_primary ? LLView::getWindow()->pasteTextFromPrimary(dst) : LLView::getWindow()->pasteTextFromClipboard(dst));
+ if (res)
{
- *source_id = mSourceID;
+ 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, "");
-}
diff --git a/indra/llui/llclipboard.h b/indra/llui/llclipboard.h
index 9371b94284..fd2e7610df 100644
--- a/indra/llui/llclipboard.h
+++ b/indra/llui/llclipboard.h
@@ -27,46 +27,68 @@
#ifndef LL_LLCLIPBOARD_H
#define LL_LLCLIPBOARD_H
+#include <boost/function.hpp>
#include "llstring.h"
#include "lluuid.h"
#include "stdenums.h"
+#include "llsingleton.h"
+#include "llassettype.h"
#include "llinventory.h"
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Class LLClipboard
+//
+// This class is used to cut/copy/paste text strings and inventory items around
+// the world. Use LLClipboard::instance().method() to use its methods.
+// Note that the text and UUIDs are loosely coupled only. There are few cases
+// where the viewer does offer a serialized version of the UUID on the clipboard.
+// In those case, the text is overridden when copying/cutting the item.
+// In all other cases, the text and the UUIDs are very much independent.
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-class LLClipboard
+class LLClipboard : public LLSingleton<LLClipboard>
{
public:
LLClipboard();
~LLClipboard();
+
+ // Clears the clipboard
+ void reset();
+ // Returns the state of the clipboard so client can know if it has been modified (comparing with tracked state)
+ int getGeneration() const { return mGeneration; }
- /* We support two flavors of clipboard. The default is the explicitly
- copy-and-pasted clipboard. The second is the so-called 'primary' clipboard
- which is implicitly copied upon selection on platforms which expect this
- (i.e. X11/Linux). */
-
- 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);
+ // Text strings management:
+ // ------------------------
+ // We support two flavors of text clipboards. The default is the explicitly
+ // copy-and-pasted clipboard. The second is the so-called 'primary' clipboard
+ // which is implicitly copied upon selection on platforms which expect this
+ // (i.e. X11/Linux, Mac).
+ bool copyToClipboard(const LLWString& src, S32 pos, S32 len, bool use_primary = false);
+ bool addToClipboard(const LLWString& src, S32 pos, S32 len, bool use_primary = false);
+ bool pasteFromClipboard(LLWString& dst, bool use_primary = false);
+ bool isTextAvailable(bool use_primary = false) const;
+
+ // Object list management:
+ // -----------------------
+ // Clears and adds one single object to the clipboard
+ bool copyToClipboard(const LLUUID& src, const LLAssetType::EType type = LLAssetType::AT_NONE);
+ // Adds one object to the current list of objects on the clipboard
+ bool addToClipboard(const LLUUID& src, const LLAssetType::EType type = LLAssetType::AT_NONE);
+ // Gets a copy of the objects on the clipboard
+ bool pasteFromClipboard(std::vector<LLUUID>& inventory_objects) const;
+
+ bool hasContents() const; // True if the clipboard has pasteable objects
+ bool isOnClipboard(const LLUUID& object) const; // True if the input object uuid is on the clipboard
- 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);
+ bool isCutMode() const { return mCutMode; }
+ void setCutMode(bool mode) { mCutMode = mode; mGeneration++; }
- // Support clipboard for object known only by their uuid and asset type
- void setSourceObject(const LLUUID& source_id, LLAssetType::EType type);
- const LLInventoryObject* getSourceObject() { return mSourceItem; }
-
private:
- LLUUID mSourceID;
- LLWString mString;
- LLInventoryObject* mSourceItem;
+ std::vector<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) if the asset type is knowable.
+ bool mCutMode; // This is a convenience flag for the viewer.
+ int mGeneration; // Incremented when the clipboard changes so that interested parties can check for changes on the clipboard.
};
-
-// Global singleton
-extern LLClipboard gClipboard;
-
-
#endif // LL_LLCLIPBOARD_H
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp
index 7e84814c51..d0fbf4b913 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 );
- gClipboard.copyFromSubstring( mText.getWString(), left_pos, length );
+ LLClipboard::instance().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 );
- gClipboard.copyFromSubstring( mText.getWString(), left_pos, length );
+ LLClipboard::instance().copyToClipboard( mText.getWString(), left_pos, length );
}
}
BOOL LLLineEditor::canPaste() const
{
- return !mReadOnly && gClipboard.canPasteString();
+ return !mReadOnly && LLClipboard::instance().isTextAvailable();
}
void LLLineEditor::paste()
@@ -1115,14 +1115,7 @@ void LLLineEditor::pasteHelper(bool is_primary)
if (can_paste_it)
{
LLWString paste;
- if (is_primary)
- {
- paste = gClipboard.getPastePrimaryWString();
- }
- else
- {
- paste = gClipboard.getPasteWString();
- }
+ LLClipboard::instance().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 );
- gClipboard.copyFromPrimarySubstring( mText.getWString(), left_pos, length );
+ LLClipboard::instance().copyToClipboard( mText.getWString(), left_pos, length, true);
}
}
BOOL LLLineEditor::canPastePrimary() const
{
- return !mReadOnly && gClipboard.canPastePrimaryString();
+ return !mReadOnly && LLClipboard::instance().isTextAvailable(true);
}
void LLLineEditor::updatePrimary()
diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp
index 466fac33ea..b3e1b63db5 100644
--- a/indra/llui/llscrolllistctrl.cpp
+++ b/indra/llui/llscrolllistctrl.cpp
@@ -2504,7 +2504,7 @@ void LLScrollListCtrl::copy()
{
buffer += (*itor)->getContentsCSV() + "\n";
}
- gClipboard.copyFromSubstring(utf8str_to_wstring(buffer), 0, buffer.length());
+ LLClipboard::instance().copyToClipboard(utf8str_to_wstring(buffer), 0, buffer.length());
}
// virtual
diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp
index 3409b6817d..9720dded6c 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 );
- gClipboard.copyFromSubstring( getWText(), left_pos, length, mSourceID );
+ LLClipboard::instance().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 );
- gClipboard.copyFromSubstring(getWText(), left_pos, length, mSourceID);
+ LLClipboard::instance().copyToClipboard(getWText(), left_pos, length);
}
BOOL LLTextEditor::canPaste() const
{
- return !mReadOnly && gClipboard.canPasteString();
+ return !mReadOnly && LLClipboard::instance().isTextAvailable();
}
// paste from clipboard
@@ -1393,16 +1393,8 @@ void LLTextEditor::pasteHelper(bool is_primary)
return;
}
- LLUUID source_id;
LLWString paste;
- if (is_primary)
- {
- paste = gClipboard.getPastePrimaryWString(&source_id);
- }
- else
- {
- paste = gClipboard.getPasteWString(&source_id);
- }
+ LLClipboard::instance().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 );
- gClipboard.copyFromPrimarySubstring(getWText(), left_pos, length, mSourceID);
+ LLClipboard::instance().copyToClipboard(getWText(), left_pos, length, true);
}
BOOL LLTextEditor::canPastePrimary() const
{
- return !mReadOnly && gClipboard.canPastePrimaryString();
+ return !mReadOnly && LLClipboard::instance().isTextAvailable(true);
}
void LLTextEditor::updatePrimary()