Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Breadcrumbs/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ViewContextMenuStrip.cs @ 10042

Last change on this file since 10042 was 10042, checked in by jkarder, 11 years ago

#2116: added prototype of a breadcrumb navigation

File size: 3.8 KB
RevLine 
[3742]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 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
22using System;
[3437]23using System.Collections.Generic;
[9186]24using System.ComponentModel;
[3437]25using System.Linq;
26using System.Windows.Forms;
27
28namespace HeuristicLab.MainForm.WindowsForms {
29  public sealed partial class ViewContextMenuStrip : ContextMenuStrip {
30    public ViewContextMenuStrip() {
31      InitializeComponent();
[10042]32      menuItems = new Dictionary<Type, ToolStripMenuItem>();
33      ignoredViewTypes = new List<Type>();
[3437]34    }
35
[9186]36    public ViewContextMenuStrip(IContainer container)
37      : base(container) {
[10042]38      InitializeComponent();
39      menuItems = new Dictionary<Type, ToolStripMenuItem>();
40      ignoredViewTypes = new List<Type>();
41      ShowBreadcrumbsToolStripMenuItem = new ToolStripMenuItem("Show Breadcrumbs");
42      ShowBreadcrumbsToolStripMenuItem.Click += ShowBreadcrumbsToolStripMenuItem_Click;
43      ShowBreadcrumbsToolStripMenuItem.CheckedChanged += ShowBreadcrumbsToolStripMenuItem_CheckedChanged;
[3437]44    }
45
46    private object item;
47    public object Item {
[10042]48      get { return item; }
[3437]49      set {
[10042]50        if (item != value) {
51          item = value;
52          RefreshMenuItems();
[3437]53        }
54      }
55    }
56
57    private List<Type> ignoredViewTypes;
58    public IEnumerable<Type> IgnoredViewTypes {
[10042]59      get { return ignoredViewTypes; }
60      set { ignoredViewTypes = new List<Type>(value); RefreshMenuItems(); }
[3437]61    }
62
63    private Dictionary<Type, ToolStripMenuItem> menuItems;
64    public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems {
[10042]65      get { return menuItems; }
[3437]66    }
67
[10042]68    public ToolStripMenuItem ShowBreadcrumbsToolStripMenuItem { get; private set; }
69
[3437]70    private void RefreshMenuItems() {
[3464]71      if (InvokeRequired) Invoke((Action)RefreshMenuItems);
72      else {
[9180]73        foreach (ToolStripMenuItem m in menuItems.Values)
74          m.Dispose();
[10042]75        Items.Clear();
76        menuItems.Clear();
[3437]77
[10042]78        if (item != null) {
[3464]79          ToolStripMenuItem menuItem;
80          IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(), true);
81          foreach (Type t in types.Except(IgnoredViewTypes)) {
82            menuItem = new ToolStripMenuItem();
83            menuItem.Tag = t;
84            menuItem.Text = ViewAttribute.GetViewName(t);
[3437]85
[10042]86            menuItems.Add(t, menuItem);
87            Items.Add(menuItem);
[3464]88          }
[10042]89          if (Items.Count > 0)
90            Items.Add(new ToolStripSeparator());
91          Items.Add(ShowBreadcrumbsToolStripMenuItem);
[3437]92        }
93      }
94    }
[10042]95
96    public event EventHandler ShowBreadcrumbsChanged;
97    private void OnShowBreadcrumbsChanged() {
98      var handler = ShowBreadcrumbsChanged;
99      if (handler != null) handler(this, EventArgs.Empty);
100    }
101
102    private void ShowBreadcrumbsToolStripMenuItem_CheckedChanged(object sender, EventArgs e) {
103      OnShowBreadcrumbsChanged();
104    }
105
106    private void ShowBreadcrumbsToolStripMenuItem_Click(object sender, EventArgs e) {
107      ShowBreadcrumbsToolStripMenuItem.Checked = !ShowBreadcrumbsToolStripMenuItem.Checked;
108    }
[3437]109  }
110}
Note: See TracBrowser for help on using the repository browser.