- Timestamp:
- 02/13/10 05:21:23 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.cs
r2790 r2792 35 35 private Dictionary<Type, ToolStripMenuItem> typeMenuItemTable; 36 36 37 public IEnumerable<Type> AvailableViewTypes { 38 get { return typeMenuItemTable.Keys; } 39 } 40 37 41 private object content; 38 42 public object Content { … … 50 54 InitializeComponent(); 51 55 Initialize(); 56 } 57 58 public void ShowView(Type viewType) { 59 if (!typeMenuItemTable.ContainsKey(viewType)) 60 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 61 viewType.GetPrettyName(), 62 content.GetType().GetPrettyName())); 63 64 foreach (ToolStripMenuItem item in typeMenuItemTable.Values) { 65 item.Checked = false; 66 item.Enabled = true; 67 } 68 typeMenuItemTable[viewType].Checked = true; 69 typeMenuItemTable[viewType].Enabled = false; 70 71 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); 72 viewPanel.Controls.Clear(); 73 Control view = (Control)MainFormManager.CreateView(viewType, Content); 74 viewPanel.Controls.Add(view); 75 viewPanel.Tag = view; 76 view.Dock = DockStyle.Fill; 77 viewPanel.Enabled = true; 78 viewPanel.Visible = true; 52 79 } 53 80 … … 68 95 orderby t.Name ascending 69 96 select t; 70 foreach (Type v iewTypein viewTypes) {71 ToolStripMenuItem item = new ToolStripMenuItem(v iewType.GetPrettyName());72 item.Name = v iewType.FullName;73 item.ToolTipText = v iewType.GetPrettyName(true);74 item.Tag = v iewType;97 foreach (Type v in viewTypes) { 98 ToolStripMenuItem item = new ToolStripMenuItem(v.GetPrettyName()); 99 item.Name = v.FullName; 100 item.ToolTipText = v.GetPrettyName(true); 101 item.Tag = v; 75 102 contextMenuStrip.Items.Add(item); 76 typeMenuItemTable.Add(v iewType, item);103 typeMenuItemTable.Add(v, item); 77 104 } 78 105 if (contextMenuStrip.Items.Count == 0) { … … 85 112 } 86 113 87 Control view = (Control)MainFormManager.CreateDefaultView(Content); 88 if ((view == null) && (contextMenuStrip.Items.Count > 0)) // create first available view if default view is not available 89 view = (Control)MainFormManager.CreateView((Type)contextMenuStrip.Items[0].Tag, Content); 90 if (view != null) { 91 viewPanel.Controls.Add(view); 92 viewPanel.Tag = view; 93 view.Dock = DockStyle.Fill; 94 viewPanel.Enabled = true; 95 viewPanel.Visible = true; 96 typeMenuItemTable[view.GetType()].Checked = true; 97 typeMenuItemTable[view.GetType()].Enabled = false; 98 } 114 Type viewType = MainFormManager.GetDefaultViewType(Content.GetType()); 115 if ((viewType == null) && (contextMenuStrip.Items.Count > 0)) // create first available view if default view is not available 116 viewType = (Type)contextMenuStrip.Items[0].Tag; 117 if (viewType != null) 118 ShowView(viewType); 99 119 } 100 120 } … … 105 125 protected void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { 106 126 Type viewType = (Type)e.ClickedItem.Tag; 107 foreach (ToolStripMenuItem item in typeMenuItemTable.Values) { 108 item.Checked = false; 109 item.Enabled = true; 110 } 111 typeMenuItemTable[viewType].Checked = true; 112 typeMenuItemTable[viewType].Enabled = false; 113 114 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); 115 viewPanel.Controls.Clear(); 116 Control view = (Control)MainFormManager.CreateView(viewType, Content); 117 viewPanel.Controls.Add(view); 118 viewPanel.Tag = view; 119 view.Dock = DockStyle.Fill; 127 ShowView(viewType); 120 128 } 121 129 }
Note: See TracChangeset
for help on using the changeset viewer.