public void AddVerb(DesignerVerb verb)
 {
     if (verbs.Contains(verb))
     {
         throw new InvalidOperationException("The MenuCommandService already contains that Designer Verb");
     }
     verbs.Add(verb);
 }
        public void Contains_Value_ReturnsExpected()
        {
            var verb       = new DesignerVerb("Text", null);
            var collection = new DesignerVerbCollection {
                verb
            };

            Assert.True(collection.Contains(verb));
            Assert.False(collection.Contains(new DesignerVerb("Text", null)));
            Assert.False(collection.Contains(null));
        }
 /// <summary>
 /// Removes the specified designer verb from the collection of global designer verbs.
 /// </summary>
 /// <param name="verb">The <see cref="T:System.ComponentModel.Design.DesignerVerb"/> to remove.</param>
 public void RemoveVerb(DesignerVerb verb)
 {
     if (verbs.Contains(verb))
     {
         verbs.Remove(verb);
     }
 }
 /// <summary>
 /// Removes the specified designer verb from the collection of global designer verbs.
 /// </summary>
 /// <param name="verb">The <see cref="T:System.ComponentModel.Design.DesignerVerb"/> to remove.</param>
 public void RemoveVerb(DesignerVerb verb)
 {
     if ((verbsCollection != null) && verbsCollection.Contains(verb))
     {
         verbsCollection.Remove(verb);
     }
 }
Beispiel #5
0
        public virtual void RemoveVerb(DesignerVerb verb)
        {
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }

            if (_globalVerbs.Contains(verb))
            {
                _globalVerbs.Remove(verb);
            }

            this.OnCommandsChanged(new MenuCommandsChangedEventArgs(MenuCommandsChangedType.CommandRemoved, verb));
        }
Beispiel #6
0
 public virtual void AddVerb(DesignerVerb verb)
 {
     if (verb == null)
     {
         throw new ArgumentNullException("verb");
     }
     this.EnsureVerbs();
     if (!_verbs.Contains(verb))
     {
         if (_globalVerbs == null)
         {
             _globalVerbs = new DesignerVerbCollection();
         }
         _globalVerbs.Add(verb);
     }
     this.OnCommandsChanged(new MenuCommandsChangedEventArgs(MenuCommandsChangedType.CommandAdded, verb));
 }
Beispiel #7
0
        // DesignerVerbCollection
        public void DesignerVerbCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty DesignerVerbCollection.
            DesignerVerbCollection collection = new DesignerVerbCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a DesignerVerb to the collection.
            collection.Add(new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent)));
            //</Snippet3>

            //<Snippet4>
            // Adds an array of DesignerVerb objects to the collection.
            DesignerVerb[] verbs = { new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent)), new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent)) };
            collection.AddRange(verbs);

            // Adds a collection of DesignerVerb objects to the collection.
            DesignerVerbCollection verbsCollection = new DesignerVerbCollection();

            verbsCollection.Add(new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent)));
            verbsCollection.Add(new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent)));
            collection.AddRange(verbsCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a DesignerVerb in the collection,
            // and retrieves its index if it is found.
            DesignerVerb testVerb  = new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent));
            int          itemIndex = -1;

            if (collection.Contains(testVerb))
            {
                itemIndex = collection.IndexOf(testVerb);
            }
            //</Snippet5>

            //<Snippet6>
            // Copies the contents of the collection, beginning at index 0,
            // to the specified DesignerVerb array.
            // 'verbs' is a DesignerVerb array.
            collection.CopyTo(verbs, 0);
            //</Snippet6>

            //<Snippet7>
            // Retrieves the count of the items in the collection.
            int collectionCount = collection.Count;

            //</Snippet7>

            //<Snippet8>
            // Inserts a DesignerVerb at index 0 of the collection.
            collection.Insert(0, new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent)));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified DesignerVerb from the collection.
            DesignerVerb verb = new DesignerVerb("Example designer verb", new EventHandler(this.ExampleEvent));

            collection.Remove(verb);
            //</Snippet9>

            //<Snippet10>
            // Removes the DesignerVerb at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }