Commits

leslie_linden committed f649f39

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

Comments (0)

Files changed (3)

indra/llui/lltoolbar.cpp

 	mPadBetween(p.pad_between),
 	mMinGirth(p.min_girth),
 	mPopupMenuHandle(),
+	mRightMouseTargetButton(NULL),
 	mStartDragItemCallback(NULL),
 	mHandleDragItemCallback(NULL),
 	mHandleDropCallback(NULL),
 
 		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));
 
 	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();
 	}
 }
 
+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);
 			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;
 	{
 		// 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;
 		}
 	}
 	mButtons.clear();
 	mButtonMap.clear();
+	mRightMouseTargetButton = NULL;
 	
 	BOOST_FOREACH(LLCommandId& command_id, mButtonCommands)
 	{

indra/llui/lltoolbar.h

 
 	BOOL handleMouseDown(S32 x, S32 y, MASK mask);
 	BOOL handleHover(S32 x, S32 y, MASK mask);
+
 	void reshape(S32 width, S32 height, BOOL called_from_parent = true);
 	void setEnabled(BOOL enabled);
 	void setCommandId(const LLCommandId& id) { mId = id; }
 	void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth);
 	BOOL isSettingChecked(const LLSD& userdata);
 	void onSettingEnable(const LLSD& userdata);
+	void onRemoveSelectedCommand();
 
 private:
 	// static layout state
 	LLPanel*						mButtonPanel;
 	LLHandle<class LLContextMenu>	mPopupMenuHandle;
 
+	LLToolBarButton*				mRightMouseTargetButton;
+
 	bool							mNeedsLayout;
 	bool							mModified;
 

indra/newview/skins/default/xui/en/menu_toolbars.xml

       layout="topleft"
       name="Toolbars Popup"
       visible="false">
+  <menu_item_call label="Remove this button"
+                  layout="topleft"
+                  name="Remove button">
+    <menu_item_call.on_click function="Toolbars.RemoveSelectedCommand" />
+  </menu_item_call>
+  <menu_item_separator layout="topleft" />
   <menu_item_call label="Toolbar buttons..."
                   layout="topleft"
-                  name="Chose Buttons">
+                  name="Choose Buttons">
     <menu_item_call.on_click function="Floater.Show"
                              parameter="toybox" />
   </menu_item_call>