Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewContextMenuStrip.cs @ 10377

Last change on this file since 10377 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Linq;
26using System.Windows.Forms;
27
28namespace HeuristicLab.MainForm.WindowsForms {
29  public sealed partial class ViewContextMenuStrip : ContextMenuStrip {
30    public ViewContextMenuStrip() {
31      InitializeComponent();
32      this.menuItems = new Dictionary<Type, ToolStripMenuItem>();
33      this.ignoredViewTypes = new List<Type>();
34    }
35
36    public ViewContextMenuStrip(IContainer container)
37      : base(container) {
38        InitializeComponent();
39      this.menuItems = new Dictionary<Type, ToolStripMenuItem>();
40      this.ignoredViewTypes = new List<Type>();
41    }
42
43    private object item;
44    public object Item {
45      get { return this.item; }
46      set {
47        if (this.item != value) {
48          this.item = value;
49          this.RefreshMenuItems();
50        }
51      }
52    }
53
54    private List<Type> ignoredViewTypes;
55    public IEnumerable<Type> IgnoredViewTypes {
56      get { return this.ignoredViewTypes; }
57      set { this.ignoredViewTypes = new List<Type>(value); RefreshMenuItems(); }
58    }
59
60    private Dictionary<Type, ToolStripMenuItem> menuItems;
61    public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems {
62      get { return this.menuItems; }
63    }
64
65    private void RefreshMenuItems() {
66      if (InvokeRequired) Invoke((Action)RefreshMenuItems);
67      else {
68        foreach (ToolStripMenuItem m in menuItems.Values)
69          m.Dispose();
70        this.Items.Clear();
71        this.menuItems.Clear();
72
73        if (this.item != null) {
74          ToolStripMenuItem menuItem;
75          IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(), true);
76          foreach (Type t in types.Except(IgnoredViewTypes)) {
77            menuItem = new ToolStripMenuItem();
78            menuItem.Tag = t;
79            menuItem.Text = ViewAttribute.GetViewName(t);
80
81            this.menuItems.Add(t, menuItem);
82            this.Items.Add(menuItem);
83          }
84        }
85      }
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.