private void IteratePanels([NotNull] IMainRibbonExtension factory) { bool found = false; var children = MdiChildren.ToArray(); if (children.Any()) { bool current = false; foreach (var child in children) { if (current && child.Tag == factory) { current = false; found = true; child.Focus(); break; } if (child == ActiveMdiChild) { current = true; } } if (current) { foreach (var child in children) { if (child.Tag == factory) { found = true; child.Focus(); break; } } } } if (!found) { if (_panelListActionId.TryGetValue(factory.Id, out var actionId) && _panelsListButtons.TryGetValue(actionId, out var button)) { var subItem = button.SubItems.OfType <ButtonItem>().FirstOrDefault(); subItem?.RaiseClick(); } } }