Free cookie consent management tool by TermsFeed Policy Generator

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

first version of redesigned MainForm (ticket #857)

Location:
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2
Files:
2 added
7 edited
7 copied

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.