Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewContextMenuStrip.cs @ 3521

Last change on this file since 3521 was 3389, checked in by mkommend, 15 years ago

enhanced caching of views in ViewHost and adapted MainFormManager to use IContentView (ticket #972)

File size: 1.8 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      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}
Note: See TracBrowser for help on using the repository browser.