summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorMerov Linden <merov@lindenlab.com>2012-02-03 18:38:03 -0800
committerMerov Linden <merov@lindenlab.com>2012-02-03 18:38:03 -0800
commitdb824cff75696c42fff80ba29dbb60f12d10a1da (patch)
treea75b7732fcd322660d5c3e581ed0a6356298b147 /indra/llui
parentc1636911c84f948e542f445d3c7495e6df185912 (diff)
EXP-1862 : Suppress LLInventoryClipboard, move its functions to the unified LLClipboard and use this only
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llclipboard.cpp102
-rw-r--r--indra/llui/llclipboard.h27
2 files changed, 109 insertions, 20 deletions
diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp
index 984c4ec5fb..8917dc2d88 100644
--- a/indra/llui/llclipboard.cpp
+++ b/indra/llui/llclipboard.cpp
@@ -34,44 +34,104 @@
#include "llview.h"
#include "llwindow.h"
-// Global singleton
-LLClipboard gClipboard;
+LLClipboard::LLClipboard()
+: mCutMode(false)
+{
+}
+LLClipboard::~LLClipboard()
+{
+ reset();
+}
-LLClipboard::LLClipboard()
+void LLClipboard::add(const LLUUID& object)
{
+ mObjects.put(object);
}
+void LLClipboard::store(const LLUUID& object)
+{
+ reset();
+ mObjects.put(object);
+}
-LLClipboard::~LLClipboard()
+void LLClipboard::store(const LLDynamicArray<LLUUID>& inv_objects)
{
+ reset();
+ S32 count = inv_objects.count();
+ for(S32 i = 0; i < count; i++)
+ {
+ mObjects.put(inv_objects[i]);
+ }
+}
+
+void LLClipboard::cut(const LLUUID& object)
+{
+ if(!mCutMode && !mObjects.empty())
+ {
+ //looks like there are some stored items, reset clipboard state
+ reset();
+ }
+ mCutMode = true;
+ add(object);
+}
+void LLClipboard::retrieve(LLDynamicArray<LLUUID>& inv_objects) const
+{
+ inv_objects.reset();
+ S32 count = mObjects.count();
+ for(S32 i = 0; i < count; i++)
+ {
+ inv_objects.put(mObjects[i]);
+ }
+}
+
+void LLClipboard::reset()
+{
+ mObjects.reset();
+ mCutMode = false;
+}
+
+// returns true if the clipboard has something pasteable in it.
+BOOL LLClipboard::hasContents() const
+{
+ return (mObjects.count() > 0);
}
void LLClipboard::copyFromSubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
{
- mSourceID = source_id;
+ 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 );
}
void LLClipboard::copyFromString(const LLWString &src, const LLUUID& source_id )
{
- mSourceID = source_id;
+ 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( mSourceID.notNull() )
+ if (hasContents())
{
LLWString temp_string;
LLView::getWindow()->pasteTextFromClipboard(temp_string);
- if( temp_string != mString )
+ if (temp_string != mString)
{
- mSourceID.setNull();
+ reset();
mString = temp_string;
}
}
@@ -80,11 +140,13 @@ const LLWString& LLClipboard::getPasteWString( LLUUID* source_id )
LLView::getWindow()->pasteTextFromClipboard(mString);
}
- if( source_id )
+ if (source_id)
{
- *source_id = mSourceID;
+ *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;
}
@@ -97,7 +159,11 @@ BOOL LLClipboard::canPasteString() const
void LLClipboard::copyFromPrimarySubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
{
- mSourceID = source_id;
+ reset();
+ if (source_id.notNull())
+ {
+ store(source_id);
+ }
mString = src.substr(pos, len);
LLView::getWindow()->copyTextToPrimary( mString );
}
@@ -105,14 +171,14 @@ void LLClipboard::copyFromPrimarySubstring(const LLWString &src, S32 pos, S32 le
const LLWString& LLClipboard::getPastePrimaryWString( LLUUID* source_id )
{
- if( mSourceID.notNull() )
+ if (hasContents())
{
LLWString temp_string;
LLView::getWindow()->pasteTextFromPrimary(temp_string);
- if( temp_string != mString )
+ if (temp_string != mString)
{
- mSourceID.setNull();
+ reset();
mString = temp_string;
}
}
@@ -121,11 +187,11 @@ const LLWString& LLClipboard::getPastePrimaryWString( LLUUID* source_id )
LLView::getWindow()->pasteTextFromPrimary(mString);
}
- if( source_id )
+ if (source_id)
{
- *source_id = mSourceID;
+ *source_id = (hasContents() ? mObjects[0] : LLUUID::null);
}
-
+
return mString;
}
diff --git a/indra/llui/llclipboard.h b/indra/llui/llclipboard.h
index 2567eaab48..2cb857145e 100644
--- a/indra/llui/llclipboard.h
+++ b/indra/llui/llclipboard.h
@@ -34,6 +34,13 @@
#include "llsingleton.h"
#include "llinventory.h"
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Class LLClipboard
+//
+// This class is used to cut/copy/paste text strings and inventory items around
+// the world. Use LLClipboard::getInstance()->method() to use its methods.
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
class LLClipboard : public LLSingleton<LLClipboard>
{
public:
@@ -45,20 +52,36 @@ 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; }
+ //void setSourceObject(const LLUUID& source_id) { mSourceID = source_id; }
+
+ // Object list management
+ void add(const LLUUID& object); // Adds to the current list of objects on the clipboard
+ void store(const LLUUID& object); // Stores a single inventory object
+ void store(const LLDynamicArray<LLUUID>& inventory_objects); // Stores an array of objects
+ void cut(const LLUUID& object); // Adds to the current list of cut objects on the clipboard
+ void retrieve(LLDynamicArray<LLUUID>& inventory_objects) const; // Gets a copy of the objects on the clipboard
+ void reset(); // Clears the clipboard
+ BOOL hasContents() const; // true if the clipboard has something pasteable in it
+ bool isCutMode() const { return mCutMode; }
+
private:
- LLUUID mSourceID;
+ // *TODO: To know if an asset ID can be serialized, check out LLAssetType::lookupIsAssetIDKnowable(EType asset_type)
+ LLDynamicArray<LLUUID> mObjects;
+ bool mCutMode;
+
LLWString mString;
};