EXP-1841 : Final deep scrub on LLClipboard API, clean up the use of copy and cut everywhere.

master
Merov Linden 2012-02-07 22:46:04 -08:00
parent c744603af9
commit ee3c3c15b7
8 changed files with 120 additions and 127 deletions

View File

@ -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)
{
mObjects.put(object);
}
void LLClipboard::store(const LLUUID& object)
{
reset();
mObjects.put(object);
}
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;
mString = LLWString();
}
// Copy the input uuid to the LL clipboard
bool LLClipboard::copyToClipboard(const LLUUID& src, const LLAssetType::EType type)
{
reset();
return addToClipboard(src, type);
}
// 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)
{
bool res = false;
if (src.notNull())
{
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;
}
bool LLClipboard::pasteFromClipboard(LLDynamicArray<LLUUID>& inv_objects) const
{
bool res = false;
S32 count = mObjects.count();
if (count > 0)
{
res = true;
inv_objects.reset();
for (S32 i = 0; i < count; i++)
{
inv_objects.put(mObjects[i]);
}
}
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.

View File

@ -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 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 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 pasteable objects
bool isOnClipboard(const LLUUID& object) const; // True if the input object uuid is on the clipboard
// 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
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; }
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

View File

@ -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++)

View File

@ -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);

View File

@ -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;

View File

@ -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 &current_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)

View File

@ -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);

View File

@ -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