Changeset 3389 for trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2
- Timestamp:
- 04/18/10 02:08:29 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ContentView.cs
r2961 r3389 34 34 public object Content { 35 35 get { return content; } 36 protectedset {36 set { 37 37 if ((value != null) && (!MainFormManager.ViewCanViewObject(this, value))) 38 38 throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name)); -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewContextMenuStrip.cs
r2992 r3389 12 12 InitializeComponent(); 13 13 this.menuItems = new Dictionary<Type, ToolStripMenuItem>(); 14 this.ignoredViewTypes = new List<Type>(); 14 15 } 15 16 … … 30 31 } 31 32 33 private List<Type> ignoredViewTypes; 34 public IEnumerable<Type> IgnoredViewTypes { 35 get { return this.ignoredViewTypes; } 36 set { this.ignoredViewTypes = new List<Type>(value); RefreshMenuItems(); } 37 } 38 32 39 private Dictionary<Type, ToolStripMenuItem> menuItems; 33 40 public IEnumerable<KeyValuePair<Type, ToolStripMenuItem>> MenuItems { … … 42 49 ToolStripMenuItem menuItem; 43 50 IEnumerable<Type> types = MainFormManager.GetViewTypes(item.GetType(),true); 44 foreach (Type t in types ) {51 foreach (Type t in types.Except(IgnoredViewTypes)) { 45 52 menuItem = new ToolStripMenuItem(); 46 53 menuItem.Tag = t; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.cs
r3388 r3389 27 27 28 28 namespace HeuristicLab.MainForm.WindowsForms { 29 public sealed partial class ViewHost : View { 30 private Dictionary<Type, IView> cachedViews; 29 [Content(typeof(object))] 30 public sealed partial class ViewHost : ContentView { 31 private Dictionary<Type, IContentView> cachedViews; 31 32 public ViewHost() { 32 33 InitializeComponent(); 33 cachedViews = new Dictionary<Type, I View>();34 cachedViews = new Dictionary<Type, IContentView>(); 34 35 viewType = null; 35 36 Content = null; 37 viewContextMenuStrip.IgnoredViewTypes = new List<Type>() { typeof(ViewHost) }; 36 38 } 37 public ViewHost( bool readOnly)39 public ViewHost(object content) 38 40 : this() { 39 this. ReadOnly = readOnly;41 this.Content = content; 40 42 } 41 43 … … 54 56 } 55 57 56 private object content; 57 public object Content { 58 get { return this.content; } 58 public new object Content { 59 get { return base.Content; } 59 60 set { 60 if (value != this.content) { 61 if (value == null || this.content == null || value.GetType() != this.content.GetType()) 62 cachedViews.Clear(); 63 viewContextMenuStrip.Item = value; 64 this.viewsLabel.Enabled = value != null; 65 this.content = value; 66 this.OnContentChanged(); 67 } 68 61 if (value == null || this.Content == null || value.GetType() != this.Content.GetType()) 62 cachedViews.Clear(); 63 viewContextMenuStrip.Item = value; 64 this.viewsLabel.Enabled = value != null; 65 base.Content = value; 69 66 } 70 67 } … … 82 79 protected override void OnReadOnlyChanged() { 83 80 base.OnReadOnlyChanged(); 84 foreach (I View view in cachedViews.Values)81 foreach (IContentView view in cachedViews.Values) 85 82 view.ReadOnly = this.ReadOnly; 86 83 } 87 84 88 pr ivate void OnContentChanged() {85 protected override void OnContentChanged() { 89 86 messageLabel.Visible = false; 90 87 viewsLabel.Visible = false; … … 100 97 101 98 if (!ViewCanShowContent(viewType, Content)) { 102 viewType = MainFormManager.GetDefaultViewType(Content.GetType());99 ViewType = MainFormManager.GetDefaultViewType(Content.GetType()); 103 100 if ((viewType == null) && (viewContextMenuStrip.Items.Count > 0)) // create first available view if default view is not available 104 viewType = (Type)viewContextMenuStrip.Items[0].Tag;101 ViewType = (Type)viewContextMenuStrip.Items[0].Tag; 105 102 } 106 UpdateView(); 103 foreach (IContentView view in cachedViews.Values) 104 view.Content = this.Content; 105 } else { 106 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose(); 107 viewPanel.Controls.Clear(); 108 cachedViews.Clear(); 107 109 } 108 110 } … … 120 122 121 123 UpdateActiveMenuItem(); 122 I View view;124 IContentView view; 123 125 if (cachedViews.ContainsKey(ViewType)) 124 126 view = cachedViews[ViewType]; 125 127 else { 126 128 view = MainFormManager.CreateView(viewType, Content, ReadOnly); 127 cachedViews.Add(viewType, ((IView)view));129 cachedViews.Add(viewType, view); 128 130 } 129 131
Note: See TracChangeset
for help on using the changeset viewer.