From ede74731ab154a5f661cc64d8b47ed97c7863d89 Mon Sep 17 00:00:00 2001 From: Leslie Linden Date: Thu, 3 Nov 2011 14:36:40 -0700 Subject: EXP-1533 FIX -- As a FUI user, I'd like to be able to remove toolbar buttons without having to drag them anywhere * Added "Remove this button" option to the toolbar context menu * Added code to track the right mouse click and execute the action to remove the appropriate button on the toolbar. Reviewed by surly leyla --- indra/llui/lltoolbar.cpp | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'indra/llui/lltoolbar.cpp') diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 287e3e2b41..e7642ae190 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -109,6 +109,7 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p) mPadBetween(p.pad_between), mMinGirth(p.min_girth), mPopupMenuHandle(), + mRightMouseTargetButton(NULL), mStartDragItemCallback(NULL), mHandleDragItemCallback(NULL), mHandleDropCallback(NULL), @@ -139,6 +140,7 @@ void LLToolBar::createContextMenu() LLUICtrl::CommitCallbackRegistry::ScopedRegistrar commit_reg; commit_reg.add("Toolbars.EnableSetting", boost::bind(&LLToolBar::onSettingEnable, this, _2)); + commit_reg.add("Toolbars.RemoveSelectedCommand", boost::bind(&LLToolBar::onRemoveSelectedCommand, this)); LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_reg; enable_reg.add("Toolbars.CheckSetting", boost::bind(&LLToolBar::isSettingChecked, this, _2)); @@ -397,6 +399,20 @@ BOOL LLToolBar::handleRightMouseDown(S32 x, S32 y, MASK mask) if (handle_it_here) { + // Determine which button the mouse was over during the click in case the context menu action + // is intended to affect the button. + BOOST_FOREACH(LLToolBarButton* button, mButtons) + { + LLRect button_rect; + button->localRectToOtherView(button->getLocalRect(), &button_rect, this); + + if (button_rect.pointInRect(x, y)) + { + mRightMouseTargetButton = button; + break; + } + } + createContextMenu(); LLContextMenu * menu = (LLContextMenu *) mPopupMenuHandle.get(); @@ -446,6 +462,18 @@ void LLToolBar::onSettingEnable(const LLSD& userdata) } } +void LLToolBar::onRemoveSelectedCommand() +{ + llassert(!mReadOnly); + + if (mRightMouseTargetButton) + { + removeCommand(mRightMouseTargetButton->getCommandId()); + + mRightMouseTargetButton = NULL; + } +} + void LLToolBar::setButtonType(LLToolBarEnums::ButtonType button_type) { bool regenerate_buttons = (mButtonType != button_type); @@ -524,11 +552,11 @@ int LLToolBar::getRankFromPosition(S32 x, S32 y) S32 mid_point = (button_rect.mRight + button_rect.mLeft) / 2; if (button_panel_x < mid_point) { - mDragx = button_rect.mLeft - mPadLeft; - mDragy = button_rect.mTop + mPadTop; - } - else - { + mDragx = button_rect.mLeft - mPadLeft; + mDragy = button_rect.mTop + mPadTop; + } + else + { rank++; mDragx = button_rect.mRight + mPadRight - 1; mDragy = button_rect.mTop + mPadTop; @@ -555,12 +583,12 @@ int LLToolBar::getRankFromPosition(S32 x, S32 y) { // We hit passed the end of the list so put the insertion point at the end if (orientation == LLLayoutStack::HORIZONTAL) - { + { mDragx = button_rect.mRight + mPadRight; mDragy = button_rect.mTop + mPadTop; - } - else - { + } + else + { mDragx = button_rect.mLeft - mPadLeft; mDragy = button_rect.mBottom - mPadBottom; } @@ -836,6 +864,7 @@ void LLToolBar::createButtons() } mButtons.clear(); mButtonMap.clear(); + mRightMouseTargetButton = NULL; BOOST_FOREACH(LLCommandId& command_id, mButtonCommands) { -- cgit v1.2.3