Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/13/09 10:58:31 (15 years ago)
Author:
mkommend
Message:

initial version of refactored mainform (ticket #771)

Location:
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms
Files:
8 added
21 copied

Legend:

Unmodified
Added
Removed
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/DockForm.Designer.cs

    r2420 r2426  
    2020#endregion
    2121
    22 namespace HeuristicLab.MainForm {
     22namespace HeuristicLab.MainForm.WindowsForms {
    2323  partial class DockForm {
    2424    /// <summary>
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/DockForm.cs

    r2420 r2426  
    2929using WeifenLuo.WinFormsUI.Docking;
    3030
    31 namespace HeuristicLab.MainForm {
     31namespace HeuristicLab.MainForm.WindowsForms {
    3232  /// <summary>
    3333  /// Displays the used view.
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/DockingMainForm.Designer.cs

    r2420 r2426  
    1 namespace HeuristicLab.MainForm {
     1namespace HeuristicLab.MainForm.WindowsForms {
    22  partial class DockingMainForm {
    33    /// <summary>
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/DockingMainForm.cs

    r2420 r2426  
    3030using WeifenLuo.WinFormsUI.Docking;
    3131
    32 namespace HeuristicLab.MainForm {
     32namespace HeuristicLab.MainForm.WindowsForms {
    3333  public partial class DockingMainForm : MainFormBase {
    3434    public DockingMainForm()
     
    5353          DockContent dockForm = new DockForm(view);
    5454          dockForm.Activated += new EventHandler(DockFormActivated);
    55           dockForm.FormClosing += new FormClosingEventHandler(view.FormClosing);
     55          dockForm.FormClosing += new FormClosingEventHandler(view.OnClosing);
     56          dockForm.FormClosed += new FormClosedEventHandler(view.OnClosed);
    5657          dockForm.FormClosed += new FormClosedEventHandler(DockFormClosed);
    57           foreach (IToolStripItem item in ToolStripItems)
    58             view.StateChanged += new EventHandler(item.ViewChanged);
     58          foreach (IUserInterfaceItem item in UserInterfaceItems)
     59            view.Changed += new EventHandler(item.ViewChanged);
    5960          dockForm.Show(dockPanel);
    6061        }
     
    7576      ViewClosed(dockForm.View);
    7677      dockForm.Activated -= new EventHandler(DockFormActivated);
    77       dockForm.FormClosing -= new FormClosingEventHandler(dockForm.View.FormClosing);
     78      dockForm.FormClosing -= new FormClosingEventHandler(dockForm.View.OnClosing);
     79      dockForm.FormClosed -= new FormClosedEventHandler(dockForm.View.OnClosed);
    7880      dockForm.FormClosed -= new FormClosedEventHandler(DockFormClosed);
    79       foreach (IToolStripItem item in ToolStripItems)
    80         dockForm.View.StateChanged -= new EventHandler(item.ViewChanged);
     81      foreach (IUserInterfaceItem item in UserInterfaceItems)
     82        dockForm.View.Changed -= new EventHandler(item.ViewChanged);
    8183    }
    8284
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/DocumentForm.Designer.cs

    r2420 r2426  
    2020#endregion
    2121
    22 namespace HeuristicLab.MainForm {
     22namespace HeuristicLab.MainForm.WindowsForms {
    2323  partial class DocumentForm {
    2424    /// <summary>
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/DocumentForm.cs

    r2420 r2426  
    2828using System.Windows.Forms;
    2929
    30 namespace HeuristicLab.MainForm {
     30namespace HeuristicLab.MainForm.WindowsForms {
    3131  public partial class DocumentForm : Form {
    3232    private IView myView;
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/HeuristicLabMainFormWindowsFormsPlugin.cs

    r2420 r2426  
    2525using HeuristicLab.PluginInfrastructure;
    2626
    27 namespace HeuristicLab.Modeling.Database {
    28   [ClassInfo(Name = "HeuristicLab.MainForm.Test-3.2")]
    29   [PluginFile(Filename = "HeuristicLab.MainForm.Test-3.2.dll", Filetype = PluginFileType.Assembly)] 
     27namespace HeuristicLab.MainForm.WindowsForms {
     28  [ClassInfo(Name = "HeuristicLab.MainForm.WindowsForms-3.2")]
     29  [PluginFile(Filename = "HeuristicLab.MainForm.WindowsForms-3.2.dll", Filetype = PluginFileType.Assembly)] 
    3030  [Dependency(Dependency = "HeuristicLab.MainForm-3.2")]
    31   [Dependency(Dependency = "HeuristicLab.Common.Resources-3.2")]
    3231  public class HeuristicLabMainFormTestPlugin : PluginBase {
    3332  }
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MainFormBase.Designer.cs

    r2420 r2426  
    1 namespace HeuristicLab.MainForm {
     1namespace HeuristicLab.MainForm.WindowsForms {
    22  partial class MainFormBase {
    33    /// <summary>
     
    2828      this.toolStrip = new System.Windows.Forms.ToolStrip();
    2929      this.statusStrip = new System.Windows.Forms.StatusStrip();
    30       this.toolStripProgressBar = new System.Windows.Forms.ToolStripProgressBar();
    31       this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
    3230      this.statusStrip.SuspendLayout();
    3331      this.SuspendLayout();
     
    5048      // statusStrip
    5149      //
    52       this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    53             this.toolStripProgressBar,
    54             this.toolStripStatusLabel});
    5550      this.statusStrip.Location = new System.Drawing.Point(0, 390);
    5651      this.statusStrip.Name = "statusStrip";
     
    5853      this.statusStrip.TabIndex = 2;
    5954      this.statusStrip.Text = "statusStrip";
    60       //
    61       // toolStripProgressBar
    62       //
    63       this.toolStripProgressBar.Name = "toolStripProgressBar";
    64       this.toolStripProgressBar.Size = new System.Drawing.Size(100, 16);
    65       this.toolStripProgressBar.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
    66       this.toolStripProgressBar.Visible = false;
    67       //
    68       // toolStripStatusLabel
    69       //
    70       this.toolStripStatusLabel.Name = "toolStripStatusLabel";
    71       this.toolStripStatusLabel.Size = new System.Drawing.Size(112, 17);
    72       this.toolStripStatusLabel.Text = "toolStripStatusLabel";
    7355      //
    7456      // MainFormBase
     
    9274    #endregion
    9375
    94     private System.Windows.Forms.ToolStrip toolStrip;
    95     private System.Windows.Forms.StatusStrip statusStrip;
     76    protected System.Windows.Forms.ToolStrip toolStrip;
     77    protected System.Windows.Forms.StatusStrip statusStrip;
    9678    protected System.Windows.Forms.MenuStrip menuStrip;
    97     private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar;
    98     private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel;
    9979  }
    10080}
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MainFormBase.cs

    r2420 r2426  
    3131using HeuristicLab.PluginInfrastructure;
    3232
    33 namespace HeuristicLab.MainForm {
     33namespace HeuristicLab.MainForm.WindowsForms {
    3434  public partial class MainFormBase : Form, IMainForm {
    3535    protected MainFormBase()
    3636      : base() {
    3737      InitializeComponent();
    38       views = new List<IView>();
    39       toolStripItems = new List<IToolStripItem>();
    40       this.StatusStripText = "";
     38      this.views = new List<IView>();
     39      this.userInterfaceItems = new List<IUserInterfaceItem>();
     40      MainFormManager.RegisterMainForm(this);
    4141    }
    4242
     
    5858        } else
    5959          this.Text = value;
    60       }
    61     }
    62 
    63     public string StatusStripText {
    64       get { return this.toolStripStatusLabel.Text; }
    65       set {
    66         if (InvokeRequired) {
    67           Action<string> action = delegate(string s) { this.StatusStripText = s; };
    68           Invoke(action, value);
    69         } else
    70           this.toolStripStatusLabel.Text = value;
    71       }
    72     }
    73 
    74     public bool StatusStripProgressBarVisible {
    75       get { return this.toolStripProgressBar.Visible; }
    76       set {
    77         if (InvokeRequired) {
    78           Action<bool> action = delegate(bool b) { this.StatusStripProgressBarVisible = b; };
    79           Invoke(action, value);
    80         } else
    81           this.toolStripProgressBar.Visible = value;
    8260      }
    8361    }
     
    12199    }
    122100
    123     private List<IToolStripItem> toolStripItems;
    124     protected IEnumerable<IToolStripItem> ToolStripItems {
    125       get { return this.toolStripItems; }
     101    private List<IUserInterfaceItem> userInterfaceItems;
     102    protected IEnumerable<IUserInterfaceItem> UserInterfaceItems {
     103      get { return this.userInterfaceItems; }
    126104    }
    127105
     
    134112    }
    135113
    136     public event EventHandler MainFormChanged;
     114    public event EventHandler Changed;
    137115    public void FireMainFormChanged() {
    138116      OnMainFormChanged();
     
    141119      if (InvokeRequired)
    142120        Invoke((MethodInvoker)FireMainFormChanged);
    143       else if (MainFormChanged != null)
    144         MainFormChanged(this, new EventArgs());
     121      else if (Changed != null)
     122        Changed(this, new EventArgs());
    145123    }
    146124
    147125    public virtual void ShowView(IView view) {
    148126      if (!views.Contains(view)) {
    149         view.MainForm = this;
    150127        views.Add(view);
    151         ActiveView = view;
    152       }
     128      }
     129      this.ActiveView = view;
    153130    }
    154131
     
    173150
    174151      object[] items = ds.GetInstances(userInterfaceItemType);
    175       IEnumerable<IToolStripMenuItem> toolStripMenuItems =
     152      IEnumerable<MenuItemBase> toolStripMenuItems =
    176153        from mi in items
    177         where mi is IToolStripMenuItem
    178         orderby ((IToolStripMenuItem)mi).Position
    179         select (IToolStripMenuItem)mi;
    180       foreach (IToolStripMenuItem menuItem in toolStripMenuItems)
     154        where mi is MenuItemBase
     155        orderby ((MenuItemBase)mi).Position
     156        select (MenuItemBase)mi;
     157      foreach (MenuItemBase menuItem in toolStripMenuItems)
    181158        AddToolStripMenuItem(menuItem);
    182159
    183160      items = ds.GetInstances(userInterfaceItemType);
    184       IEnumerable<IToolStripButtonItem> toolStripButtonItems =
     161      IEnumerable<ToolBarItemBase> toolStripButtonItems =
    185162        from bi in items
    186         where bi is IToolStripButtonItem
    187         orderby ((IToolStripButtonItem)bi).Position
    188         select (IToolStripButtonItem)bi;
    189       foreach (IToolStripButtonItem toolStripButtonItem in toolStripButtonItems)
     163        where bi is ToolBarItemBase
     164        orderby ((ToolBarItemBase)bi).Position
     165        select (ToolBarItemBase)bi;
     166      foreach (ToolBarItemBase toolStripButtonItem in toolStripButtonItems)
    190167        AddToolStripButtonItem(toolStripButtonItem);
    191168    }
    192169
    193     private void AddToolStripMenuItem(IToolStripMenuItem menuItem) {
     170    private void AddToolStripMenuItem(MenuItemBase menuItem) {
    194171      ToolStripMenuItem item = new ToolStripMenuItem();
    195172      SetToolStripItemProperties(item, menuItem);
     173      menuItem.ToolStripItem = item;
    196174      item.ShortcutKeys = menuItem.ShortCutKeys;
    197 
    198       ToolStripDropDownItem parent = FindParent(menuItem, menuStrip.Items);
    199       if (parent == null)
    200         menuStrip.Items.Add(item);
    201       else
    202         parent.DropDownItems.Add(item);
    203     }
    204 
    205     private void AddToolStripButtonItem(IToolStripButtonItem buttonItem) {
     175      item.DisplayStyle = menuItem.ToolStripItemDisplayStyle;
     176      this.InsertItem(menuItem.Structure, typeof(ToolStripMenuItem), item, menuStrip.Items);
     177    }
     178
     179    private void AddToolStripButtonItem(ToolBarItemBase buttonItem) {
    206180      ToolStripItem item;
    207181      if (buttonItem.IsDropDownButton)
     
    211185
    212186      SetToolStripItemProperties(item, buttonItem);
    213       ToolStripDropDownItem parent = FindParent(buttonItem, toolStrip.Items);
    214       if (parent == null)
    215         toolStrip.Items.Add(item);
    216       else
    217         parent.DropDownItems.Add(item);
    218     }
    219 
    220     private ToolStripDropDownItem FindParent(IToolStripItem item, ToolStripItemCollection parentItems) {
    221       if (String.IsNullOrEmpty(item.Structure))
    222         return null;
    223 
     187      item.DisplayStyle = buttonItem.ToolStripItemDisplayStyle;
     188      buttonItem.ToolStripItem = item;
     189      this.InsertItem(buttonItem.Structure, typeof(ToolStripDropDownButton), item, toolStrip.Items);
     190    }
     191
     192    private void InsertItem(IEnumerable<string> structure, Type t,ToolStripItem item, ToolStripItemCollection parentItems) {
    224193      ToolStripDropDownItem parent = null;
    225       foreach (string structure in item.Structure.Split(item.StructureSeparator)) {
    226         if (parentItems.ContainsKey(structure))
    227           parent = (ToolStripDropDownItem)parentItems[structure];
    228         else
    229           throw new ArgumentException("Structure string for item " + item.Name +
    230             " is invalid. Could not find " + structure + " in toolstrip!");
     194      foreach (string s in structure) {
     195        if (parentItems.ContainsKey(s))
     196          parent = (ToolStripDropDownItem)parentItems[s];
     197        else {
     198          parent = (ToolStripDropDownItem)Activator.CreateInstance(t, s,null,null,s); ;
     199          parentItems.Add(parent);
     200        }
    231201        parentItems = parent.DropDownItems;
    232202      }
    233       return parent;
    234     }
    235 
    236     private void SetToolStripItemProperties(ToolStripItem toolStripItem, IToolStripItem iToolStripItem) {
    237       toolStripItem.Text = iToolStripItem.Name;
    238       toolStripItem.Name = iToolStripItem.Name;
    239       toolStripItem.Tag = iToolStripItem;
    240       toolStripItem.Image = iToolStripItem.Image;
    241       toolStripItem.DisplayStyle = iToolStripItem.DisplayStyle;
    242       this.ActiveViewChanged += new EventHandler(iToolStripItem.ActiveViewChanged);
    243       this.MainFormChanged += new EventHandler(iToolStripItem.MainFormChanged);
     203      parentItems.Add(item);
     204    }
     205
     206    private void SetToolStripItemProperties(ToolStripItem toolStripItem, IUserInterfaceItem userInterfaceItem) {
     207      toolStripItem.Name = userInterfaceItem.Name;
     208      toolStripItem.Text = userInterfaceItem.Name;
     209      toolStripItem.ToolTipText = userInterfaceItem.ToolTipText;
     210      toolStripItem.Tag = userInterfaceItem;
     211      toolStripItem.Image = userInterfaceItem.Image;
     212      this.ActiveViewChanged += new EventHandler(userInterfaceItem.ActiveViewChanged);
     213      this.Changed += new EventHandler(userInterfaceItem.MainFormChanged);
    244214      toolStripItem.Click += new EventHandler(ToolStripItemClicked);
    245       this.toolStripItems.Add(iToolStripItem);
    246       iToolStripItem.ToolStripItem = toolStripItem;
     215      this.userInterfaceItems.Add(userInterfaceItem);
    247216    }
    248217
    249218    private void ToolStripItemClicked(object sender, EventArgs e) {
    250219      System.Windows.Forms.ToolStripItem item = (System.Windows.Forms.ToolStripItem)sender;
    251       ((IAction)item.Tag).Execute(this);
     220      ((IUserInterfaceItem)item.Tag).Execute();
    252221    }
    253222    #endregion
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.Designer.cs

    r2420 r2426  
    1 namespace HeuristicLab.MainForm {
     1namespace HeuristicLab.MainForm.WindowsForms {
    22  partial class MultipleDocumentMainForm {
    33    /// <summary>
     
    3636      this.ResumeLayout(false);
    3737      this.PerformLayout();
    38 
    3938    }
    40 
    4139    #endregion
    4240  }
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MultipleDocumentMainForm.cs

    r2420 r2426  
    2929using System.Windows.Forms;
    3030
    31 namespace HeuristicLab.MainForm {
     31namespace HeuristicLab.MainForm.WindowsForms {
    3232  public partial class MultipleDocumentMainForm : MainFormBase {
    3333    public MultipleDocumentMainForm()
     
    5959          DocumentForm form = new DocumentForm(view);
    6060          form.Activated += new EventHandler(MultipleDocumentFormActivated);
    61           form.FormClosing += new FormClosingEventHandler(view.FormClosing);
     61          form.FormClosing += new FormClosingEventHandler(view.OnClosing);
     62          form.FormClosed += new FormClosedEventHandler(view.OnClosed);
    6263          form.FormClosed += new FormClosedEventHandler(MultipleDocumentFormClosed);
    6364          form.MdiParent = this;
    64           foreach (IToolStripItem item in ToolStripItems)
    65             view.StateChanged += new EventHandler(item.ViewChanged);
     65          foreach (IUserInterfaceItem item in UserInterfaceItems)
     66            view.Changed += new EventHandler(item.ViewChanged);
    6667          form.Show();
    6768        }
     
    8687      ViewClosed(form.View);
    8788      form.Activated -= new EventHandler(MultipleDocumentFormActivated);
    88       form.FormClosing -= new FormClosingEventHandler(form.View.FormClosing);
     89      form.FormClosing -= new FormClosingEventHandler(form.View.OnClosing);
     90      form.FormClosed -= new FormClosedEventHandler(form.View.OnClosed);
    8991      form.FormClosed -= new FormClosedEventHandler(MultipleDocumentFormClosed);
    90       foreach (IToolStripItem item in ToolStripItems)
    91         form.View.StateChanged -= new EventHandler(item.ViewChanged);
     92      foreach (IUserInterfaceItem item in UserInterfaceItems)
     93        form.View.Changed -= new EventHandler(item.ViewChanged);
    9294    }
    9395
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/SingleDocumentMainForm.Designer.cs

    r2420 r2426  
    1 namespace HeuristicLab.MainForm {
     1namespace HeuristicLab.MainForm.WindowsForms {
    22  partial class SingleDocumentMainForm {
    33    /// <summary>
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/SingleDocumentMainForm.cs

    r2420 r2426  
    3030using WeifenLuo.WinFormsUI.Docking;
    3131
    32 namespace HeuristicLab.MainForm {
     32namespace HeuristicLab.MainForm.WindowsForms {
    3333  public partial class SingleDocumentMainForm : MainFormBase {
    3434    public SingleDocumentMainForm()
     
    5454          form.ShowInTaskbar = true;
    5555          form.Activated += new EventHandler(DocumentFormActivated);
    56           form.FormClosing += new FormClosingEventHandler(view.FormClosing);
     56          form.FormClosing += new FormClosingEventHandler(view.OnClosing);
     57          form.FormClosed += new FormClosedEventHandler(view.OnClosed);
    5758          form.FormClosed += new FormClosedEventHandler(DocumentFormClosed);
    58           foreach (IToolStripItem item in ToolStripItems)
    59             view.StateChanged += new EventHandler(item.ViewChanged);
     59          foreach (IUserInterfaceItem item in UserInterfaceItems)
     60            view.Changed += new EventHandler(item.ViewChanged);
    6061          form.Show(this);
    6162        }
     
    7677      ViewClosed(form.View);
    7778      form.Activated -= new EventHandler(DocumentFormActivated);
    78       form.FormClosing -= new FormClosingEventHandler(form.View.FormClosing);
     79      form.FormClosing -= new FormClosingEventHandler(form.View.OnClosing);
     80      form.FormClosed -= new FormClosedEventHandler(form.View.OnClosed);
    7981      form.FormClosed -= new FormClosedEventHandler(DocumentFormClosed);
    80       foreach (IToolStripItem item in ToolStripItems)
    81         form.View.StateChanged -= new EventHandler(item.ViewChanged);
     82      foreach (IUserInterfaceItem item in UserInterfaceItems)
     83        form.View.Changed -= new EventHandler(item.ViewChanged);
    8284    }
    8385
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/ViewBase.Designer.cs

    r2420 r2426  
    2222using System;
    2323
    24 namespace HeuristicLab.MainForm {
     24namespace HeuristicLab.MainForm.WindowsForms {
    2525  partial class ViewBase {
    2626    /// <summary>
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/ViewBase.cs

    r2420 r2426  
    2929using System.Windows.Forms;
    3030
    31 namespace HeuristicLab.MainForm {
     31namespace HeuristicLab.MainForm.WindowsForms {
    3232  public partial class ViewBase : UserControl,IView {
    3333    public ViewBase() {
    3434      InitializeComponent();
    35     }
    36 
    37     public ViewBase(IMainForm mainForm)
    38       : this() {
    39       this.mainForm = mainForm;
    4035    }
    4136
     
    5752    }
    5853
    59     public event EventHandler StateChanged;
    60     protected virtual void OnStateChanged() {
    61       if (StateChanged != null)
    62         StateChanged(this, new EventArgs());
     54    public event EventHandler Changed;
     55    protected virtual void OnChanged() {
     56      if (Changed != null)
     57        Changed(this, new EventArgs());
    6358    }
    6459
    65     private IMainForm mainForm;
    66     public IMainForm MainForm {
    67       get { return this.mainForm; }
    68       set { this.mainForm = value; }
     60    public virtual void OnClosing(object sender, CancelEventArgs e) {
    6961    }
    7062
    71     public virtual void FormClosing(object sender, FormClosingEventArgs e) {
     63    public virtual void OnClosed(object sender, EventArgs e) {
    7264    }
    7365  }
Note: See TracChangeset for help on using the changeset viewer.