diff options
author | Merov Linden <merov@lindenlab.com> | 2012-02-07 22:46:04 -0800 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2012-02-07 22:46:04 -0800 |
commit | ee3c3c15b714f8f68e98a2d4064afaec665bd64a (patch) | |
tree | a75780d299d9cff782186107bebc7e193046de11 /indra/llui | |
parent | c744603af9b53c6bc73fefbd56de68cf2778ed70 (diff) |
EXP-1841 : Final deep scrub on LLClipboard API, clean up the use of copy and cut everywhere.
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/llclipboard.cpp | 96 | ||||
-rw-r--r-- | indra/llui/llclipboard.h | 44 |
2 files changed, 70 insertions, 70 deletions
diff --git a/indra/llui/llclipboard.cpp b/indra/llui/llclipboard.cpp index a2a3f7f285..7794a0537f 100644 --- a/indra/llui/llclipboard.cpp +++ b/indra/llui/llclipboard.cpp @@ -35,8 +35,8 @@ #include "llwindow.h" LLClipboard::LLClipboard() -: mCutMode(false) { + reset(); } LLClipboard::~LLClipboard() @@ -44,55 +44,59 @@ LLClipboard::~LLClipboard() reset(); } -void LLClipboard::add(const LLUUID& object) +void LLClipboard::reset() { - mObjects.put(object); + mObjects.reset(); + mCutMode = false; + mString = LLWString(); } -void LLClipboard::store(const LLUUID& object) +// Copy the input uuid to the LL clipboard +bool LLClipboard::copyToClipboard(const LLUUID& src, const LLAssetType::EType type) { reset(); - mObjects.put(object); + return addToClipboard(src, type); } -void LLClipboard::store(const LLDynamicArray<LLUUID>& inv_objects) +// 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) { - reset(); - S32 count = inv_objects.count(); - for(S32 i = 0; i < count; i++) + bool res = false; + if (src.notNull()) { - mObjects.put(inv_objects[i]); + res = true; + if (LLAssetType::lookupIsAssetIDKnowable(type)) + { + LLWString source = utf8str_to_wstring(src.asString()); + res = addToClipboard(source, 0, source.size()); + } + if (res) + { + mObjects.put(src); + } } + return res; } -void LLClipboard::cut(const LLUUID& object) +bool LLClipboard::pasteFromClipboard(LLDynamicArray<LLUUID>& inv_objects) const { - 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(); + bool res = false; S32 count = mObjects.count(); - for(S32 i = 0; i < count; i++) + if (count > 0) { - inv_objects.put(mObjects[i]); + res = true; + inv_objects.reset(); + for (S32 i = 0; i < count; i++) + { + inv_objects.put(mObjects[i]); + } } -} - -void LLClipboard::reset() -{ - mObjects.reset(); - mCutMode = false; + return res; } // Returns true if the LL Clipboard has pasteable items in it -BOOL LLClipboard::hasContents() const +bool LLClipboard::hasContents() const { return (mObjects.count() > 0); } @@ -107,30 +111,22 @@ bool LLClipboard::isOnClipboard(const LLUUID& object) const bool LLClipboard::copyToClipboard(const LLWString &src, S32 pos, S32 len, bool use_primary) { reset(); - mString = src.substr(pos, len); - return (use_primary ? LLView::getWindow()->copyTextToPrimary(mString) : LLView::getWindow()->copyTextToClipboard(mString)); + return addToClipboard(src, pos, len, use_primary); } -// 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) +// Concatenate the input string to the LL and the system clipboard +bool LLClipboard::addToClipboard(const LLWString &src, S32 pos, S32 len, bool use_primary) { - bool res = false; - reset(); - if (src.notNull()) + const LLWString sep(utf8str_to_wstring(std::string(", "))); + if (mString.length() == 0) { - res = true; - if (LLAssetType::lookupIsAssetIDKnowable(type)) - { - LLWString source = utf8str_to_wstring(src.asString()); - res = copyToClipboard(source, 0, source.size()); - } - if (res) - { - store(src); - } + mString = src.substr(pos, len); } - return res; + else + { + mString = mString + sep + src.substr(pos, len); + } + return (use_primary ? LLView::getWindow()->copyTextToPrimary(mString) : LLView::getWindow()->copyTextToClipboard(mString)); } // Copy the System clipboard to the output string. diff --git a/indra/llui/llclipboard.h b/indra/llui/llclipboard.h index 8e417a490d..608ea246a7 100644 --- a/indra/llui/llclipboard.h +++ b/indra/llui/llclipboard.h @@ -48,34 +48,38 @@ public: LLClipboard(); ~LLClipboard(); - /* 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). */ - - // 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; + // 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 - 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 + // Object list management: + // ----------------------- + // Clears the clipboard + void reset(); + // 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(LLDynamicArray<LLUUID>& inventory_objects) const; - BOOL hasContents() const; // true if the clipboard has something pasteable in it + 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 + bool isCutMode() const { return mCutMode; } void setCutMode(bool mode) { mCutMode = mode; } - bool isOnClipboard(const LLUUID& object) const; private: LLDynamicArray<LLUUID> mObjects; - bool mCutMode; LLWString mString; + bool mCutMode; // This is a convenience flag for the viewer. It has no influence on the cliboard management. }; #endif // LL_LLCLIPBOARD_H |