// For all items in a menu, attempt to take a string like "{0} peptides" and return one like "{0} molecules" if menu item is not purely proteomic // Update keyboard accelerators as needed public static void TranslateMenuItems(ToolStripItemCollection items, SrmDocument.DOCUMENT_TYPE modeUI, ModeUIExtender extender) { var mapper = new PeptideToMoleculeTextMapper(modeUI, extender); if (items != null) { mapper.FindInUseKeyboardAccelerators(items); var activeItems = new List <ToolStripItem>(); for (int i = 0; i < items.Count; i++) { var item = items[i]; ModeUIExtender.MODE_UI_HANDLING_TYPE handlingType; if (!mapper.HandledComponents.TryGetValue(item, out handlingType)) { handlingType = ModeUIExtender.MODE_UI_HANDLING_TYPE.auto; } bool isActive; switch (modeUI) { case SrmDocument.DOCUMENT_TYPE.proteomic: isActive = handlingType != ModeUIExtender.MODE_UI_HANDLING_TYPE.small_mol && handlingType != ModeUIExtender.MODE_UI_HANDLING_TYPE.small_mol_only && handlingType != ModeUIExtender.MODE_UI_HANDLING_TYPE.mixed_only; break; case SrmDocument.DOCUMENT_TYPE.small_molecules: isActive = handlingType != ModeUIExtender.MODE_UI_HANDLING_TYPE.proteomic && handlingType != ModeUIExtender.MODE_UI_HANDLING_TYPE.mixed_only; break; case SrmDocument.DOCUMENT_TYPE.mixed: isActive = handlingType != ModeUIExtender.MODE_UI_HANDLING_TYPE.small_mol_only; break; default: isActive = false; Assume.Fail(@"unknown UI mode"); break; } if (isActive) { activeItems.Add(item); } item.Visible = isActive; } mapper.Translate(activeItems); // Update the menu items that aren't inherently wrong for current UI mode } }
// For all controls in a form, attempt to take a string like "{0} peptides" and return one like "{0} molecules" if doctype is not purely proteomic public static void TranslateForm(Form form, SrmDocument.DOCUMENT_TYPE modeUI, ModeUIExtender extender = null) { if (form != null) { var mapper = new PeptideToMoleculeTextMapper(modeUI, extender); form.Text = mapper.TranslateString(form.Text); // Update the title // Find tooltip components in the form, if any mapper.ToolTips = (from field in form.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) where typeof(Component).IsAssignableFrom(field.FieldType) let component = (Component)field.GetValue(form) where component is ToolTip select component as ToolTip).ToList(); mapper.FindInUseKeyboardAccelerators(form.Controls); mapper.Translate(form.Controls); // Update the controls } }