Changeset 2443
- Timestamp:
- 10/20/09 15:34:02 (15 years ago)
- Location:
- branches/Mainform refactoring
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/Actions/NewEditorAction.cs
r2426 r2443 6 6 7 7 namespace HeuristicLab.MainForm.Test { 8 public class NewEditorAction{ 9 public void Execute(IMainForm mainform) { 10 MessageBox.Show("New Editor action called"); 11 EditorView x = new EditorView(); 12 x.Caption = "Editor View"; 13 mainform.ShowView(x); 8 public static class NewEditorAction{ 9 private static IView view; 10 public static void Execute(IMainForm mainform) { 11 if (view == null) 12 view = new EditorView(); 13 view.Caption = "Editor View"; 14 mainform.ShowView(view); 14 15 } 15 16 } -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/Actions/NewFormAction.cs
r2437 r2443 8 8 public class NewFormAction { 9 9 public void Execute(IMainForm mainform) { 10 MessageBox.Show("New form called");11 10 FormView1 x = new FormView1(); 12 11 x.Caption = "FormView"; -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/ButtonItems/NewEditorToolStripButtonItem.cs
r2433 r2443 24 24 25 25 public override void Execute() { 26 new NewEditorAction().Execute(MainFormManager.MainForm);26 NewEditorAction.Execute(MainFormManager.MainForm); 27 27 } 28 28 } -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/EditorView.cs
r2437 r2443 12 12 namespace HeuristicLab.MainForm.Test { 13 13 [DefaultView] 14 public partial class EditorView : ViewBase< IList> {14 public partial class EditorView : ViewBase<ArrayList> { 15 15 public EditorView() { 16 16 InitializeComponent(); … … 31 31 //def3.ToString(); 32 32 33 MainFormManager.MainForm.HideView(this); 33 34 this.OnChanged(); 34 35 } … … 44 45 } 45 46 } 46 47 #region IView<string> Members48 49 public void View(string item) {50 throw new NotImplementedException();51 }52 53 #endregion54 47 } 55 48 } -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView.cs
r2437 r2443 8 8 using System.Windows.Forms; 9 9 using HeuristicLab.MainForm.WindowsForms; 10 using System.Collections; 10 11 11 12 namespace HeuristicLab.MainForm.Test { 12 13 [DefaultView] 13 public partial class FormView1 : ViewBase<IC loneable>{14 public partial class FormView1 : ViewBase<ICollection> { 14 15 private int[] array; 15 16 public FormView1() { -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView2.cs
r2437 r2443 10 10 11 11 namespace HeuristicLab.MainForm.Test { 12 public partial class FormView2 : ViewBase< ArrayList> {12 public partial class FormView2 : ViewBase<IEnumerable> { 13 13 private int[] array; 14 14 public FormView2() { -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/MenuItems/NewEditorToolStripMenuItem.cs
r2433 r2443 23 23 24 24 public override void Execute() { 25 new NewEditorAction().Execute(MainFormManager.MainForm);25 NewEditorAction.Execute(MainFormManager.MainForm); 26 26 } 27 27 } -
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/DockingMainForm.cs
r2434 r2443 42 42 } 43 43 44 public override voidShowView(IView view) {45 if (InvokeRequired) Invoke((Action<IView>)ShowView, view);44 public override bool ShowView(IView view) { 45 if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view); 46 46 else { 47 if (views.Contains(view)) { 48 DockForm dockform = FindForm(view); 49 if (dockform != null) 50 dockform.Activate(); 51 } else { 52 base.ShowView(view); 53 DockContent dockForm = new DockForm(view); 54 dockForm.Activated += new EventHandler(DockFormActivated); 55 dockForm.GotFocus += new EventHandler(DockFormActivated); 56 dockForm.FormClosing += new FormClosingEventHandler(view.OnClosing); 57 dockForm.FormClosed += new FormClosedEventHandler(view.OnClosed); 58 dockForm.FormClosed += new FormClosedEventHandler(DockFormClosed); 59 foreach (IUserInterfaceItem item in UserInterfaceItems) 60 view.Changed += new EventHandler(item.ViewChanged); 61 dockForm.Show(dockPanel); 62 } 47 bool ret = base.ShowView(view); 48 if (ret) 49 ((DockForm)GetForm(view)).Show(dockPanel); 50 else 51 ((DockForm)GetForm(view)).Activate(); 52 return ret; 53 } 54 } 55 public override void HideView(IView view) { 56 if (InvokeRequired) Invoke((Action<IView>)HideView, view); 57 else { 58 Form form = base.GetForm(view); 59 if (form != null) 60 ((DockForm)form).Hide(); 63 61 } 64 62 } 65 63 66 public override void CloseView(IView view) { 67 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 68 else { 69 DockForm dockform = FindForm(view); 70 if (dockform != null) 71 dockform.Close(); 72 } 64 protected override Form CreateForm(IView view) { 65 return new DockForm(view); 73 66 } 74 67 75 private void DockFormClosed(object sender, FormClosedEventArgs e) {76 DockForm dockForm = (DockForm)sender;77 ViewClosed(dockForm.View);78 dockForm.Activated -= new EventHandler(DockFormActivated);79 dockForm.GotFocus -= new EventHandler(DockFormActivated);80 dockForm.FormClosing -= new FormClosingEventHandler(dockForm.View.OnClosing);81 dockForm.FormClosed -= new FormClosedEventHandler(dockForm.View.OnClosed);82 dockForm.FormClosed -= new FormClosedEventHandler(DockFormClosed);83 foreach (IUserInterfaceItem item in UserInterfaceItems)84 dockForm.View.Changed -= new EventHandler(item.ViewChanged);85 }86 87 private void DockFormActivated(object sender, EventArgs e) {88 base.ActiveView = ((DockForm)sender).View;89 }90 91 protected DockForm FindForm(IView view) {92 IEnumerable<DockForm> dockforms;93 94 dockforms = from df in dockPanel.Documents95 where ((DockForm)df).View == view96 select (DockForm)df;97 if (dockforms.Count() == 1)98 return dockforms.Single();99 100 dockforms = from fw in dockPanel.FloatWindows101 from np in fw.NestedPanes102 from dc in np.Contents103 where ((DockForm)dc).View == view104 select (DockForm)dc;105 if (dockforms.Count() == 1)106 return dockforms.Single();107 108 dockforms = from dw in dockPanel.DockWindows109 from np in dw.NestedPanes110 from dc in np.Contents111 where ((DockForm)dc).View == view112 select (DockForm)dc;113 if (dockforms.Count() == 1)114 return dockforms.Single();115 116 return null;117 }118 68 } 119 69 } -
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MainFormBase.cs
r2437 r2443 36 36 : base() { 37 37 InitializeComponent(); 38 this.views = new List<IView>();38 this.views = new Dictionary<IView, Form>(); 39 39 this.userInterfaceItems = new List<IUserInterfaceItem>(); 40 40 MainFormManager.RegisterMainForm(this); … … 77 77 } 78 78 79 pr otected List<IView> views;79 private Dictionary<IView, Form> views; 80 80 public IEnumerable<IView> Views { 81 get { return views; } 81 get { return views.Keys; } 82 } 83 84 public Form GetForm(IView view) { 85 if (views.ContainsKey(view)) 86 return views[view]; 87 return null; 82 88 } 83 89 … … 117 123 protected virtual void OnMainFormChanged() { 118 124 if (InvokeRequired) 119 Invoke((MethodInvoker) FireMainFormChanged);125 Invoke((MethodInvoker)OnMainFormChanged); 120 126 else if (Changed != null) 121 127 Changed(this, new EventArgs()); 122 128 } 123 129 124 public virtual void ShowView(IView view) { 125 if (!views.Contains(view)) { 126 views.Add(view); 127 } 128 this.ActiveView = view; 129 } 130 131 public virtual void CloseView(IView view) { 130 protected virtual Form CreateForm(IView view) { 131 throw new NotImplementedException("CreateForm must be implemented in subclasses of MainFormBase."); 132 } 133 134 public virtual bool ShowView(IView view) { 135 if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view); 136 else { 137 if (!views.Keys.Contains(view)) { 138 Form form = CreateForm(view); 139 views[view] = form; 140 form.Activated += new EventHandler(FormActivated); 141 form.GotFocus += new EventHandler(FormActivated); 142 form.FormClosing += new FormClosingEventHandler(view.OnClosing); 143 form.FormClosed += new FormClosedEventHandler(view.OnClosed); 144 form.FormClosed += new FormClosedEventHandler(ChildFormClosed); 145 foreach (IUserInterfaceItem item in UserInterfaceItems) 146 view.Changed += new EventHandler(item.ViewChanged); 147 return true; 148 } else 149 return false; 150 } 151 } 152 153 public virtual void HideView(IView view) { 154 if (InvokeRequired) Invoke((Action<IView>)HideView, view); 155 else { 156 if (views.ContainsKey(view)) 157 views[view].Hide(); 158 } 159 } 160 161 public void CloseView(IView view) { 162 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 163 else { 164 if (views.ContainsKey(view)) 165 views[view].Close(); 166 } 132 167 } 133 168 134 169 public virtual void CloseAllViews() { 135 foreach (IView view in views. ToArray())170 foreach (IView view in views.Keys.ToArray()) 136 171 CloseView(view); 137 172 } 138 139 protected virtual void ViewClosed(IView view) { 173 #endregion 174 175 #region events 176 private void ChildFormClosed(object sender, FormClosedEventArgs e) { 177 Form form = (Form)sender; 178 IView view = GetViewForForm(form); 179 180 form.Activated -= new EventHandler(FormActivated); 181 form.GotFocus -= new EventHandler(FormActivated); 182 form.FormClosing -= new FormClosingEventHandler(view.OnClosing); 183 form.FormClosed -= new FormClosedEventHandler(view.OnClosed); 184 form.FormClosed -= new FormClosedEventHandler(ChildFormClosed); 185 foreach (IUserInterfaceItem item in UserInterfaceItems) 186 view.Changed -= new EventHandler(item.ViewChanged); 187 140 188 views.Remove(view); 141 189 if (ActiveView == view) 142 190 ActiveView = null; 191 } 192 193 private void FormActivated(object sender, EventArgs e) { 194 this.ActiveView = GetViewForForm((Form)sender); 195 } 196 197 private IView GetViewForForm(Form form) { 198 return views.Where(x => x.Value == form).Single().Key; 143 199 } 144 200 #endregion … … 189 245 } 190 246 191 private void InsertItem(IEnumerable<string> structure, Type t, ToolStripItem item, ToolStripItemCollection parentItems) {247 private void InsertItem(IEnumerable<string> structure, Type t, ToolStripItem item, ToolStripItemCollection parentItems) { 192 248 ToolStripDropDownItem parent = null; 193 249 foreach (string s in structure) { … … 195 251 parent = (ToolStripDropDownItem)parentItems[s]; 196 252 else { 197 parent = (ToolStripDropDownItem)Activator.CreateInstance(t, s, null,null,s); ;253 parent = (ToolStripDropDownItem)Activator.CreateInstance(t, s, null, null, s); ; 198 254 parentItems.Add(parent); 199 255 } -
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.Designer.cs
r2426 r2443 14 14 components.Dispose(); 15 15 } 16 this.MdiChildActivate -= new System.EventHandler(MultipleDocumentFormActivated);17 16 base.Dispose(disposing); 18 17 } -
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.cs
r2434 r2443 48 48 } 49 49 50 public override voidShowView(IView view) {51 if (InvokeRequired) Invoke((Action<IView>)ShowView, view);50 public override bool ShowView(IView view) { 51 if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view); 52 52 else { 53 if (views.Contains(view)) { 54 DocumentForm documentForm = FindForm(view); 55 if (documentForm != null) 56 documentForm.Focus(); 57 } else { 58 base.ShowView(view); 59 DocumentForm form = new DocumentForm(view); 60 form.Activated += new EventHandler(MultipleDocumentFormActivated); 61 form.GotFocus += new EventHandler(MultipleDocumentFormActivated); 62 form.FormClosing += new FormClosingEventHandler(view.OnClosing); 63 form.FormClosed += new FormClosedEventHandler(view.OnClosed); 64 form.FormClosed += new FormClosedEventHandler(MultipleDocumentFormClosed); 65 form.MdiParent = this; 66 foreach (IUserInterfaceItem item in UserInterfaceItems) 67 view.Changed += new EventHandler(item.ViewChanged); 68 form.Show(); 53 bool ret = base.ShowView(view); 54 if (ret) 55 GetForm(view).Show(); 56 else { 57 GetForm(view).Visible = true; 58 GetForm(view).Activate(); 69 59 } 60 return ret; 70 61 } 71 62 } 72 63 73 public override void CloseView(IView view) { 74 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 75 else { 76 DocumentForm documentForm = FindForm(view); 77 if (documentForm != null) 78 documentForm.Close(); 79 } 80 } 81 82 private void MultipleDocumentFormActivated(object sender, EventArgs e) { 83 base.ActiveView = ((DocumentForm)sender).View; 84 } 85 86 private void MultipleDocumentFormClosed(object sender, FormClosedEventArgs e) { 87 DocumentForm form = (DocumentForm)sender; 88 ViewClosed(form.View); 89 form.Activated -= new EventHandler(MultipleDocumentFormActivated); 90 form.GotFocus -= new EventHandler(MultipleDocumentFormActivated); 91 form.FormClosing -= new FormClosingEventHandler(form.View.OnClosing); 92 form.FormClosed -= new FormClosedEventHandler(form.View.OnClosed); 93 form.FormClosed -= new FormClosedEventHandler(MultipleDocumentFormClosed); 94 foreach (IUserInterfaceItem item in UserInterfaceItems) 95 form.View.Changed -= new EventHandler(item.ViewChanged); 96 } 97 98 protected DocumentForm FindForm(IView view) { 99 IEnumerable<DocumentForm> forms = 100 from df in MdiChildren 101 where ((DocumentForm)df).View == view 102 select (DocumentForm)df; 103 if (forms.Count() == 1) 104 return forms.Single(); 105 return null; 64 protected override Form CreateForm(IView view) { 65 Form form = new DocumentForm(view); 66 form.MdiParent = this; 67 return form; 106 68 } 107 69 } -
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/SingleDocumentMainForm.cs
r2434 r2443 42 42 } 43 43 44 public override voidShowView(IView view) {45 if (InvokeRequired) Invoke((Action<IView>)ShowView, view);44 public override bool ShowView(IView view) { 45 if (InvokeRequired) return (bool)Invoke((Func<IView, bool>)ShowView, view); 46 46 else { 47 if (views.Contains(view)) { 48 DocumentForm documentForm = FindForm(view); 49 if (documentForm != null) 50 documentForm.Focus(); 51 } else { 52 base.ShowView(view); 53 DocumentForm form = new DocumentForm(view); 54 form.ShowInTaskbar = true; 55 form.Activated += new EventHandler(DocumentFormActivated); 56 form.GotFocus += new EventHandler(DocumentFormActivated); 57 form.FormClosing += new FormClosingEventHandler(view.OnClosing); 58 form.FormClosed += new FormClosedEventHandler(view.OnClosed); 59 form.FormClosed += new FormClosedEventHandler(DocumentFormClosed); 60 foreach (IUserInterfaceItem item in UserInterfaceItems) 61 view.Changed += new EventHandler(item.ViewChanged); 62 form.Show(this); 47 bool ret = base.ShowView(view); 48 if (ret) 49 GetForm(view).Show(this); 50 else { 51 GetForm(view).Visible = true; 52 GetForm(view).Activate(); 63 53 } 54 return ret; 64 55 } 65 56 } 66 57 67 public override void CloseView(IView view) { 68 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 69 else { 70 DocumentForm documentForm = FindForm(view); 71 if (documentForm != null) 72 documentForm.Close(); 73 } 74 } 75 76 private void DocumentFormClosed(object sender, FormClosedEventArgs e) { 77 DocumentForm form = (DocumentForm)sender; 78 ViewClosed(form.View); 79 form.Activated -= new EventHandler(DocumentFormActivated); 80 form.GotFocus -= new EventHandler(DocumentFormActivated); 81 form.FormClosing -= new FormClosingEventHandler(form.View.OnClosing); 82 form.FormClosed -= new FormClosedEventHandler(form.View.OnClosed); 83 form.FormClosed -= new FormClosedEventHandler(DocumentFormClosed); 84 foreach (IUserInterfaceItem item in UserInterfaceItems) 85 form.View.Changed -= new EventHandler(item.ViewChanged); 86 } 87 88 private void DocumentFormActivated(object sender, EventArgs e) { 89 base.ActiveView = ((DocumentForm)sender).View; 90 } 91 92 protected DocumentForm FindForm(IView view) { 93 IEnumerable<DocumentForm> forms = 94 from df in OwnedForms 95 where ((DocumentForm)df).View == view 96 select (DocumentForm)df; 97 if (forms.Count() == 1) 98 return forms.Single(); 99 return null; 58 protected override Form CreateForm(IView view) { 59 DocumentForm form = new DocumentForm(view); 60 form.ShowInTaskbar = true; 61 return form; 100 62 } 101 63 } -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/Interfaces/IMainForm.cs
r2426 r2443 36 36 37 37 Type UserInterfaceItemType { get; } 38 void ShowView(IView view); 38 bool ShowView(IView view); //return value indicates if a new form for the view is created 39 void HideView(IView view); 39 40 void CloseView(IView view); 40 41 void CloseAllViews(); -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/MainFormManager.cs
r2438 r2443 113 113 if (t1.IsAssignableFrom(t2)) 114 114 return 1; 115 return -1; 115 else if (t2.IsAssignableFrom(t1)) 116 return -1; 117 else 118 return 0; 116 119 } 117 120 ); … … 121 124 throw new Exception("Could not determine which is the default view for type " + viewableType.ToString() + "."); 122 125 } 123 } 126 } 124 127 } 125 128
Note: See TracChangeset
for help on using the changeset viewer.