- Timestamp:
- 04/19/10 00:09:19 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.cs
r3398 r3403 29 29 [Content(typeof(object))] 30 30 public sealed partial class ViewHost : AsynchronousContentView { 31 private Dictionary<Type, IContentView> cachedViews;32 31 public ViewHost() { 33 32 InitializeComponent(); … … 37 36 startDragAndDrop = false; 38 37 viewContextMenuStrip.IgnoredViewTypes = new List<Type>() { typeof(ViewHost) }; 38 activeView = null; 39 39 } 40 40 public ViewHost(object content) … … 43 43 } 44 44 45 public ViewHost(IContentView contentView) :this(){ 45 public ViewHost(IContentView contentView) 46 : this() { 46 47 this.viewType = contentView.GetType(); 47 48 this.Content = contentView.Content; 48 49 this.cachedViews.Add(contentView.GetType(), contentView); 49 this.UpdateView(); 50 } 51 50 this.activeView = contentView; 51 this.RegisterActiveViewEvents(); 52 this.OnViewTypeChanged(); 53 this.ActiveViewChanged(); 54 } 55 56 private Dictionary<Type, IContentView> cachedViews; 57 public IEnumerable<IContentView> Views { 58 get { return cachedViews.Values; } 59 } 60 61 private IContentView activeView; 62 public IContentView ActiveView { 63 get { return this.activeView; } 64 private set { 65 if (activeView != value) { 66 if (activeView != null) { 67 DeregisterActiveViewEvents(); 68 View view = activeView as View; 69 if (view != null) 70 view.OnHidden(EventArgs.Empty); 71 } 72 activeView = value; 73 if (activeView != null) { 74 RegisterActiveViewEvents(); 75 View view = activeView as View; 76 if (view != null) 77 view.OnShown(new ViewShownEventArgs(view,false)); 78 } 79 ActiveViewChanged(); 80 OnViewTypeChanged(); 81 } 82 } 83 } 52 84 private Type viewType; 53 85 public Type ViewType { … … 59 91 value, Content.GetType())); 60 92 viewType = value; 61 UpdateView(); 62 } 63 } 64 } 65 93 OnViewTypeChanged(); 94 } 95 } 96 } 66 97 public new object Content { 67 98 get { return base.Content; } … … 107 138 ViewType = (Type)viewContextMenuStrip.Items[0].Tag; 108 139 } 140 109 141 foreach (IContentView view in cachedViews.Values) 110 142 view.Content = this.Content; … … 117 149 118 150 119 private void UpdateView() {151 private void OnViewTypeChanged() { 120 152 viewPanel.Controls.Clear(); 121 122 153 if (viewType == null || Content == null) 123 154 return; 124 125 155 if (!ViewCanShowContent(viewType, Content)) 126 156 throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".", … … 135 165 cachedViews.Add(viewType, view); 136 166 } 137 this.Caption = view.Caption; 138 this.SaveEnabled = view.SaveEnabled; 167 this.ActiveView = view; 139 168 140 169 Control control = (Control)view; … … 144 173 } 145 174 175 176 177 private void RegisterActiveViewEvents() { 178 activeView.Changed += new EventHandler(activeView_Changed); 179 activeView.CaptionChanged += new EventHandler(activeView_CaptionChanged); 180 } 181 private void DeregisterActiveViewEvents() { 182 activeView.Changed -= new EventHandler(activeView_Changed); 183 activeView.CaptionChanged -= new EventHandler(activeView_CaptionChanged); 184 } 185 private void activeView_CaptionChanged(object sender, EventArgs e) { 186 this.ActiveViewChanged(); 187 } 188 private void activeView_Changed(object sender, EventArgs e) { 189 this.ActiveViewChanged(); 190 } 191 private void ActiveViewChanged() { 192 if (ActiveView != null) { 193 this.Caption = this.ActiveView.Caption; 194 this.SaveEnabled = this.ActiveView.SaveEnabled; 195 } 196 } 197 198 #region forwarding of view events 199 internal protected override void OnShown(ViewShownEventArgs e) { 200 base.OnShown(e); 201 View view = this.ActiveView as View; 202 if (view != null) 203 view.OnShown(e); 204 } 205 206 internal protected override void OnHidden(EventArgs e) { 207 base.OnHidden(e); 208 View view = this.ActiveView as View; 209 if (view != null) 210 view.OnHidden(e); 211 } 212 213 internal protected override void OnClosing(FormClosingEventArgs e) { 214 base.OnClosing(e); 215 foreach (View view in this.Views.OfType<View>()) 216 view.OnClosing(e); 217 } 218 219 internal protected override void OnClosed(FormClosedEventArgs e) { 220 base.OnClosed(e); 221 foreach (View view in this.Views.OfType<View>()) 222 view.OnClosed(e); 223 } 224 #endregion 225 226 #region GUI actions 146 227 private void UpdateActiveMenuItem() { 147 228 foreach (KeyValuePair<Type, ToolStripMenuItem> item in viewContextMenuStrip.MenuItems) { … … 167 248 MainFormManager.CreateView(viewType, Content, ReadOnly).Show(); 168 249 } 169 170 250 private void viewContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { 171 251 Type viewType = (Type)e.ClickedItem.Tag; … … 178 258 viewsLabel.Capture = false; 179 259 } 180 181 260 private void viewsLabel_MouseLeave(object sender, EventArgs e) { 182 261 if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left && startDragAndDrop) { … … 188 267 startDragAndDrop = false; 189 268 } 269 #endregion 190 270 } 191 271 }
Note: See TracChangeset
for help on using the changeset viewer.