Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2696 for trunk/sources


Ignore:
Timestamp:
01/28/10 16:15:21 (14 years ago)
Author:
mkommend
Message:

first version of redesigned MainForm (ticket #857)

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  
    1111      EditorView view = new EditorView();
    1212      view.Caption = "Editor View " + mainform.Views.Count();
    13       mainform.ShowView(view);
     13      view.Show();
    1414    }
    1515  }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/Actions/NewFormAction.cs

    r2458 r2696  
    1010      FormView1 x = new FormView1();
    1111      x.Caption = "FormView";
    12       mainform.ShowView(x);
     12      x.Show();
    1313    }
    1414  }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/NewEditorToolStripButtonItem.cs

    r2458 r2696  
    66
    77namespace HeuristicLab.MainForm.Test {
    8   public class NewEditorToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItemBase, ITestUserInterfaceItemProvider {
     8  public class NewEditorToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider {
    99    public override int Position {
    1010      get { return 12; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/NewFormToolStripButtonItem.cs

    r2458 r2696  
    66
    77namespace HeuristicLab.MainForm.Test {
    8   public class NewFormToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItemBase, ITestUserInterfaceItemProvider {
     8  public class NewFormToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider {
    99    public override int Position {
    1010      get { return 11; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/NewToolStripButtonItem.cs

    r2458 r2696  
    66
    77namespace HeuristicLab.MainForm.Test {
    8   public class NewToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItemBase, ITestUserInterfaceItemProvider {
     8  public class NewToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider {
    99    public override int Position {
    1010      get { return 10; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/OpenToolStripButtonItem.cs

    r2636 r2696  
    66
    77namespace 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    }
    914    public override int Position {
    1015      get { return 20; }
     
    2328    }
    2429
    25     public override void ActiveViewChanged(object sender, EventArgs e) {
     30    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    2631      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;
    2934    }
    3035  }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/SaveToolStripButtonItem.cs

    r2458 r2696  
    66
    77namespace HeuristicLab.MainForm.Test {
    8   public class SaveToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItemBase, ITestUserInterfaceItemProvider {
     8  public class SaveToolStripButtonItem : HeuristicLab.MainForm.WindowsForms.ToolBarItem, ITestUserInterfaceItemProvider {
    99    public override int Position {
    1010      get { return 30; }
     
    2323    }
    2424
    25     public override void ActiveViewChanged(object sender, EventArgs e) {
     25    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    2626      IMainForm mainform = MainFormManager.MainForm;
    2727      if (mainform.ActiveView == null)
     
    3131    }
    3232
    33     public override void ViewChanged(object sender, EventArgs e) {
     33    protected override void OnViewChanged(object sender, EventArgs e) {
    3434      this.ToolStripItem.Enabled = !this.ToolStripItem.Enabled;
    3535    }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/ButtonItems/SeparatorToolStripButtonItem.cs

    r2514 r2696  
    66
    77namespace HeuristicLab.MainForm.Test {
    8   public class SeparatorToolStripButtonItem : ToolBarSeparatorItemBase, ITestUserInterfaceItemProvider {
     8  public class SeparatorToolStripButtonItem : ToolBarSeparatorItem, ITestUserInterfaceItemProvider {
    99    public override int Position {
    1010      get { return 15; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/EditorView.Designer.cs

    r2254 r2696  
    5656      this.ForeColor = System.Drawing.SystemColors.ControlText;
    5757      this.Name = "EditorView";
     58      this.VisibleChanged += new System.EventHandler(this.EditorView_VisibleChanged);
    5859      this.ResumeLayout(false);
    5960      this.PerformLayout();
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/EditorView.cs

    r2466 r2696  
    66using System.Linq;
    77using System.Text;
    8 using System.Windows.Forms;
    98using HeuristicLab.MainForm.WindowsForms;
    109using System.Collections;
     10using System.Windows.Forms;
    1111
    1212namespace 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 {
    1515    public EditorView()
    1616      : base() {
     
    2525      IEnumerable<Type> views = MainFormManager.GetViewTypes(typeof(ArrayList));
    2626      views.ToString();
    27       IEnumerable<Type> views1 = MainFormManager.GetViewTypes(typeof(IList));
     27      IEnumerable<Type> views1 = MainFormManager.GetViewTypes(typeof(List<string>));
    2828      views1.ToString();
    29       IEnumerable<Type> views2 = MainFormManager.GetViewTypes(typeof(IEnumerable));
     29      IEnumerable<Type> views2 = MainFormManager.GetViewTypes(typeof(List<>));
    3030      views2.ToString();
     31      IEnumerable<Type> views3 = MainFormManager.GetViewTypes(typeof(ICollection<>));
     32      views3.ToString();
    3133
    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();
    3542      this.OnChanged();
    3643    }
    3744
    38     public override void OnClosing(object sender, CancelEventArgs e) {
     45    protected override void OnClosing(FormClosingEventArgs e) {
    3946      if (DialogResult.Yes != MessageBox.Show(
    4047             "Recent changes have not been saved. Close the editor anyway?", "Close editor?",
     
    4653      }
    4754    }
     55
     56    private void EditorView_VisibleChanged(object sender, EventArgs e) {
     57      MainFormManager.MainForm.Title = "visible: " + this.Visible;
     58    }
    4859  }
    4960}
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/FormView.cs

    r2466 r2696  
    1111
    1212namespace 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> {
    1515    public FormView1() {
    1616      InitializeComponent();
    1717    }
     18
     19    public FormView1(List<string> list)
     20      : this() {
     21    }
    1822  }
    1923}
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/FormView2.Designer.cs

    r2458 r2696  
    11namespace HeuristicLab.MainForm.Test {
    2   partial class FormView2 {
     2  partial class FormView2<T> {
    33    /// <summary>
    44    /// Required designer variable.
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/FormView2.cs

    r2466 r2696  
    11using System;
    2 using System.Collections;
     2using System.Collections.Generic;
    33using System.ComponentModel;
    44using System.Drawing;
     
    66using System.Linq;
    77using System.Text;
    8 using System.Windows.Forms;
    98using HeuristicLab.MainForm.WindowsForms;
    109
    1110namespace HeuristicLab.MainForm.Test {
    12   [Content(typeof(IEnumerable))]
    13   public partial class FormView2 : ViewBase {
     11  [Content(typeof(ICollection<>),true)]
     12  public partial class FormView2<T> : View where T: IMenuItem {
    1413    public FormView2() {
     14      InitializeComponent();
     15    }
     16    public FormView2(ICollection<T> x) {
    1517      InitializeComponent();
    1618    }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/ExitToolStripMenuItem.cs

    r2458 r2696  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class CloseToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItemBase, ITestUserInterfaceItemProvider {
     11  public class CloseToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    1313      get { return "Exit"; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/NewEditorToolStripMenuItem.cs

    r2458 r2696  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class NewEditorToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItemBase, ITestUserInterfaceItemProvider {
     11  public class NewEditorToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    1313      get { return "Editor"; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/NewFormToolStripMenuItem.cs

    r2458 r2696  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class NewFormToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItemBase, ITestUserInterfaceItemProvider {
     11  public class NewFormToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    1313      get { return "Form"; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/OpenToolStripMenuItem.cs

    r2458 r2696  
    88
    99namespace HeuristicLab.MainForm.Test {
    10   public class OpenToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItemBase, ITestUserInterfaceItemProvider {
     10  public class OpenToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider {
    1111    public override string Name {
    1212      get { return "Open"; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/SaveToolStripMenuItem.cs

    r2458 r2696  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class SaveToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItemBase, ITestUserInterfaceItemProvider {
     11  public class SaveToolStripMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    1313      get { return "Save"; }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/SeparatorMenuItem.cs

    r2514 r2696  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class SeparatorMenuItem : MenuSeparatorItemBase, ITestUserInterfaceItemProvider {
     11  public class SeparatorMenuItem : MenuSeparatorItem, ITestUserInterfaceItemProvider {
    1212    public override IEnumerable<string> Structure {
    1313      get { return new string[] { "File" }; }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/DockForm.cs

    r2458 r2696  
    3333  /// Displays the used view.
    3434  /// </summary>
    35   public partial class DockForm : DockContent {
     35  internal partial class DockForm : DockContent {
    3636    public DockForm(IView view) {
    3737      InitializeComponent();
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/DockingMainForm.cs

    r2636 r2696  
    3131
    3232namespace HeuristicLab.MainForm.WindowsForms {
    33   public partial class DockingMainForm : MainFormBase {
     33  public partial class DockingMainForm : MainForm {
    3434    public DockingMainForm()
    3535      : base() {
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/DocumentForm.cs

    r2458 r2696  
    2929
    3030namespace HeuristicLab.MainForm.WindowsForms {
    31   public partial class DocumentForm : Form {
     31  internal partial class DocumentForm : Form {
    3232    private IView myView;
    3333    public IView View {
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/HeuristicLab.MainForm.WindowsForms-3.2.csproj

    r2649 r2696  
    8282  </ItemGroup>
    8383  <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>
    8490    <Compile Include="DockForm.cs">
    8591      <SubType>Form</SubType>
     
    101107    </Compile>
    102108    <Compile Include="HeuristicLabMainFormWindowsFormsPlugin.cs" />
    103     <Compile Include="MainFormBase.cs">
    104       <SubType>Form</SubType>
    105     </Compile>
    106     <Compile Include="MainFormBase.Designer.cs">
    107       <DependentUpon>MainFormBase.cs</DependentUpon>
    108     </Compile>
    109     <Compile Include="MenuItemBase.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" />
    110116    <Compile Include="MultipleDocumentMainForm.cs">
    111117      <SubType>Form</SubType>
     
    121127      <DependentUpon>SingleDocumentMainForm.cs</DependentUpon>
    122128    </Compile>
    123     <Compile Include="ToolBarItemBase.cs" />
    124     <Compile Include="ViewBase.cs">
     129    <Compile Include="ToolBarItem.cs" />
     130    <Compile Include="View.cs">
    125131      <SubType>UserControl</SubType>
    126132    </Compile>
    127     <Compile Include="ViewBase.Designer.cs">
    128       <DependentUpon>ViewBase.cs</DependentUpon>
     133    <Compile Include="View.Designer.cs">
     134      <DependentUpon>View.cs</DependentUpon>
    129135    </Compile>
    130136    <Compile Include="ViewContextMenuStrip.cs">
     
    165171      <SubType>Designer</SubType>
    166172    </EmbeddedResource>
    167     <EmbeddedResource Include="MainFormBase.resx">
    168       <DependentUpon>MainFormBase.cs</DependentUpon>
     173    <EmbeddedResource Include="MainForm.resx">
     174      <DependentUpon>MainForm.cs</DependentUpon>
    169175    </EmbeddedResource>
    170176    <EmbeddedResource Include="MultipleDocumentMainForm.resx">
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MainForm.Designer.cs

    r2689 r2696  
    2020#endregion
    2121namespace HeuristicLab.MainForm.WindowsForms {
    22   partial class MainFormBase {
     22  partial class MainForm {
    2323    /// <summary>
    2424    /// Required designer variable.
     
    4444    /// </summary>
    4545    private void InitializeComponent() {
    46       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainFormBase));
     46      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
    4747      this.menuStrip = new System.Windows.Forms.MenuStrip();
    4848      this.toolStrip = new System.Windows.Forms.ToolStrip();
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MainForm.cs

    r2689 r2696  
    3030
    3131using HeuristicLab.PluginInfrastructure;
     32using System.Collections;
    3233
    3334namespace HeuristicLab.MainForm.WindowsForms {
    34   public partial class MainFormBase : Form, IMainForm {
    35 
     35  public partial class MainForm : Form, IMainForm {
    3636    private bool initialized;
    37     protected MainFormBase()
     37
     38    protected MainForm()
    3839      : base() {
    3940      InitializeComponent();
     
    4344    }
    4445
    45     protected MainFormBase(Type userInterfaceItemType)
     46    protected MainForm(Type userInterfaceItemType)
    4647      : this() {
    4748      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
    6552    public string Title {
    6653      get { return this.Text; }
     
    9380    public IEnumerable<IView> Views {
    9481      get { return views.Keys; }
    95     }
    96 
    97     public Form GetForm(IView view) {
    98       if (views.ContainsKey(view))
    99         return views[view];
    100       return null;
    10182    }
    10283
     
    121102      get { return this.userInterfaceItems; }
    122103    }
    123 
     104    #endregion
     105
     106    #region events
    124107    public event EventHandler ActiveViewChanged;
    125108    protected virtual void OnActiveViewChanged() {
     
    155138
    156139    public event EventHandler Changed;
    157     public void FireMainFormChanged() {
    158       OnMainFormChanged();
    159     }
    160     protected virtual void OnMainFormChanged() {
     140    protected void FireMainFormChanged() {
    161141      if (InvokeRequired)
    162         Invoke((MethodInvoker)OnMainFormChanged);
     142        Invoke((MethodInvoker)FireMainFormChanged);
    163143      else if (Changed != null)
    164144        Changed(this, new EventArgs());
    165145    }
    166146
     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
    167180    protected virtual Form CreateForm(IView view) {
    168181      throw new NotImplementedException("CreateForm must be implemented in subclasses of MainFormBase.");
    169182    }
    170183
    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);
    173196      else {
    174         if (!views.Keys.Contains(view)) {
     197        if (firstTimeShown) {
    175198          Form form = CreateForm(view);
    176           views[view] = form;
     199          this.views[view] = form;
    177200          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);
    181201          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);
    190205      }
    191206    }
     
    194209    }
    195210
    196     public void HideView(IView view) {
     211    internal void HideView(IView view) {
    197212      if (InvokeRequired) Invoke((Action<IView>)HideView, view);
    198213      else {
     
    207222    }
    208223
    209     public void CloseView(IView view) {
     224    internal void CloseView(IView view) {
    210225      if (InvokeRequired) Invoke((Action<IView>)CloseView, view);
    211226      else {
     
    217232    }
    218233
    219     public void CloseView(IView view, CloseReason closeReason) {
     234    internal void CloseView(IView view, CloseReason closeReason) {
    220235      if (InvokeRequired) Invoke((Action<IView>)CloseView, view);
    221236      else {
    222237        if (this.views.ContainsKey(view)) {
    223           ((ViewBase)view).closeReason = closeReason;
     238          ((View)view).closeReason = closeReason;
    224239          this.CloseView(view);
    225240        }
     
    227242    }
    228243
    229     public virtual void CloseAllViews() {
     244    public void CloseAllViews() {
    230245      foreach (IView view in views.Keys.ToArray())
    231246        CloseView(view);
    232247    }
    233248
    234     public virtual void CloseAllViews(CloseReason closeReason) {
     249    public void CloseAllViews(CloseReason closeReason) {
    235250      foreach (IView view in views.Keys.ToArray())
    236251        CloseView(view, closeReason);
     
    238253    #endregion
    239254
    240     #region events
    241     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     #endregion
    267 
    268255    #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() {
    285291    }
    286292
    287293    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);
    298307    }
    299308
    300309    private void AddToolStripButtonItem(IToolBarItem buttonItem) {
    301       ToolStripItem item = null;
    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)
    305314          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);
    315321      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);
    316326    }
    317327
     
    330340    }
    331341
    332     private void SetToolStripItemProperties(ToolStripItem toolStripItem, IUserInterfaceItem userInterfaceItem) {
     342    private void SetToolStripItemProperties(ToolStripItem toolStripItem, IActionUserInterfaceItem userInterfaceItem) {
    333343      toolStripItem.Name = userInterfaceItem.Name;
    334344      toolStripItem.Text = userInterfaceItem.Name;
     
    336346      toolStripItem.Tag = userInterfaceItem;
    337347      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);
    341348      toolStripItem.Click += new EventHandler(ToolStripItemClicked);
    342349      this.userInterfaceItems.Add(userInterfaceItem);
     
    345352    private void ToolStripItemClicked(object sender, EventArgs e) {
    346353      System.Windows.Forms.ToolStripItem item = (System.Windows.Forms.ToolStripItem)sender;
    347       ((IUserInterfaceItem)item.Tag).Execute();
     354      ((IActionUserInterfaceItem)item.Tag).Execute();
    348355    }
    349356    #endregion
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MenuItem.cs

    r2689 r2696  
    2626
    2727namespace HeuristicLab.MainForm.WindowsForms {
    28   public abstract class MenuItemBase : HeuristicLab.MainForm.MenuItemBase{
     28  public abstract class MenuItem : HeuristicLab.MainForm.MenuItem{
    2929    public virtual Keys ShortCutKeys {
    3030      get { return Keys.None; }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.cs

    r2548 r2696  
    3030
    3131namespace HeuristicLab.MainForm.WindowsForms {
    32   public partial class MultipleDocumentMainForm : MainFormBase {
     32  public partial class MultipleDocumentMainForm : MainForm {
    3333    public MultipleDocumentMainForm()
    3434      : base() {
     
    4141    }
    4242
    43     protected override void CreateGUI() {
    44       base.CreateGUI();
     43    protected override void AdditionalCreationOfGUIElements() {
     44      base.AdditionalCreationOfGUIElements();
    4545      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);
    4848    }
    4949
     
    5353        base.Show(view, firstTimeShown);
    5454        if (firstTimeShown)
    55           GetForm(view).Show(this);
     55          this.GetForm(view).Show();
    5656        else {
    57           GetForm(view).Visible = true;
    58           GetForm(view).Activate();
     57          this.GetForm(view).Visible = true;
     58          this.GetForm(view).Activate();
    5959        }
    6060      }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/SingleDocumentMainForm.cs

    r2548 r2696  
    3131
    3232namespace HeuristicLab.MainForm.WindowsForms {
    33   public partial class SingleDocumentMainForm : MainFormBase {
     33  public partial class SingleDocumentMainForm : MainForm {
    3434    public SingleDocumentMainForm()
    3535      : base() {
     
    4747        base.Show(view, firstTimeShown);
    4848        if (firstTimeShown)
    49           GetForm(view).Show(this);
     49          this.GetForm(view).Show(this);
    5050        else {
    51           GetForm(view).Visible = true;
    52           GetForm(view).Activate();
     51          this.GetForm(view).Visible = true;
     52          this.GetForm(view).Activate();
    5353        }
    5454      }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ToolBarItem.cs

    r2689 r2696  
    1919 */
    2020#endregion
     21
    2122using System;
    2223using System.Collections.Generic;
     
    2627
    2728namespace HeuristicLab.MainForm.WindowsForms {
    28   public abstract class ToolBarItemBase : HeuristicLab.MainForm.ToolBarItemBase {
     29  public abstract class ToolBarItem : HeuristicLab.MainForm.ToolBarItem {
    2930    private ToolStripItem toolStripItem;
    3031    public virtual ToolStripItem ToolStripItem {
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.Designer.cs

    r2689 r2696  
    2121
    2222namespace HeuristicLab.MainForm.WindowsForms {
    23   partial class ViewBase {
     23  partial class View {
    2424    /// <summary>
    2525    /// Required designer variable.
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.cs

    r2689 r2696  
    3030
    3131namespace HeuristicLab.MainForm.WindowsForms {
    32   public partial class ViewBase : UserControl, IView {
     32  public partial class View : UserControl, IView {
    3333    private bool initialized;
    34     public ViewBase() {
     34    public View() {
    3535      InitializeComponent();
    3636      this.initialized = false;
     
    5454    }
    5555
     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
    5688    public event EventHandler CaptionChanged;
    5789    protected virtual void OnCaptionChanged() {
     
    68100    }
    69101
    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) {
    71106    }
    72107
     
    74109    internal void OnClosingHelper(object sender, FormClosingEventArgs e) {
    75110      if (this.closeReason != CloseReason.None)
    76         this.OnClosing(sender, new FormClosingEventArgs(this.closeReason, e.Cancel));
     111        this.OnClosing(new FormClosingEventArgs(this.closeReason, e.Cancel));
    77112      else
    78         this.OnClosing(sender, e);
     113        this.OnClosing(e);
    79114
    80115      this.closeReason = CloseReason.None;
    81116    }
    82117
    83     public virtual void OnClosing(object sender, FormClosingEventArgs e) {
     118    protected virtual void OnClosing(FormClosingEventArgs e) {
    84119    }
    85120
    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;
    87131    }
    88132
    89     public event EventHandler Initialized;
     133    protected virtual void OnClosed(FormClosedEventArgs e) {
     134    }
    90135
    91136    private void ViewBase_Load(object sender, EventArgs e) {
    92137      if (!this.initialized && !this.DesignMode) {
    93         if (this.Initialized != null)
    94           this.Initialized(this, new EventArgs());
     138        this.OnInitialized(e);
    95139        this.initialized = true;
    96140      }
    97141    }
     142
     143    protected virtual void OnInitialized(EventArgs e) {
     144    }
    98145  }
    99146}
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewContextMenuStrip.cs

    r2545 r2696  
    3434        Type viewType = e.ClickedItem.Tag as Type;
    3535        IView view = MainFormManager.CreateView(viewType, this.item);
    36         MainFormManager.MainForm.ShowView(view);
     36        view.Show();
    3737      }
    3838    }
  • trunk/sources/HeuristicLab.MainForm/3.2/ActionUserInterfaceItem.cs

    r2687 r2696  
    2626
    2727namespace 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;
    3034    }
    3135
    3236    public abstract string Name { get; }
    33     public abstract int Position { get; }
    3437
    3538    public virtual System.Drawing.Image Image {
     
    4346    public abstract void Execute();
    4447
    45     public virtual void ActiveViewChanged(object sender, EventArgs e) {
     48    protected virtual void OnActiveViewChanged(object sender, EventArgs e) {
    4649    }
    4750
    48     public virtual void ViewChanged(object sender, EventArgs e) {
     51    protected virtual void OnMainFormChanged(object sender, EventArgs e) {
    4952    }
    5053
    51     public virtual void MainFormChanged(object sender, EventArgs e) {
     54    protected virtual void OnViewChanged(object sender, EventArgs e) {
    5255    }
    5356
    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;
    5564    }
    5665  }
  • trunk/sources/HeuristicLab.MainForm/3.2/ContentAttribute.cs

    r2540 r2696  
    1919 */
    2020#endregion
     21
    2122using System;
    2223using System.Collections.Generic;
     
    5051    public static bool CanViewType(Type viewType, Type content) {
    5152      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));
    5354    }
    5455
    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) {
    6757      ContentAttribute[] attributes = (ContentAttribute[])viewType.GetCustomAttributes(typeof(ContentAttribute), false);
    6858      return from a in attributes
  • trunk/sources/HeuristicLab.MainForm/3.2/HeuristicLab.MainForm-3.2.csproj

    r2548 r2696  
    8181  </ItemGroup>
    8282  <ItemGroup>
     83    <Compile Include="Interfaces\IActionUserInterfaceItem.cs" />
     84    <Compile Include="Interfaces\IPositionableUserInterfaceItem.cs" />
     85    <Compile Include="PositionableUserInterfaceItem.cs" />
     86    <Compile Include="TypeExtension.cs" />
    8387    <Compile Include="ViewShownEventArgs.cs" />
    8488    <Compile Include="ViewEventArgs.cs" />
    85     <Compile Include="ToolBarSeparatorItemBase.cs" />
     89    <Compile Include="ToolBarSeparatorItem.cs" />
    8690    <Compile Include="Interfaces\IToolBarSeparatorItem.cs" />
    8791    <Compile Include="Interfaces\IMenuItem.cs" />
     
    8993    <Compile Include="Interfaces\IToolBarItem.cs" />
    9094    <Compile Include="MainFormManager.cs" />
    91     <Compile Include="MenuItemBase.cs" />
    92     <Compile Include="MenuSeparatorItemBase.cs" />
    93     <Compile Include="ToolBarItemBase.cs" />
     95    <Compile Include="MenuItem.cs" />
     96    <Compile Include="MenuSeparatorItem.cs" />
     97    <Compile Include="ToolBarItem.cs" />
    9498    <Compile Include="HeuristicLabMainFormPlugin.cs" />
    9599    <Compile Include="Interfaces\IMainForm.cs" />
     
    97101    <Compile Include="Interfaces\IView.cs" />
    98102    <Compile Include="Properties\AssemblyInfo.cs" />
    99     <Compile Include="UserInterfaceItemBase.cs" />
     103    <Compile Include="ActionUserInterfaceItem.cs" />
    100104    <Compile Include="ContentAttribute.cs" />
    101105  </ItemGroup>
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IMainForm.cs

    r2548 r2696  
    2525using System.Text;
    2626using System.Drawing;
     27using System.ComponentModel;
    2728
    2829namespace HeuristicLab.MainForm {
     
    3536    event EventHandler ActiveViewChanged;
    3637    event EventHandler Changed;
    37    
     38
    3839    event EventHandler<ViewEventArgs> ViewClosed;
    3940    event EventHandler<ViewShownEventArgs> ViewShown;
     
    4142
    4243    Type UserInterfaceItemType { get; }
    43     void ShowView(IView view);
    44     void HideView(IView view);
    45     void CloseView(IView view);
    4644    void CloseAllViews();
    4745    void Close();
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IMenuItem.cs

    r2458 r2696  
    2727
    2828namespace HeuristicLab.MainForm {
    29   public interface IMenuItem : IUserInterfaceItem {
    30     IEnumerable<string> Structure { get; }
     29  public interface IMenuItem : IActionUserInterfaceItem {
    3130  }
    3231}
  • 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
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    526
    627namespace HeuristicLab.MainForm {
    7   public interface IMenuSeparatorItem : IMenuItem {
     28  public interface IMenuSeparatorItem : IPositionableUserInterfaceItem {
    829  }
    930}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IToolBarItem.cs

    r2458 r2696  
    2626
    2727namespace HeuristicLab.MainForm {
    28   public interface IToolBarItem : IUserInterfaceItem {
    29     IEnumerable<string> Structure { get; }
     28  public interface IToolBarItem : IActionUserInterfaceItem {
    3029  }
    3130}
  • 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
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    526
    627namespace HeuristicLab.MainForm {
    7   public interface IToolBarSeparatorItem : IToolBarItem {
     28  public interface IToolBarSeparatorItem : IPositionableUserInterfaceItem {
    829  }
    930}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IUserInterfaceItem.cs

    r2541 r2696  
    2828namespace HeuristicLab.MainForm {
    2929  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);
    4130  }
    4231}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IView.cs

    r2466 r2696  
    2727namespace HeuristicLab.MainForm {
    2828  public interface IView {
     29
    2930    string Caption { get; set; }
    3031    event EventHandler CaptionChanged;
    3132    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();
    3437  }
    3538}
  • trunk/sources/HeuristicLab.MainForm/3.2/MainFormManager.cs

    r2591 r2696  
    1919 */
    2020#endregion
     21
    2122using System;
    2223using System.Collections.Generic;
     
    2425using System.Text;
    2526using HeuristicLab.PluginInfrastructure;
     27using System.Diagnostics;
    2628
    2729namespace HeuristicLab.MainForm {
     30  class StringDict<T> : Dictionary<string, T> {
     31  }
    2832  public static class MainFormManager {
    2933    private static object locker;
     
    3640      views = new HashSet<Type>();
    3741      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));
    3882    }
    3983
    4084    public static void RegisterMainForm(IMainForm mainform) {
    4185      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;
    58104          }
    59         } else
    60           throw new ArgumentException("A mainform was already associated with the mainform manager.");
     105        }
    61106      }
    62107    }
     
    87132      //check base classes for default view
    88133      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        }
    90139        type = type.BaseType;
    91140      }
    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
    96143      List<Type> temp = (from t in defaultViews.Keys
    97                          where t.IsAssignableFrom(contentType) && t.IsInterface
     144                         where t.IsInterface && contentType.IsAssignableTo(t)
    98145                         select t).ToList();
    99146      if (temp.Count == 1)
     
    109156      if (t == null)
    110157        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);
    113164    }
    114165
     
    116167      if (!typeof(IView).IsAssignableFrom(viewType))
    117168        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
    118172      return (IView)Activator.CreateInstance(viewType);
    119173    }
     
    122176      if (!typeof(IView).IsAssignableFrom(viewType))
    123177        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;
    125202    }
    126203  }
  • trunk/sources/HeuristicLab.MainForm/3.2/MenuItem.cs

    r2689 r2696  
    2626
    2727namespace 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{
    3229  }
    3330}
  • 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
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    526
    627namespace 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 {
    4329  }
    4430}
  • trunk/sources/HeuristicLab.MainForm/3.2/ToolBarItem.cs

    r2689 r2696  
    2626
    2727namespace 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 {
    3229  }
    3330}
  • 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
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    526
    627namespace 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 {
    4529  }
    4630}
Note: See TracChangeset for help on using the changeset viewer.