private void UpdateDynamicMenus(IDocument doc) { IDynamicMenu newMenu = null; if (doc != null) newMenu = doc.GetDynamicMenu(); if (newMenu != dynamicMenu) { if (dynamicMenu != null) { foreach (ToolStripMenuItem menuItem in dynamicMenu.GetMenuItems()) MainMenuStrip.Items.Remove(menuItem); dynamicMenu.Close(); } if (newMenu != null) { int preferredIndex = newMenu.PreferredIndex; if (preferredIndex < 0) preferredIndex = 3; foreach (ToolStripMenuItem menuItem in newMenu.GetMenuItems()) MainMenuStrip.Items.Insert(preferredIndex++, menuItem); } dynamicMenu = newMenu; } }