Ejemplo n.º 1
0
        public void ToString_NullCommandI_ReturnsExpected()
        {
            var command = new MenuCommand(new EventHandler(EventHandler), null);

            if (!PlatformDetection.IsFullFramework)
            {
                Assert.Equal(" : Supported|Enabled|Visible", command.ToString());
            }
            else
            {
                Assert.Throws <NullReferenceException>(() => command.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <include file='doc\MenuCommandService.uex' path='docs/doc[@for="MenuCommandService.AddCommand"]/*' />
        /// <devdoc>
        ///     Adds a menu command to the document.  The menu command must already exist
        ///     on a menu; this merely adds a handler for it.
        /// </devdoc>
        public void AddCommand(MenuCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // If the command already exists, it is an error to add
            // a duplicate.
            //
            if (FindCommand(command.CommandID) != null)
            {
                throw new InvalidOperationException(SR.GetString(SR.MENUCOMMANDSERVICEDuplicateCommand, command.CommandID.ToString()));
            }

            if (commands == null)
            {
                commands = new MenuCommand[10];
            }

            if (commandCount == commands.Length)
            {
                MenuCommand[] newArray = new MenuCommand[commands.Length * 2];
                Array.Copy(commands, newArray, commands.Length);
                commands = newArray;
            }

            commands[commandCount++] = command;
            command.CommandChanged  += commandChangedHandler;
            Debug.WriteLineIf(Switches.MENUSERVICE.TraceVerbose, "Command added: " + command.ToString());

            // Now that we've added a new command, we must mark this command as dirty.
            //
            OnCommandChanged(command, EventArgs.Empty);
        }
Ejemplo n.º 3
0
 public void ToString_Invoke_ReturnsExpected(MenuCommand command, string expected)
 {
     Assert.Equal(expected, command.ToString());
 }
Ejemplo n.º 4
0
        /// <include file='doc\MenuCommandService.uex' path='docs/doc[@for="MenuCommandService.RemoveCommand"]/*' />
        /// <devdoc>
        ///     Removes the given menu command from the document.
        /// </devdoc>
        public void RemoveCommand(MenuCommand command)
        {
            for (int i = 0; i < commandCount; i++)
            {
                if (commands[i].Equals(command))
                {
                    commands[i].CommandChanged -= commandChangedHandler;

                    // The order of these commands is not important; just
                    // move the last command to the deleted one.
                    //
                    commands[i] = commands[commandCount - 1];
                    commandCount--;
                    Debug.WriteLineIf(Switches.MENUSERVICE.TraceVerbose, "Command removed: " + command.ToString());

                    // Now that we've removed a new command, we must mark this command as dirty.
                    //
                    OnCommandChanged(command, EventArgs.Empty);
                    return;
                }
            }
            Debug.WriteLineIf(Switches.MENUSERVICE.TraceVerbose, "Unable to remove command: " + command.ToString());
        }
Ejemplo n.º 5
0
        public void ToString_NullCommandId_ThrowsNullReferenceException()
        {
            var command = new MenuCommand(new EventHandler(EventHandler), null);

            Assert.Throws <NullReferenceException>(() => command.ToString());
        }