From 6d5df7c9af0515a28bdf4d80b4450b033d3ddd82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liru=20F=C3=A6rs?= Date: Sun, 24 Nov 2019 06:03:46 -0500 Subject: [PATCH] Make TextEditor an IDBearer, via slurl segments! --- indra/llui/lltexteditor.cpp | 160 +++--------------- indra/llui/lltexteditor.h | 18 +- indra/newview/llviewermenu.cpp | 56 +----- .../default/xui/en-us/menu_url_agent.xml | 97 +++++------ .../default/xui/en-us/menu_url_experience.xml | 2 +- .../default/xui/en-us/menu_url_group.xml | 4 +- .../default/xui/en-us/menu_url_objectim.xml | 2 +- 7 files changed, 81 insertions(+), 258 deletions(-) diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index 344666112..29095cf90 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -244,8 +244,6 @@ private: /////////////////////////////////////////////////////////////////// -LLTextEditor::is_friend_signal_t* LLTextEditor::mIsFriendSignal = nullptr; -LLTextEditor::is_blocked_signal_t* LLTextEditor::mIsObjectBlockedSignal = nullptr; LLTextEditor::LLTextEditor( const std::string& name, @@ -372,9 +370,6 @@ LLTextEditor::~LLTextEditor() menu->die(); mPopupMenuHandle.markDead(); } - /* Singu Note: Static this, we'll use it wherever we can! - delete mIsFriendSignal; - delete mIsObjectBlockedSignal;*/ } const std::string& LLTextEditor::getMenuSegmentUrl() const @@ -384,24 +379,36 @@ const std::string& LLTextEditor::getMenuSegmentUrl() const return style ? style->getLinkHREF() : LLStringUtil::null; } -static LLTextEditor* get_focused_text_editor() +static LFIDBearer::Type get_type_from_url(const std::string& url) { - auto* te = -#ifdef SHOW_ASSERT - dynamic_cast -#else - static_cast -#endif - (gFocusMgr.getKeyboardFocus()); - llassert(te); // This listener only applies to text editors - return te; + auto pos = url.find("/app/"); + if (pos != std::string::npos && pos + 10 <= url.size()) + { + auto type = url.substr(pos + 5, 5); + return type == "agent" ? LFIDBearer::AVATAR + : type == "group" ? LFIDBearer::GROUP + : LFIDBearer::OBJECT; + } + return LFIDBearer::NONE; +} + +LLUUID LLTextEditor::getStringUUIDSelectedItem() const +{ + const auto& url = getMenuSegmentUrl(); + const auto& type = get_type_from_url(url); + return type == LFIDBearer::NONE ? LLUUID::null : LLUUID(type == OBJECT ? LLUrlAction::getObjectId(url) : LLUrlAction::getUserID(url)); +} + +LFIDBearer::Type LLTextEditor::getSelectedType() const +{ + return get_type_from_url(getMenuSegmentUrl()); } class CopyRawText : public LLMemberListener { bool handleEvent(LLPointer, const LLSD& userdata) override { - get_focused_text_editor()->copyRaw(); + LFIDBearer::getActive()->copyRaw(); return true; } }; @@ -415,16 +422,11 @@ class TextEditorVisible : public LLMemberListener } }; -static const std::string& get_focused_url() -{ - return get_focused_text_editor()->getMenuSegmentUrl(); -} - class ContextUrl : public LLMemberListener { bool handleEvent(LLPointer, const LLSD& userdata) override { - const auto& url = get_focused_url(); + const auto& url = LFIDBearer::getActive()->getMenuSegmentUrl(); const auto& op = userdata.asStringRef(); if (op == "Open") LLUrlAction::openURL(url); else if (op == "OpenInternal") LLUrlAction::openURLInternal(url); @@ -433,10 +435,6 @@ class ContextUrl : public LLMemberListener else if (op == "Block") LLUrlAction::blockObject(url); else if (op == "Unblock") LLUrlAction::unblockObject(url); else if (op == "Teleport") LLUrlAction::teleportToLocation(url); - else if (op == "ShowProfile") LLUrlAction::showProfile(url); - else if (op == "AddFriend") LLUrlAction::addFriend(url); - else if (op == "RemoveFriend") LLUrlAction::removeFriend(url); - else if (op == "SendIM") LLUrlAction::sendIM(url); else if (op == "ShowOnMap") LLUrlAction::showLocationOnMap(url); else if (op == "CopyLabel") LLUrlAction::copyLabelToClipboard(url); else if (op == "CopyUrl") LLUrlAction::copyURLToClipboard(url); @@ -444,67 +442,15 @@ class ContextUrl : public LLMemberListener } }; -class ContextIDUrl : public LLMemberListener -{ -protected: - std::string getID(const std::string& type) const - { - const auto& url = get_focused_url(); - // Empty works like avatar and group, "object" is an object (you needed to be told this) - return type.empty() ? LLUrlAction::getUserID(url) : LLUrlAction::getObjectId(url); - } -}; - -class ContextUrlCopy : public ContextIDUrl +class ContextUrlCopy : public LLMemberListener { bool handleEvent(LLPointer, const LLSD& userdata) override { - LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(getID(userdata.asStringRef()))); + LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(LFIDBearer::getActiveSelectedID().asString())); return true; } }; -class ContextUrlExt : public ContextIDUrl -{ - bool handleEvent(LLPointer, const LLSD& userdata) override - { - std::string cmd = userdata.asStringRef(); - std::string type; - const auto sep = cmd.find(','); - if (sep != std::string::npos) - { - type = cmd.substr(sep); - cmd = cmd.substr(0, sep); - } - mExtCallback(cmd, LLUUID(getID(type))); - return true; - } - LLTextEditor::ext_slurl_cb mExtCallback; -public: - ContextUrlExt(LLTextEditor::ext_slurl_cb cb) : mExtCallback(cb) {} -}; - -class ContextUrlExtVisible : public ContextIDUrl -{ - bool handleEvent(LLPointer, const LLSD& userdata) override - { - std::string cmd = userdata["data"]; - std::string type; - const auto sep = cmd.find(','); - if (sep != std::string::npos) - { - type = cmd.substr(sep); - cmd = cmd.substr(0, sep); - } - - LLMenuGL::sMenuContainer->findControl(userdata["control"].asString())->setValue(mExtVCB(cmd, LLUUID(getID(type)))); - return true; - } - LLTextEditor::ext_slurl_visible_cb mExtVCB; -public: - ContextUrlExtVisible(LLTextEditor::ext_slurl_visible_cb vcb) : mExtVCB(vcb) {} -}; - void LLTextEditor::spell_correct(void* data) { @@ -581,14 +527,12 @@ void LLTextEditor::spell_add(void* data) } //static -void LLTextEditor::addMenuListeners(ext_slurl_cb cb, ext_slurl_visible_cb vcb) +void LLTextEditor::addMenuListeners() { (new CopyRawText)->registerListener(LLMenuGL::sMenuContainer, "CopyRawText"); (new TextEditorVisible)->registerListener(LLMenuGL::sMenuContainer, "TextEditorVisible"); (new ContextUrl)->registerListener(LLMenuGL::sMenuContainer, "Text.Url"); (new ContextUrlCopy)->registerListener(LLMenuGL::sMenuContainer, "Text.Url.CopyUUID"); - (new ContextUrlExt(cb))->registerListener(LLMenuGL::sMenuContainer, "Text.Url.Ext"); - (new ContextUrlExtVisible(vcb))->registerListener(LLMenuGL::sMenuContainer, "Text.Url.ExtVisible"); } void LLTextEditor::setTrackColor( const LLColor4& color ) @@ -767,34 +711,6 @@ LLMenuGL* LLTextEditor::createUrlContextMenu(S32 x, S32 y, const std::string &in // create and return the context menu from the XUI file llassert(LLMenuGL::sMenuContainer != NULL); auto menu = LLUICtrlFactory::instance().buildMenu(xui_file, LLMenuGL::sMenuContainer); - if (menu) - { - if (mIsFriendSignal) - { - bool isFriend = *(*mIsFriendSignal)(LLUUID(LLUrlAction::getUserID(url))); - LLView* addFriendButton = menu->findChild("add_friend"); - LLView* removeFriendButton = menu->findChild("remove_friend"); - - if (addFriendButton && removeFriendButton) - { - addFriendButton->setVisible(!isFriend); - removeFriendButton->setVisible(isFriend); - } - } - - if (mIsObjectBlockedSignal) - { - bool is_blocked = *(*mIsObjectBlockedSignal)(LLUUID(LLUrlAction::getObjectId(url)), LLUrlAction::getObjectName(url)); - LLView* blockButton = menu->findChild("block_object"); - LLView* unblockButton = menu->findChild("unblock_object"); - - if (blockButton && unblockButton) - { - blockButton->setVisible(!is_blocked); - unblockButton->setVisible(is_blocked); - } - } - } return menu; } @@ -1575,9 +1491,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) mLastContextMenuX = x; mLastContextMenuY = y; - menu->buildDrawLabels(); - menu->updateParent(LLMenuGL::sMenuContainer); - LLMenuGL::showPopup(this, menu, x, y); + showMenu(this, menu, x, y); } return TRUE; } @@ -5179,24 +5093,6 @@ BOOL LLTextEditor::exportBuffer(std::string &buffer ) return TRUE; } -boost::signals2::connection LLTextEditor::setIsFriendCallback(const is_friend_signal_t::slot_type& cb) -{ - if (!mIsFriendSignal) - { - mIsFriendSignal = new is_friend_signal_t(); - } - return mIsFriendSignal->connect(cb); -} - -boost::signals2::connection LLTextEditor::setIsObjectBlockedCallback(const is_blocked_signal_t::slot_type& cb) -{ - if (!mIsObjectBlockedSignal) - { - mIsObjectBlockedSignal = new is_blocked_signal_t(); - } - return mIsObjectBlockedSignal->connect(cb); -} - ////////////////////////////////////////////////////////////////////////// // LLTextSegment diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index a18907749..692e43147 100644 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -43,6 +43,7 @@ #include "lleditmenuhandler.h" #include "llpreeditor.h" +#include "lfidbearer.h" class LLFontGL; class LLKeywordToken; @@ -50,6 +51,7 @@ class LLMenuGL; class LLTextCmd; class LLTextEditor : public LLUICtrl, LLEditMenuHandler, protected LLPreeditor +, public LFIDBearer { public: // @@ -71,16 +73,12 @@ public: const std::string& getMenuSegmentUrl() const; + LLUUID getStringUUIDSelectedItem() const override final; + Type getSelectedType() const override final; + typedef boost::signals2::signal keystroke_signal_t; - typedef boost::signals2::signal is_friend_signal_t; - typedef boost::signals2::signal is_blocked_signal_t; - static boost::signals2::connection setIsFriendCallback(const is_friend_signal_t::slot_type& cb); - static boost::signals2::connection setIsObjectBlockedCallback(const is_blocked_signal_t::slot_type& cb); - - typedef std::function ext_slurl_cb; - typedef std::function ext_slurl_visible_cb; - static void addMenuListeners(ext_slurl_cb cb, ext_slurl_visible_cb vcb); + static void addMenuListeners(); void setKeystrokeCallback(const keystroke_signal_t::slot_type& callback); @@ -468,10 +466,6 @@ protected: void (*mOnScrollEndCallback)(void*); void *mOnScrollEndData; - // Used to check if user with given ID is avatar's friend - static is_friend_signal_t* mIsFriendSignal; - static is_blocked_signal_t* mIsObjectBlockedSignal; - LLWString mPreeditWString; LLWString mPreeditOverwrittenWString; std::vector mPreeditPositions; diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index cb11edd25..f758902a3 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -9489,60 +9489,6 @@ class ListToggleMute : public view_listener_t } }; -struct MenuSLURLDict : public LLSingleton -{ - typedef std::function cb; - typedef std::function vcb; - typedef std::map> slurl_menu_map; - slurl_menu_map mEntries; - MenuSLURLDict() - { - // Text Editor menus - LLTextEditor::setIsObjectBlockedCallback(boost::bind(&LLMuteList::isMuted, LLMuteList::getInstance(), _1, _2, 0)); - LLTextEditor::setIsFriendCallback(LLAvatarActions::isFriend); - LLTextEditor::addMenuListeners(boost::bind(&MenuSLURLDict::action, this, _1, _2), boost::bind(&MenuSLURLDict::visible, this, _1, _2)); - - // Add the entries - insert("ShowWebProfile", boost::bind(LLAvatarActions::showProfile, _1, true), boost::bind(can_show_web_profile)); - insert("Pay", LLAvatarActions::pay); - insert("Call", LLAvatarActions::startCall); - insert("Share", LLAvatarActions::share); - insert("AbuseReport", LLFloaterReporter::showFromObject); - insert("InviteToGroup", [](const LLUUID& id) { LLAvatarActions::inviteToGroup(id); }); - insert("BanFromGroup", [](const LLUUID& id) { ban_from_group(uuid_vec_t(1, id)); }); - insert("ShowLog", [](const LLUUID& id) { show_log_browser(id); }); - insert("OfferTeleport", [](const LLUUID& id) { LLAvatarActions::offerTeleport(id); }, [](const LLUUID& id) { return LLAvatarActions::canOfferTeleport(id); }); - insert("RequestTeleport", LLAvatarActions::teleportRequest); - void teleport_to(const LLUUID& id); - insert("TeleportTo", teleport_to, is_nearby); - insert("Track", track_av, is_nearby); - insert("Focus", LLFloaterAvatarList::setFocusAvatar, is_nearby); - insert("ParcelEject", [](const LLUUID& id) { confirm_eject(uuid_vec_t(1, id)); }, is_nearby); - insert("Freeze", [](const LLUUID& id) { confirm_freeze(uuid_vec_t(1, id)); }, is_nearby); - insert("EstateBan", [](const LLUUID& id) { confirm_estate_ban(uuid_vec_t(1, id)); }, is_nearby); - insert("EstateEject", [](const LLUUID & id) { confirm_estate_kick(uuid_vec_t(1, id)); }, is_nearby); - insert("Mute", LLAvatarActions::toggleBlock, [](const LLUUID& id) { return LLAvatarActions::canBlock(id) && !LLAvatarActions::isBlocked(id); }); - insert("Unmute", LLAvatarActions::toggleBlock, LLAvatarActions::isBlocked); - } - - void insert(const std::string& key, cb callback, vcb vcallback = nullptr) - { - mEntries[key] = std::make_pair(callback, vcallback); - } - - void action(const std::string& cmd, LLUUID id) const - { - auto it = mEntries.find(cmd); - if (it != mEntries.end()) - (*it).second.first(id); - } - bool visible(const std::string& cmd, LLUUID id) const - { - auto it = mEntries.find(cmd); - return it == mEntries.end() || !(*it).second.second || (*it).second.second(id); - } -}; - class ListIsInGroup : public view_listener_t { bool handleEvent(LLPointer event, const LLSD& userdata) @@ -9990,7 +9936,7 @@ void initialize_menus() add_radar_listeners(); - MenuSLURLDict::getInstance(); + LLTextEditor::addMenuListeners(); // Media Ctrl menus addMenu(new MediaCtrlCopyURL(), "Copy.PageURL"); diff --git a/indra/newview/skins/default/xui/en-us/menu_url_agent.xml b/indra/newview/skins/default/xui/en-us/menu_url_agent.xml index a22aad8ea..046af1bf1 100644 --- a/indra/newview/skins/default/xui/en-us/menu_url_agent.xml +++ b/indra/newview/skins/default/xui/en-us/menu_url_agent.xml @@ -4,69 +4,58 @@ label="User" name="Url Popup"> - + - - + + + - - + + - - + - - + + - - + + + + + + + - - - - - + - - + - - + + - - + - - + - - + - - + + - - + + - + - - + + - - + + - - + - - + - - + + - - + + - - + + - - + + diff --git a/indra/newview/skins/default/xui/en-us/menu_url_experience.xml b/indra/newview/skins/default/xui/en-us/menu_url_experience.xml index 24a9f4095..88f82ee51 100644 --- a/indra/newview/skins/default/xui/en-us/menu_url_experience.xml +++ b/indra/newview/skins/default/xui/en-us/menu_url_experience.xml @@ -11,7 +11,7 @@ function="Text.Url" userdata="CopyUrl" /> - + diff --git a/indra/newview/skins/default/xui/en-us/menu_url_group.xml b/indra/newview/skins/default/xui/en-us/menu_url_group.xml index 99b8c6d67..c6fa002b8 100644 --- a/indra/newview/skins/default/xui/en-us/menu_url_group.xml +++ b/indra/newview/skins/default/xui/en-us/menu_url_group.xml @@ -8,7 +8,7 @@ layout="topleft" name="show_group"> + function="List.ShowProfile" /> @@ -27,7 +27,7 @@ function="Text.Url" userdata="CopyUrl" /> - + diff --git a/indra/newview/skins/default/xui/en-us/menu_url_objectim.xml b/indra/newview/skins/default/xui/en-us/menu_url_objectim.xml index befbada9a..18b07a189 100644 --- a/indra/newview/skins/default/xui/en-us/menu_url_objectim.xml +++ b/indra/newview/skins/default/xui/en-us/menu_url_objectim.xml @@ -57,7 +57,7 @@ function="Text.Url" userdata="CopyUrl" /> - +