Free cookie consent management tool by TermsFeed Policy Generator

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

adapted MainForm to create DropDownButtons (ticket #716)

Location:
trunk/sources/HeuristicLab.MainForm/3.2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • 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.