Changeset 2800
- Timestamp:
- 02/15/10 14:58:07 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Core.Views/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.Designer.cs
r2790 r2800 109 109 #endregion 110 110 111 pr otectedSystem.Windows.Forms.Panel viewPanel;112 pr otectedSystem.Windows.Forms.Label viewsLabel;113 pr otectedSystem.Windows.Forms.Label messageLabel;114 pr otectedSystem.Windows.Forms.ContextMenuStrip contextMenuStrip;115 pr otectedSystem.Windows.Forms.ToolTip toolTip;111 private System.Windows.Forms.Panel viewPanel; 112 private System.Windows.Forms.Label viewsLabel; 113 private System.Windows.Forms.Label messageLabel; 114 private System.Windows.Forms.ContextMenuStrip contextMenuStrip; 115 private System.Windows.Forms.ToolTip toolTip; 116 116 117 117 } -
trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.cs
r2797 r2800 32 32 33 33 namespace HeuristicLab.Core.Views { 34 public partial class ViewHost : UserControl {34 public sealed partial class ViewHost : UserControl { 35 35 private Dictionary<Type, ToolStripMenuItem> typeMenuItemTable; 36 36 37 public IEnumerable<Type> AvailableViewTypes { 37 38 get { return typeMenuItemTable.Keys; } 39 } 40 41 private Type viewType; 42 public Type ViewType { 43 get { return this.viewType; } 44 set { 45 if (!ViewCanShowContent(value, content)) 46 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 47 value.GetPrettyName(), 48 content.GetType().GetPrettyName())); 49 viewType = value; 50 UpdateView(); 51 } 38 52 } 39 53 … … 49 63 } 50 64 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 64 65 public ViewHost() { 65 66 typeMenuItemTable = new Dictionary<Type, ToolStripMenuItem>(); … … 70 71 } 71 72 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)) 80 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 81 viewType.GetPrettyName(), 82 Content.GetType().GetPrettyName())); 83 84 foreach (ToolStripMenuItem item in typeMenuItemTable.Values) { 85 item.Checked = false; 86 item.Enabled = true; 87 } 88 typeMenuItemTable[viewType].Checked = true; 89 typeMenuItemTable[viewType].Enabled = false; 90 91 Control view = (Control)MainFormManager.CreateView(viewType, Content); 92 viewPanel.Controls.Add(view); 93 viewPanel.Tag = view; 94 view.Dock = DockStyle.Fill; 95 viewPanel.Enabled = true; 96 viewPanel.Visible = true; 97 } 98 99 protected virtual void Initialize() { 73 private void Initialize() { 100 74 viewsLabel.Enabled = false; 101 75 viewsLabel.Visible = false; … … 130 104 } 131 105 132 if (!View TypeCanShowContent(viewType, Content)) {106 if (!ViewCanShowContent(viewType, Content)) { 133 107 viewType = MainFormManager.GetDefaultViewType(Content.GetType()); 134 108 if ((viewType == null) && (contextMenuStrip.Items.Count > 0)) // create first available view if default view is not available 135 109 viewType = (Type)contextMenuStrip.Items[0].Tag; 136 110 } 137 ShowView();111 UpdateView(); 138 112 } 139 113 } 140 114 141 private bool ViewTypeCanShowContent(Type viewType, object content) { 115 private void UpdateView() { 116 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); 117 viewPanel.Controls.Clear(); 118 119 if (viewType == null || content == null) 120 return; 121 122 if (!ViewCanShowContent(viewType, content) || !typeMenuItemTable.ContainsKey(viewType)) 123 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 124 viewType.GetPrettyName(), 125 Content.GetType().GetPrettyName())); 126 127 foreach (ToolStripMenuItem item in typeMenuItemTable.Values) { 128 item.Checked = false; 129 item.Enabled = true; 130 } 131 typeMenuItemTable[viewType].Checked = true; 132 typeMenuItemTable[viewType].Enabled = false; 133 134 Control view = (Control)MainFormManager.CreateView(viewType, Content); 135 viewPanel.Controls.Add(view); 136 viewPanel.Tag = view; 137 view.Dock = DockStyle.Fill; 138 viewPanel.Enabled = true; 139 viewPanel.Visible = true; 140 } 141 142 private bool ViewCanShowContent(Type viewType, object content) { 142 143 if (content == null) // every view can display null 143 144 return true; … … 150 151 MainFormManager.CreateView(viewPanel.Tag.GetType(), Content).Show(); 151 152 } 152 pr otectedvoid contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {153 private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { 153 154 Type viewType = (Type)e.ClickedItem.Tag; 154 155 ViewType = viewType; 155 ShowView();156 156 } 157 157 }
Note: See TracChangeset
for help on using the changeset viewer.