Changeset 2249


Ignore:
Timestamp:
08/06/09 13:57:51 (12 years ago)
Author:
mkommend
Message:

adapted MainForm to create DropDownButtons (ticket #716)

Location:
trunk/sources
Files:
13 added
1 deleted
9 edited
3 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/HeuristicLab.MainForm.Test-3.2.csproj

    r2247 r2249  
    8282  </ItemGroup>
    8383  <ItemGroup>
    84     <Compile Include="OpenMenuItem.cs" />
    85     <Compile Include="SaveMenuItem.cs" />
     84    <Compile Include="Actions\NewEditorAction.cs" />
     85    <Compile Include="ButtonItems\NewEditorToolStripButtonItem.cs" />
     86    <Compile Include="ButtonItems\NewFormToolStripButtonItem.cs" />
     87    <Compile Include="ButtonItems\SaveToolStripButtonItem.cs" />
     88    <Compile Include="ButtonItems\OpenToolStripButtonItem.cs" />
     89    <Compile Include="MenuItems\NewFormToolStripMenuItem.cs" />
     90    <Compile Include="MenuItems\NewEditorToolStripMenuItem.cs" />
     91    <Compile Include="MenuItems\FileToolStripMenuItem.cs" />
     92    <Compile Include="MenuItems\NewToolStripMenuItem.cs" />
     93    <Compile Include="Actions\NewFormAction.cs" />
     94    <Compile Include="Actions\OpenAction.cs" />
     95    <Compile Include="MenuItems\OpenToolStripMenuItem.cs" />
     96    <Compile Include="Actions\SaveAction.cs" />
     97    <Compile Include="MenuItems\SaveToolStripMenuItem.cs" />
    8698    <Compile Include="HeuristicLabMainFormTestApplication.cs" />
    8799    <Compile Include="HeuristicLabMainFormTestPlugin.cs" />
    88100    <Compile Include="ITestUserInterfaceItemProvider.cs" />
    89101    <Compile Include="Properties\AssemblyInfo.cs" />
    90     <Compile Include="ViewsMenuItem.cs">
    91       <SubType>Code</SubType>
    92     </Compile>
     102    <Compile Include="ButtonItems\NewToolStripButtonItem.cs" />
    93103  </ItemGroup>
    94104  <ItemGroup>
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/NewEditorToolStripMenuItem.cs

    r2247 r2249  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class SaveMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
     11  public class NewEditorToolStripMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    13       get { return "Save"; }
     13      get { return "Editor"; }
    1414    }
    1515
    16     public override string MenuStructure {
    17       get { return "File"; }
     16    public override string Structure {
     17      get { return "File/New"; }
    1818    }
    1919
    2020    public override int Position {
    21       get { return 1200; }
    22     }
    23 
    24     public override Keys ShortCutKeys {
    25       get { return Keys.Control | Keys.S; }
    26     }
    27 
    28     public override System.Drawing.Image Image {
    29       get { return Resources.SaveIcon; }
     21      get { return 1120; }
    3022    }
    3123
    3224    public override void Execute(IMainForm mainform) {
    33       MessageBox.Show("Save Execute called");
     25      new NewEditorAction().Execute(mainform);
    3426    }
    3527  }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/NewFormToolStripMenuItem.cs

    r2247 r2249  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class SaveMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
     11  public class NewFormToolStripMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    13       get { return "Save"; }
     13      get { return "Form"; }
    1414    }
    1515
    16     public override string MenuStructure {
    17       get { return "File"; }
     16    public override string Structure {
     17      get { return "File/New"; }
    1818    }
    1919
    2020    public override int Position {
    21       get { return 1200; }
    22     }
    23 
    24     public override Keys ShortCutKeys {
    25       get { return Keys.Control | Keys.S; }
    26     }
    27 
    28     public override System.Drawing.Image Image {
    29       get { return Resources.SaveIcon; }
     21      get { return 1110; }
    3022    }
    3123
    3224    public override void Execute(IMainForm mainform) {
    33       MessageBox.Show("Save Execute called");
     25      new NewFormAction().Execute(mainform);
    3426    }
    3527  }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/NewToolStripMenuItem.cs

    r2247 r2249  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class SaveMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
     11  public class NewToolStripMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    13       get { return "Save"; }
     13      get { return "New"; }
    1414    }
    1515
    16     public override string MenuStructure {
     16    public override string Structure {
    1717      get { return "File"; }
    1818    }
    1919
    2020    public override int Position {
    21       get { return 1200; }
    22     }
    23 
    24     public override Keys ShortCutKeys {
    25       get { return Keys.Control | Keys.S; }
     21      get { return 1100; }
    2622    }
    2723
    2824    public override System.Drawing.Image Image {
    29       get { return Resources.SaveIcon; }
     25      get { return Resources.NewIcon; }
    3026    }
    3127
    3228    public override void Execute(IMainForm mainform) {
    33       MessageBox.Show("Save Execute called");
    3429    }
    3530  }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/OpenToolStripMenuItem.cs

    r2247 r2249  
    88
    99namespace HeuristicLab.MainForm.Test {
    10   public class OpenMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
     10  public class OpenToolStripMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
    1111    public override string Name {
    1212      get { return "Open"; }
    1313    }   
    1414
    15     public override string MenuStructure {
     15    public override string Structure {
    1616      get { return "File"; }
    1717    }
    1818
    1919    public override int Position {
    20       get { return 1100; }
     20      get { return 1200; }
    2121    }
    2222
     
    3030
    3131    public override void Execute(IMainForm mainform) {
    32       MessageBox.Show("Open Execute called");
     32      new OpenAction().Execute(mainform);
    3333    }
    3434  }
  • trunk/sources/HeuristicLab.MainForm.Test/3.2/MenuItems/SaveToolStripMenuItem.cs

    r2247 r2249  
    99
    1010namespace HeuristicLab.MainForm.Test {
    11   public class SaveMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
     11  public class SaveToolStripMenuItem : ToolStripMenuItemBase, ITestUserInterfaceItemProvider {
    1212    public override string Name {
    1313      get { return "Save"; }
    1414    }
    1515
    16     public override string MenuStructure {
     16    public override string Structure {
    1717      get { return "File"; }
    1818    }
    1919
    2020    public override int Position {
    21       get { return 1200; }
     21      get { return 1300; }
    2222    }
    2323
     
    3131
    3232    public override void Execute(IMainForm mainform) {
    33       MessageBox.Show("Save Execute called");
     33      new SaveAction().Execute(mainform);
    3434    }
    3535  }
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IToolStripButtonItem.cs

    r2243 r2249  
    2727namespace HeuristicLab.MainForm {
    2828  public interface IToolStripButtonItem : IToolStripItem {
     29    bool IsDropDownButton { get; }
    2930  }
    3031}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IToolStripItem.cs

    r2247 r2249  
    3232    Image Image { get; }
    3333    ToolStripItemDisplayStyle DisplayStyle { get; }
     34
     35    string Structure { get; }
     36    char StructureSeparator { get; }
     37
    3438    ToolStripItem ToolStripItem { get; set; }
    3539  }
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IToolStripMenuItem.cs

    r2243 r2249  
    2828namespace HeuristicLab.MainForm {
    2929  public interface IToolStripMenuItem : IToolStripItem {
    30     string MenuStructure { get; }
    31     char MenuStructureSeparator { get; }
    3230    Keys ShortCutKeys { get; }
    3331  }
  • trunk/sources/HeuristicLab.MainForm/3.2/MainFormBase.cs

    r2247 r2249  
    7777    private void CreateGUI() {
    7878      DiscoveryService ds = new DiscoveryService();
    79       Type[] userInterfaceTypes = ds.GetTypes(userInterfaceItemType);
    8079
    8180      object[] items = ds.GetInstances(userInterfaceItemType);
     
    9695    private void AddToolStripMenuItem(IToolStripMenuItem menuItem) {
    9796      ToolStripMenuItem item = new ToolStripMenuItem();
    98       SetToolStripItemProperties(item, menuItem);   
     97      SetToolStripItemProperties(item, menuItem);
    9998      item.ShortcutKeys = menuItem.ShortCutKeys;
    10099
    101       ToolStripMenuItem parent = null;
    102       if (!String.IsNullOrEmpty(menuItem.MenuStructure)) {
    103         ToolStripItemCollection parentItems = menuStrip.Items;
    104         foreach (string structure in menuItem.MenuStructure.Split(menuItem.MenuStructureSeparator)) {
    105           if (parentItems.ContainsKey(structure))
    106             parent = (ToolStripMenuItem)parentItems[structure];
    107           else {
    108             parent = new ToolStripMenuItem(structure);
    109             parent.Name = structure;
    110             parentItems.Add(parent);
    111           }
    112           parentItems = parent.DropDownItems;
    113         }
    114       }
    115 
     100      ToolStripDropDownItem parent = FindParent(menuItem, menuStrip.Items);
    116101      if (parent == null)
    117102        menuStrip.Items.Add(item);
     
    121106
    122107    private void AddToolStripButtonItem(IToolStripButtonItem buttonItem) {
    123       ToolStripButton item = new ToolStripButton();
     108      ToolStripItem item;
     109      if (buttonItem.IsDropDownButton)
     110        item = new ToolStripDropDownButton();
     111      else
     112        item = new ToolStripButton();
     113
    124114      SetToolStripItemProperties(item, buttonItem);
    125       toolStrip.Items.Add(item);
     115      ToolStripDropDownItem parent = FindParent(buttonItem,toolStrip.Items);
     116      if (parent == null)
     117        toolStrip.Items.Add(item);
     118      else
     119        parent.DropDownItems.Add(item);
     120    }
     121
     122    private ToolStripDropDownItem FindParent(IToolStripItem item, ToolStripItemCollection parentItems) {
     123      ToolStripDropDownItem parent = null;
     124      foreach (string structure in item.Structure.Split(item.StructureSeparator)) {
     125        if (parentItems.ContainsKey(structure))
     126          parent = (ToolStripDropDownItem)parentItems[structure];
     127        else
     128          break;
     129        parentItems = parent.DropDownItems;
     130      }
     131      return parent;
    126132    }
    127133
  • trunk/sources/HeuristicLab.MainForm/3.2/ToolStripButtonItemBase.cs

    r2243 r2249  
    2727
    2828namespace HeuristicLab.MainForm {
    29   public abstract class ToolStripButtonItemBase : ToolStripItemBase, IToolStripItem {
     29  public abstract class ToolStripButtonItemBase : ToolStripItemBase, IToolStripButtonItem {
    3030    public override ToolStripItemDisplayStyle DisplayStyle {
    3131      get {
     
    3636      }
    3737    }
     38
     39    public virtual bool IsDropDownButton {
     40      get { return false; }
     41    }
    3842  }
    3943}
  • trunk/sources/HeuristicLab.MainForm/3.2/ToolStripItemBase.cs

    r2247 r2249  
    4646      set { this.toolStripItem = value; }
    4747    }
     48
     49    public virtual string Structure {
     50      get { return string.Empty; }
     51    }
     52
     53    public static readonly char structureSeparator = '/';
     54    public char StructureSeparator {
     55      get { return ToolStripMenuItemBase.structureSeparator; }
     56    }
    4857    #endregion
    4958  }
  • trunk/sources/HeuristicLab.MainForm/3.2/ToolStripMenuItemBase.cs

    r2247 r2249  
    3131      get { return Keys.None; }
    3232    }
    33     public virtual string MenuStructure {
    34       get { return string.Empty; }
    35     }
    3633
    3734    public override ToolStripItemDisplayStyle DisplayStyle {
    3835      get { return ToolStripItemDisplayStyle.ImageAndText; }
    3936    }
    40 
    41     public static readonly char StructureSeparator = '/';
    42     public char MenuStructureSeparator {
    43       get { return ToolStripMenuItemBase.StructureSeparator; }
    44     }
    4537  }
    4638}
  • trunk/sources/HeuristicLab.MainForm/3.2/UserInterfaceItemBase.cs

    r2243 r2249  
    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;
Note: See TracChangeset for help on using the changeset viewer.