STORM-248 FIXED The 'Share' button in My Inventory now respects multiple selection.

- The button is now enabled only if all selected items are shareable.
  (it had checked only one currently selected item)
- Eliminated some copy&paste.
master
Vadim ProductEngine 2010-09-28 22:14:22 +03:00
parent df290ee4d4
commit b0cadec6fb
3 changed files with 85 additions and 25 deletions

View File

@ -49,6 +49,7 @@
#include "llfloaterpay.h"
#include "llfloaterworldmap.h"
#include "llgiveinventory.h"
#include "llinventorybridge.h"
#include "llinventorymodel.h" // for gInventory.findCategoryUUIDForType
#include "llinventorypanel.h"
#include "llimview.h" // for gIMMgr
@ -443,17 +444,27 @@ namespace action_give_inventory
}
/**
* Checks My Inventory visibility.
* @return active inventory panel, or NULL if there's no such panel
*/
static bool is_give_inventory_acceptable()
static LLInventoryPanel* get_active_inventory_panel()
{
LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE);
if (!active_panel)
{
active_panel = get_outfit_editor_inventory_panel();
if (!active_panel) return false;
}
return active_panel;
}
/**
* Checks My Inventory visibility.
*/
static bool is_give_inventory_acceptable()
{
LLInventoryPanel* active_panel = get_active_inventory_panel();
if (!active_panel) return false;
// check selection in the panel
const uuid_set_t inventory_selected_uuids = active_panel->getRootFolder()->getSelectionList();
if (inventory_selected_uuids.empty()) return false; // nothing selected
@ -543,12 +554,8 @@ namespace action_give_inventory
return;
}
LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE);
if (!active_panel)
{
active_panel = get_outfit_editor_inventory_panel();
if (!active_panel) return;
}
LLInventoryPanel* active_panel = get_active_inventory_panel();
if (!active_panel) return;
const uuid_set_t inventory_selected_uuids = active_panel->getRootFolder()->getSelectionList();
if (inventory_selected_uuids.empty())
@ -632,12 +639,8 @@ namespace action_give_inventory
llassert(avatar_names.size() == avatar_uuids.size());
LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE);
if (!active_panel)
{
active_panel = get_outfit_editor_inventory_panel();
if (!active_panel) return;
}
LLInventoryPanel* active_panel = get_active_inventory_panel();
if (!active_panel) return;
const uuid_set_t inventory_selected_uuids = active_panel->getRootFolder()->getSelectionList();
if (inventory_selected_uuids.empty())
@ -672,6 +675,53 @@ void LLAvatarActions::shareWithAvatars()
LLNotificationsUtil::add("ShareNotification");
}
// static
bool LLAvatarActions::canShareSelectedItems(LLInventoryPanel* inv_panel /* = NULL*/)
{
using namespace action_give_inventory;
if (!inv_panel)
{
LLInventoryPanel* active_panel = get_active_inventory_panel();
if (!active_panel) return false;
inv_panel = active_panel;
}
// check selection in the panel
LLFolderView* root_folder = inv_panel->getRootFolder();
const uuid_set_t inventory_selected_uuids = root_folder->getSelectionList();
if (inventory_selected_uuids.empty()) return false; // nothing selected
bool can_share = true;
uuid_set_t::const_iterator it = inventory_selected_uuids.begin();
const uuid_set_t::const_iterator it_end = inventory_selected_uuids.end();
for (; it != it_end; ++it)
{
LLViewerInventoryCategory* inv_cat = gInventory.getCategory(*it);
// any category can be offered.
if (inv_cat)
{
continue;
}
// check if inventory item can be given
LLFolderViewItem* item = root_folder->getItemByID(*it);
if (!item) return false;
LLInvFVBridge* bridge = dynamic_cast<LLInvFVBridge*>(item->getListener());
if (bridge && bridge->canShare())
{
continue;
}
// there are neither item nor category in inventory
can_share = false;
break;
}
return can_share;
}
// static
void LLAvatarActions::toggleBlock(const LLUUID& id)
{

View File

@ -34,6 +34,8 @@
#include <string>
#include <vector>
class LLInventoryPanel;
/**
* Friend-related actions (add, remove, offer teleport, etc)
*/
@ -183,6 +185,15 @@ public:
*/
static bool canOfferTeleport(const uuid_vec_t& ids);
/**
* Checks whether all items selected in the given inventory panel can be shared
*
* @param inv_panel Inventory panel to get selection from. If NULL, the active inventory panel is used.
*
* @return false if the selected items cannot be shared or the active inventory panel cannot be obtained
*/
static bool canShareSelectedItems(LLInventoryPanel* inv_panel = NULL);
private:
static bool callbackAddFriend(const LLSD& notification, const LLSD& response);
static bool callbackAddFriendWithMessage(const LLSD& notification, const LLSD& response);

View File

@ -311,18 +311,17 @@ bool LLSidepanelInventory::canShare()
LLPanelMainInventory* panel_main_inventory =
mInventoryPanel->findChild<LLPanelMainInventory>("panel_main_inventory");
LLFolderView* root_folder =
panel_main_inventory->getActivePanel()->getRootFolder();
if (!panel_main_inventory)
{
llwarns << "Failed to get the main inventory panel" << llendl;
return false;
}
LLFolderViewItem* current_item = root_folder->hasVisibleChildren()
? root_folder->getCurSelectedItem()
: NULL;
LLInventoryPanel* active_panel = panel_main_inventory->getActivePanel();
// Avoid flicker in the Recent tab while inventory is being loaded.
if (!active_panel->getRootFolder()->hasVisibleChildren()) return false;
LLInvFVBridge* bridge = current_item
? dynamic_cast <LLInvFVBridge*> (current_item->getListener())
: NULL;
return bridge ? bridge->canShare() : false;
return LLAvatarActions::canShareSelectedItems(active_panel);
}
LLInventoryItem *LLSidepanelInventory::getSelectedItem()