bool CGUIMediaWindow::OnPopupMenu(int iItem) { // popup the context menu // grab our context menu CContextButtons buttons; GetContextButtons(iItem, buttons); if (buttons.size()) { // mark the item if (iItem >= 0 && iItem < m_vecItems->Size()) m_vecItems->Get(iItem)->Select(true); CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)m_gWindowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU); if (!pMenu) return false; // load our menu pMenu->Initialize(); // add the buttons and execute it for (CContextButtons::iterator it = buttons.begin(); it != buttons.end(); it++) pMenu->AddButton((*it).second); // position it correctly float posX = 200; float posY = 100; const CGUIControl *pList = GetControl(CONTROL_VIEW_START); if (pList) { posX = pList->GetXPosition() + pList->GetWidth() / 2; posY = pList->GetYPosition() + pList->GetHeight() / 2; } pMenu->SetPosition(posX - pMenu->GetWidth() / 2, posY - pMenu->GetHeight() / 2); pMenu->DoModal(); // translate our button press CONTEXT_BUTTON btn = CONTEXT_BUTTON_CANCELLED; if (pMenu->GetButton() > 0 && pMenu->GetButton() <= (int)buttons.size()) btn = buttons[pMenu->GetButton() - 1].first; // deselect our item if (iItem >= 0 && iItem < m_vecItems->Size()) m_vecItems->Get(iItem)->Select(false); if (btn != CONTEXT_BUTTON_CANCELLED) return OnContextButton(iItem, btn); } return false; }
bool CGUIDialogContextMenu::SourcesMenu(const CStdString &strType, const CFileItemPtr item, float posX, float posY) { // TODO: This should be callable even if we don't have any valid items if (!item) return false; // popup the context menu CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)g_windowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU); if (pMenu) { // load our menu pMenu->Initialize(); // grab our context menu CContextButtons buttons; GetContextButtons(strType, item, buttons); // add the buttons and execute it for (CContextButtons::iterator it = buttons.begin(); it != buttons.end(); it++) pMenu->AddButton((*it).second); // position it correctly pMenu->OffsetPosition(posX, posY); pMenu->DoModal(); // translate our button press CONTEXT_BUTTON btn = CONTEXT_BUTTON_CANCELLED; if (pMenu->GetButton() > 0 && pMenu->GetButton() <= (int)buttons.size()) btn = buttons[pMenu->GetButton() - 1].first; if (btn != CONTEXT_BUTTON_CANCELLED) return OnContextButton(strType, item, btn); } return false; }
bool CGUIMediaWindow::OnPopupMenu(int iItem) { // popup the context menu // grab our context menu CContextButtons buttons; GetContextButtons(iItem, buttons); if (buttons.size()) { // mark the item if (iItem >= 0 && iItem < m_vecItems->Size()) m_vecItems->Get(iItem)->Select(true); CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)m_gWindowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU); if (!pMenu) return false; // load our menu pMenu->Initialize(); // add the buttons and execute it for (CContextButtons::iterator it = buttons.begin(); it != buttons.end(); it++) pMenu->AddButton((*it).second); // position it correctly CPoint pos = GetContextPosition(); pMenu->OffsetPosition(pos.x, pos.y); pMenu->DoModal(); // translate our button press CONTEXT_BUTTON btn = CONTEXT_BUTTON_CANCELLED; if (pMenu->GetButton() > 0 && pMenu->GetButton() <= (int)buttons.size()) btn = buttons[pMenu->GetButton() - 1].first; // deselect our item if (iItem >= 0 && iItem < m_vecItems->Size()) m_vecItems->Get(iItem)->Select(false); if (btn != CONTEXT_BUTTON_CANCELLED) return OnContextButton(iItem, btn); } return false; }
bool CGUIDialogPVRItemsViewBase::ContextMenu(int itemIdx) { auto InRange = [](size_t i, std::pair<size_t, size_t> range){ return i >= range.first && i < range.second; }; if (itemIdx < 0 || itemIdx >= m_vecItems->Size()) return false; const CFileItemPtr item = m_vecItems->Get(itemIdx); if (!item) return false; CContextButtons buttons; // Add the global menu const ContextMenuView globalMenu = CServiceBroker::GetContextMenuManager().GetItems(*item, CContextMenuManager::MAIN); auto globalMenuRange = std::make_pair(buttons.size(), buttons.size() + globalMenu.size()); for (const auto& menu : globalMenu) buttons.emplace_back(~buttons.size(), menu->GetLabel(*item)); // Add addon menus const ContextMenuView addonMenu = CServiceBroker::GetContextMenuManager().GetAddonItems(*item, CContextMenuManager::MAIN); auto addonMenuRange = std::make_pair(buttons.size(), buttons.size() + addonMenu.size()); for (const auto& menu : addonMenu) buttons.emplace_back(~buttons.size(), menu->GetLabel(*item)); if (buttons.empty()) return true; int idx = CGUIDialogContextMenu::Show(buttons); if (idx < 0 || idx >= static_cast<int>(buttons.size())) return false; Close(); if (InRange(idx, globalMenuRange)) return CONTEXTMENU::LoopFrom(*globalMenu[idx - globalMenuRange.first], item); return CONTEXTMENU::LoopFrom(*addonMenu[idx - addonMenuRange.first], item); }
int CGUIDialogContextMenu::ShowAndGetChoice(const CContextButtons &choices) { if (choices.size() == 0) return -1; CGUIDialogContextMenu *pMenu = (CGUIDialogContextMenu *)g_windowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU); if (pMenu) { pMenu->m_buttons = choices; pMenu->Initialize(); pMenu->PositionAtCurrentFocus(); pMenu->DoModal(); return pMenu->m_clickedButton; } return -1; }
void CContextMenuManager::AddVisibleItems( const CFileItemPtr& item, CContextButtons& list, const CContextMenuItem& root /* = CContextMenuItem::MAIN */) { if (!item) return; const int initialSize = list.size(); for (const auto& kv : m_items) if (IsVisible(kv.second, root, item)) list.push_back(std::make_pair(kv.first, kv.second.GetLabel())); if (root == MAIN || root == MANAGE) { std::stable_sort(list.begin() + initialSize, list.end(), [](const std::pair<int, std::string>& lhs, const std::pair<int, std::string>& rhs) { return lhs.second < rhs.second; } ); } }
bool CGUIMediaWindow::OnPopupMenu(int iItem) { // popup the context menu // grab our context menu CContextButtons buttons; GetContextButtons(iItem, buttons); if (buttons.size()) { // mark the item if (iItem >= 0 && iItem < m_vecItems->Size()) m_vecItems->Get(iItem)->Select(true); int choice = CGUIDialogContextMenu::ShowAndGetChoice(buttons); // deselect our item if (iItem >= 0 && iItem < m_vecItems->Size()) m_vecItems->Get(iItem)->Select(false); if (choice >= 0) return OnContextButton(iItem, (CONTEXT_BUTTON)choice); } return false; }