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 | this.Items.Clear();
|
---|
46 | this.menuItems.Clear();
|
---|
47 |
|
---|
48 | if (this.item != null) {
|
---|
49 | ToolStripMenuItem menuItem;
|
---|
50 | IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(),true);
|
---|
51 | foreach (Type t in types.Except(IgnoredViewTypes)) {
|
---|
52 | menuItem = new ToolStripMenuItem();
|
---|
53 | menuItem.Tag = t;
|
---|
54 | menuItem.Text = ViewAttribute.GetViewName(t);
|
---|
55 |
|
---|
56 | this.menuItems.Add(t, menuItem);
|
---|
57 | this.Items.Add(menuItem);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|