1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Diagnostics;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Text;
|
---|
7 | using System.Windows.Forms;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.MainForm.WindowsForms {
|
---|
10 | public sealed partial class ViewContextMenuStrip : ContextMenuStrip {
|
---|
11 | public ViewContextMenuStrip() {
|
---|
12 | InitializeComponent();
|
---|
13 | this.menuItems = new Dictionary<Type, ToolStripMenuItem>();
|
---|
14 | this.ignoredViewTypes = new List<Type>();
|
---|
15 | }
|
---|
16 |
|
---|
17 | public ViewContextMenuStrip(object item)
|
---|
18 | : this() {
|
---|
19 | this.Item = item;
|
---|
20 | }
|
---|
21 |
|
---|
22 | private object item;
|
---|
23 | public object Item {
|
---|
24 | get { return this.item; }
|
---|
25 | set {
|
---|
26 | if (this.item != value) {
|
---|
27 | this.item = value;
|
---|
28 | this.RefreshMenuItems();
|
---|
29 | }
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | private List<Type> ignoredViewTypes;
|
---|
34 | public IEnumerable<Type> IgnoredViewTypes {
|
---|
35 | get { return this.ignoredViewTypes; }
|
---|
36 | set { this.ignoredViewTypes = new List<Type>(value); RefreshMenuItems(); }
|
---|
37 | }
|
---|
38 |
|
---|
39 | private Dictionary<Type, ToolStripMenuItem> menuItems;
|
---|
40 | public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems {
|
---|
41 | get { return this.menuItems; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | private void RefreshMenuItems() {
|
---|
45 | if (InvokeRequired) Invoke((Action)RefreshMenuItems);
|
---|
46 | else {
|
---|
47 | this.Items.Clear();
|
---|
48 | this.menuItems.Clear();
|
---|
49 |
|
---|
50 | if (this.item != null) {
|
---|
51 | ToolStripMenuItem menuItem;
|
---|
52 | IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(), true);
|
---|
53 | foreach (Type t in types.Except(IgnoredViewTypes)) {
|
---|
54 | menuItem = new ToolStripMenuItem();
|
---|
55 | menuItem.Tag = t;
|
---|
56 | menuItem.Text = ViewAttribute.GetViewName(t);
|
---|
57 |
|
---|
58 | this.menuItems.Add(t, menuItem);
|
---|
59 | this.Items.Add(menuItem);
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|