示例#1
0
        public void AddCommand(IToolCommand command, string classification)
        {
            ToolStripMenuItem parent = null;

            foreach (ToolStripMenuItem pItem in this.mainMenu.Items)
            {
                if (pItem.Text.Equals(classification))
                {
                    parent = pItem;
                    break;
                }
            }

            if (parent == null)
            {
                parent = new ToolStripMenuItem(classification);
                this.mainMenu.Items.Add(parent);
            }

            if (command is IToolSecondLevelCommand)
            {
                ToolStripMenuItem sMenu = null;
                var sCommand            = (IToolSecondLevelCommand)command;
                foreach (ToolStripItem subItem in parent.DropDownItems)
                {
                    if (subItem.Text.Equals(sCommand.GetSecondLevelCommandItem()))
                    {
                        sMenu = subItem as ToolStripMenuItem;
                        break;
                    }
                }

                if (null == sMenu)
                {
                    sMenu = new ToolStripMenuItem(sCommand.GetSecondLevelCommandItem());
                    parent.DropDownItems.Add(sMenu);
                }

                parent = sMenu;
            }

            if (command is ToolCommandSeparator)
            {
                parent.DropDownItems.Add(new ToolStripSeparator());
            }
            else
            {
                var caption = command.GetCaption();
                if (command.GetVersion().Length > 0)
                {
                    caption = caption + " - " + command.GetVersion();
                }
                var currCommand = new ToolStripMenuItem(caption);
                currCommand.Tag    = command;
                currCommand.Click += CommandClick;
                parent.DropDownItems.Add(currCommand);
            }
        }
 public void AddCommand(IToolCommand command)
 {
     AddCommand(command, command.GetClassification());
 }
 public IToolRunner AddTool(String name, IToolCommand command)
 {
     commands.Add(name, command);
     return(this);
 }
示例#4
0
    public void AddCommand(IToolCommand command, string classification)
    {
      var ctype = command.GetType();
      if (!(command is ToolCommandSeparator) && addedCommands.Contains(ctype))
      {
        return;
      }
      addedCommands.Add(ctype);

      ToolStripMenuItem parent = null;
      foreach (ToolStripMenuItem pItem in this.mainMenu.Items)
      {
        if (pItem.Text.Equals(classification))
        {
          parent = pItem;
          break;
        }
      }

      if (parent == null)
      {
        parent = new ToolStripMenuItem(classification);
        this.mainMenu.Items.Add(parent);
      }

      if (command is IToolSecondLevelCommand)
      {
        ToolStripMenuItem sMenu = null;
        var sCommand = (IToolSecondLevelCommand)command;
        foreach (ToolStripItem subItem in parent.DropDownItems)
        {
          if (subItem.Text.Equals(sCommand.GetSecondLevelCommandItem()))
          {
            sMenu = subItem as ToolStripMenuItem;
            break;
          }
        }

        if (null == sMenu)
        {
          sMenu = new ToolStripMenuItem(sCommand.GetSecondLevelCommandItem());
          parent.DropDownItems.Add(sMenu);
        }

        parent = sMenu;
      }

      if (command is ToolCommandSeparator)
      {
        parent.DropDownItems.Add(new ToolStripSeparator());
      }
      else
      {
        var caption = command.GetCaption();
        if (command.GetVersion().Length > 0)
        {
          caption = caption + " - " + command.GetVersion();
        }
        var currCommand = new ToolStripMenuItem(caption);
        currCommand.Tag = command;
        currCommand.Click += CommandClick;
        parent.DropDownItems.Add(currCommand);
      }
    }
示例#5
0
 public void AddCommand(IToolCommand command)
 {
   AddCommand(command, command.GetClassification());
 }