std::vector<IMenu*> LayoutManager::findAllMenus(IWindow& window, const char* path) { // create a collection of all menus associated with this window. auto& windowMenus = window.menus(); std::vector<IMenu*> menus(windowMenus.size() + dynamicMenus_.size()); // copy all the menus owned by the window auto it = std::transform(windowMenus.begin(), windowMenus.end(), menus.begin(), [](const std::unique_ptr<IMenu>& menu) { return menu.get(); }); // copy all the menus dynamically registered for this window auto windowId = safe_str(window.id()); it = std::copy_if(dynamicMenus_.begin(), dynamicMenus_.end(), it, [&](IMenu* menu) { auto menuWindowId = safe_str(menu->windowId()); return strcmp(windowId, menuWindowId) == 0; }); // resize the collection to the actual number of menus that were collected menus.erase(it, menus.end()); for (auto it = menus.begin(); it != menus.end();) { if (matchMenu(**it, path)) { ++it; continue; } it = menus.erase(it); } return menus; }
void LayoutManager::removeWindow(IWindow& window) { auto windowId = safe_str(window.id()); auto windowIt = windows_.find(windowId); if (windowIt == windows_.end()) { return; } removeActions(window); removeViews(window); windows_.erase(windowId); }
void LayoutManager::addWindow(IWindow& window) { auto windowId = safe_str(window.id()); auto windowIt = windows_.find(windowId); if (windowIt != windows_.end()) { // error? return; } windows_[windowId] = &window; // after adding a window we need to reevaluate all the actions and views that we registered // against this window as they now all need to be added to the UI refreshActions(window); refreshViews(window); }