Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ViewContextMenuStrip.cs @ 3714

Last change on this file since 3714 was 3464, checked in by gkronber, 15 years ago

Added invoke-required check in ViewContextMenuStrip #972.

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Diagnostics;
5using System.Linq;
6using System.Text;
7using System.Windows.Forms;
8
9namespace 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}
Note: See TracBrowser for help on using the repository browser.