From eae60da6839906059d904c12cc155f4c2738c893 Mon Sep 17 00:00:00 2001 From: Yuri Chebotarev Date: Wed, 2 Dec 2009 19:37:33 +0200 Subject: fix for EXT-2886 Context menu for Nearby chat text field should look like context menu for any text editor, should include such items as (cut,copy, paste etc) --HG-- branch : product-engine --- indra/newview/llbottomtray.cpp | 93 +++++++++++++++++++++- indra/newview/llbottomtray.h | 4 + .../skins/default/xui/en/menu_bottomtray.xml | 53 ++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) (limited to 'indra') diff --git a/indra/newview/llbottomtray.cpp b/indra/newview/llbottomtray.cpp index 9cc7b8c785..10ebd5d8dc 100644 --- a/indra/newview/llbottomtray.cpp +++ b/indra/newview/llbottomtray.cpp @@ -45,6 +45,7 @@ #include "llsplitbutton.h" #include "llsyswellwindow.h" #include "llfloatercamera.h" +#include "lltexteditor.h" LLBottomTray::LLBottomTray(const LLSD&) : mChicletPanel(NULL), @@ -254,7 +255,9 @@ void LLBottomTray::showBottomTrayContextMenu(S32 x, S32 y, MASK mask) // We should show BottomTrayContextMenu in last turn if (mBottomTrayContextMenu && !LLMenuGL::sMenuContainer->getVisibleMenu()) { - //there are no other context menu (IM chiclet etc ), so we can show BottomTrayContextMenu + //there are no other context menu (IM chiclet etc ), so we can show BottomTrayContextMenu + + updateContextMenu(x, y, mask); mBottomTrayContextMenu->buildDrawLabels(); mBottomTrayContextMenu->updateParent(LLMenuGL::sMenuContainer); LLMenuGL::showPopup(this, mBottomTrayContextMenu, x, y); @@ -262,6 +265,33 @@ void LLBottomTray::showBottomTrayContextMenu(S32 x, S32 y, MASK mask) } } +void LLBottomTray::updateContextMenu(S32 x, S32 y, MASK mask) +{ + LLUICtrl* edit_box = mNearbyChatBar->getChild("chat_box"); + + S32 local_x = x - mNearbyChatBar->getRect().mLeft - edit_box->getRect().mLeft; + S32 local_y = y - mNearbyChatBar->getRect().mBottom - edit_box->getRect().mBottom; + + bool in_edit_box = edit_box->pointInView(local_x, local_y); + + LLMenuItemGL* menu_item; + menu_item = mBottomTrayContextMenu->findChild("NearbyChatBar_Cut"); + if(menu_item) + menu_item->setVisible(in_edit_box); + menu_item = mBottomTrayContextMenu->findChild("NearbyChatBar_Copy"); + if(menu_item) + menu_item->setVisible(in_edit_box); + menu_item = mBottomTrayContextMenu->findChild("NearbyChatBar_Paste"); + if(menu_item) + menu_item->setVisible(in_edit_box); + menu_item = mBottomTrayContextMenu->findChild("NearbyChatBar_Delete"); + if(menu_item) + menu_item->setVisible(in_edit_box); + menu_item = mBottomTrayContextMenu->findChild("NearbyChatBar_Select_All"); + if(menu_item) + menu_item->setVisible(in_edit_box); +} + void LLBottomTray::showGestureButton(BOOL visible) { setTrayButtonVisibleIfPossible(RS_BUTTON_GESTURES, visible); @@ -293,9 +323,14 @@ namespace BOOL LLBottomTray::postBuild() { + + LLUICtrl::CommitCallbackRegistry::currentRegistrar().add("NearbyChatBar.Action", boost::bind(&LLBottomTray::onContextMenuItemClicked, this, _2)); + LLUICtrl::EnableCallbackRegistry::currentRegistrar().add("NearbyChatBar.EnableMenuItem", boost::bind(&LLBottomTray::onContextMenuItemEnabled, this, _2)); + mBottomTrayContextMenu = LLUICtrlFactory::getInstance()->createFromFile("menu_bottomtray.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); gMenuHolder->addChild(mBottomTrayContextMenu); + mNearbyChatBar = getChild("chat_bar"); mToolbarStack = getChild("toolbar_stack"); mMovementPanel = getChild("movement_panel"); @@ -328,6 +363,62 @@ BOOL LLBottomTray::postBuild() return TRUE; } +bool LLBottomTray::onContextMenuItemEnabled(const LLSD& userdata) +{ + std::string item = userdata.asString(); + LLLineEditor* edit_box = mNearbyChatBar->findChild("chat_box"); + + if (item == "can_cut") + { + return edit_box->canCut(); + } + else if (item == "can_copy") + { + return edit_box->canCopy(); + } + else if (item == "can_paste") + { + return edit_box->canPaste(); + } + else if (item == "can_delete") + { + return edit_box->canDoDelete(); + } + else if (item == "can_select_all") + { + return edit_box->canSelectAll(); + } + return true; +} + + +void LLBottomTray::onContextMenuItemClicked(const LLSD& userdata) +{ + std::string item = userdata.asString(); + LLLineEditor* edit_box = mNearbyChatBar->findChild("chat_box"); + + if (item == "cut") + { + edit_box->cut(); + } + else if (item == "copy") + { + edit_box->copy(); + } + else if (item == "paste") + { + edit_box->paste(); + } + else if (item == "delete") + { + edit_box->doDelete(); + } + else if (item == "select_all") + { + edit_box->selectAll(); + } +} + void LLBottomTray::log(LLView* panel, const std::string& descr) { if (NULL == panel) return; diff --git a/indra/newview/llbottomtray.h b/indra/newview/llbottomtray.h index 7640cdcf9d..5d2ae2f199 100644 --- a/indra/newview/llbottomtray.h +++ b/indra/newview/llbottomtray.h @@ -174,6 +174,10 @@ protected: static void* createNearbyChatBar(void* userdata); + void updateContextMenu(S32 x, S32 y, MASK mask); + void onContextMenuItemClicked(const LLSD& userdata); + bool onContextMenuItemEnabled(const LLSD& userdata); + /** * Creates IM Chiclet based on session type (IM chat or Group chat) */ diff --git a/indra/newview/skins/default/xui/en/menu_bottomtray.xml b/indra/newview/skins/default/xui/en/menu_bottomtray.xml index a7abb223ba..7ef91a1d85 100644 --- a/indra/newview/skins/default/xui/en/menu_bottomtray.xml +++ b/indra/newview/skins/default/xui/en/menu_bottomtray.xml @@ -52,4 +52,57 @@ function="CheckControl" parameter="ShowSnapshotButton" /> + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3