Ejemplo n.º 1
0
 // Potentially replace "peptide" with "molecule" etc in all controls on open, or possibly disable non-proteomic components etc
 public void OnLoad(Form form)
 {
     if (!IgnoreModeUI)
     {
         PeptideToMoleculeTextMapper.TranslateForm(form, ModeUI, _modeUIExtender);
     }
 }
Ejemplo n.º 2
0
            // 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
                }
            }
Ejemplo n.º 3
0
            // 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
                }
            }
Ejemplo n.º 4
0
            internal void AdjustMenusForModeUI(ToolStripItemCollection items)
            {
                var dictOriginalText = _modeUIExtender.GetOriginalToolStripText();

                foreach (var item in items)
                {
                    if (item is ToolStripMenuItem menuItem)
                    {
                        if (!dictOriginalText.TryGetValue(menuItem, out var originalText))
                        {
                            // Preserve original text in case we need to restore later
                            dictOriginalText[menuItem] = menuItem.Text;
                        }
                        else
                        {
                            // Restore original text so translator has a clean start
                            menuItem.Text = originalText;
                        }
                    }
                }

                // Update text, swapping "peptide" for "molecule" etc, except as specifically prohibited
                PeptideToMoleculeTextMapper.TranslateMenuItems(items, ModeUI, _modeUIExtender);


                var owner = items[0].Owner;

                if (owner != null)
                {
                    owner.Update();
                }

                // Recurse into sub menus
                foreach (var item in items)
                {
                    if (item is ToolStripMenuItem menuItem && menuItem.DropDownItems.Count > 0)
                    {
                        AdjustMenusForModeUI(menuItem.DropDownItems);
                    }
                }
            }
Ejemplo n.º 5
0
 // Like string.Format, but does UIMode translation on the format string (but not the args)
 public string Format(string format, params object[] args)
 {
     return(IgnoreModeUI ? string.Format(format, args) : PeptideToMoleculeTextMapper.Format(format, ModeUI, args));
 }
Ejemplo n.º 6
0
 public string Translate(string txt)
 {
     return(IgnoreModeUI ? txt : PeptideToMoleculeTextMapper.Translate(txt, ModeUI));
 }