Make the right click avatar slurl menu as good as the list ones

This commit is contained in:
Liru Færs
2019-08-29 22:00:22 -04:00
parent 2e465ba04a
commit 4b97f76aa7
5 changed files with 325 additions and 23 deletions

View File

@@ -436,20 +436,67 @@ class ContextUrl : public LLMemberListener<LLView>
}
};
class ContextUrlCopy : public LLMemberListener<LLView>
class ContextIDUrl : public LLMemberListener<LLView>
{
bool handleEvent(LLPointer<LLOldEvents::LLEvent>, const LLSD& userdata) override
protected:
std::string getID(const std::string& type) const
{
const auto& url = get_focused_url();
const auto& type = userdata.asStringRef();
// Empty works like avatar and group, "object" is an object (you needed to be told this)
const auto& id = type.empty() ? LLUrlAction::getUserID(url) : LLUrlAction::getObjectId(url);
LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(id));
return type.empty() ? LLUrlAction::getUserID(url) : LLUrlAction::getObjectId(url);
}
};
class ContextUrlCopy : public ContextIDUrl
{
bool handleEvent(LLPointer<LLOldEvents::LLEvent>, const LLSD& userdata) override
{
LLView::getWindow()->copyTextToClipboard(utf8str_to_wstring(getID(userdata.asStringRef())));
return true;
}
};
class ContextUrlExt : public ContextIDUrl
{
bool handleEvent(LLPointer<LLOldEvents::LLEvent>, 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<LLOldEvents::LLEvent>, 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)
{
@@ -528,11 +575,13 @@ void LLTextEditor::spell_add(void* data)
}
//static
void LLTextEditor::addMenuListeners()
void LLTextEditor::addMenuListeners(ext_slurl_cb cb, ext_slurl_visible_cb vcb)
{
(new ContextText)->registerListener(LLMenuGL::sMenuContainer, "Text");
(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 )
@@ -721,8 +770,8 @@ LLMenuGL* LLTextEditor::createUrlContextMenu(S32 x, S32 y, const std::string &in
if (addFriendButton && removeFriendButton)
{
addFriendButton->setEnabled(!isFriend);
removeFriendButton->setEnabled(isFriend);
addFriendButton->setVisible(!isFriend);
removeFriendButton->setVisible(isFriend);
}
}