- Timestamp:
- 02/15/10 14:09:49 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.cs
r2792 r2797 31 31 using HeuristicLab.MainForm; 32 32 33 namespace HeuristicLab.Core.Views { 33 namespace HeuristicLab.Core.Views { 34 34 public partial class ViewHost : UserControl { 35 35 private Dictionary<Type, ToolStripMenuItem> typeMenuItemTable; 36 37 36 public IEnumerable<Type> AvailableViewTypes { 38 37 get { return typeMenuItemTable.Keys; } … … 50 49 } 51 50 51 private Type viewType; 52 public Type ViewType { 53 get { return this.viewType; } 54 set { 55 if (!ViewTypeCanShowContent(value, content)) 56 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 57 value.GetPrettyName(), 58 content.GetType().GetPrettyName())); 59 viewType = value; 60 ShowView(); 61 } 62 } 63 52 64 public ViewHost() { 53 65 typeMenuItemTable = new Dictionary<Type, ToolStripMenuItem>(); 66 viewType = null; 67 content = null; 54 68 InitializeComponent(); 55 69 Initialize(); 56 70 } 57 71 58 public void ShowView(Type viewType) { 59 if (!typeMenuItemTable.ContainsKey(viewType)) 72 private void ShowView() { 73 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); 74 viewPanel.Controls.Clear(); 75 76 if (viewType == null || content == null) 77 return; 78 79 if (!ViewTypeCanShowContent(viewType, content) || !typeMenuItemTable.ContainsKey(viewType)) 60 80 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 61 81 viewType.GetPrettyName(), 62 content.GetType().GetPrettyName()));82 Content.GetType().GetPrettyName())); 63 83 64 84 foreach (ToolStripMenuItem item in typeMenuItemTable.Values) { … … 69 89 typeMenuItemTable[viewType].Enabled = false; 70 90 71 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();72 viewPanel.Controls.Clear();73 91 Control view = (Control)MainFormManager.CreateView(viewType, Content); 74 92 viewPanel.Controls.Add(view); … … 112 130 } 113 131 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); 132 if (!ViewTypeCanShowContent(viewType, Content)) { 133 viewType = MainFormManager.GetDefaultViewType(Content.GetType()); 134 if ((viewType == null) && (contextMenuStrip.Items.Count > 0)) // create first available view if default view is not available 135 viewType = (Type)contextMenuStrip.Items[0].Tag; 136 } 137 ShowView(); 119 138 } 139 } 140 141 private bool ViewTypeCanShowContent(Type viewType, object content) { 142 if (content == null) // every view can display null 143 return true; 144 if (viewType == null) 145 return false; 146 return ContentAttribute.CanViewType(viewType, Content.GetType()); 120 147 } 121 148 … … 125 152 protected void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { 126 153 Type viewType = (Type)e.ClickedItem.Tag; 127 ShowView(viewType); 154 ViewType = viewType; 155 ShowView(); 128 156 } 129 157 }
Note: See TracChangeset
for help on using the changeset viewer.