Introduce Types for ID Bearer IDs

This commit is contained in:
Liru Færs
2019-11-23 23:05:33 -05:00
parent ab207727fd
commit 5a561e03b8
8 changed files with 64 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
/* Copyright (C) 2019 Liru Færs
*
* LFIDBearer is a class that holds an ID or IDs that menus can use
* This class also bears the type of ID/IDs that it is holding
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -26,15 +27,27 @@ class LLView;
struct LFIDBearer
{
enum Type : S8
{
MULTIPLE = -2,
NONE = -1,
AVATAR = 0,
GROUP,
OBJECT,
COUNT
};
virtual ~LFIDBearer() { if (sActive == this) sActive = nullptr; }
virtual LLUUID getStringUUIDSelectedItem() const = 0;
virtual uuid_vec_t getSelectedIDs() const { return { getStringUUIDSelectedItem() }; }
virtual S32 getNumSelected() const { return getStringUUIDSelectedItem().notNull(); }
virtual Type getSelectedType() const { return AVATAR; }
template<typename T> static T* getActive() { return static_cast<T*>(sActive); }
static LLUUID getActiveSelectedID() { return sActive->getStringUUIDSelectedItem(); }
static uuid_vec_t getActiveSelectedIDs() { return sActive->getSelectedIDs(); }
static S32 getActiveNumSelected() { return sActive->getNumSelected(); }
static Type getActiveType() { return sActive->getSelectedType(); }
void showMenu(LLView* self, LLMenuGL* menu, S32 x, S32 y);
static void addCommonMenu(LLMenuGL* menu) { sMenus.push_back(menu); }

View File

@@ -1128,7 +1128,7 @@ void LLFloaterIMPanel::removeDynamicFocus()
findChild<LLComboBox>("instant_message_flyout")->remove(getString("focus"));
}
void copy_profile_uri(const LLUUID& id, bool group = false);
void copy_profile_uri(const LLUUID& id, LFIDBearer::Type type = LFIDBearer::AVATAR);
void LLFloaterIMPanel::onFlyoutCommit(LLComboBox* flyout, const LLSD& value)
{

View File

@@ -142,6 +142,32 @@ BOOL LLNameListCtrl::handleDoubleClick(S32 x, S32 y, MASK mask)
return handled;
}
#define CONVERT_TO_RETTYPE(nametype, rettype) \
nametype: \
{ \
if (ret == NONE) \
ret = rettype; \
else if (ret != rettype) \
return MULTIPLE; \
break; \
}
LFIDBearer::Type LLNameListCtrl::getSelectedType() const
{
auto ret = NONE;
for (const auto& item : getAllSelected())
{
switch (static_cast<LLNameListItem*>(item)->getNameType())
{
CONVERT_TO_RETTYPE(case LLNameListItem::INDIVIDUAL, AVATAR);
CONVERT_TO_RETTYPE(case LLNameListItem::GROUP, GROUP)
CONVERT_TO_RETTYPE(default, COUNT) // Invalid, but just use count instead
}
}
return ret;
}
#undef CONVERT_TO_RETTYPE
// public
void LLNameListCtrl::addGroupNameItem(const LLUUID& group_id, EAddPosition pos,
BOOL enabled)

View File

@@ -149,6 +149,8 @@ public:
std::string& tooltip_msg);
BOOL handleDoubleClick(S32 x, S32 y, MASK mask) override;
Type getSelectedType() const override final;
void setAllowCallingCardDrop(BOOL b) { mAllowCallingCardDrop = b; }
void sortByName(BOOL ascending);

View File

@@ -49,6 +49,7 @@ struct LLNameUI : public LFIDBearer
LLUUID getStringUUIDSelectedItem() const override final { return mNameID; }
S32 getNumSelected() const override final { return 1; }
Type getSelectedType() const override final { return mIsGroup ? GROUP : AVATAR; }
void setIsGroup(bool is_group);
void setNameID(const LLUUID& name_id, bool is_group);

View File

@@ -1399,7 +1399,7 @@ void LLPanelAvatar::onClickCopy(const LLSD& val)
}
else
{
void copy_profile_uri(const LLUUID& id, bool group = false);
void copy_profile_uri(const LLUUID& id, LFIDBearer::Type type = LFIDBearer::AVATAR);
copy_profile_uri(mAvatarID);
}
}

View File

@@ -34,6 +34,7 @@
#include "llpanelgroup.h"
// Library includes
#include "lfidbearer.h"
#include "llbutton.h"
#include "lltabcontainer.h"
#include "lltextbox.h"
@@ -129,7 +130,7 @@ void LLPanelGroupTab::handleClickHelp()
}
}
void copy_profile_uri(const LLUUID& id, bool group);
void copy_profile_uri(const LLUUID& id, LFIDBearer::Type type);
LLPanelGroup::LLPanelGroup(const LLUUID& group_id)
: LLPanel("PanelGroup", LLRect(), FALSE),
@@ -161,7 +162,7 @@ LLPanelGroup::LLPanelGroup(const LLUUID& group_id)
LLGroupMgr::getInstance()->addObserver(this);
mCommitCallbackRegistrar.add("Group.CopyURI", boost::bind(copy_profile_uri, boost::ref(mID), true));
mCommitCallbackRegistrar.add("Group.CopyURI", boost::bind(copy_profile_uri, boost::ref(mID), LFIDBearer::GROUP));
// Pass on construction of this panel to the control factory.
LLUICtrlFactory::getInstance()->buildPanel(this, "panel_group.xml", &getFactoryMap());
}

View File

@@ -94,6 +94,7 @@
#include "llframestats.h"
#include "llavataractions.h"
#include "llgivemoney.h"
#include "llgroupactions.h"
#include "llgroupmgr.h"
#include "llhoverview.h"
#include "llhudeffecttrail.h"
@@ -9034,16 +9035,19 @@ template<typename T> T* get_focused()
return t;
}
const LLWString get_slurl_for(const LLUUID& id, bool group)
const std::string get_slurl_for(const LLUUID& id, LFIDBearer::Type type)
{
std::string str("secondlife:///app/");
str += group ? "group/" : "agent/";
return utf8str_to_wstring(str + id.asString() + "/about");
return type == LFIDBearer::GROUP ? LLGroupActions::getSLURL(id) : LLAvatarActions::getSLURL(id);
}
void copy_profile_uri(const LLUUID& id, bool group)
const LLWString get_wslurl_for(const LLUUID& id, LFIDBearer::Type type)
{
gViewerWindow->getWindow()->copyTextToClipboard(get_slurl_for(id, group));
return utf8str_to_wstring(get_slurl_for(id, type));
}
void copy_profile_uri(const LLUUID& id, LFIDBearer::Type type)
{
gViewerWindow->getWindow()->copyTextToClipboard(get_wslurl_for(id, type));
}
class ListEnableAnySelected : public view_listener_t
@@ -9145,7 +9149,7 @@ class ListCopySLURL : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
copy_profile_uri(LFIDBearer::getActiveSelectedID(), false);
copy_profile_uri(LFIDBearer::getActiveSelectedID(), LFIDBearer::getActiveType());
return true;
}
};
@@ -9242,7 +9246,12 @@ class ListShowProfile : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLAvatarActions::showProfiles(LFIDBearer::getActiveSelectedIDs());
switch (LFIDBearer::getActiveType())
{
case LFIDBearer::AVATAR: LLAvatarActions::showProfiles(LFIDBearer::getActiveSelectedIDs()); break;
case LFIDBearer::GROUP: LLGroupActions::showProfiles(LFIDBearer::getActiveSelectedIDs()); break;
default: break;
}
return true;
}
};