示例#1
0
        private void chromatogramsMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            ToolStripMenuItem menu = chromatogramsMenuItem;

            if (!DocumentUI.Settings.HasResults)
            {
                // Strange problem in .NET where a dropdown will show when
                // its menuitem is disabled.
                chromatogramsMenuItem.HideDropDown();
                return;
            }

            // If MeasuredResults is null, then this menuitem is incorrectly enabled
            var chromatograms = DocumentUI.Settings.MeasuredResults.Chromatograms;

            int i = 0;

            menu.DropDown.SuspendLayout();
            try
            {
                foreach (var chrom in chromatograms)
                {
                    string            name = chrom.Name;
                    ToolStripMenuItem item = null;
                    if (i < menu.DropDownItems.Count)
                    {
                        item = menu.DropDownItems[i] as ToolStripMenuItem;
                    }
                    if (item == null || name != item.Name)
                    {
                        // Remove the rest of the existing items
                        while (!ReferenceEquals(menu.DropDownItems[i], toolStripSeparatorReplicates))
                        {
                            menu.DropDownItems.RemoveAt(i);
                        }

                        ShowChromHandler handler = new ShowChromHandler(SkylineWindow, chrom.Name);
                        item = new ToolStripMenuItem(chrom.Name, null,
                                                     handler.menuItem_Click);
                        menu.DropDownItems.Insert(i, item);
                    }

                    i++;
                }

                // Remove the rest of the existing items
                while (!ReferenceEquals(menu.DropDownItems[i], toolStripSeparatorReplicates))
                {
                    menu.DropDownItems.RemoveAt(i);
                }
            }
            finally
            {
                menu.DropDown.ResumeLayout();
            }

            closeChromatogramMenuItem.Enabled = !string.IsNullOrEmpty(SkylineWindow.SelectedGraphChromName);
        }
示例#2
0
        private void chromatogramsMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            ToolStripMenuItem menu = chromatogramsMenuItem;
            if (!DocumentUI.Settings.HasResults)
            {
                // Strange problem in .NET where a dropdown will show when
                // its menuitem is disabled.
                chromatogramsMenuItem.HideDropDown();
                return;
            }

            // If MeasuredResults is null, then this menuitem is incorrectly enabled
            var chromatograms = DocumentUI.Settings.MeasuredResults.Chromatograms;

            int i = 0;
            foreach (var chrom in chromatograms)
            {
                string name = chrom.Name;
                ToolStripMenuItem item = null;
                if (i < menu.DropDownItems.Count)
                    item = menu.DropDownItems[i] as ToolStripMenuItem;
                if (item == null || name != item.Name)
                {
                    // Remove the rest of the existing items
                    while (!ReferenceEquals(menu.DropDownItems[i], toolStripSeparatorReplicates))
                        menu.DropDownItems.RemoveAt(i);

                    ShowChromHandler handler = new ShowChromHandler(this, chrom.Name);
                    item = new ToolStripMenuItem(chrom.Name, null,
                        handler.menuItem_Click);
                    menu.DropDownItems.Insert(i, item);
                }

                i++;
            }

            // Remove the rest of the existing items
            while (!ReferenceEquals(menu.DropDownItems[i], toolStripSeparatorReplicates))
                menu.DropDownItems.RemoveAt(i);
        }