bool CContextMenuManager::OnClick(unsigned int id, const CFileItemPtr& item) { if (!item) return false; auto it = std::find_if(m_items.begin(), m_items.end(), [id](const Item& kv){ return kv.first == id; }); if (it == m_items.end()) { CLog::Log(LOGERROR, "CContextMenuManager: unknown button id '%u'", id); return false; } CContextMenuItem menuItem = it->second; if (menuItem.IsGroup()) { CLog::Log(LOGDEBUG, "CContextMenuManager: showing group '%s'", menuItem.ToString().c_str()); CContextButtons choices; AddVisibleItems(item, choices, menuItem); if (choices.empty()) { CLog::Log(LOGERROR, "CContextMenuManager: no items in group '%s'", menuItem.ToString().c_str()); return false; } int choice = CGUIDialogContextMenu::ShowAndGetChoice(choices); if (choice == -1) return false; return OnClick(choice, item); } return menuItem.Execute(item); }
bool CContextMenuItem::operator==(const CContextMenuItem& other) const { if (IsGroup() && other.IsGroup()) return (m_groupId == other.m_groupId && m_parent == other.m_parent); return (IsGroup() == other.IsGroup()) && (m_parent == other.m_parent) && (m_library == other.m_library) && ((!m_addon && !other.m_addon) || (m_addon && other.m_addon && m_addon->ID() == other.m_addon->ID())); }
bool CContextMenuManager::IsVisible( const CContextMenuItem& menuItem, const CContextMenuItem& root, const CFileItemPtr& fileItem) { if (menuItem.GetLabel().empty() || !root.IsParentOf(menuItem)) return false; if (menuItem.IsGroup()) return std::any_of(m_items.begin(), m_items.end(), [&](const Item& kv){ return menuItem.IsParentOf(kv.second) && kv.second.IsVisible(fileItem); }); return menuItem.IsVisible(fileItem); }
bool CContextMenuManager::IsVisible( const CContextMenuItem& menuItem, const CContextMenuItem& root, const CFileItem& fileItem) const { if (menuItem.GetLabel(fileItem).empty() || !root.IsParentOf(menuItem)) return false; if (menuItem.IsGroup()) { CSingleLock lock(m_criticalSection); return std::any_of(m_addonItems.begin(), m_addonItems.end(), [&](const CContextMenuItem& other){ return menuItem.IsParentOf(other) && other.IsVisible(fileItem); }); } return menuItem.IsVisible(fileItem); }