Exemple #1
0
        public CommandBarControl NewButtonObsolete(IContext context, string caption, int index, string binding, object newItemValue)
        {
            var validValueTypes = new[] { typeof(ScriptBlock), typeof(string) };

            if (null == newItemValue || !validValueTypes.Contains(newItemValue.GetType()))
            {
                var validNames = String.Join(", ", validValueTypes.ToList().ConvertAll(t => t.FullName).ToArray());
                throw new ArgumentException(
                          "new item values for command bar buttons must be one of the following types: " + validNames);
            }



            index = Math.Max(index, 1);
            ShellCommand shellCommand = CommandUtilities.GetOrCreateCommand(
                context,
                _commandBar.Application as DTE2,
                caption,
                newItemValue
                );

            if (!String.IsNullOrEmpty(binding))
            {
                shellCommand.Bindings = new[] { (object)binding };
            }

            Command command = shellCommand.AsCommand();
            var     ctl     = command.AddControl(_commandBar, index) as CommandBarControl;

            return(ctl);
        }