#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 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();
this.menuItems = new Dictionary();
this.ignoredViewTypes = new List();
}
public ViewContextMenuStrip(IContainer container)
: base(container) {
InitializeComponent();
this.menuItems = new Dictionary();
this.ignoredViewTypes = new List();
}
private object item;
public object Item {
get { return this.item; }
set {
if (this.item != value) {
this.item = value;
this.RefreshMenuItems();
}
}
}
private List ignoredViewTypes;
public IEnumerable IgnoredViewTypes {
get { return this.ignoredViewTypes; }
set { this.ignoredViewTypes = new List(value); RefreshMenuItems(); }
}
private Dictionary menuItems;
public IEnumerable> MenuItems {
get { return this.menuItems; }
}
private void RefreshMenuItems() {
if (InvokeRequired) Invoke((Action)RefreshMenuItems);
else {
foreach (ToolStripMenuItem m in menuItems.Values)
m.Dispose();
this.Items.Clear();
this.menuItems.Clear();
if (this.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);
this.menuItems.Add(t, menuItem);
this.Items.Add(menuItem);
}
}
}
}
}
}