Changeset 2696 for trunk/sources
- Timestamp:
- 01/28/10 16:15:21 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 added
- 36 edited
- 12 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.Test/3.2/Actions/NewEditorAction.cs
r2636 r2696 11 11 EditorView view = new EditorView(); 12 12 view.Caption = "Editor View " + mainform.Views.Count(); 13 mainform.ShowView(view);13 view.Show(); 14 14 } 15 15 } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/Actions/NewFormAction.cs
r2458 r2696 10 10 FormView1 x = new FormView1(); 11 11 x.Caption = "FormView"; 12 mainform.ShowView(x);12 x.Show(); 13 13 } 14 14 } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/NewEditorToolStripButtonItem.cs
r2458 r2696 6 6 7 7 namespace HeuristicLab.MainForm.Test { 8 public class NewEditorToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem Base, ITestUserInterfaceItemProvider {8 public class NewEditorToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider { 9 9 public override int Position { 10 10 get { return 12; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/NewFormToolStripButtonItem.cs
r2458 r2696 6 6 7 7 namespace HeuristicLab.MainForm.Test { 8 public class NewFormToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem Base, ITestUserInterfaceItemProvider {8 public class NewFormToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider { 9 9 public override int Position { 10 10 get { return 11; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/NewToolStripButtonItem.cs
r2458 r2696 6 6 7 7 namespace HeuristicLab.MainForm.Test { 8 public class NewToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem Base, ITestUserInterfaceItemProvider {8 public class NewToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider { 9 9 public override int Position { 10 10 get { return 10; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/OpenToolStripButtonItem.cs
r2636 r2696 6 6 7 7 namespace HeuristicLab.MainForm.Test { 8 public class OpenToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItemBase, ITestUserInterfaceItemProvider { 8 public class OpenToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider { 9 10 public OpenToolStripButtonItem() 11 : base() { 12 System.Console.Out.Write("test"); 13 } 9 14 public override int Position { 10 15 get { return 20; } … … 23 28 } 24 29 25 p ublic override voidActiveViewChanged(object sender, EventArgs e) {30 protected override void OnActiveViewChanged(object sender, EventArgs e) { 26 31 this.ToolStripItem.Enabled = !this.ToolStripItem.Enabled; 27 MainFormManager.MainForm.Title =28 MainFormManager.MainForm.ActiveView == null ? "null" : MainFormManager.MainForm.ActiveView.Caption;32 //MainFormManager.MainForm.Title = 33 // MainFormManager.MainForm.ActiveView == null ? "null" : MainFormManager.MainForm.ActiveView.Caption; 29 34 } 30 35 } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/SaveToolStripButtonItem.cs
r2458 r2696 6 6 7 7 namespace HeuristicLab.MainForm.Test { 8 public class SaveToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem Base, ITestUserInterfaceItemProvider {8 public class SaveToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider { 9 9 public override int Position { 10 10 get { return 30; } … … 23 23 } 24 24 25 p ublic override voidActiveViewChanged(object sender, EventArgs e) {25 protected override void OnActiveViewChanged(object sender, EventArgs e) { 26 26 IMainForm mainform = MainFormManager.MainForm; 27 27 if (mainform.ActiveView == null) … … 31 31 } 32 32 33 p ublic override voidViewChanged(object sender, EventArgs e) {33 protected override void OnViewChanged(object sender, EventArgs e) { 34 34 this.ToolStripItem.Enabled = !this.ToolStripItem.Enabled; 35 35 } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/SeparatorToolStripButtonItem.cs
r2514 r2696 6 6 7 7 namespace HeuristicLab.MainForm.Test { 8 public class SeparatorToolStripButtonItem : ToolBarSeparatorItem Base, ITestUserInterfaceItemProvider {8 public class SeparatorToolStripButtonItem : ToolBarSeparatorItem, ITestUserInterfaceItemProvider { 9 9 public override int Position { 10 10 get { return 15; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/EditorView.Designer.cs
r2254 r2696 56 56 this.ForeColor = System.Drawing.SystemColors.ControlText; 57 57 this.Name = "EditorView"; 58 this.VisibleChanged += new System.EventHandler(this.EditorView_VisibleChanged); 58 59 this.ResumeLayout(false); 59 60 this.PerformLayout(); -
trunk/sources/HeuristicLab.MainForm.Test/3.2/EditorView.cs
r2466 r2696 6 6 using System.Linq; 7 7 using System.Text; 8 using System.Windows.Forms;9 8 using HeuristicLab.MainForm.WindowsForms; 10 9 using System.Collections; 10 using System.Windows.Forms; 11 11 12 12 namespace HeuristicLab.MainForm.Test { 13 [Content(typeof(ArrayList), IsDefaultView=true)]14 public partial class EditorView : ViewBase{13 [Content(typeof(ArrayList), IsDefaultView = true)] 14 public partial class EditorView : HeuristicLab.MainForm.WindowsForms.View { 15 15 public EditorView() 16 16 : base() { … … 25 25 IEnumerable<Type> views = MainFormManager.GetViewTypes(typeof(ArrayList)); 26 26 views.ToString(); 27 IEnumerable<Type> views1 = MainFormManager.GetViewTypes(typeof( IList));27 IEnumerable<Type> views1 = MainFormManager.GetViewTypes(typeof(List<string>)); 28 28 views1.ToString(); 29 IEnumerable<Type> views2 = MainFormManager.GetViewTypes(typeof( IEnumerable));29 IEnumerable<Type> views2 = MainFormManager.GetViewTypes(typeof(List<>)); 30 30 views2.ToString(); 31 IEnumerable<Type> views3 = MainFormManager.GetViewTypes(typeof(ICollection<>)); 32 views3.ToString(); 31 33 32 ArrayList list = new ArrayList(); 33 IView defaultView = MainFormManager.CreateDefaultView(list); 34 MainFormManager.MainForm.ShowView(defaultView); 34 List<MenuItem> ilist = new List<MenuItem>(); 35 IView defaultView = MainFormManager.CreateDefaultView(ilist); 36 defaultView.Show(); 37 38 List<object> list = new List<object>(); 39 IView dView = MainFormManager.CreateDefaultView(list); 40 if (dView != null) 41 dView.Show(); 35 42 this.OnChanged(); 36 43 } 37 44 38 p ublic override void OnClosing(object sender, CancelEventArgs e) {45 protected override void OnClosing(FormClosingEventArgs e) { 39 46 if (DialogResult.Yes != MessageBox.Show( 40 47 "Recent changes have not been saved. Close the editor anyway?", "Close editor?", … … 46 53 } 47 54 } 55 56 private void EditorView_VisibleChanged(object sender, EventArgs e) { 57 MainFormManager.MainForm.Title = "visible: " + this.Visible; 58 } 48 59 } 49 60 } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/FormView.cs
r2466 r2696 11 11 12 12 namespace HeuristicLab.MainForm.Test { 13 [Content(typeof( IList),true)]14 public partial class FormView1 : FormView2 {13 [Content(typeof(List<string>), true)] 14 public partial class FormView1 : FormView2<MenuItem> { 15 15 public FormView1() { 16 16 InitializeComponent(); 17 17 } 18 19 public FormView1(List<string> list) 20 : this() { 21 } 18 22 } 19 23 } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/FormView2.Designer.cs
r2458 r2696 1 1 namespace HeuristicLab.MainForm.Test { 2 partial class FormView2 {2 partial class FormView2<T> { 3 3 /// <summary> 4 4 /// Required designer variable. -
trunk/sources/HeuristicLab.MainForm.Test/3.2/FormView2.cs
r2466 r2696 1 1 using System; 2 using System.Collections ;2 using System.Collections.Generic; 3 3 using System.ComponentModel; 4 4 using System.Drawing; … … 6 6 using System.Linq; 7 7 using System.Text; 8 using System.Windows.Forms;9 8 using HeuristicLab.MainForm.WindowsForms; 10 9 11 10 namespace HeuristicLab.MainForm.Test { 12 [Content(typeof(I Enumerable))]13 public partial class FormView2 : ViewBase{11 [Content(typeof(ICollection<>),true)] 12 public partial class FormView2<T> : View where T: IMenuItem { 14 13 public FormView2() { 14 InitializeComponent(); 15 } 16 public FormView2(ICollection<T> x) { 15 17 InitializeComponent(); 16 18 } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/ExitToolStripMenuItem.cs
r2458 r2696 9 9 10 10 namespace HeuristicLab.MainForm.Test { 11 public class CloseToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem Base, ITestUserInterfaceItemProvider {11 public class CloseToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider { 12 12 public override string Name { 13 13 get { return "Exit"; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/NewEditorToolStripMenuItem.cs
r2458 r2696 9 9 10 10 namespace HeuristicLab.MainForm.Test { 11 public class NewEditorToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem Base, ITestUserInterfaceItemProvider {11 public class NewEditorToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider { 12 12 public override string Name { 13 13 get { return "Editor"; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/NewFormToolStripMenuItem.cs
r2458 r2696 9 9 10 10 namespace HeuristicLab.MainForm.Test { 11 public class NewFormToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem Base, ITestUserInterfaceItemProvider {11 public class NewFormToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider { 12 12 public override string Name { 13 13 get { return "Form"; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/OpenToolStripMenuItem.cs
r2458 r2696 8 8 9 9 namespace HeuristicLab.MainForm.Test { 10 public class OpenToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem Base, ITestUserInterfaceItemProvider {10 public class OpenToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider { 11 11 public override string Name { 12 12 get { return "Open"; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/SaveToolStripMenuItem.cs
r2458 r2696 9 9 10 10 namespace HeuristicLab.MainForm.Test { 11 public class SaveToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem Base, ITestUserInterfaceItemProvider {11 public class SaveToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider { 12 12 public override string Name { 13 13 get { return "Save"; } -
trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/SeparatorMenuItem.cs
r2514 r2696 9 9 10 10 namespace HeuristicLab.MainForm.Test { 11 public class SeparatorMenuItem : MenuSeparatorItem Base, ITestUserInterfaceItemProvider {11 public class SeparatorMenuItem : MenuSeparatorItem, ITestUserInterfaceItemProvider { 12 12 public override IEnumerable<string> Structure { 13 13 get { return new string[] { "File" }; } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/DockForm.cs
r2458 r2696 33 33 /// Displays the used view. 34 34 /// </summary> 35 publicpartial class DockForm : DockContent {35 internal partial class DockForm : DockContent { 36 36 public DockForm(IView view) { 37 37 InitializeComponent(); -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/DockingMainForm.cs
r2636 r2696 31 31 32 32 namespace HeuristicLab.MainForm.WindowsForms { 33 public partial class DockingMainForm : MainForm Base{33 public partial class DockingMainForm : MainForm { 34 34 public DockingMainForm() 35 35 : base() { -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/DocumentForm.cs
r2458 r2696 29 29 30 30 namespace HeuristicLab.MainForm.WindowsForms { 31 publicpartial class DocumentForm : Form {31 internal partial class DocumentForm : Form { 32 32 private IView myView; 33 33 public IView View { -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/HeuristicLab.MainForm.WindowsForms-3.2.csproj
r2649 r2696 82 82 </ItemGroup> 83 83 <ItemGroup> 84 <Compile Include="ContentView.cs"> 85 <SubType>UserControl</SubType> 86 </Compile> 87 <Compile Include="ContentView.Designer.cs"> 88 <DependentUpon>ContentView.cs</DependentUpon> 89 </Compile> 84 90 <Compile Include="DockForm.cs"> 85 91 <SubType>Form</SubType> … … 101 107 </Compile> 102 108 <Compile Include="HeuristicLabMainFormWindowsFormsPlugin.cs" /> 103 <Compile Include="MainForm Base.cs">104 <SubType>Form</SubType> 105 </Compile> 106 <Compile Include="MainForm Base.Designer.cs">107 <DependentUpon>MainForm Base.cs</DependentUpon>108 </Compile> 109 <Compile Include="MenuItem Base.cs" />109 <Compile Include="MainForm.cs"> 110 <SubType>Form</SubType> 111 </Compile> 112 <Compile Include="MainForm.Designer.cs"> 113 <DependentUpon>MainForm.cs</DependentUpon> 114 </Compile> 115 <Compile Include="MenuItem.cs" /> 110 116 <Compile Include="MultipleDocumentMainForm.cs"> 111 117 <SubType>Form</SubType> … … 121 127 <DependentUpon>SingleDocumentMainForm.cs</DependentUpon> 122 128 </Compile> 123 <Compile Include="ToolBarItem Base.cs" />124 <Compile Include="View Base.cs">129 <Compile Include="ToolBarItem.cs" /> 130 <Compile Include="View.cs"> 125 131 <SubType>UserControl</SubType> 126 132 </Compile> 127 <Compile Include="View Base.Designer.cs">128 <DependentUpon>View Base.cs</DependentUpon>133 <Compile Include="View.Designer.cs"> 134 <DependentUpon>View.cs</DependentUpon> 129 135 </Compile> 130 136 <Compile Include="ViewContextMenuStrip.cs"> … … 165 171 <SubType>Designer</SubType> 166 172 </EmbeddedResource> 167 <EmbeddedResource Include="MainForm Base.resx">168 <DependentUpon>MainForm Base.cs</DependentUpon>173 <EmbeddedResource Include="MainForm.resx"> 174 <DependentUpon>MainForm.cs</DependentUpon> 169 175 </EmbeddedResource> 170 176 <EmbeddedResource Include="MultipleDocumentMainForm.resx"> -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MainForm.Designer.cs
r2689 r2696 20 20 #endregion 21 21 namespace HeuristicLab.MainForm.WindowsForms { 22 partial class MainForm Base{22 partial class MainForm { 23 23 /// <summary> 24 24 /// Required designer variable. … … 44 44 /// </summary> 45 45 private void InitializeComponent() { 46 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm Base));46 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); 47 47 this.menuStrip = new System.Windows.Forms.MenuStrip(); 48 48 this.toolStrip = new System.Windows.Forms.ToolStrip(); -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MainForm.cs
r2689 r2696 30 30 31 31 using HeuristicLab.PluginInfrastructure; 32 using System.Collections; 32 33 33 34 namespace HeuristicLab.MainForm.WindowsForms { 34 public partial class MainFormBase : Form, IMainForm { 35 35 public partial class MainForm : Form, IMainForm { 36 36 private bool initialized; 37 protected MainFormBase() 37 38 protected MainForm() 38 39 : base() { 39 40 InitializeComponent(); … … 43 44 } 44 45 45 protected MainForm Base(Type userInterfaceItemType)46 protected MainForm(Type userInterfaceItemType) 46 47 : this() { 47 48 this.userInterfaceItemType = userInterfaceItemType; 48 CreateGUI(); 49 } 50 51 private void MainFormBase_Load(object sender, EventArgs e) { 52 if (!DesignMode) { 53 MainFormManager.RegisterMainForm(this); 54 if (!this.initialized) { 55 this.initialized = true; 56 if (this.Initialized != null) 57 this.Initialized(this, new EventArgs()); 58 } 59 } 60 } 61 62 public event EventHandler Initialized; 63 64 #region IMainForm Members 49 } 50 51 #region properties 65 52 public string Title { 66 53 get { return this.Text; } … … 93 80 public IEnumerable<IView> Views { 94 81 get { return views.Keys; } 95 }96 97 public Form GetForm(IView view) {98 if (views.ContainsKey(view))99 return views[view];100 return null;101 82 } 102 83 … … 121 102 get { return this.userInterfaceItems; } 122 103 } 123 104 #endregion 105 106 #region events 124 107 public event EventHandler ActiveViewChanged; 125 108 protected virtual void OnActiveViewChanged() { … … 155 138 156 139 public event EventHandler Changed; 157 public void FireMainFormChanged() { 158 OnMainFormChanged(); 159 } 160 protected virtual void OnMainFormChanged() { 140 protected void FireMainFormChanged() { 161 141 if (InvokeRequired) 162 Invoke((MethodInvoker) OnMainFormChanged);142 Invoke((MethodInvoker)FireMainFormChanged); 163 143 else if (Changed != null) 164 144 Changed(this, new EventArgs()); 165 145 } 166 146 147 private void MainFormBase_Load(object sender, EventArgs e) { 148 if (!DesignMode) { 149 MainFormManager.RegisterMainForm(this); 150 if (!this.initialized) { 151 this.initialized = true; 152 this.OnInitialized(new EventArgs()); 153 } 154 this.CreateGUI(); 155 } 156 } 157 158 protected virtual void OnInitialized(EventArgs e) { 159 } 160 161 private void ChildFormClosed(object sender, FormClosedEventArgs e) { 162 Form form = (Form)sender; 163 IView view = GetView(form); 164 165 form.Activated -= new EventHandler(FormActivated); 166 form.FormClosed -= new FormClosedEventHandler(ChildFormClosed); 167 168 views.Remove(view); 169 this.OnViewClosed(view); 170 if (ActiveView == view) 171 ActiveView = null; 172 } 173 174 private void FormActivated(object sender, EventArgs e) { 175 this.ActiveView = GetView((Form)sender); 176 } 177 #endregion 178 179 #region create, get, show, hide, close views 167 180 protected virtual Form CreateForm(IView view) { 168 181 throw new NotImplementedException("CreateForm must be implemented in subclasses of MainFormBase."); 169 182 } 170 183 171 public void ShowView(IView view) { 172 if (InvokeRequired) Invoke((Action<IView>)ShowView, view); 184 internal Form GetForm(IView view) { 185 if (views.ContainsKey(view)) 186 return views[view]; 187 return null; 188 } 189 190 internal IView GetView(Form form) { 191 return views.Where(x => x.Value == form).Single().Key; 192 } 193 194 internal void ShowView(IView view,bool firstTimeShown) { 195 if (InvokeRequired) Invoke((Action<IView, bool>)ShowView, view,firstTimeShown); 173 196 else { 174 if ( !views.Keys.Contains(view)) {197 if (firstTimeShown) { 175 198 Form form = CreateForm(view); 176 views[view] = form;199 this.views[view] = form; 177 200 form.Activated += new EventHandler(FormActivated); 178 form.FormClosing += new FormClosingEventHandler(view.OnClosing);179 form.FormClosing += new FormClosingEventHandler(((ViewBase)view).OnClosingHelper);180 form.FormClosed += new FormClosedEventHandler(view.OnClosed);181 201 form.FormClosed += new FormClosedEventHandler(ChildFormClosed); 182 foreach (IUserInterfaceItem item in UserInterfaceItems) 183 view.Changed += new EventHandler(item.ViewChanged); 184 this.Show(view, true); 185 this.OnViewShown(view, true); 186 } else { 187 this.Show(view, false); 188 this.OnViewShown(view, false); 189 } 202 } 203 this.Show(view, firstTimeShown); 204 this.OnViewShown(view, firstTimeShown); 190 205 } 191 206 } … … 194 209 } 195 210 196 publicvoid HideView(IView view) {211 internal void HideView(IView view) { 197 212 if (InvokeRequired) Invoke((Action<IView>)HideView, view); 198 213 else { … … 207 222 } 208 223 209 publicvoid CloseView(IView view) {224 internal void CloseView(IView view) { 210 225 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 211 226 else { … … 217 232 } 218 233 219 publicvoid CloseView(IView view, CloseReason closeReason) {234 internal void CloseView(IView view, CloseReason closeReason) { 220 235 if (InvokeRequired) Invoke((Action<IView>)CloseView, view); 221 236 else { 222 237 if (this.views.ContainsKey(view)) { 223 ((View Base)view).closeReason = closeReason;238 ((View)view).closeReason = closeReason; 224 239 this.CloseView(view); 225 240 } … … 227 242 } 228 243 229 public v irtual void CloseAllViews() {244 public void CloseAllViews() { 230 245 foreach (IView view in views.Keys.ToArray()) 231 246 CloseView(view); 232 247 } 233 248 234 public v irtual void CloseAllViews(CloseReason closeReason) {249 public void CloseAllViews(CloseReason closeReason) { 235 250 foreach (IView view in views.Keys.ToArray()) 236 251 CloseView(view, closeReason); … … 238 253 #endregion 239 254 240 #region events241 private void ChildFormClosed(object sender, FormClosedEventArgs e) {242 Form form = (Form)sender;243 IView view = GetViewForForm(form);244 245 form.Activated -= new EventHandler(FormActivated);246 form.FormClosing -= new FormClosingEventHandler(view.OnClosing);247 form.FormClosing -= new FormClosingEventHandler(((ViewBase)view).OnClosingHelper);248 form.FormClosed -= new FormClosedEventHandler(view.OnClosed);249 form.FormClosed -= new FormClosedEventHandler(ChildFormClosed);250 foreach (IUserInterfaceItem item in UserInterfaceItems)251 view.Changed -= new EventHandler(item.ViewChanged);252 253 views.Remove(view);254 this.OnViewClosed(view);255 if (ActiveView == view)256 ActiveView = null;257 }258 259 private void FormActivated(object sender, EventArgs e) {260 this.ActiveView = GetViewForForm((Form)sender);261 }262 263 private IView GetViewForForm(Form form) {264 return views.Where(x => x.Value == form).Single().Key;265 }266 #endregion267 268 255 #region create menu and toolbar 269 protected virtual void CreateGUI() { 270 IEnumerable<IMenuItem> toolStripMenuItems = 271 from mi in ApplicationManager.Manager.GetInstances(userInterfaceItemType) 272 where mi is IMenuItem 273 orderby ((IMenuItem)mi).Position 274 select (IMenuItem)mi; 275 foreach (IMenuItem menuItem in toolStripMenuItems) 276 AddToolStripMenuItem(menuItem); 277 278 IEnumerable<IToolBarItem> toolStripButtonItems = 279 from bi in ApplicationManager.Manager.GetInstances(userInterfaceItemType) 280 where bi is IToolBarItem 281 orderby ((IToolBarItem)bi).Position 282 select (IToolBarItem)bi; 283 foreach (IToolBarItem toolStripButtonItem in toolStripButtonItems) 284 AddToolStripButtonItem(toolStripButtonItem); 256 private void CreateGUI() { 257 IEnumerable<object> allUserInterfaceItems = ApplicationManager.Manager.GetInstances(userInterfaceItemType); 258 259 IEnumerable<IPositionableUserInterfaceItem> toolStripMenuItems = 260 from mi in allUserInterfaceItems 261 where (mi is IPositionableUserInterfaceItem) && 262 (mi is IMenuItem || mi is IMenuSeparatorItem) 263 orderby ((IPositionableUserInterfaceItem)mi).Position 264 select (IPositionableUserInterfaceItem)mi; 265 266 foreach (IPositionableUserInterfaceItem menuItem in toolStripMenuItems) { 267 if (menuItem is IMenuItem) 268 AddToolStripMenuItem((IMenuItem)menuItem); 269 else if (menuItem is IMenuSeparatorItem) 270 AddToolStripMenuItem((IMenuSeparatorItem)menuItem); 271 } 272 273 IEnumerable<IPositionableUserInterfaceItem> toolStripButtonItems = 274 from bi in allUserInterfaceItems 275 where (bi is IPositionableUserInterfaceItem) && 276 (bi is IToolBarItem || bi is IToolBarSeparatorItem) 277 orderby ((IPositionableUserInterfaceItem)bi).Position 278 select (IPositionableUserInterfaceItem)bi; 279 280 foreach (IPositionableUserInterfaceItem toolStripButtonItem in toolStripButtonItems) { 281 if (toolStripButtonItem is IToolBarItem) 282 AddToolStripButtonItem((IToolBarItem)toolStripButtonItem); 283 else if (toolStripButtonItem is IToolBarSeparatorItem) 284 AddToolStripButtonItem((IToolBarSeparatorItem)toolStripButtonItem); 285 } 286 287 this.AdditionalCreationOfGUIElements(); 288 } 289 290 protected virtual void AdditionalCreationOfGUIElements() { 285 291 } 286 292 287 293 private void AddToolStripMenuItem(IMenuItem menuItem) { 288 if (menuItem is MenuItemBase) { 289 ToolStripMenuItem item = new ToolStripMenuItem(); 290 SetToolStripItemProperties(item, menuItem); 291 ((MenuItemBase)menuItem).ToolStripItem = item; 292 item.ShortcutKeys = ((MenuItemBase)menuItem).ShortCutKeys; 293 item.DisplayStyle = ((MenuItemBase)menuItem).ToolStripItemDisplayStyle; 294 this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), item, menuStrip.Items); 295 } else if (menuItem is MenuSeparatorItemBase) { 296 this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), new ToolStripSeparator(), menuStrip.Items); 297 } 294 ToolStripMenuItem item = new ToolStripMenuItem(); 295 this.SetToolStripItemProperties(item, menuItem); 296 if (menuItem is MenuItem) { 297 MenuItem menuItemBase = (MenuItem)menuItem; 298 menuItemBase.ToolStripItem = item; 299 item.ShortcutKeys = menuItemBase.ShortCutKeys; 300 item.DisplayStyle = menuItemBase.ToolStripItemDisplayStyle; 301 } 302 this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), item, menuStrip.Items); 303 } 304 305 private void AddToolStripMenuItem(IMenuSeparatorItem menuItem) { 306 this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), new ToolStripSeparator(), menuStrip.Items); 298 307 } 299 308 300 309 private void AddToolStripButtonItem(IToolBarItem buttonItem) { 301 ToolStripItem item = n ull;302 303 if (buttonItem is ToolBarItemBase) {304 if ( ((ToolBarItemBase)buttonItem).IsDropDownButton)310 ToolStripItem item = new ToolStripButton(); 311 if (buttonItem is ToolBarItem) { 312 ToolBarItem buttonItemBase = (ToolBarItem)buttonItem; 313 if (buttonItemBase.IsDropDownButton) 305 314 item = new ToolStripDropDownButton(); 306 else 307 item = new ToolStripButton(); 308 309 SetToolStripItemProperties(item, buttonItem); 310 item.DisplayStyle = ((ToolBarItemBase)buttonItem).ToolStripItemDisplayStyle; 311 ((ToolBarItemBase)buttonItem).ToolStripItem = item; 312 } else if (buttonItem is IToolBarSeparatorItem) 313 item = new ToolStripSeparator(); 314 315 316 item.DisplayStyle = buttonItemBase.ToolStripItemDisplayStyle; 317 buttonItemBase.ToolStripItem = item; 318 } 319 320 this.SetToolStripItemProperties(item, buttonItem); 315 321 this.InsertItem(buttonItem.Structure, typeof(ToolStripDropDownButton), item, toolStrip.Items); 322 } 323 324 private void AddToolStripButtonItem(IToolBarSeparatorItem buttonItem) { 325 this.InsertItem(buttonItem.Structure, typeof(ToolStripDropDownButton), new ToolStripSeparator(), toolStrip.Items); 316 326 } 317 327 … … 330 340 } 331 341 332 private void SetToolStripItemProperties(ToolStripItem toolStripItem, I UserInterfaceItem userInterfaceItem) {342 private void SetToolStripItemProperties(ToolStripItem toolStripItem, IActionUserInterfaceItem userInterfaceItem) { 333 343 toolStripItem.Name = userInterfaceItem.Name; 334 344 toolStripItem.Text = userInterfaceItem.Name; … … 336 346 toolStripItem.Tag = userInterfaceItem; 337 347 toolStripItem.Image = userInterfaceItem.Image; 338 this.ActiveViewChanged += new EventHandler(userInterfaceItem.ActiveViewChanged);339 this.Changed += new EventHandler(userInterfaceItem.MainFormChanged);340 this.Initialized += new EventHandler(userInterfaceItem.MainFormInitialized);341 348 toolStripItem.Click += new EventHandler(ToolStripItemClicked); 342 349 this.userInterfaceItems.Add(userInterfaceItem); … … 345 352 private void ToolStripItemClicked(object sender, EventArgs e) { 346 353 System.Windows.Forms.ToolStripItem item = (System.Windows.Forms.ToolStripItem)sender; 347 ((I UserInterfaceItem)item.Tag).Execute();354 ((IActionUserInterfaceItem)item.Tag).Execute(); 348 355 } 349 356 #endregion -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MenuItem.cs
r2689 r2696 26 26 27 27 namespace HeuristicLab.MainForm.WindowsForms { 28 public abstract class MenuItem Base : HeuristicLab.MainForm.MenuItemBase{28 public abstract class MenuItem : HeuristicLab.MainForm.MenuItem{ 29 29 public virtual Keys ShortCutKeys { 30 30 get { return Keys.None; } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.cs
r2548 r2696 30 30 31 31 namespace HeuristicLab.MainForm.WindowsForms { 32 public partial class MultipleDocumentMainForm : MainForm Base{32 public partial class MultipleDocumentMainForm : MainForm { 33 33 public MultipleDocumentMainForm() 34 34 : base() { … … 41 41 } 42 42 43 protected override void CreateGUI() {44 base. CreateGUI();43 protected override void AdditionalCreationOfGUIElements() { 44 base.AdditionalCreationOfGUIElements(); 45 45 ToolStripMenuItem window = new ToolStripMenuItem("Windows"); 46 base.menuStrip.MdiWindowListItem = window;47 base.menuStrip.Items.Add(window);46 this.menuStrip.MdiWindowListItem = window; 47 this.menuStrip.Items.Add(window); 48 48 } 49 49 … … 53 53 base.Show(view, firstTimeShown); 54 54 if (firstTimeShown) 55 GetForm(view).Show(this);55 this.GetForm(view).Show(); 56 56 else { 57 GetForm(view).Visible = true;58 GetForm(view).Activate();57 this.GetForm(view).Visible = true; 58 this.GetForm(view).Activate(); 59 59 } 60 60 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/SingleDocumentMainForm.cs
r2548 r2696 31 31 32 32 namespace HeuristicLab.MainForm.WindowsForms { 33 public partial class SingleDocumentMainForm : MainForm Base{33 public partial class SingleDocumentMainForm : MainForm { 34 34 public SingleDocumentMainForm() 35 35 : base() { … … 47 47 base.Show(view, firstTimeShown); 48 48 if (firstTimeShown) 49 GetForm(view).Show(this);49 this.GetForm(view).Show(this); 50 50 else { 51 GetForm(view).Visible = true;52 GetForm(view).Activate();51 this.GetForm(view).Visible = true; 52 this.GetForm(view).Activate(); 53 53 } 54 54 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ToolBarItem.cs
r2689 r2696 19 19 */ 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; … … 26 27 27 28 namespace HeuristicLab.MainForm.WindowsForms { 28 public abstract class ToolBarItem Base : HeuristicLab.MainForm.ToolBarItemBase{29 public abstract class ToolBarItem : HeuristicLab.MainForm.ToolBarItem { 29 30 private ToolStripItem toolStripItem; 30 31 public virtual ToolStripItem ToolStripItem { -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.Designer.cs
r2689 r2696 21 21 22 22 namespace HeuristicLab.MainForm.WindowsForms { 23 partial class View Base{23 partial class View { 24 24 /// <summary> 25 25 /// Required designer variable. -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.cs
r2689 r2696 30 30 31 31 namespace HeuristicLab.MainForm.WindowsForms { 32 public partial class View Base: UserControl, IView {32 public partial class View : UserControl, IView { 33 33 private bool initialized; 34 public View Base() {34 public View() { 35 35 InitializeComponent(); 36 36 this.initialized = false; … … 54 54 } 55 55 56 public void Show() { 57 MainForm mainform = MainFormManager.GetMainForm<MainForm>(); 58 bool firstTimeShown = mainform.GetForm(this) == null; 59 60 MainFormManager.GetMainForm<MainForm>().ShowView(this,firstTimeShown); 61 if (firstTimeShown) { 62 Form form = mainform.GetForm(this); 63 form.FormClosed += new FormClosedEventHandler(OnClosedHelper); 64 form.FormClosing += new FormClosingEventHandler(OnClosingHelper); 65 } 66 this.OnShown(new ViewShownEventArgs(this,firstTimeShown)); 67 } 68 69 public void Close() { 70 MainForm mainform = MainFormManager.GetMainForm<MainForm>(); 71 Form form = mainform.GetForm(this); 72 if (form != null) 73 mainform.CloseView(this); 74 } 75 76 public void Close(CloseReason closeReason) { 77 MainForm mainform = MainFormManager.GetMainForm<MainForm>(); 78 Form form = mainform.GetForm(this); 79 if (form != null) 80 mainform.CloseView(this,closeReason); 81 } 82 83 public void Hide() { 84 MainFormManager.GetMainForm<MainForm>().HideView(this); 85 this.OnHidden(new EventArgs()); 86 } 87 56 88 public event EventHandler CaptionChanged; 57 89 protected virtual void OnCaptionChanged() { … … 68 100 } 69 101 70 public virtual void OnClosing(object sender, CancelEventArgs e) { 102 protected virtual void OnShown(ViewShownEventArgs e) { 103 } 104 105 protected virtual void OnHidden(EventArgs e) { 71 106 } 72 107 … … 74 109 internal void OnClosingHelper(object sender, FormClosingEventArgs e) { 75 110 if (this.closeReason != CloseReason.None) 76 this.OnClosing( sender,new FormClosingEventArgs(this.closeReason, e.Cancel));111 this.OnClosing(new FormClosingEventArgs(this.closeReason, e.Cancel)); 77 112 else 78 this.OnClosing( sender,e);113 this.OnClosing(e); 79 114 80 115 this.closeReason = CloseReason.None; 81 116 } 82 117 83 p ublic virtual void OnClosing(object sender,FormClosingEventArgs e) {118 protected virtual void OnClosing(FormClosingEventArgs e) { 84 119 } 85 120 86 public virtual void OnClosed(object sender, EventArgs e) { 121 internal void OnClosedHelper(object sender, FormClosedEventArgs e) { 122 if (this.closeReason != CloseReason.None) 123 this.OnClosed(new FormClosedEventArgs(this.closeReason)); 124 else 125 this.OnClosed(e); 126 127 Form form = (Form)sender; 128 form.FormClosed -= new FormClosedEventHandler(OnClosedHelper); 129 form.FormClosing -= new FormClosingEventHandler(OnClosingHelper); 130 this.closeReason = CloseReason.None; 87 131 } 88 132 89 public event EventHandler Initialized; 133 protected virtual void OnClosed(FormClosedEventArgs e) { 134 } 90 135 91 136 private void ViewBase_Load(object sender, EventArgs e) { 92 137 if (!this.initialized && !this.DesignMode) { 93 if (this.Initialized != null) 94 this.Initialized(this, new EventArgs()); 138 this.OnInitialized(e); 95 139 this.initialized = true; 96 140 } 97 141 } 142 143 protected virtual void OnInitialized(EventArgs e) { 144 } 98 145 } 99 146 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewContextMenuStrip.cs
r2545 r2696 34 34 Type viewType = e.ClickedItem.Tag as Type; 35 35 IView view = MainFormManager.CreateView(viewType, this.item); 36 MainFormManager.MainForm.ShowView(view);36 view.Show(); 37 37 } 38 38 } -
trunk/sources/HeuristicLab.MainForm/3.2/ActionUserInterfaceItem.cs
r2687 r2696 26 26 27 27 namespace HeuristicLab.MainForm { 28 public abstract class UserInterfaceItemBase : IUserInterfaceItem{ 29 protected UserInterfaceItemBase() { 28 public abstract class ActionUserInterfaceItem : PositionableUserInterfaceItem, IActionUserInterfaceItem { 29 protected ActionUserInterfaceItem() { 30 MainFormManager.MainForm.ActiveViewChanged += this.OnActiveViewChanged; 31 MainFormManager.MainForm.Changed += this.OnMainFormChanged; 32 MainFormManager.MainForm.ViewShown += this.OnViewShown; 33 MainFormManager.MainForm.ViewClosed += this.OnViewClosed; 30 34 } 31 35 32 36 public abstract string Name { get; } 33 public abstract int Position { get; }34 37 35 38 public virtual System.Drawing.Image Image { … … 43 46 public abstract void Execute(); 44 47 45 p ublic virtual voidActiveViewChanged(object sender, EventArgs e) {48 protected virtual void OnActiveViewChanged(object sender, EventArgs e) { 46 49 } 47 50 48 p ublic virtual void ViewChanged(object sender, EventArgs e) {51 protected virtual void OnMainFormChanged(object sender, EventArgs e) { 49 52 } 50 53 51 p ublic virtual void MainFormChanged(object sender, EventArgs e) {54 protected virtual void OnViewChanged(object sender, EventArgs e) { 52 55 } 53 56 54 public virtual void MainFormInitialized(object sender, EventArgs e) { 57 private void OnViewShown(object sender, ViewShownEventArgs e) { 58 if (e.FirstTimeShown) 59 e.View.Changed += this.OnViewChanged; 60 } 61 62 private void OnViewClosed(object sender, ViewEventArgs e) { 63 e.View.Changed -= this.OnViewChanged; 55 64 } 56 65 } -
trunk/sources/HeuristicLab.MainForm/3.2/ContentAttribute.cs
r2540 r2696 19 19 */ 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; … … 50 51 public static bool CanViewType(Type viewType, Type content) { 51 52 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 52 return attributes.Any(a => a.type.IsAssignableFrom(content));53 return attributes.Any(a => content.IsAssignableTo(a.type)); 53 54 } 54 55 55 public static IEnumerable<Type> GetViewableTypes(Type viewType) { 56 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 57 return from a in attributes 58 select a.type; 59 } 60 61 public static bool IsDefaultViewForType(Type viewType, Type content) { 62 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 63 return attributes.Any(a => a.isDefaultView && a.type == content); 64 } 65 66 public static IEnumerable<Type> GetDefaultViewableTypes(Type viewType) { 56 internal static IEnumerable<Type> GetDefaultViewableTypes(Type viewType) { 67 57 ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false); 68 58 return from a in attributes -
trunk/sources/HeuristicLab.MainForm/3.2/HeuristicLab.MainForm-3.2.csproj
r2548 r2696 81 81 </ItemGroup> 82 82 <ItemGroup> 83 <Compile Include="Interfaces\IActionUserInterfaceItem.cs" /> 84 <Compile Include="Interfaces\IPositionableUserInterfaceItem.cs" /> 85 <Compile Include="PositionableUserInterfaceItem.cs" /> 86 <Compile Include="TypeExtension.cs" /> 83 87 <Compile Include="ViewShownEventArgs.cs" /> 84 88 <Compile Include="ViewEventArgs.cs" /> 85 <Compile Include="ToolBarSeparatorItem Base.cs" />89 <Compile Include="ToolBarSeparatorItem.cs" /> 86 90 <Compile Include="Interfaces\IToolBarSeparatorItem.cs" /> 87 91 <Compile Include="Interfaces\IMenuItem.cs" /> … … 89 93 <Compile Include="Interfaces\IToolBarItem.cs" /> 90 94 <Compile Include="MainFormManager.cs" /> 91 <Compile Include="MenuItem Base.cs" />92 <Compile Include="MenuSeparatorItem Base.cs" />93 <Compile Include="ToolBarItem Base.cs" />95 <Compile Include="MenuItem.cs" /> 96 <Compile Include="MenuSeparatorItem.cs" /> 97 <Compile Include="ToolBarItem.cs" /> 94 98 <Compile Include="HeuristicLabMainFormPlugin.cs" /> 95 99 <Compile Include="Interfaces\IMainForm.cs" /> … … 97 101 <Compile Include="Interfaces\IView.cs" /> 98 102 <Compile Include="Properties\AssemblyInfo.cs" /> 99 <Compile Include=" UserInterfaceItemBase.cs" />103 <Compile Include="ActionUserInterfaceItem.cs" /> 100 104 <Compile Include="ContentAttribute.cs" /> 101 105 </ItemGroup> -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IMainForm.cs
r2548 r2696 25 25 using System.Text; 26 26 using System.Drawing; 27 using System.ComponentModel; 27 28 28 29 namespace HeuristicLab.MainForm { … … 35 36 event EventHandler ActiveViewChanged; 36 37 event EventHandler Changed; 37 38 38 39 event EventHandler<ViewEventArgs> ViewClosed; 39 40 event EventHandler<ViewShownEventArgs> ViewShown; … … 41 42 42 43 Type UserInterfaceItemType { get; } 43 void ShowView(IView view);44 void HideView(IView view);45 void CloseView(IView view);46 44 void CloseAllViews(); 47 45 void Close(); -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IMenuItem.cs
r2458 r2696 27 27 28 28 namespace HeuristicLab.MainForm { 29 public interface IMenuItem : IUserInterfaceItem { 30 IEnumerable<string> Structure { get; } 29 public interface IMenuItem : IActionUserInterfaceItem { 31 30 } 32 31 } -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IMenuSeparatorItem.cs
r2514 r2696 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 5 26 6 27 namespace HeuristicLab.MainForm { 7 public interface IMenuSeparatorItem : I MenuItem {28 public interface IMenuSeparatorItem : IPositionableUserInterfaceItem { 8 29 } 9 30 } -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IToolBarItem.cs
r2458 r2696 26 26 27 27 namespace HeuristicLab.MainForm { 28 public interface IToolBarItem : IUserInterfaceItem { 29 IEnumerable<string> Structure { get; } 28 public interface IToolBarItem : IActionUserInterfaceItem { 30 29 } 31 30 } -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IToolBarSeparatorItem.cs
r2514 r2696 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 5 26 6 27 namespace HeuristicLab.MainForm { 7 public interface IToolBarSeparatorItem : I ToolBarItem {28 public interface IToolBarSeparatorItem : IPositionableUserInterfaceItem { 8 29 } 9 30 } -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IUserInterfaceItem.cs
r2541 r2696 28 28 namespace HeuristicLab.MainForm { 29 29 public interface IUserInterfaceItem { 30 string Name { get; }31 int Position { get; }32 Image Image { get; }33 string ToolTipText { get; }34 35 void Execute();36 37 void ActiveViewChanged(object sender, EventArgs e);38 void ViewChanged(object sender, EventArgs e);39 void MainFormChanged(object sender, EventArgs e);40 void MainFormInitialized(object sender, EventArgs e);41 30 } 42 31 } -
trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IView.cs
r2466 r2696 27 27 namespace HeuristicLab.MainForm { 28 28 public interface IView { 29 29 30 string Caption { get; set; } 30 31 event EventHandler CaptionChanged; 31 32 event EventHandler Changed; 32 void OnClosing(object sender, CancelEventArgs e); 33 void OnClosed(object sender, EventArgs e); 33 34 void Show(); 35 void Hide(); 36 void Close(); 34 37 } 35 38 } -
trunk/sources/HeuristicLab.MainForm/3.2/MainFormManager.cs
r2591 r2696 19 19 */ 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; … … 24 25 using System.Text; 25 26 using HeuristicLab.PluginInfrastructure; 27 using System.Diagnostics; 26 28 27 29 namespace HeuristicLab.MainForm { 30 class StringDict<T> : Dictionary<string, T> { 31 } 28 32 public static class MainFormManager { 29 33 private static object locker; … … 36 40 views = new HashSet<Type>(); 37 41 defaultViews = new Dictionary<Type, Type>(); 42 43 Type listString = typeof(List<string>); 44 Type list = typeof(List<>); 45 Type ilist = typeof(IList<>); 46 Type stringStringDict = typeof(Dictionary<string, string>); 47 Type dict = typeof(Dictionary<,>); 48 Type stringDict = typeof(StringDict<>); 49 Type stringIntDict = typeof(StringDict<int>); 50 Type stringStringDict2 = typeof(StringDict<string>); 51 52 bool result; 53 result = listString.IsAssignableTo(list); 54 Debug.Assert(result); 55 56 Debug.Assert(stringStringDict2.IsAssignableTo(stringDict)); 57 Debug.Assert(stringStringDict2.IsAssignableTo(stringStringDict)); 58 Debug.Assert(stringStringDict2.IsAssignableTo(dict)); 59 Debug.Assert(!stringStringDict2.IsAssignableTo(stringIntDict)); 60 Debug.Assert(!stringIntDict.IsAssignableTo(stringStringDict)); 61 62 result = list.IsAssignableTo(ilist); 63 Debug.Assert(result); 64 result = listString.IsAssignableTo(ilist); 65 Debug.Assert(result); 66 result = list.IsAssignableTo(listString); 67 Debug.Assert(!result); 68 result = ilist.IsAssignableTo(listString); 69 Debug.Assert(!result); 70 result = ilist.IsAssignableTo(list); 71 Debug.Assert(!result); 72 73 Type stackedListList = list.MakeGenericType(typeof(List<>)); 74 Type stackedListListint = typeof(List<List<int>>); 75 Type istackedListListint = typeof(IList<List<int>>); 76 Type stackedListIListint = typeof(List<IList<int>>); 77 Debug.Assert(stackedListListint.IsAssignableTo(list)); 78 Debug.Assert(stackedListListint.IsAssignableTo(ilist)); 79 Debug.Assert(!stackedListListint.IsAssignableTo(listString)); 80 Debug.Assert(stackedListListint.IsAssignableTo(istackedListListint)); 81 Debug.Assert(!stackedListListint.IsAssignableTo(stackedListIListint)); 38 82 } 39 83 40 84 public static void RegisterMainForm(IMainForm mainform) { 41 85 lock (locker) { 42 if (MainFormManager.mainform == null) { 43 MainFormManager.mainform = mainform; 44 45 IEnumerable<Type> types = 46 from t in ApplicationManager.Manager.GetTypes(typeof(IView)) 47 where !t.IsAbstract && !t.IsInterface && !t.IsGenericType && ContentAttribute.HasContentAttribute(t) 48 select t; 49 50 foreach (Type viewType in types) { 51 views.Add(viewType); 52 foreach (Type contentType in ContentAttribute.GetDefaultViewableTypes(viewType)) { 53 if (defaultViews.ContainsKey(contentType)) 54 throw new ArgumentException("DefaultView for type " + contentType + " is " + defaultViews[contentType] + 55 ". Can't register additional DefaultView " + viewType + "."); 56 defaultViews[contentType] = viewType; 57 } 86 if (MainFormManager.mainform != null) 87 throw new ArgumentException("A mainform was already associated with the mainform manager."); 88 if (mainform == null) 89 throw new ArgumentException("Could not associate null as a mainform in the mainform manager."); 90 91 MainFormManager.mainform = mainform; 92 IEnumerable<Type> types = 93 from t in ApplicationManager.Manager.GetTypes(typeof(IView)) 94 where !t.IsAbstract && !t.IsInterface && ContentAttribute.HasContentAttribute(t) 95 select t; 96 97 foreach (Type viewType in types) { 98 views.Add(viewType); 99 foreach (Type contentType in ContentAttribute.GetDefaultViewableTypes(viewType)) { 100 if (defaultViews.ContainsKey(contentType)) 101 throw new ArgumentException("DefaultView for type " + contentType + " is " + defaultViews[contentType] + 102 ". Can't register additional DefaultView " + viewType + "."); 103 defaultViews[contentType] = viewType; 58 104 } 59 } else 60 throw new ArgumentException("A mainform was already associated with the mainform manager."); 105 } 61 106 } 62 107 } … … 87 132 //check base classes for default view 88 133 Type type = contentType; 89 while (type.BaseType != null && !defaultViews.ContainsKey(type)) { 134 while (type != null) { 135 foreach (Type defaultViewType in defaultViews.Keys) { 136 if (type == defaultViewType || type.CheckGenericTypes(defaultViewType)) 137 return defaultViews[defaultViewType]; 138 } 90 139 type = type.BaseType; 91 140 } 92 if (defaultViews.ContainsKey(type)) 93 return defaultViews[type]; 94 95 //check if exact one implemented interface has a default view 141 142 //check if exactly one implemented interface has a default view 96 143 List<Type> temp = (from t in defaultViews.Keys 97 where t.Is AssignableFrom(contentType) && t.IsInterface144 where t.IsInterface && contentType.IsAssignableTo(t) 98 145 select t).ToList(); 99 146 if (temp.Count == 1) … … 109 156 if (t == null) 110 157 return null; 111 else 112 return (IView)Activator.CreateInstance(t, objectToView); 158 159 Type viewType = TransformGenericTypeDefinition(t, objectToView); 160 if (viewType == null) 161 return null; 162 163 return (IView)Activator.CreateInstance(viewType, objectToView); 113 164 } 114 165 … … 116 167 if (!typeof(IView).IsAssignableFrom(viewType)) 117 168 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IView."); 169 if (viewType.IsGenericTypeDefinition) 170 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is a generic type definition."); 171 118 172 return (IView)Activator.CreateInstance(viewType); 119 173 } … … 122 176 if (!typeof(IView).IsAssignableFrom(viewType)) 123 177 throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IView."); 124 return (IView)Activator.CreateInstance(viewType, objectToView); 178 179 Type t = TransformGenericTypeDefinition(viewType, objectToView); 180 if (t == null) 181 return null; 182 183 return (IView)Activator.CreateInstance(t, objectToView); 184 } 185 186 private static Type TransformGenericTypeDefinition(Type type, object objectToView) { 187 if (!type.IsGenericTypeDefinition) 188 return type; 189 190 Type[] typeGenericArguments = type.GetGenericArguments(); 191 Type[] objectGenericArguments = objectToView.GetType().GetGenericArguments(); 192 193 for (int i = 0; i < typeGenericArguments.Length; i++) { 194 foreach (Type typeConstraint in typeGenericArguments[i].GetGenericParameterConstraints()) { 195 if (!typeConstraint.IsAssignableFrom(objectGenericArguments[i])) 196 return null; 197 } 198 } 199 200 Type t = type.MakeGenericType(objectToView.GetType().GetGenericArguments()); 201 return t; 125 202 } 126 203 } -
trunk/sources/HeuristicLab.MainForm/3.2/MenuItem.cs
r2689 r2696 26 26 27 27 namespace HeuristicLab.MainForm { 28 public abstract class MenuItemBase : UserInterfaceItemBase, IMenuItem{ 29 public virtual IEnumerable<string> Structure { 30 get { return Enumerable.Empty<string>(); } 31 } 28 public abstract class MenuItem : ActionUserInterfaceItem, IMenuItem{ 32 29 } 33 30 } -
trunk/sources/HeuristicLab.MainForm/3.2/MenuSeparatorItem.cs
r2689 r2696 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 5 26 6 27 namespace HeuristicLab.MainForm { 7 public abstract class MenuSeparatorItemBase : IMenuSeparatorItem { 8 public abstract IEnumerable<string> Structure { get; } 9 public abstract int Position { get; } 10 11 12 public string Name { 13 get { return string.Empty; } 14 } 15 16 public System.Drawing.Image Image { 17 get { return null; } 18 } 19 20 public string ToolTipText { 21 get { return string.Empty; } 22 } 23 24 public void Execute() { 25 throw new NotImplementedException(); 26 } 27 28 public void ActiveViewChanged(object sender, EventArgs e) { 29 throw new NotImplementedException(); 30 } 31 32 public void ViewChanged(object sender, EventArgs e) { 33 throw new NotImplementedException(); 34 } 35 36 public void MainFormChanged(object sender, EventArgs e) { 37 throw new NotImplementedException(); 38 } 39 40 public void MainFormInitialized(object sender, EventArgs e) { 41 throw new NotImplementedException(); 42 } 28 public abstract class MenuSeparatorItem : PositionableUserInterfaceItem, IMenuSeparatorItem { 43 29 } 44 30 } -
trunk/sources/HeuristicLab.MainForm/3.2/ToolBarItem.cs
r2689 r2696 26 26 27 27 namespace HeuristicLab.MainForm { 28 public abstract class ToolBarItemBase : UserInterfaceItemBase, IToolBarItem { 29 public virtual IEnumerable<string> Structure { 30 get { return Enumerable.Empty<string>(); } 31 } 28 public abstract class ToolBarItem : ActionUserInterfaceItem, IToolBarItem { 32 29 } 33 30 } -
trunk/sources/HeuristicLab.MainForm/3.2/ToolBarSeparatorItem.cs
r2689 r2696 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 5 26 6 27 namespace HeuristicLab.MainForm { 7 public abstract class ToolBarSeparatorItemBase : IToolBarSeparatorItem { 8 public abstract int Position { get; } 9 10 public IEnumerable<string> Structure { 11 get { return new List<string>(); } 12 } 13 14 public string Name { 15 get { return string.Empty; } 16 } 17 18 public System.Drawing.Image Image { 19 get { return null; } 20 } 21 22 public string ToolTipText { 23 get { return string.Empty; } 24 } 25 26 public void Execute() { 27 throw new NotImplementedException(); 28 } 29 30 public void ActiveViewChanged(object sender, EventArgs e) { 31 throw new NotImplementedException(); 32 } 33 34 public void ViewChanged(object sender, EventArgs e) { 35 throw new NotImplementedException(); 36 } 37 38 public void MainFormChanged(object sender, EventArgs e) { 39 throw new NotImplementedException(); 40 } 41 42 public void MainFormInitialized(object sender, EventArgs e) { 43 throw new NotImplementedException(); 44 } 28 public abstract class ToolBarSeparatorItem : PositionableUserInterfaceItem,IToolBarSeparatorItem { 45 29 } 46 30 }
Note: See TracChangeset
for help on using the changeset viewer.