Add in menus for groups, and rework LFIDBearer to handle its menus

Also allow List.StartIM for multiselect
Add IsInGroup, NotInGroup, Leave, Join, and Activate "List." menu options
This commit is contained in:
Liru Færs
2019-11-24 00:27:19 -05:00
parent f5c19b9e5c
commit 1b913443ad
9 changed files with 161 additions and 22 deletions

View File

@@ -20,10 +20,33 @@
#include "linden_common.h"
#include "lfidbearer.h"
#include "llmenugl.h"
#include "lluictrlfactory.h"
const std::array<const std::string, LFIDBearer::COUNT> LFIDBearer::sMenuStrings
{
"menu_avs_list.xml" // 0
, "menu_groups_list.xml" // 1 // Singu TODO
, "menu_objects_list.xml" // 2 // Singu TODO
};
std::array<LLMenuGL*, LFIDBearer::COUNT> LFIDBearer::sMenus {};
std::vector<LLMenuGL*> LFIDBearer::sMenus = {};
LFIDBearer* LFIDBearer::sActive = nullptr;
void LFIDBearer::buildMenus()
{
auto& factory = LLUICtrlFactory::instance();
for (auto i = 0; i < COUNT; ++i)
sMenus[i] = factory.buildMenu(sMenuStrings[i], LLMenuGL::sMenuContainer);
}
LLMenuGL* LFIDBearer::showMenu(LLView* self, const std::string& menu_name, S32 x, S32 y, std::function<void(LLMenuGL*)> on_menu_built)
{
auto menu = LLUICtrlFactory::instance().buildMenu(menu_name, LLMenuGL::sMenuContainer);
if (on_menu_built) on_menu_built(menu);
showMenu(self, menu, x, y);
return menu;
}
void LFIDBearer::showMenu(LLView* self, LLMenuGL* menu, S32 x, S32 y)
{
sActive = this; // Menu listeners rely on this

View File

@@ -49,10 +49,13 @@ struct LFIDBearer
static S32 getActiveNumSelected() { return sActive->getNumSelected(); }
static Type getActiveType() { return sActive->getSelectedType(); }
static void buildMenus();
LLMenuGL* showMenu(LLView* self, const std::string& menu_name, S32 x, S32 y, std::function<void(LLMenuGL*)> on_menu_built = nullptr);
void showMenu(LLView* self, LLMenuGL* menu, S32 x, S32 y);
static void addCommonMenu(LLMenuGL* menu) { sMenus.push_back(menu); }
protected:
static std::vector<LLMenuGL*> sMenus; // Menus that recur, such as general avatars or groups menus
// 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;
};

View File

@@ -2036,6 +2036,11 @@ void LLScrollListCtrl::setFilter(const std::string& filter)
adjustScrollbar(unfiltered_count);
}
void LLScrollListCtrl::setContextMenu(const std::string& menu)
{
setContextMenu(LLUICtrlFactory::instance().buildMenu(menu, LLMenuGL::sMenuContainer));
}
BOOL LLScrollListCtrl::handleHover(S32 x,S32 y,MASK mask)
{
@@ -2695,17 +2700,17 @@ void LLScrollListCtrl::setScrollListParameters(LLXMLNodePtr node)
if (node->hasAttribute("menu_num"))
{
// Some scroll lists use common menus identified by number
// 0 is menu_avs_list.xml, 1 will be for groups, 2 could be for lists of objects
// Some UI uses common menus identified by number
// 0 is avatars, 1 will be for groups, others could be for lists of objects or locations or experiences
S32 menu_num;
node->getAttributeS32("menu_num", menu_num);
setContextMenu(menu_num);
mPopupMenu = sMenus[menu_num];
}
else if (node->hasAttribute("menu_file"))
{
std::string menu_file;
node->getAttributeString("menu_file", menu_file);
mPopupMenu = LLUICtrlFactory::getInstance()->buildMenu(menu_file, LLMenuGL::sMenuContainer);
std::string menu;
node->getAttributeString("menu_file", menu);
if (!menu.empty()) setContextMenu(menu);
}
}

View File

@@ -254,9 +254,10 @@ public:
bool filterItem(LLScrollListItem* item);
void setFilter(const std::string& filter);
// support right-click context menus for avatar/group lists
// Context Menus
void setContextMenu(LLMenuGL* menu) { mPopupMenu = menu; }
void setContextMenu(S32 index) { mPopupMenu = sMenus[index]; }
void setContextMenu(U8 index) { mPopupMenu = sMenus[index]; }
void setContextMenu(const std::string& menu);
// Overridden from LLView
/*virtual*/ void draw();

View File

@@ -67,10 +67,9 @@ BOOL LLNameBox::handleRightMouseDown(S32 x, S32 y, MASK mask)
auto handled = LLTextBox::handleRightMouseDown(x, y, mask);
if (mAllowInteract && !handled)
{
// Singu TODO: Generic menus for groups
if (!mIsGroup && mNameID.notNull())
if (mNameID.notNull())
{
showMenu(this, sMenus[0], x, y);
showMenu(this, sMenus[getSelectedType()], x, y);
handled = true;
}
}

View File

@@ -76,15 +76,14 @@ BOOL LLNameEditor::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
bool simple_menu = mContextMenuHandle.get()->getName() == "rclickmenu";
std::string new_menu;
// Singu TODO: Generic menus for groups
bool needs_simple = mIsGroup || !mAllowInteract || mNameID.isNull(); // Need simple if no ID or blocking interaction
bool needs_simple = !mAllowInteract || mNameID.isNull(); // Need simple if no ID or blocking interaction
if (!simple_menu && needs_simple) // Switch to simple menu
{
new_menu = "menu_texteditor.xml";
}
else if (!needs_simple && simple_menu)
else // TODO: This is lazy, but I cannot recall a name editor that switches between group and avatar, so logic is not needed yet.
{
new_menu = "menu_nameeditor_avatar.xml";
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;

View File

@@ -749,8 +749,7 @@ void init_menus()
gMenuHolder->addChild(gLoginMenuBarView);
// Singu Note: Initialize common ScrollListMenus here
LFIDBearer::addCommonMenu(LLUICtrlFactory::getInstance()->buildMenu("menu_avs_list.xml", gMenuHolder)); // 0
//LFIDBearer::addCommonMenu(LLUICtrlFactory::getInstance()->buildMenu("menu_groups_list.xml")); // 1 // Singu TODO
LFIDBearer::buildMenus();
LLView* ins = gMenuBarView->getChildView("insert_world", true, false);
ins->setVisible(false);
@@ -9328,7 +9327,7 @@ class ListStartCall : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLAvatarActions::startCall(LFIDBearer::getActiveSelectedID());
(LFIDBearer::getActiveType == LFIDBearer::GROUP ? LLGroupActions::startCall : LLAvatarActions::startCall)(LFIDBearer::getActiveSelectedID());
return true;
}
};
@@ -9346,7 +9345,9 @@ class ListStartIM : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
LLAvatarActions::startIM(LFIDBearer::getActiveSelectedID());
const auto&& im = LFIDBearer::getActiveType() == LFIDBearer::GROUP ? [](const LLUUID& id) { LLGroupActions::startIM(id); } : LLAvatarActions::startIM;
for (const auto& id : LFIDBearer::getActiveSelectedIDs())
im(id);
return true;
}
};
@@ -9542,6 +9543,62 @@ struct MenuSLURLDict : public LLSingleton<MenuSLURLDict>
}
};
class ListIsInGroup : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
auto in_group = false;
for (const auto& id : LFIDBearer::getActiveSelectedIDs())
if (!(in_group = LLGroupActions::isInGroup(id)))
break;
gMenuHolder->findControl(userdata["control"].asString())->setValue(in_group);
return true;
}
};
class ListNotInGroup : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
auto in_group = true;
for (const auto& id : LFIDBearer::getActiveSelectedIDs())
if (in_group = LLGroupActions::isInGroup(id))
break;
gMenuHolder->findControl(userdata["control"].asString())->setValue(!in_group);
return true;
}
};
class ListLeave : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
for (const auto& id : LFIDBearer::getActiveSelectedIDs())
LLGroupActions::leave(id);
return true;
}
};
class ListJoin : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
for (const auto& id : LFIDBearer::getActiveSelectedIDs())
LLGroupActions::join(id);
return true;
}
};
class ListActivate : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{
for (const auto& id : LFIDBearer::getActiveSelectedIDs())
LLGroupActions::activate(id);
return true;
}
};
class MediaCtrlCopyURL : public view_listener_t
{
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
@@ -9925,6 +9982,11 @@ void initialize_menus()
addMenu(new ListEstateBan(), "List.EstateBan");
addMenu(new ListEstateEject(), "List.EstateEject");
addMenu(new ListToggleMute(), "List.ToggleMute");
addMenu(new ListIsInGroup, "List.IsInGroup");
addMenu(new ListNotInGroup, "List.NotInGroup");
addMenu(new ListLeave, "List.Leave");
addMenu(new ListJoin, "List.Join");
addMenu(new ListActivate, "List.Activate");
add_radar_listeners();

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<menu label="Group" name="groups_menu">
<menu_item_call label="Show Profile" name="show_group">
<on_click function="List.ShowProfile"/>
<on_visible function="List.EnableAnySelected"/>
</menu_item_call>
<menu_item_call label="Open Group Chat" name="im_group">
<on_click function="List.StartIM"/>
<on_visible function="List.IsInGroup"/>
</menu_item_call>
<menu_item_call label="Call Group" name="call_group">
<on_click function="List.StartCall"/>
<on_enable function="List.EnableCall"/>
<on_enable function="List.EnableSingleSelected"/>
<on_visible function="List.IsInGroup"/>
</menu_item_call>
<menu_item_call label="Activate Group" name="activate_group">
<on_click function="List.Activate"/>
<on_enable function="List.EnableSingleSelected"/>
<on_visible function="List.IsInGroup"/>
</menu_item_call>
<menu_item_call label="Join Group" name="join_group">
<on_click function="List.Join"/>
<on_visible function="List.NotInGroup"/>
</menu_item_call>
<menu_item_separator/>
<menu_item_call label="Leave Group" name="leave_group">
<on_click function="List.Leave"/>
<on_visible function="List.IsInGroup"/>
</menu_item_call>
<menu_item_separator/>
<menu_item_call label="Copy Name" name="copy_name">
<on_click function="List.CopyNames"/>
<on_visible function="List.EnableAnySelected"/>
</menu_item_call>
<menu_item_call label="Copy SLURL" name="copy_url">
<on_click function="List.CopySLURL"/>
<on_visible function="List.EnableAnySelected"/>
</menu_item_call>
<menu_item_call label="Copy Key" name="copy_key">
<on_click function="List.CopyUUIDs" />
<on_visible function="List.EnableAnySelected"/>
</menu_item_call>
</menu>

View File

@@ -0,0 +1,3 @@
<menu name="Group Name Editor Menu" filename="menu_groups_list.xml">
<menu name="Text" filename="menu_texteditor.xml"/>
</menu>