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 | |
parent | c744603af9b53c6bc73fefbd56de68cf2778ed70 (diff) |
EXP-1841 : Final deep scrub on LLClipboard API, clean up the use of copy and cut everywhere.
-rw-r--r-- | indra/llui/llclipboard.cpp | 96 | ||||
-rw-r--r-- | indra/llui/llclipboard.h | 44 | ||||
-rw-r--r-- | indra/newview/llfavoritesbar.cpp | 6 | ||||
-rw-r--r-- | indra/newview/llfloatergesture.cpp | 10 | ||||
-rw-r--r-- | indra/newview/llfoldervieweventlistener.h | 2 | ||||
-rw-r--r-- | indra/newview/llinventorybridge.cpp | 52 | ||||
-rw-r--r-- | indra/newview/llinventorybridge.h | 6 | ||||
-rw-r--r-- | indra/newview/llpanelobjectinventory.cpp | 5 |
8 files changed, 107 insertions, 114 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 diff --git a/indra/newview/llfavoritesbar.cpp b/indra/newview/llfavoritesbar.cpp index 4308bf2d3c..d4bce1e3a1 100644 --- a/indra/newview/llfavoritesbar.cpp +++ b/indra/newview/llfavoritesbar.cpp @@ -1187,7 +1187,7 @@ void LLFavoritesBarCtrl::doToSelected(const LLSD& userdata) } else if (action == "copy") { - LLClipboard::getInstance()->store(mSelectedItemID); + LLClipboard::getInstance()->copyToClipboard(mSelectedItemID, LLAssetType::AT_LANDMARK); } else if (action == "paste") { @@ -1217,7 +1217,7 @@ BOOL LLFavoritesBarCtrl::isClipboardPasteable() const } LLDynamicArray<LLUUID> objects; - LLClipboard::getInstance()->retrieve(objects); + LLClipboard::getInstance()->pasteFromClipboard(objects); S32 count = objects.count(); for(S32 i = 0; i < count; i++) { @@ -1246,7 +1246,7 @@ void LLFavoritesBarCtrl::pastFromClipboard() const { LLInventoryItem* item = NULL; LLDynamicArray<LLUUID> objects; - LLClipboard::getInstance()->retrieve(objects); + LLClipboard::getInstance()->pasteFromClipboard(objects); S32 count = objects.count(); LLUUID parent_id(mFavoriteFolderId); for(S32 i = 0; i < count; i++) diff --git a/indra/newview/llfloatergesture.cpp b/indra/newview/llfloatergesture.cpp index 3c647284f6..d449c4ff1b 100644 --- a/indra/newview/llfloatergesture.cpp +++ b/indra/newview/llfloatergesture.cpp @@ -395,7 +395,7 @@ bool LLFloaterGesture::isActionEnabled(const LLSD& command) return false; LLDynamicArray<LLUUID> ids; - LLClipboard::getInstance()->retrieve(ids); + LLClipboard::getInstance()->pasteFromClipboard(ids); for(LLDynamicArray<LLUUID>::iterator it = ids.begin(); it != ids.end(); it++) { LLInventoryItem* item = gInventory.getItem(*it); @@ -490,26 +490,26 @@ void LLFloaterGesture::onActivateBtnClick() void LLFloaterGesture::onCopyPasteAction(const LLSD& command) { std::string command_name = command.asString(); - // since we select this comman inventory item had already arrived . + // Since we select this command, the inventory items must have already arrived if("copy_gesture" == command_name) { uuid_vec_t ids; getSelectedIds(ids); - // make sure that clopboard is empty + // Make sure the clipboard is empty LLClipboard::getInstance()->reset(); for(uuid_vec_t::iterator it = ids.begin(); it != ids.end(); it++) { LLInventoryItem* item = gInventory.getItem(*it); if(item && item->getInventoryType() == LLInventoryType::IT_GESTURE) { - LLClipboard::getInstance()->add(item->getUUID()); + LLClipboard::getInstance()->addToClipboard(item->getUUID(),LLAssetType::AT_GESTURE); } } } else if ("paste" == command_name) { LLDynamicArray<LLUUID> ids; - LLClipboard::getInstance()->retrieve(ids); + LLClipboard::getInstance()->pasteFromClipboard(ids); if(ids.empty() || !gInventory.isCategoryComplete(mGestureFolderID)) return; LLInventoryCategory* gesture_dir = gInventory.getCategory(mGestureFolderID); diff --git a/indra/newview/llfoldervieweventlistener.h b/indra/newview/llfoldervieweventlistener.h index aee31ca033..06682dcbf1 100644 --- a/indra/newview/llfoldervieweventlistener.h +++ b/indra/newview/llfoldervieweventlistener.h @@ -75,7 +75,7 @@ public: virtual void move( LLFolderViewEventListener* parent_listener ) = 0; virtual BOOL isItemCopyable() const = 0; virtual BOOL copyToClipboard() const = 0; - virtual void cutToClipboard() = 0; + virtual BOOL cutToClipboard() const = 0; virtual BOOL isClipboardPasteable() const = 0; virtual void pasteFromClipboard() = 0; virtual void pasteLinkFromClipboard() = 0; diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp index 7ba914eaf6..9775e54d6a 100644 --- a/indra/newview/llinventorybridge.cpp +++ b/indra/newview/llinventorybridge.cpp @@ -208,13 +208,27 @@ BOOL LLInvFVBridge::isLink() const /** * @brief Adds this item into clipboard storage */ -void LLInvFVBridge::cutToClipboard() +BOOL LLInvFVBridge::cutToClipboard() const { - if (isItemMovable() && isItemRemovable()) + LLViewerInventoryItem* inv_item = gInventory.getItem(mUUID); + if (inv_item && isItemMovable() && isItemRemovable()) { - LLClipboard::getInstance()->cut(mUUID); + LLClipboard::getInstance()->setCutMode(true); + return LLClipboard::getInstance()->addToClipboard(mUUID,inv_item->getType()); } + return FALSE; } + +BOOL LLInvFVBridge::copyToClipboard() const +{ + LLViewerInventoryItem* inv_item = gInventory.getItem(mUUID); + if (inv_item && isItemCopyable()) + { + return LLClipboard::getInstance()->addToClipboard(mUUID,inv_item->getType()); + } + return FALSE; +} + // *TODO: make sure this does the right thing void LLInvFVBridge::showProperties() { @@ -413,7 +427,7 @@ BOOL LLInvFVBridge::isClipboardPasteable() const // 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); + LLClipboard::getInstance()->pasteFromClipboard(objects); S32 count = objects.count(); for(S32 i = 0; i < count; i++) { @@ -451,7 +465,7 @@ BOOL LLInvFVBridge::isClipboardPasteableAsLink() const } LLDynamicArray<LLUUID> objects; - LLClipboard::getInstance()->retrieve(objects); + LLClipboard::getInstance()->pasteFromClipboard(objects); S32 count = objects.count(); for(S32 i = 0; i < count; i++) { @@ -1673,16 +1687,6 @@ BOOL LLItemBridge::isItemCopyable() const return FALSE; } -BOOL LLItemBridge::copyToClipboard() const -{ - if(isItemCopyable()) - { - LLClipboard::getInstance()->add(mUUID); - return TRUE; - } - return FALSE; -} - LLViewerInventoryItem* LLItemBridge::getItem() const { LLViewerInventoryItem* item = NULL; @@ -1785,16 +1789,6 @@ BOOL LLFolderBridge::isItemCopyable() const return gSavedSettings.getBOOL("InventoryLinking"); } -BOOL LLFolderBridge::copyToClipboard() const -{ - if(isItemCopyable()) - { - LLClipboard::getInstance()->add(mUUID); - return TRUE; - } - return FALSE; -} - BOOL LLFolderBridge::isClipboardPasteable() const { if ( ! LLInvFVBridge::isClipboardPasteable() ) @@ -1810,7 +1804,7 @@ BOOL LLFolderBridge::isClipboardPasteable() const } LLDynamicArray<LLUUID> objects; - LLClipboard::getInstance()->retrieve(objects); + LLClipboard::getInstance()->pasteFromClipboard(objects); const LLViewerInventoryCategory *current_cat = getCategory(); // Search for the direct descendent of current Friends subfolder among all pasted items, @@ -1848,7 +1842,7 @@ BOOL LLFolderBridge::isClipboardPasteableAsLink() const const BOOL is_in_friend_folder = LLFriendCardsManager::instance().isCategoryInFriendFolder( current_cat ); const LLUUID ¤t_cat_id = current_cat->getUUID(); LLDynamicArray<LLUUID> objects; - LLClipboard::getInstance()->retrieve(objects); + LLClipboard::getInstance()->pasteFromClipboard(objects); S32 count = objects.count(); for(S32 i = 0; i < count; i++) { @@ -2844,7 +2838,7 @@ void LLFolderBridge::pasteFromClipboard() const LLUUID parent_id(mUUID); LLDynamicArray<LLUUID> objects; - LLClipboard::getInstance()->retrieve(objects); + LLClipboard::getInstance()->pasteFromClipboard(objects); for (LLDynamicArray<LLUUID>::const_iterator iter = objects.begin(); iter != objects.end(); ++iter) @@ -2900,7 +2894,7 @@ void LLFolderBridge::pasteLinkFromClipboard() const LLUUID parent_id(mUUID); LLDynamicArray<LLUUID> objects; - LLClipboard::getInstance()->retrieve(objects); + LLClipboard::getInstance()->pasteFromClipboard(objects); for (LLDynamicArray<LLUUID>::const_iterator iter = objects.begin(); iter != objects.end(); ++iter) diff --git a/indra/newview/llinventorybridge.h b/indra/newview/llinventorybridge.h index 3bcd71557c..f13ff15bc5 100644 --- a/indra/newview/llinventorybridge.h +++ b/indra/newview/llinventorybridge.h @@ -105,8 +105,8 @@ public: virtual void removeBatch(LLDynamicArray<LLFolderViewEventListener*>& batch); virtual void move(LLFolderViewEventListener* new_parent_bridge) {} virtual BOOL isItemCopyable() const { return FALSE; } - virtual BOOL copyToClipboard() const { return FALSE; } - virtual void cutToClipboard(); + virtual BOOL copyToClipboard() const; + virtual BOOL cutToClipboard() const; virtual BOOL isClipboardPasteable() const; virtual BOOL isClipboardPasteableAsLink() const; virtual void pasteFromClipboard() {} @@ -211,7 +211,6 @@ public: virtual BOOL renameItem(const std::string& new_name); virtual BOOL removeItem(); virtual BOOL isItemCopyable() const; - virtual BOOL copyToClipboard() const; virtual BOOL hasChildren() const { return FALSE; } virtual BOOL isUpToDate() const { return TRUE; } @@ -274,7 +273,6 @@ public: virtual BOOL isItemCopyable() const; virtual BOOL isClipboardPasteable() const; virtual BOOL isClipboardPasteableAsLink() const; - virtual BOOL copyToClipboard() const; static void createWearable(LLFolderBridge* bridge, LLWearableType::EType type); diff --git a/indra/newview/llpanelobjectinventory.cpp b/indra/newview/llpanelobjectinventory.cpp index 98ea680504..eb0a257def 100644 --- a/indra/newview/llpanelobjectinventory.cpp +++ b/indra/newview/llpanelobjectinventory.cpp @@ -124,7 +124,7 @@ public: virtual void move(LLFolderViewEventListener* parent_listener); virtual BOOL isItemCopyable() const; virtual BOOL copyToClipboard() const; - virtual void cutToClipboard(); + virtual BOOL cutToClipboard() const; virtual BOOL isClipboardPasteable() const; virtual void pasteFromClipboard(); virtual void pasteLinkFromClipboard(); @@ -524,8 +524,9 @@ BOOL LLTaskInvFVBridge::copyToClipboard() const return FALSE; } -void LLTaskInvFVBridge::cutToClipboard() +BOOL LLTaskInvFVBridge::cutToClipboard() const { + return FALSE; } BOOL LLTaskInvFVBridge::isClipboardPasteable() const |