From f3a4a48d8ed20b4bbd65d7cdb9b191c9faf2544b Mon Sep 17 00:00:00 2001 From: Leslie Linden Date: Wed, 19 Oct 2011 17:33:10 -0700 Subject: * Fixed issue where dragging disabled buttons from the toybox to the toybox would remove them from the surrounding toolbars. * Removed dead drag & drop code * Fixed issue where saving didn't necessarily work because toolbar populated with command id's that didn't have associated names. --- indra/llui/lltoolbar.cpp | 10 ++-- indra/llui/lltoolbar.h | 3 +- indra/newview/llfloatertoybox.cpp | 6 +- indra/newview/llfloatertoybox.h | 1 - indra/newview/lltoolbarview.cpp | 115 +++++++++++++------------------------- indra/newview/lltoolbarview.h | 15 ++--- 6 files changed, 53 insertions(+), 97 deletions(-) diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index c559a2bf1d..bceda9bf54 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -217,7 +217,7 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank) if ((rank >= mButtonCommands.size()) || (rank == RANK_NONE)) { // In that case, back load - mButtonCommands.push_back(commandId); + mButtonCommands.push_back(command->id()); mButtons.push_back(button); } else @@ -232,7 +232,7 @@ bool LLToolBar::addCommand(const LLCommandId& commandId, int rank) rank--; } // ...then insert - mButtonCommands.insert(it_command,commandId); + mButtonCommands.insert(it_command, command->id()); mButtons.insert(it_button,button); } @@ -821,7 +821,7 @@ LLToolBarButton* LLToolBar::createButton(const LLCommandId& id) if (!commandp) return NULL; LLToolBarButton::Params button_p; - button_p.name = id.name(); + button_p.name = commandp->id().name(); // Make sure to retrieve the name from the command itself, not the passed in id button_p.label = LLTrans::getString(commandp->labelRef()); button_p.tool_tip = LLTrans::getString(commandp->tooltipRef()); button_p.image_overlay = LLUI::getUIImage(commandp->icon()); @@ -999,13 +999,13 @@ BOOL LLToolBarButton::handleHover(S32 x, S32 y, MASK mask) { if (!mIsDragged) { - mStartDragItemCallback(x,y,mId.uuid()); + mStartDragItemCallback(x, y, this); mIsDragged = true; handled = TRUE; } else { - handled = mHandleDragItemCallback(x,y,mId.uuid(),LLAssetType::AT_WIDGET); + handled = mHandleDragItemCallback(x, y, mId.uuid(), LLAssetType::AT_WIDGET); } } else diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index ad42d1fa35..e634e57f93 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -36,8 +36,9 @@ #include "llassettype.h" class LLToolBar; +class LLToolBarButton; -typedef boost::function tool_startdrag_callback_t; +typedef boost::function tool_startdrag_callback_t; typedef boost::function tool_handledrag_callback_t; typedef boost::function tool_handledrop_callback_t; diff --git a/indra/newview/llfloatertoybox.cpp b/indra/newview/llfloatertoybox.cpp index b4c9894271..66f644748e 100644 --- a/indra/newview/llfloatertoybox.cpp +++ b/indra/newview/llfloatertoybox.cpp @@ -39,7 +39,6 @@ LLFloaterToybox::LLFloaterToybox(const LLSD& key) : LLFloater(key) - , mBtnRestoreDefaults(NULL) , mToolBar(NULL) { mCommitCallbackRegistrar.add("Toybox.RestoreDefaults", boost::bind(&LLFloaterToybox::onBtnRestoreDefaults, this)); @@ -59,20 +58,19 @@ bool compare_localized_command_labels(LLCommand * cmd1, LLCommand * cmd2) BOOL LLFloaterToybox::postBuild() { - mBtnRestoreDefaults = getChild("btn_restore_defaults"); mToolBar = getChild("toybox_toolbar"); + mToolBar->setStartDragCallback(boost::bind(LLToolBarView::startDragTool,_1,_2,_3)); mToolBar->setHandleDragCallback(boost::bind(LLToolBarView::handleDragTool,_1,_2,_3,_4)); mToolBar->setHandleDropCallback(boost::bind(LLToolBarView::handleDropTool,_1,_2,_3,_4)); - LLCommandManager& cmdMgr = LLCommandManager::instance(); - // // Sort commands by localized labels so they will appear alphabetized in all languages // std::list alphabetized_commands; + LLCommandManager& cmdMgr = LLCommandManager::instance(); for (U32 i = 0; i < cmdMgr.commandCount(); i++) { LLCommand * command = cmdMgr.getCommand(i); diff --git a/indra/newview/llfloatertoybox.h b/indra/newview/llfloatertoybox.h index f0a6cf1a8b..62bf68680d 100644 --- a/indra/newview/llfloatertoybox.h +++ b/indra/newview/llfloatertoybox.h @@ -53,7 +53,6 @@ protected: void onBtnRestoreDefaults(); public: - LLButton * mBtnRestoreDefaults; LLToolBar * mToolBar; }; diff --git a/indra/newview/lltoolbarview.cpp b/indra/newview/lltoolbarview.cpp index c7c8268eb9..75bec15082 100644 --- a/indra/newview/lltoolbarview.cpp +++ b/indra/newview/lltoolbarview.cpp @@ -63,7 +63,9 @@ LLToolBarView::LLToolBarView(const LLToolBarView::Params& p) : LLUICtrl(p), mToolbarLeft(NULL), mToolbarRight(NULL), - mToolbarBottom(NULL) + mToolbarBottom(NULL), + mDragStarted(false), + mDragToolbarButton(NULL) { } @@ -278,13 +280,19 @@ void LLToolBarView::saveToolbars() const // Enumerate the commands in command_list and add them as Params to the toolbar void LLToolBarView::addToToolset(command_id_list_t& command_list, Toolbar& toolbar) const { + LLCommandManager& mgr = LLCommandManager::instance(); + for (command_id_list_t::const_iterator it = command_list.begin(); it != command_list.end(); ++it) { - LLCommandId::Params command; - command.name = it->name(); - toolbar.commands.add(command); + LLCommand* command = mgr.getCommand(*it); + if (command) + { + LLCommandId::Params commandParams; + commandParams.name = command->id().name(); + toolbar.commands.add(commandParams); + } } } @@ -328,13 +336,11 @@ void LLToolBarView::draw() // ---------------------------------------- -void LLToolBarView::startDragTool( S32 x, S32 y, const LLUUID& uuid) +void LLToolBarView::startDragTool(S32 x, S32 y, LLToolBarButton* button) { + resetDragTool(button); + // 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 ); } @@ -361,30 +367,6 @@ BOOL LLToolBarView::handleDragTool( S32 x, S32 y, const LLUUID& uuid, LLAssetTyp gToolBarView->mToolbarLeft->stopCommandInProgress(command_id); gToolBarView->mToolbarRight->stopCommandInProgress(command_id); gToolBarView->mToolbarBottom->stopCommandInProgress(command_id); - - // 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)); - } - */ gToolBarView->mDragStarted = true; return TRUE; @@ -413,42 +395,32 @@ BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* t LLCommand* command = mgr.getCommand(command_id); if (command) { - // Convert the (x,y) position in rank in toolbar - int new_rank = LLToolBar::RANK_NONE; - if (!toolbar->isReadOnly()) - { - new_rank = toolbar->getRankFromPosition(x,y); - } // Suppress the command from the toolbars (including the one it's dropped in, // this will handle move position). - int old_rank = LLToolBar::RANK_NONE; + bool command_present = gToolBarView->hasCommand(command_id); LLToolBar* old_toolbar = NULL; - int rank; - if ((rank = gToolBarView->mToolbarLeft->removeCommand(command_id)) != LLToolBar::RANK_NONE) - { - old_rank = rank; - old_toolbar = gToolBarView->mToolbarLeft; - } - if ((rank = gToolBarView->mToolbarRight->removeCommand(command_id)) != LLToolBar::RANK_NONE) - { - old_rank = rank; - old_toolbar = gToolBarView->mToolbarRight; - } - if ((rank = gToolBarView->mToolbarBottom->removeCommand(command_id)) != LLToolBar::RANK_NONE) + + if (command_present) { - old_rank = rank; - old_toolbar = gToolBarView->mToolbarBottom; + llassert(gToolBarView->mDragToolbarButton); + old_toolbar = gToolBarView->mDragToolbarButton->getParentByType(); + if (old_toolbar->isReadOnly() && toolbar->isReadOnly()) + { + // do nothing + } + else + { + gToolBarView->mToolbarBottom->removeCommand(command_id); + gToolBarView->mToolbarLeft->removeCommand(command_id); + gToolBarView->mToolbarRight->removeCommand(command_id); + } } - // Now insert it in the toolbar at the detected rank + + // Convert the (x,y) position in rank in toolbar if (!toolbar->isReadOnly()) { - if ((old_toolbar == toolbar) && (old_rank != LLToolBar::RANK_NONE) && (old_rank < new_rank)) - { - // If we just removed the command from the same toolbar, we need to consider that it might - // change the target rank. - new_rank -= 1; - } - toolbar->addCommand(command->id(),new_rank); + int new_rank = toolbar->getRankFromPosition(x,y); + toolbar->addCommand(command_id, new_rank); } } else @@ -456,27 +428,16 @@ BOOL LLToolBarView::handleDropTool( void* cargo_data, S32 x, S32 y, LLToolBar* t llwarns << "Command couldn't be found in command manager" << llendl; } } - stopDragTool(); + + resetDragTool(NULL); return handled; } -void LLToolBarView::stopDragTool() +void LLToolBarView::resetDragTool(LLToolBarButton* button) { // 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(); + gToolBarView->mDragToolbarButton = button; } void LLToolBarView::setToolBarsVisible(bool visible) diff --git a/indra/newview/lltoolbarview.h b/indra/newview/lltoolbarview.h index 8b3af43875..60ad6316f8 100644 --- a/indra/newview/lltoolbarview.h +++ b/indra/newview/lltoolbarview.h @@ -76,11 +76,10 @@ public: static bool loadDefaultToolbars(); - static void startDragTool( S32 x, S32 y, const LLUUID& uuid); - 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(); + static void startDragTool(S32 x, S32 y, LLToolBarButton* button); + 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 resetDragTool(LLToolBarButton* button); bool isModified() const; @@ -100,10 +99,8 @@ private: LLToolBar* mToolbarRight; LLToolBar* mToolbarBottom; - LLCommandId mDragCommand; - int mDragRank; - LLToolBar* mDragToolbar; - bool mDragStarted; + bool mDragStarted; + LLToolBarButton* mDragToolbarButton; }; extern LLToolBarView* gToolBarView; -- cgit v1.2.3