Changeset 3557 for trunk/sources/HeuristicLab.MainForm.WindowsForms
- Timestamp:
- 04/29/10 15:10:17 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ContentView.cs
r3483 r3557 37 37 get { return content; } 38 38 set { 39 if ((value != null) && (!MainFormManager.ViewCanView Object(this, value)))39 if ((value != null) && (!MainFormManager.ViewCanViewContent(this, value))) 40 40 throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name)); 41 41 if (InvokeRequired) { … … 57 57 InitializeComponent(); 58 58 this.locked = false; 59 }60 public ContentView(IContent content)61 : this() {62 this.content = content;63 59 } 64 60 -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/DockingMainForm.cs
r3437 r3557 40 40 InitializeComponent(); 41 41 } 42 public DockingMainForm(Type userInterfaceItemType, bool show ViewsInViewHost)42 public DockingMainForm(Type userInterfaceItemType, bool showContentInViewHost) 43 43 : this(userInterfaceItemType) { 44 this.Show ViewsInViewHost = showViewsInViewHost;44 this.ShowContentInViewHost = showContentInViewHost; 45 45 } 46 46 … … 67 67 68 68 protected override Form CreateForm(IView view) { 69 DockForm form; 70 IContentView contentView = view as IContentView; 71 if (ShowViewsInViewHost && contentView != null && contentView.GetType() != typeof(ViewHost)) { 72 ViewHost viewHost = new ViewHost(contentView); 73 form = new DockForm(viewHost); 74 this.AddViewFormCombination(viewHost, form); 75 } else { 76 form = new DockForm(view); 77 this.AddViewFormCombination(view, form); 78 } 79 return form; 69 return new DockForm(view); 80 70 } 81 71 -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForm.cs
r3488 r3557 32 32 using System.Collections; 33 33 using WeifenLuo.WinFormsUI.Docking; 34 using HeuristicLab.Common; 34 35 35 36 namespace HeuristicLab.MainForm.WindowsForms { … … 43 44 this.userInterfaceItems = new List<IUserInterfaceItem>(); 44 45 this.initialized = false; 45 this.show ViewsInViewHost = false;46 this.showContentInViewHost = false; 46 47 } 47 48 … … 52 53 53 54 #region properties 54 private bool show ViewsInViewHost;55 public bool Show ViewsInViewHost {56 get { return this.show ViewsInViewHost; }57 set { this.show ViewsInViewHost = value; }55 private bool showContentInViewHost; 56 public bool ShowContentInViewHost { 57 get { return this.showContentInViewHost; } 58 set { this.showContentInViewHost = value; } 58 59 } 59 60 … … 88 89 public IEnumerable<IView> Views { 89 90 get { return views.Keys; } 90 }91 protected void AddViewFormCombination(IView view, Form form) {92 this.views.Add(view, form);93 view.Changed += new EventHandler(View_Changed);94 91 } 95 92 … … 216 213 217 214 internal Form GetForm(IView view) { 218 IView internalView = GetView(view); 219 if (internalView != null && views.ContainsKey(internalView)) 220 return views[internalView]; 215 if (views.ContainsKey(view)) 216 return views[view]; 221 217 return null; 222 218 } … … 224 220 return views.Where(x => x.Value == form).Single().Key; 225 221 } 226 private IView GetView(IView view) { 227 if (view == null || views.ContainsKey(view)) 228 return view; 229 IContentView contentView = view as IContentView; 230 if (contentView != null) { 231 IView viewHost = 232 (from ViewHost v in views.Keys.OfType<ViewHost>() 233 where v.Views.Contains(contentView) 234 select v).SingleOrDefault(); 235 return viewHost; 236 } 237 return contentView; 222 223 public IContentView ShowContent(IContent content) { 224 IContentView view; 225 if (this.ShowContentInViewHost) 226 view = new ViewHost(); 227 else 228 view = MainFormManager.CreateDefaultView(content.GetType()); 229 230 if (view != null) { 231 view.Show(); 232 view.Content = content; 233 } 234 return view; 238 235 } 239 236 … … 243 240 Form form = GetForm(view); 244 241 bool firstTimeShown = form == null; 245 if (f orm == null) {242 if (firstTimeShown) { 246 243 form = CreateForm(view); 247 244 form.Activated += new EventHandler(FormActivated); 248 245 form.FormClosed += new FormClosedEventHandler(ChildFormClosed); 249 } 250 IView internalView = GetView(form); 251 this.ShowView(internalView, firstTimeShown); 252 this.OnViewShown(internalView, firstTimeShown); 246 view.Changed += new EventHandler(View_Changed); 247 views[view] = form; 248 } 249 this.ShowView(view, firstTimeShown); 250 this.OnViewShown(view, firstTimeShown); 253 251 } 254 252 } … … 267 265 if (InvokeRequired) Invoke((Action<IView>)HideView, view); 268 266 else { 269 IView internalView = this.GetView(view); 270 if (internalView != null && this.views.ContainsKey(internalView)) { 271 this.Hide(internalView); 272 if (this.activeView == internalView) 273 this.ActiveView = null; 274 this.OnViewHidden(internalView); 275 } 267 this.Hide(view); 268 if (this.activeView == view) 269 this.ActiveView = null; 270 this.OnViewHidden(view); 276 271 } 277 272 } … … 296 291 internal void CloseView(IView view) { 297 292 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 298 else { 299 IView internalView = GetView(view); 300 if (internalView != null && this.views.ContainsKey(internalView)) { 301 this.views[internalView].Close(); 302 this.OnViewClosed(internalView); 303 } 293 else if (views.ContainsKey(view)) { 294 this.views[view].Close(); 295 this.OnViewClosed(view); 304 296 } 305 297 } … … 307 299 internal void CloseView(IView view, CloseReason closeReason) { 308 300 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 309 else { 310 IView internalView = GetView(view); 311 if (internalView != null && this.views.ContainsKey(internalView)) { 312 ((View)internalView).CloseReason = closeReason; 313 this.CloseView(internalView); 314 } 301 else if (views.ContainsKey(view)) { 302 ((View)view).CloseReason = closeReason; 303 this.CloseView(view); 315 304 } 316 305 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MultipleDocumentMainForm.cs
r3437 r3557 39 39 InitializeComponent(); 40 40 } 41 public MultipleDocumentMainForm(Type userInterfaceItemType, bool show ViewsInViewHost)41 public MultipleDocumentMainForm(Type userInterfaceItemType, bool showContentInViewHost) 42 42 : this(userInterfaceItemType) { 43 this.Show ViewsInViewHost = showViewsInViewHost;43 this.ShowContentInViewHost = showContentInViewHost; 44 44 } 45 45 … … 76 76 77 77 protected override Form CreateForm(IView view) { 78 Form form; 79 IContentView contentView = view as IContentView; 80 if (ShowViewsInViewHost && contentView != null && contentView.GetType() != typeof(ViewHost)) { 81 ViewHost viewHost = new ViewHost(contentView); 82 form = new DocumentForm(viewHost); 83 this.AddViewFormCombination(viewHost, form); 84 } else { 85 form = new DocumentForm(view); 86 this.AddViewFormCombination(view, form); 87 } 88 78 Form form = new DocumentForm(view); 89 79 form.MdiParent = this; 90 80 return form; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/SingleDocumentMainForm.cs
r3437 r3557 40 40 InitializeComponent(); 41 41 } 42 public SingleDocumentMainForm(Type userInterfaceItemType, bool show ViewsInViewHost)42 public SingleDocumentMainForm(Type userInterfaceItemType, bool showContentInViewHost) 43 43 : this(userInterfaceItemType) { 44 this.Show ViewsInViewHost = showViewsInViewHost;44 this.ShowContentInViewHost = showContentInViewHost; 45 45 } 46 46 … … 70 70 71 71 protected override Form CreateForm(IView view) { 72 Form form; 73 IContentView contentView = view as IContentView; 74 if (ShowViewsInViewHost && contentView != null && contentView.GetType() != typeof(ViewHost)) { 75 ViewHost viewHost = new ViewHost(contentView); 76 form = new DocumentForm(viewHost); 77 this.AddViewFormCombination(viewHost, form); 78 } else { 79 form = new DocumentForm(view); 80 this.AddViewFormCombination(view, form); 81 } 82 72 Form form = new DocumentForm(view); 83 73 form.ShowInTaskbar = true; 84 74 return form; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/View.cs
r3437 r3557 35 35 this.closeReason = CloseReason.None; 36 36 this.readOnly = false; 37 }38 39 public View(bool readOnly)40 : this() {41 this.readOnly = readOnly;42 37 } 43 38 -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ViewHost.cs
r3552 r3557 28 28 29 29 namespace HeuristicLab.MainForm.WindowsForms { 30 [Content(typeof( object))]30 [Content(typeof(IContent))] 31 31 public sealed partial class ViewHost : AsynchronousContentView { 32 32 public ViewHost() { … … 39 39 Content = null; 40 40 OnContentChanged(); 41 }42 public ViewHost(IContent content)43 : this() {44 this.Content = content;45 }46 47 public ViewHost(IContentView contentView)48 : this() {49 this.viewType = contentView.GetType();50 this.Content = contentView.Content;51 this.cachedViews.Add(contentView.GetType(), contentView);52 this.activeView = contentView;53 this.RegisterActiveViewEvents();54 this.OnViewTypeChanged();55 this.ActiveViewChanged();56 41 } 57 42 … … 117 102 } 118 103 119 120 121 104 protected override void OnContentChanged() { 122 105 messageLabel.Visible = false; … … 133 116 } 134 117 135 136 118 if (!ViewCanShowContent(viewType, Content)) { 137 119 ViewType = MainFormManager.GetDefaultViewType(Content.GetType()); … … 148 130 } 149 131 } 150 151 132 152 133 private void OnViewTypeChanged() { … … 176 157 } 177 158 178 179 180 159 private void RegisterActiveViewEvents() { 181 160 activeView.Changed += new EventHandler(activeView_Changed); … … 256 235 257 236 private void viewsLabel_DoubleClick(object sender, EventArgs e) { 258 IContentView view = MainFormManager. CreateView(viewType,Content);237 IContentView view = MainFormManager.MainForm.ShowContent(this.Content); 259 238 view.ReadOnly = this.ReadOnly; 260 239 view.Locked = this.Locked; 261 view.Show();262 240 } 263 241 private void viewContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.