#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows.Forms; namespace HeuristicLab.MainForm.WindowsForms { public sealed partial class ViewContextMenuStrip : ContextMenuStrip { public ViewContextMenuStrip() { InitializeComponent(); menuItems = new Dictionary(); ignoredViewTypes = new List(); } public ViewContextMenuStrip(IContainer container) : base(container) { InitializeComponent(); menuItems = new Dictionary(); ignoredViewTypes = new List(); ShowBreadcrumbsToolStripMenuItem = new ToolStripMenuItem("Show Breadcrumbs"); ShowBreadcrumbsToolStripMenuItem.Click += ShowBreadcrumbsToolStripMenuItem_Click; ShowBreadcrumbsToolStripMenuItem.CheckedChanged += ShowBreadcrumbsToolStripMenuItem_CheckedChanged; } private object item; public object Item { get { return item; } set { if (item != value) { item = value; RefreshMenuItems(); } } } private List ignoredViewTypes; public IEnumerable IgnoredViewTypes { get { return ignoredViewTypes; } set { ignoredViewTypes = new List(value); RefreshMenuItems(); } } private Dictionary menuItems; public IEnumerable> MenuItems { get { return menuItems; } } public ToolStripMenuItem ShowBreadcrumbsToolStripMenuItem { get; private set; } private void RefreshMenuItems() { if (InvokeRequired) Invoke((Action)RefreshMenuItems); else { foreach (ToolStripMenuItem m in menuItems.Values) m.Dispose(); Items.Clear(); menuItems.Clear(); if (item != null) { ToolStripMenuItem menuItem; IEnumerable types = MainFormManager.GetViewTypes(item.GetType(), true); foreach (Type t in types.Except(IgnoredViewTypes)) { menuItem = new ToolStripMenuItem(); menuItem.Tag = t; menuItem.Text = ViewAttribute.GetViewName(t); menuItems.Add(t, menuItem); Items.Add(menuItem); } if (Items.Count > 0) Items.Add(new ToolStripSeparator()); Items.Add(ShowBreadcrumbsToolStripMenuItem); } } } public event EventHandler ShowBreadcrumbsChanged; private void OnShowBreadcrumbsChanged() { var handler = ShowBreadcrumbsChanged; if (handler != null) handler(this, EventArgs.Empty); } private void ShowBreadcrumbsToolStripMenuItem_CheckedChanged(object sender, EventArgs e) { OnShowBreadcrumbsChanged(); } private void ShowBreadcrumbsToolStripMenuItem_Click(object sender, EventArgs e) { ShowBreadcrumbsToolStripMenuItem.Checked = !ShowBreadcrumbsToolStripMenuItem.Checked; } } }