Changeset 2838
- Timestamp:
- 02/19/10 11:46:57 (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
r2800 r2838 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.components = new System.ComponentModel.Container();47 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ViewHost)); 48 48 this.viewPanel = new System.Windows.Forms.Panel(); 49 49 this.messageLabel = new System.Windows.Forms.Label(); 50 50 this.viewsLabel = new System.Windows.Forms.Label(); 51 this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); 52 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 51 this.viewContextMenuStrip = new HeuristicLab.MainForm.WindowsForms.ViewContextMenuStrip(); 53 52 this.SuspendLayout(); 54 53 // … … 76 75 // 77 76 this.viewsLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 78 this.viewsLabel.ContextMenuStrip = this. contextMenuStrip;79 this.viewsLabel.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Windows;77 this.viewsLabel.ContextMenuStrip = this.viewContextMenuStrip; 78 this.viewsLabel.Image = ((System.Drawing.Image)(resources.GetObject("viewsLabel.Image"))); 80 79 this.viewsLabel.Location = new System.Drawing.Point(211, 0); 81 80 this.viewsLabel.Name = "viewsLabel"; 82 81 this.viewsLabel.Size = new System.Drawing.Size(16, 16); 83 82 this.viewsLabel.TabIndex = 0; 84 this.toolTip.SetToolTip(this.viewsLabel, "Double-click to open a new window of the current view.\r\nRight-click to change cur" +85 "rent view.");86 83 this.viewsLabel.DoubleClick += new System.EventHandler(this.viewsLabel_DoubleClick); 87 84 // 88 // contextMenuStrip85 // viewContextMenuStrip 89 86 // 90 this.contextMenuStrip.Name = "contextMenuStrip"; 91 this.contextMenuStrip.ShowCheckMargin = true; 92 this.contextMenuStrip.ShowImageMargin = false; 93 this.contextMenuStrip.Size = new System.Drawing.Size(61, 4); 94 this.contextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.contextMenuStrip_ItemClicked); 87 this.viewContextMenuStrip.Item = null; 88 this.viewContextMenuStrip.Name = "viewContextMenuStrip"; 89 this.viewContextMenuStrip.Size = new System.Drawing.Size(61, 4); 90 this.viewContextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.viewContextMenuStrip_ItemClicked); 95 91 // 96 92 // ViewHost … … 112 108 private System.Windows.Forms.Label viewsLabel; 113 109 private System.Windows.Forms.Label messageLabel; 114 private System.Windows.Forms.ContextMenuStrip contextMenuStrip; 115 private System.Windows.Forms.ToolTip toolTip; 110 private HeuristicLab.MainForm.WindowsForms.ViewContextMenuStrip viewContextMenuStrip; 116 111 117 112 } -
trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.cs
r2818 r2838 29 29 namespace HeuristicLab.Core.Views { 30 30 public sealed partial class ViewHost : UserControl { 31 private Dictionary<Type, ToolStripMenuItem> typeMenuItemTable;32 33 public IEnumerable<Type> AvailableViewTypes {34 get { return typeMenuItemTable.Keys; }35 }36 37 31 private Type viewType; 38 32 public Type ViewType { … … 54 48 if (value != content) { 55 49 content = value; 50 viewContextMenuStrip.Item = content; 56 51 Initialize(); 57 52 } … … 60 55 61 56 public ViewHost() { 62 typeMenuItemTable = new Dictionary<Type, ToolStripMenuItem>();57 InitializeComponent(); 63 58 viewType = null; 64 59 content = null; 65 InitializeComponent();66 60 Initialize(); 67 61 } … … 70 64 viewsLabel.Enabled = false; 71 65 viewsLabel.Visible = false; 72 typeMenuItemTable.Clear(); 73 contextMenuStrip.Items.Clear(); 74 contextMenuStrip.Enabled = false; 66 viewContextMenuStrip.Enabled = false; 75 67 messageLabel.Visible = false; 68 76 69 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); 77 70 viewPanel.Controls.Clear(); … … 80 73 81 74 if (Content != null) { 82 var viewTypes = from t in MainFormManager.GetViewTypes(Content.GetType()) 83 orderby t.Name ascending 84 select t; 85 foreach (Type v in viewTypes) { 86 ToolStripMenuItem item = new ToolStripMenuItem(v.GetPrettyName()); 87 item.Name = v.FullName; 88 item.ToolTipText = v.GetPrettyName(true); 89 item.Tag = v; 90 contextMenuStrip.Items.Add(item); 91 typeMenuItemTable.Add(v, item); 92 } 93 if (contextMenuStrip.Items.Count == 0) { 75 if (viewContextMenuStrip.Items.Count == 0) { 94 76 messageLabel.Visible = true; 95 77 } else { 96 78 viewsLabel.Enabled = true; 97 79 viewsLabel.Visible = true; 98 contextMenuStrip.Enabled = true;80 viewContextMenuStrip.Enabled = true; 99 81 messageLabel.Visible = false; 100 82 } … … 102 84 if (!ViewCanShowContent(viewType, Content)) { 103 85 viewType = MainFormManager.GetDefaultViewType(Content.GetType()); 104 if ((viewType == null) && ( contextMenuStrip.Items.Count > 0)) // create first available view if default view is not available105 viewType = (Type) contextMenuStrip.Items[0].Tag;86 if ((viewType == null) && (viewContextMenuStrip.Items.Count > 0)) // create first available view if default view is not available 87 viewType = (Type)viewContextMenuStrip.Items[0].Tag; 106 88 } 107 89 UpdateView(); … … 121 103 Content.GetType().GetPrettyName())); 122 104 123 foreach (ToolStripMenuItem item in typeMenuItemTable.Values) { 124 item.Checked = false; 125 item.Enabled = true; 126 } 127 typeMenuItemTable[viewType].Checked = true; 128 typeMenuItemTable[viewType].Enabled = false; 129 105 UpdateActiveMenuItem(); 130 106 Control view = (Control)MainFormManager.CreateView(viewType, Content); 131 107 viewPanel.Controls.Add(view); … … 136 112 } 137 113 114 private void UpdateActiveMenuItem() { 115 foreach (KeyValuePair<Type, ToolStripMenuItem> item in viewContextMenuStrip.MenuItems) { 116 if (item.Key == viewType) { 117 item.Value.Checked = true; 118 item.Value.Enabled = false; 119 } else { 120 item.Value.Checked = false; 121 item.Value.Enabled = true; 122 } 123 } 124 } 125 138 126 private bool ViewCanShowContent(Type viewType, object content) { 139 127 if (content == null) // every view can display null … … 141 129 if (viewType == null) 142 130 return false; 143 return ContentAttribute.CanViewType(viewType, Content.GetType()) && typeMenuItemTable.ContainsKey(viewType);131 return ContentAttribute.CanViewType(viewType, Content.GetType()) && viewContextMenuStrip.MenuItems.Any(item => item.Key == viewType); 144 132 } 145 133 146 134 private void viewsLabel_DoubleClick(object sender, EventArgs e) { 147 MainFormManager.CreateView(view Panel.Tag.GetType(), Content).Show();135 MainFormManager.CreateView(viewType, Content).Show(); 148 136 } 149 private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { 137 138 private void viewContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { 150 139 Type viewType = (Type)e.ClickedItem.Tag; 151 140 ViewType = viewType;
Note: See TracChangeset
for help on using the changeset viewer.