[3742] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11170] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3742] | 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 |
|
---|
| 22 | using System;
|
---|
[3437] | 23 | using System.Collections.Generic;
|
---|
[9186] | 24 | using System.ComponentModel;
|
---|
[3437] | 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 |
|
---|
| 28 | namespace 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 |
|
---|
[9186] | 36 | public ViewContextMenuStrip(IContainer container)
|
---|
| 37 | : base(container) {
|
---|
| 38 | InitializeComponent();
|
---|
| 39 | this.menuItems = new Dictionary<Type, ToolStripMenuItem>();
|
---|
| 40 | this.ignoredViewTypes = new List<Type>();
|
---|
[3437] | 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() {
|
---|
[3464] | 66 | if (InvokeRequired) Invoke((Action)RefreshMenuItems);
|
---|
| 67 | else {
|
---|
[9180] | 68 | foreach (ToolStripMenuItem m in menuItems.Values)
|
---|
| 69 | m.Dispose();
|
---|
[3464] | 70 | this.Items.Clear();
|
---|
| 71 | this.menuItems.Clear();
|
---|
[3437] | 72 |
|
---|
[3464] | 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);
|
---|
[3437] | 80 |
|
---|
[3464] | 81 | this.menuItems.Add(t, menuItem);
|
---|
| 82 | this.Items.Add(menuItem);
|
---|
| 83 | }
|
---|
[3437] | 84 | }
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|