Encapsulate LFIDBearer::sActive, set with member setActive

This function caches the current type when active,
in the future it could be more useful than that.

sActive is now const, getActive returns const,
IDBearers display information, the interface should only be used for that
This commit is contained in:
Liru Færs
2020-01-06 12:22:31 -05:00
parent f73fb6424b
commit 6839cba56a
10 changed files with 31 additions and 20 deletions

View File

@@ -30,7 +30,8 @@ const std::array<const std::string, LFIDBearer::COUNT> LFIDBearer::sMenuStrings
};
std::array<LLMenuGL*, LFIDBearer::COUNT> LFIDBearer::sMenus {};
LFIDBearer* LFIDBearer::sActive = nullptr;
const LFIDBearer* LFIDBearer::sActive = nullptr;
LFIDBearer::Type LFIDBearer::sActiveType = LFIDBearer::AVATAR;
void LFIDBearer::buildMenus()
{
@@ -49,7 +50,7 @@ LLMenuGL* LFIDBearer::showMenu(LLView* self, const std::string& menu_name, S32 x
void LFIDBearer::showMenu(LLView* self, LLMenuGL* menu, S32 x, S32 y)
{
sActive = this; // Menu listeners rely on this
setActive(); // Menu listeners rely on this
menu->buildDrawLabels();
menu->updateParent(LLMenuGL::sMenuContainer);
LLMenuGL::showPopup(self, menu, x, y);

View File

@@ -43,11 +43,18 @@ struct LFIDBearer
virtual S32 getNumSelected() const { return getStringUUIDSelectedItem().notNull(); }
virtual Type getSelectedType() const { return AVATAR; }
template<typename T> static T* getActive() { return static_cast<T*>(sActive); }
template<typename T> static const T* getActive() { return static_cast<const 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(); }
static const Type& getActiveType() { return sActiveType; }
void setActive() const
{
sActive = this;
sActiveType = getSelectedType();
//sActiveIDs or even some kinda hybrid map, if Type is MULTIPLE fill the vals? and remove a buncha virtual functions?
}
static void buildMenus();
LLMenuGL* showMenu(LLView* self, const std::string& menu_name, S32 x, S32 y, std::function<void(LLMenuGL*)> on_menu_built = nullptr);
@@ -57,5 +64,8 @@ protected:
// Menus that recur, such as general avatars or groups menus
static const std::array<const std::string, COUNT> sMenuStrings;
static std::array<LLMenuGL*, COUNT> sMenus;
static LFIDBearer* sActive;
private:
static const LFIDBearer* sActive;
static Type sActiveType;
};

View File

@@ -58,6 +58,8 @@ public:
// [/RLVa:KB]
private:
friend class OverlayToggle;
friend class LLScaleMap;
LLFloaterMap(const LLSD& key = LLSD());
LLNetMap* mPanelMap;
};

View File

@@ -1340,18 +1340,15 @@ void LLFolderView::copy() const
S32 count = mSelectedItems.size();
if(getVisible() && getEnabled() && (count > 0))
{
LLFolderViewEventListener* listener = NULL;
selected_items_t::iterator item_it;
for (item_it = mSelectedItems.begin(); item_it != mSelectedItems.end(); ++item_it)
for (auto item : mSelectedItems)
{
listener = (*item_it)->getListener();
if(listener)
if(auto listener = item->getListener())
{
listener->copyToClipboard();
}
}
}
mSearchString.clear();
//mSearchString.clear(); // Singu Note: There's no good reason to clear out the jumpto item search string now, it'll time out anyway, let's remain const
}
BOOL LLFolderView::canCut() const

View File

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

View File

@@ -86,7 +86,7 @@ BOOL LLNameEditor::handleRightMouseDown(S32 x, S32 y, MASK mask)
new_menu = mIsGroup ? "menu_nameeditor_group.xml" : "menu_nameeditor_avatar.xml";
}
if (!new_menu.empty()) setContextMenu(LLUICtrlFactory::instance().buildMenu(new_menu, LLMenuGL::sMenuContainer));
sActive = this;
setActive();
return LLLineEditor::handleRightMouseDown(x, y, mask);
}

View File

@@ -53,6 +53,7 @@
#include "llavatarnamecache.h"
#include "llcallingcard.h"
#include "llcolorscheme.h"
#include "llfloatermap.h"
#include "llfloaterworldmap.h"
#include "llframetimer.h"
// [SL:KB] - Patch: World-MinimapOverlay | Checked: 2012-06-20 (Catznip-3.3.0)
@@ -1360,7 +1361,7 @@ BOOL LLNetMap::handleMouseUp( S32 x, S32 y, MASK mask )
bool OverlayToggle::handleEvent(LLPointer<LLEvent> event, const LLSD& sdParam)
{
// Force an overlay update
LFIDBearer::getActive<LLNetMap>()->mUpdateParcelImage = true;
LLFloaterMap::findInstance()->mPanelMap->mUpdateParcelImage = true;
return true;
}
// [/SL:KB]
@@ -1472,7 +1473,7 @@ BOOL LLNetMap::handleHover( S32 x, S32 y, MASK mask )
// static
bool LLScaleMap::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLNetMap *self = LFIDBearer::getActive<LLNetMap>();
auto self = LLFloaterMap::findInstance()->mPanelMap;
S32 level = userdata.asInteger();

View File

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

View File

@@ -130,7 +130,7 @@ void LLPanelGroupTab::handleClickHelp()
}
}
void copy_profile_uri(const LLUUID& id, LFIDBearer::Type type);
void copy_profile_uri(const LLUUID& id, const LFIDBearer::Type& type);
LLPanelGroup::LLPanelGroup(const LLUUID& group_id)
: LLPanel("PanelGroup", LLRect(), FALSE),

View File

@@ -9034,17 +9034,17 @@ template<typename T> T* get_focused()
return t;
}
const std::string get_slurl_for(const LLUUID& id, LFIDBearer::Type type)
const std::string get_slurl_for(const LLUUID& id, const LFIDBearer::Type& type)
{
return type == LFIDBearer::GROUP ? LLGroupActions::getSLURL(id) : LLAvatarActions::getSLURL(id);
}
const LLWString get_wslurl_for(const LLUUID& id, LFIDBearer::Type type)
const LLWString get_wslurl_for(const LLUUID& id, const LFIDBearer::Type& type)
{
return utf8str_to_wstring(get_slurl_for(id, type));
}
void copy_profile_uri(const LLUUID& id, LFIDBearer::Type type)
void copy_profile_uri(const LLUUID& id, const LFIDBearer::Type& type)
{
gViewerWindow->getWindow()->copyTextToClipboard(get_wslurl_for(id, type));
}