Last change
on this file since 2971 was
2837,
checked in by mkommend, 15 years ago
|
added ViewAttribute and adapted ViewContextMenuStrip (ticket #857)
|
File size:
1.5 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Diagnostics;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Text;
|
---|
7 | using System.Windows.Forms;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.MainForm.WindowsForms {
|
---|
10 | public sealed partial class ViewContextMenuStrip : ContextMenuStrip {
|
---|
11 | public ViewContextMenuStrip() {
|
---|
12 | InitializeComponent();
|
---|
13 | this.menuItems = new Dictionary<Type, ToolStripMenuItem>();
|
---|
14 | }
|
---|
15 |
|
---|
16 | public ViewContextMenuStrip(object item)
|
---|
17 | : this() {
|
---|
18 | this.Item = item;
|
---|
19 | }
|
---|
20 |
|
---|
21 | private object item;
|
---|
22 | public object Item {
|
---|
23 | get { return this.item; }
|
---|
24 | set {
|
---|
25 | if (this.item != value) {
|
---|
26 | this.item = value;
|
---|
27 | this.RefreshMenuItems();
|
---|
28 | }
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | private Dictionary<Type, ToolStripMenuItem> menuItems;
|
---|
33 | public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems {
|
---|
34 | get { return this.menuItems; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | private void RefreshMenuItems() {
|
---|
38 | this.Items.Clear();
|
---|
39 | this.menuItems.Clear();
|
---|
40 |
|
---|
41 | if (this.item != null) {
|
---|
42 | ToolStripMenuItem menuItem;
|
---|
43 | IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType());
|
---|
44 | foreach (Type t in types) {
|
---|
45 | menuItem = new ToolStripMenuItem();
|
---|
46 | menuItem.Tag = t;
|
---|
47 | menuItem.Text = ViewAttribute.GetViewName(t);
|
---|
48 |
|
---|
49 | this.menuItems.Add(t, menuItem);
|
---|
50 | this.Items.Add(menuItem);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.