Changeset 3403
- Timestamp:
- 04/19/10 00:09:19 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/DockingMainForm.cs
r3398 r3403 45 45 } 46 46 47 protected override void Show (IView view, bool firstTimeShown) {48 if (InvokeRequired) Invoke((Action<IView, bool>)Show , view, firstTimeShown);47 protected override void ShowView(IView view, bool firstTimeShown) { 48 if (InvokeRequired) Invoke((Action<IView, bool>)ShowView, view, firstTimeShown); 49 49 else { 50 base.Show (view, firstTimeShown);50 base.ShowView(view, firstTimeShown); 51 51 if (firstTimeShown) 52 52 ((DockForm)GetForm(view)).Show(dockPanel); … … 59 59 if (InvokeRequired) Invoke((Action<IView>)HideView, view); 60 60 else { 61 Form form = base.GetForm(view);61 Form form = this.GetForm(view); 62 62 if (form != null) { 63 63 ((DockForm)form).Hide(); … … 72 72 ViewHost viewHost = new ViewHost(contentView); 73 73 form = new DockForm(viewHost); 74 } else 74 this.AddViewFormCombination(viewHost, form); 75 } else { 75 76 form = new DockForm(view); 77 this.AddViewFormCombination(view, form); 78 } 76 79 return form; 77 80 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MainForm.cs
r3395 r3403 89 89 get { return views.Keys; } 90 90 } 91 protected void AddViewFormCombination(IView view, Form form) { 92 this.views.Add(view, form); 93 view.Changed += new EventHandler(ViewChanged); 94 } 91 95 92 96 private IView activeView; … … 124 128 protected virtual void OnViewClosed(IView view) { 125 129 if (InvokeRequired) Invoke((Action<IView>)OnViewClosed, view); 126 else if (this.ViewClosed != null) { 127 this.ViewClosed(this, new ViewEventArgs(view)); 130 else { 131 EventHandler<ViewEventArgs> handler = ViewClosed; 132 if (handler != null) 133 handler(this, new ViewEventArgs(view)); 128 134 } 129 135 } … … 132 138 protected virtual void OnViewShown(IView view, bool firstTimeShown) { 133 139 if (InvokeRequired) Invoke((Action<IView, bool>)OnViewShown, view, firstTimeShown); 134 else if (this.ViewShown != null) { 135 this.ViewShown(this, new ViewShownEventArgs(view, firstTimeShown)); 140 else { 141 EventHandler<ViewShownEventArgs> handler = ViewShown; 142 if (handler != null) 143 handler(this, new ViewShownEventArgs(view, firstTimeShown)); 136 144 } 137 145 } … … 140 148 protected virtual void OnViewHidden(IView view) { 141 149 if (InvokeRequired) Invoke((Action<IView>)OnViewHidden, view); 142 else if (this.ViewHidden != null) { 143 this.ViewHidden(this, new ViewEventArgs(view)); 150 else { 151 EventHandler<ViewEventArgs> handler = ViewHidden; 152 if (handler != null) 153 handler(this, new ViewEventArgs(view)); 144 154 } 145 155 } … … 149 159 if (InvokeRequired) 150 160 Invoke((MethodInvoker)FireMainFormChanged); 151 else if (Changed != null) 152 Changed(this, EventArgs.Empty); 161 else { 162 EventHandler handler = Changed; 163 if (handler != null) 164 Changed(this, EventArgs.Empty); 165 } 153 166 } 154 167 … … 172 185 173 186 protected override void OnFormClosing(FormClosingEventArgs e) { 174 foreach (KeyValuePair<IView, Form> pair in this.views) {187 foreach (KeyValuePair<IView, Form> pair in this.views) { 175 188 DockForm dockForm = pair.Value as DockForm; 176 189 View view = pair.Key as View; … … 203 216 204 217 internal Form GetForm(IView view) { 205 if (views.ContainsKey(view)) 206 return views[view]; 218 IView internalView = GetView(view); 219 if (internalView != null && views.ContainsKey(internalView)) 220 return views[internalView]; 207 221 return null; 208 222 } 209 210 internal IView GetView(Form form) { 223 protected IView GetView(Form form) { 211 224 return views.Where(x => x.Value == form).Single().Key; 212 225 } 213 214 internal void ShowView(IView view, bool firstTimeShown) { 215 if (InvokeRequired) Invoke((Action<IView, bool>)ShowView, view, firstTimeShown); 216 else { 217 if (firstTimeShown) { 218 Form form = CreateForm(view); 219 view.Changed += new EventHandler(ViewChanged); 220 this.views[view] = form; 226 private IView GetView(IView view) { 227 if (view == null || views.ContainsKey(view)) 228 return view; 229 IView viewHost = 230 (from ViewHost v in views.Keys.OfType<ViewHost>() 231 where v.Views.Contains(((IContentView)view)) 232 select v).SingleOrDefault(); 233 return viewHost; 234 } 235 236 237 internal void ShowView(IView view) { 238 if (InvokeRequired) Invoke((Action<IView>)ShowView, view); 239 else { 240 Form form = GetForm(view); 241 bool firstTimeShown = form == null; 242 if (form == null) { 243 form = CreateForm(view); 221 244 form.Activated += new EventHandler(FormActivated); 222 245 form.FormClosed += new FormClosedEventHandler(ChildFormClosed); 223 224 }225 this.Show (view, firstTimeShown);226 this.OnViewShown( view, firstTimeShown);246 } 247 IView internalView = GetView(form); 248 this.ShowView(internalView, firstTimeShown); 249 this.OnViewShown(internalView, firstTimeShown); 227 250 } 228 251 } … … 234 257 } 235 258 236 protected virtual void Show (IView view, bool firstTimeShown) {259 protected virtual void ShowView(IView view, bool firstTimeShown) { 237 260 } 238 261 … … 240 263 if (InvokeRequired) Invoke((Action<IView>)HideView, view); 241 264 else { 242 if (this.views.ContainsKey(view)) { 243 this.Hide(view); 244 if (this.activeView == view) 265 IView internalView = this.GetView(view); 266 if (internalView != null && this.views.ContainsKey(internalView)) { 267 this.Hide(internalView); 268 if (this.activeView == internalView) 245 269 this.ActiveView = null; 246 this.OnViewHidden( view);270 this.OnViewHidden(internalView); 247 271 } 248 272 } … … 269 293 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 270 294 else { 271 if (this.views.ContainsKey(view)) { 272 this.views[view].Close(); 273 this.OnViewClosed(view); 295 IView internalView = GetView(view); 296 if (internalView != null && this.views.ContainsKey(internalView)) { 297 this.views[internalView].Close(); 298 this.OnViewClosed(internalView); 274 299 } 275 300 } … … 279 304 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 280 305 else { 281 if (this.views.ContainsKey(view)) { 282 ((View)view).CloseReason = closeReason; 283 this.CloseView(view); 306 IView internalView = GetView(view); 307 if (internalView != null && this.views.ContainsKey(internalView)) { 308 ((View)internalView).CloseReason = closeReason; 309 this.CloseView(internalView); 284 310 } 285 311 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.cs
r3398 r3403 51 51 } 52 52 53 protected override void Show (IView view, bool firstTimeShown) {54 if (InvokeRequired) Invoke((Action<IView, bool>)Show , view, firstTimeShown);53 protected override void ShowView(IView view, bool firstTimeShown) { 54 if (InvokeRequired) Invoke((Action<IView, bool>)ShowView, view, firstTimeShown); 55 55 else { 56 base.Show (view, firstTimeShown);56 base.ShowView(view, firstTimeShown); 57 57 if (firstTimeShown) 58 58 this.GetForm(view).Show(); … … 68 68 else { 69 69 base.Hide(view); 70 this.GetForm(view).Hide(); 70 Form form = this.GetForm(view); 71 if (form != null) { 72 form.Hide(); 73 } 71 74 } 72 75 } … … 78 81 ViewHost viewHost = new ViewHost(contentView); 79 82 form = new DocumentForm(viewHost); 80 } else 83 this.AddViewFormCombination(viewHost, form); 84 } else { 81 85 form = new DocumentForm(view); 86 this.AddViewFormCombination(view, form); 87 } 82 88 83 89 form.MdiParent = this; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/SingleDocumentMainForm.cs
r3398 r3403 45 45 } 46 46 47 protected override void Show (IView view, bool firstTimeShown) {48 if (InvokeRequired) Invoke((Action<IView, bool>)Show , view, firstTimeShown);47 protected override void ShowView(IView view, bool firstTimeShown) { 48 if (InvokeRequired) Invoke((Action<IView, bool>)ShowView, view, firstTimeShown); 49 49 else { 50 base.Show (view, firstTimeShown);50 base.ShowView(view, firstTimeShown); 51 51 if (firstTimeShown) 52 52 this.GetForm(view).Show(this); … … 62 62 else { 63 63 base.Hide(view); 64 this.GetForm(view).Hide(); 64 Form form = this.GetForm(view); 65 if (form != null) { 66 form.Hide(); 67 } 65 68 } 66 69 } … … 72 75 ViewHost viewHost = new ViewHost(contentView); 73 76 form = new DocumentForm(viewHost); 74 } else 77 this.AddViewFormCombination(viewHost, form); 78 } else { 75 79 form = new DocumentForm(view); 80 this.AddViewFormCombination(view, form); 81 } 76 82 77 83 form.ShowInTaskbar = true; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.cs
r3398 r3403 82 82 83 83 this.IsShown = true; 84 mainform.ShowView(this , firstTimeShown);84 mainform.ShowView(this); 85 85 if (firstTimeShown) { 86 86 Form form = mainform.GetForm(this); … … 146 146 } 147 147 148 protected virtual void OnShown(ViewShownEventArgs e) {149 } 150 151 protected virtual void OnHidden(EventArgs e) {148 internal protected virtual void OnShown(ViewShownEventArgs e) { 149 } 150 151 internal protected virtual void OnHidden(EventArgs e) { 152 152 } 153 153 … … 170 170 } 171 171 172 protected virtual void OnClosing(FormClosingEventArgs e) {172 internal protected virtual void OnClosing(FormClosingEventArgs e) { 173 173 } 174 174 … … 185 185 } 186 186 187 protected virtual void OnClosed(FormClosedEventArgs e) {187 internal protected virtual void OnClosed(FormClosedEventArgs e) { 188 188 } 189 189 … … 215 215 public void ResumeRepaint(bool refresh) { 216 216 if (InvokeRequired) 217 Invoke((Action<bool>)ResumeRepaint, refresh);218 else 219 ((Control)this).ResumeRepaint(refresh);217 Invoke((Action<bool>)ResumeRepaint, refresh); 218 else 219 ((Control)this).ResumeRepaint(refresh); 220 220 } 221 221 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.Designer.cs
r3392 r3403 84 84 this.viewsLabel.TabIndex = 0; 85 85 this.toolTip.SetToolTip(this.viewsLabel, "Double-click to open a new window of the current view.\r\nRight-click to change cur" + 86 "rent view. ");86 "rent view. \r\n Drag icon to copy or link content in another view."); 87 87 this.viewsLabel.MouseLeave += new System.EventHandler(this.viewsLabel_MouseLeave); 88 88 this.viewsLabel.DoubleClick += new System.EventHandler(this.viewsLabel_DoubleClick); -
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.