Skip to content
Snippets Groups Projects
Commit 1478f228 authored by Merov Linden's avatar Merov Linden
Browse files

EXP-1300 : Simplify and clean up of the DaD which now doesn't duplicate the dragged tool.

parent a07c3559
No related branches found
No related tags found
No related merge requests found
......@@ -68,8 +68,8 @@ class LLCommandId
mUUID = LLUUID::generateNewID(p.name);
}
LLCommandId(const std::string& name, const LLUUID& uuid)
: mName(name),
LLCommandId(const LLUUID& uuid)
: mName(""),
mUUID(uuid)
{
}
......
......@@ -114,8 +114,6 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p)
{
mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text;
mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon;
mDraggedCommand = LLCommandId::null;
mRank = 0;
}
LLToolBar::~LLToolBar()
......@@ -211,19 +209,14 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank)
// Create the button and do the things that don't need ordering
LLToolBarButton* button = createButton(commandId);
mButtonPanel->addChild(button);
LLCommandId temp_command = commandId;
if (commandId.name() == "Drag Tool")
{
temp_command = LLCommandId("Drag Tool");
}
mButtonMap.insert(std::make_pair(temp_command.uuid(), button));
mButtonMap.insert(std::make_pair(commandId.uuid(), button));
// Insert the command and button in the right place in their respective lists
if ((rank >= mButtonCommands.size()) || (rank < 0))
if ((rank >= mButtonCommands.size()) || (rank == RANK_NONE))
{
// In that case, back load
mButtonCommands.push_back(temp_command);
mButtonCommands.push_back(commandId);
mButtons.push_back(button);
}
else
......@@ -238,7 +231,7 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank)
rank--;
}
// ...then insert
mButtonCommands.insert(it_command,temp_command);
mButtonCommands.insert(it_command,commandId);
mButtons.insert(it_button,button);
}
......@@ -247,27 +240,28 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank)
return true;
}
bool LLToolBar::removeCommand(const LLCommandId& commandId)
// Remove a command from the list
// Returns the rank of the command in the original list so that doing addCommand(id,rank) right after
// a removeCommand(id) would leave the list unchanged.
// Returns RANK_NONE if the command is not found in the list
int LLToolBar::removeCommand(const LLCommandId& commandId)
{
if (!hasCommand(commandId)) return false;
if (!hasCommand(commandId)) return RANK_NONE;
llinfos << "Merov debug : removeCommand, " << commandId.name() << ", " << commandId.uuid() << llendl;
// First erase the map record
LLCommandId temp_command = commandId;
if (commandId.name() == "Drag Tool")
{
temp_command = LLCommandId("Drag Tool");
}
command_id_map::iterator it = mButtonMap.find(temp_command.uuid());
command_id_map::iterator it = mButtonMap.find(commandId.uuid());
mButtonMap.erase(it);
// Now iterate on the commands and buttons to identify the relevant records
int rank = 0;
std::list<LLToolBarButton*>::iterator it_button = mButtons.begin();
command_id_list_t::iterator it_command = mButtonCommands.begin();
while (*it_command != temp_command)
while (*it_command != commandId)
{
++it_button;
++it_command;
++rank;
}
// Delete the button and erase the command and button records
......@@ -277,7 +271,7 @@ bool LLToolBar::removeCommand(const LLCommandId& commandId)
mNeedsLayout = true;
return true;
return rank;
}
void LLToolBar::clearCommandsList()
......@@ -292,12 +286,7 @@ bool LLToolBar::hasCommand(const LLCommandId& commandId) const
{
if (commandId != LLCommandId::null)
{
LLCommandId temp_command = commandId;
if (commandId.name() == "Drag Tool")
{
temp_command = LLCommandId("Drag Tool");
}
command_id_map::const_iterator it = mButtonMap.find(temp_command.uuid());
command_id_map::const_iterator it = mButtonMap.find(commandId.uuid());
return (it != mButtonMap.end());
}
......@@ -310,12 +299,7 @@ bool LLToolBar::enableCommand(const LLCommandId& commandId, bool enabled)
if (commandId != LLCommandId::null)
{
LLCommandId temp_command = commandId;
if (commandId.name() == "Drag Tool")
{
temp_command = LLCommandId("Drag Tool");
}
command_id_map::iterator it = mButtonMap.find(temp_command.uuid());
command_id_map::iterator it = mButtonMap.find(commandId.uuid());
if (it != mButtonMap.end())
{
it->second->setEnabled(enabled);
......@@ -410,6 +394,10 @@ void LLToolBar::resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row
}
}
// Returns the position of the coordinates as a rank in the button list.
// The rank is the position a tool dropped in (x,y) would assume in the button list.
// The value returned is between 0 and mButtons.size(), 0 being the first element to the left
// (or top) and mButtons.size() the last one to the right (or bottom).
int LLToolBar::getRankFromPosition(S32 x, S32 y)
{
int rank = 0;
......@@ -618,12 +606,6 @@ void LLToolBar::draw()
}
}
}
// HACK!!!
if (!mDragAndDropTarget)
{
removeCommand(mDraggedCommand);
mDraggedCommand = LLCommandId::null;
}
updateLayoutAsNeeded();
// rect may have shifted during layout
......@@ -654,12 +636,7 @@ void LLToolBar::createButtons()
LLToolBarButton* button = createButton(command_id);
mButtons.push_back(button);
mButtonPanel->addChild(button);
LLCommandId temp_command = command_id;
if (command_id.name() == "Drag Tool")
{
temp_command = LLCommandId("Drag Tool");
}
mButtonMap.insert(std::make_pair(temp_command.uuid(), button));
mButtonMap.insert(std::make_pair(command_id.uuid(), button));
}
mNeedsLayout = true;
}
......@@ -736,7 +713,7 @@ BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
EAcceptance* accept,
std::string& tooltip_msg)
{
//llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", x = " << x << ", y = " << y << llendl;
llinfos << "Merov debug : handleDragAndDrop. drop = " << drop << ", x = " << x << ", y = " << y << llendl;
// If we have a drop callback, that means that we can handle the drop
BOOL handled = (mHandleDropCallback ? TRUE : FALSE);
......@@ -761,19 +738,13 @@ BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
LLAssetType::EType type = inv_item->getType();
if (type == LLAssetType::AT_WIDGET)
{
mRank = getRankFromPosition(x, y);
mDraggedCommand = LLCommandId("Drag Tool",inv_item->getUUID());
removeCommand(mDraggedCommand);
addCommand(mDraggedCommand,mRank);
LLCommandId dragged_command(inv_item->getUUID());
int rank = getRankFromPosition(x, y);
removeCommand(dragged_command);
addCommand(dragged_command,rank);
mDragAndDropTarget = true;
}
}
else
{
removeCommand(mDraggedCommand);
mDraggedCommand = LLCommandId::null;
}
}
return handled;
......
......@@ -47,8 +47,8 @@ class LLToolBarButton : public LLButton
public:
struct Params : public LLInitParam::Block<Params, LLButton::Params>
{
Optional<LLUI::RangeS32::Params> button_width;
Optional<S32> desired_height;
Optional<LLUI::RangeS32> button_width;
Optional<S32> desired_height;
Params()
: button_width("button_width"),
......@@ -161,9 +161,11 @@ class LLToolBar
void* cargo_data,
EAcceptance* accept,
std::string& tooltip_msg);
static const int RANK_NONE = -1;
bool addCommand(const LLCommandId& commandId, int rank = -1);
bool removeCommand(const LLCommandId& commandId);
bool addCommand(const LLCommandId& commandId, int rank = RANK_NONE);
int removeCommand(const LLCommandId& commandId); // Returns the rank the removed command was at, RANK_NONE if not found
bool hasCommand(const LLCommandId& commandId) const;
bool enableCommand(const LLCommandId& commandId, bool enabled);
......@@ -184,8 +186,6 @@ class LLToolBar
tool_handledrag_callback_t mHandleDragItemCallback;
tool_handledrop_callback_t mHandleDropCallback;
bool mDragAndDropTarget;
int mRank;
LLCommandId mDraggedCommand;
public:
// Methods used in loading and saving toolbar settings
......
......@@ -41,7 +41,6 @@
LLToolBarView* gToolBarView = NULL;
static LLDefaultChildRegistry::Register<LLToolBarView> r("toolbar_view");
bool LLToolBarView::sDragStarted = false;
bool isToolDragged()
{
......@@ -331,18 +330,25 @@ void LLToolBarView::draw()
void LLToolBarView::startDragTool( S32 x, S32 y, const LLUUID& uuid)
{
//llinfos << "Merov debug: startDragTool() : x = " << x << ", y = " << y << llendl;
llinfos << "Merov debug: startDragTool() : x = " << x << ", y = " << y << ", uuid = " << uuid << llendl;
// Flag the tool dragging but don't start it yet
gToolBarView->mDragStarted = false;
gToolBarView->mDragCommand = LLCommandId::null;
gToolBarView->mDragRank = LLToolBar::RANK_NONE;
gToolBarView->mDragToolbar = NULL;
LLToolDragAndDrop::getInstance()->setDragStart( x, y );
sDragStarted = false;
}
BOOL LLToolBarView::handleDragTool( S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type)
{
// llinfos << "Merov debug: handleDragTool() : x = " << x << ", y = " << y << ", uuid = " << uuid << llendl;
if (LLToolDragAndDrop::getInstance()->isOverThreshold( x, y ))
{
if (!sDragStarted)
if (!gToolBarView->mDragStarted)
{
llinfos << "Merov debug: handleDragTool() : x = " << x << ", y = " << y << ", uuid = " << uuid << llendl;
// Start the tool dragging:
// First, create the global drag and drop object
std::vector<EDragAndDropType> types;
uuid_vec_t cargo_ids;
types.push_back(DAD_WIDGET);
......@@ -350,9 +356,35 @@ BOOL LLToolBarView::handleDragTool( S32 x, S32 y, const LLUUID& uuid, LLAssetTyp
gClipboard.setSourceObject(uuid,LLAssetType::AT_WIDGET);
LLToolDragAndDrop::ESource src = LLToolDragAndDrop::SOURCE_VIEWER;
LLUUID srcID;
//llinfos << "Merov debug: handleDragTool() : beginMultiDrag()" << llendl;
LLToolDragAndDrop::getInstance()->beginMultiDrag(types, cargo_ids, src, srcID);
sDragStarted = true;
llinfos << "Merov debug: beginMultiDrag() launched" << llendl;
// Second, check if the command is present in one of the 3 toolbars
// If it is, store the command, the toolbar and the rank in the toolbar and
// set a callback on end drag so that we reinsert the command if no drop happened
/*
gToolBarView->mDragCommand = LLCommandId(uuid);
if ((gToolBarView->mDragRank = gToolBarView->mToolbarLeft->removeCommand(gToolBarView->mDragCommand)) != LLToolBar::RANK_NONE)
{
gToolBarView->mDragToolbar = gToolBarView->mToolbarLeft;
}
else if ((gToolBarView->mDragRank = gToolBarView->mToolbarRight->removeCommand(gToolBarView->mDragCommand)) != LLToolBar::RANK_NONE)
{
gToolBarView->mDragToolbar = gToolBarView->mToolbarRight;
}
else if ((gToolBarView->mDragRank = gToolBarView->mToolbarBottom->removeCommand(gToolBarView->mDragCommand)) != LLToolBar::RANK_NONE)
{
gToolBarView->mDragToolbar = gToolBarView->mToolbarBottom;
}
if (gToolBarView->mDragRank != LLToolBar::RANK_NONE)
{
llinfos << "Merov debug: rank of dragged tool = " << gToolBarView->mDragRank << llendl;
LLToolDragAndDrop::getInstance()->setEndDragCallback(boost::bind(&LLToolBarView::onEndDrag, gToolBarView));
}
*/
llinfos << "Merov debug: Drag started cleanly" << llendl;
gToolBarView->mDragStarted = true;
return TRUE;
}
else
......@@ -375,7 +407,7 @@ BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* t
//llinfos << "Merov debug : handleDropTool. Drop source is a widget -> drop it in place..." << llendl;
// Get the command from its uuid
LLCommandManager& mgr = LLCommandManager::instance();
LLCommandId command_id("",inv_item->getUUID());
LLCommandId command_id(inv_item->getUUID());
LLCommand* command = mgr.getCommand(command_id);
if (command)
{
......@@ -408,5 +440,19 @@ BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* t
void LLToolBarView::stopDragTool()
{
sDragStarted = false;
// Clear the saved command, toolbar and rank
gToolBarView->mDragStarted = false;
gToolBarView->mDragCommand = LLCommandId::null;
gToolBarView->mDragRank = LLToolBar::RANK_NONE;
gToolBarView->mDragToolbar = NULL;
}
void LLToolBarView::onEndDrag()
{
// If there's a saved command, reinsert it in the saved toolbar
if (gToolBarView->mDragRank != LLToolBar::RANK_NONE)
{
gToolBarView->mDragToolbar->addCommand(gToolBarView->mDragCommand,gToolBarView->mDragRank);
}
stopDragTool();
}
\ No newline at end of file
......@@ -78,6 +78,7 @@ class LLToolBarView : public LLUICtrl
static BOOL handleDragTool( S32 x, S32 y, const LLUUID& uuid, LLAssetType::EType type);
static BOOL handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* toolbar);
static void stopDragTool();
void onEndDrag();
protected:
friend class LLUICtrlFactory;
......@@ -94,12 +95,11 @@ class LLToolBarView : public LLUICtrl
LLToolBar* mToolbarLeft;
LLToolBar* mToolbarRight;
LLToolBar* mToolbarBottom;
bool mDragging;
LLToolBarButton* mDragButton;
S32 mMouseX;
S32 mMouseY;
static bool sDragStarted;
LLCommandId mDragCommand;
int mDragRank;
LLToolBar* mDragToolbar;
bool mDragStarted;
};
extern LLToolBarView* gToolBarView;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment