Changeset 3388 for trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2
- Timestamp:
- 04/18/10 01:14:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.cs
r3361 r3388 27 27 28 28 namespace HeuristicLab.MainForm.WindowsForms { 29 public sealed partial class ViewHost : UserControl{29 public sealed partial class ViewHost : View { 30 30 private Dictionary<Type, IView> cachedViews; 31 31 public ViewHost() { 32 32 InitializeComponent(); 33 cachedViews = new Dictionary<Type, IView>(); 33 34 viewType = null; 34 content = null; 35 cachedViews = new Dictionary<Type, IView>(); 36 Initialize(); 35 Content = null; 37 36 } 38 37 public ViewHost(bool readOnly) … … 46 45 set { 47 46 if (viewType != value) { 48 if (value != null && !ViewCanShowContent(value, content))47 if (value != null && !ViewCanShowContent(value, Content)) 49 48 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 50 value, content.GetType()));49 value, Content.GetType())); 51 50 viewType = value; 52 51 UpdateView(); … … 57 56 private object content; 58 57 public object Content { 59 get { return content; }58 get { return this.content; } 60 59 set { 61 if (value != content) {62 content = value;63 viewContextMenuStrip.Item = content;64 cachedViews.Clear();60 if (value != this.content) { 61 if (value == null || this.content == null || value.GetType() != this.content.GetType()) 62 cachedViews.Clear(); 63 viewContextMenuStrip.Item = value; 65 64 this.viewsLabel.Enabled = value != null; 66 Initialize(); 65 this.content = value; 66 this.OnContentChanged(); 67 67 } 68 68 69 } 69 70 } … … 74 75 this.SuspendRepaint(); 75 76 base.Enabled = value; 76 if (Content != null && value) 77 this.viewsLabel.Enabled = value; 77 this.viewsLabel.Enabled = value; 78 78 this.ResumeRepaint(true); 79 79 } 80 80 } 81 private bool readOnly; 82 public bool ReadOnly { 83 get { return this.readOnly; } 84 set { 85 if (InvokeRequired) { 86 Action<bool> action = delegate(bool b) { this.ReadOnly = b; }; 87 Invoke(action, value); 88 } else { 89 if (value != readOnly) { 90 readOnly = value; 91 OnReadOnlyChanged(); 92 } 93 } 94 } 81 82 protected override void OnReadOnlyChanged() { 83 base.OnReadOnlyChanged(); 84 foreach (IView view in cachedViews.Values) 85 view.ReadOnly = this.ReadOnly; 95 86 } 96 87 97 public event EventHandler ReadOnlyChanged; 98 private void OnReadOnlyChanged() { 99 if (InvokeRequired) 100 Invoke((MethodInvoker)OnReadOnlyChanged); 101 else { 102 EventHandler handler = ReadOnlyChanged; 103 if (handler != null) 104 handler(this, EventArgs.Empty); 105 foreach (IView view in cachedViews.Values) 106 view.ReadOnly = this.readOnly; 107 } 108 } 109 110 private void Initialize() { 88 private void OnContentChanged() { 89 messageLabel.Visible = false; 111 90 viewsLabel.Visible = false; 112 91 viewPanel.Visible = false; … … 129 108 } 130 109 110 131 111 private void UpdateView() { 132 if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();133 112 viewPanel.Controls.Clear(); 134 113 135 if (viewType == null || content == null)114 if (viewType == null || Content == null) 136 115 return; 137 116 138 if (!ViewCanShowContent(viewType, content))117 if (!ViewCanShowContent(viewType, Content)) 139 118 throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".", 140 119 viewType, Content.GetType())); 141 120 142 121 UpdateActiveMenuItem(); 143 cachedViews.Clear(); 144 Control view = (Control)MainFormManager.CreateView(viewType, Content, ReadOnly); 145 cachedViews.Add(viewType, ((IView)view)); 146 view.Dock = DockStyle.Fill; 147 viewPanel.Controls.Add(view); 122 IView view; 123 if (cachedViews.ContainsKey(ViewType)) 124 view = cachedViews[ViewType]; 125 else { 126 view = MainFormManager.CreateView(viewType, Content, ReadOnly); 127 cachedViews.Add(viewType, ((IView)view)); 128 } 129 130 Control control = (Control)view; 131 control.Dock = DockStyle.Fill; 132 viewPanel.Controls.Add(control); 148 133 viewPanel.Visible = true; 149 134 }
Note: See TracChangeset
for help on using the changeset viewer.