/// <summary>
 /// Adds a set of Commands.
 /// </summary>
 /// <param name="commandCollection">The Command(s) to add.</param>
 public void Add(CommandCollection commandCollection)
 {
     foreach (Command command in commandCollection)
         AddCommand(command);
     OnChanged(EventArgs.Empty);
 }
 /// <summary>
 /// Removes a set of Commands.
 /// </summary>
 /// <param name="commandCollection">The Command(s) to remove.</param>
 public void Remove(CommandCollection commandCollection)
 {
     foreach (Command command in commandCollection)
         RemoveCommand(command);
     OnChanged(EventArgs.Empty);
 }
 /// <summary>
 /// Initializes a new instance of the CommandContextMenu class.
 /// </summary>
 /// <param name="container"></param>
 private CommandContextMenu(CommandCollection commandCollection, bool commandBar)
 {
     this.commandBar = commandBar;
     BuildMenuItems(commandCollection);
 }
 /// <summary>
 /// Shows a CommandContextMenu modally.
 /// </summary>
 /// <param name="parentWindow">The parent window.</param>
 /// <param name="position">The position to show the menu, in screen coordinates.</param>
 /// <param name="commandCollection">The CommandCollection to show in the menu.  These commands must be present in the CommandManager.</param>
 /// <param name="commandBar">true if this CommandContextMenu is being shown from a CommandBar; false otherwise.</param>
 /// <returns>The command that was selected; or null if no command was selected.</returns>
 public static Command ShowModal(Control parentWindow, Point position, CommandCollection commandCollection, bool commandBar)
 {
     return(ShowModal(parentWindow, position, position.X, commandCollection, commandBar));
 }
 /// <summary>
 /// Adds the entries from the specified CommandCollection to the end of this CommandCollection.
 /// </summary>
 /// <param name="value">The CommandCollection to be added to the end of this CommandCollection.</param>
 public void AddRange(CommandCollection value)
 {
     foreach (Command command in value)
         Add(command);
 }
        /// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandCollection">The CommandCollection to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <param name="commandBar">true if this CommandContextMenu is being shown from a CommandBar; false otherwise.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(Control parentWindow, Point position, int alternateXPosition, CommandCollection commandCollection, bool commandBar)
        {
            //	If the command collection was null, or contained no Commands, we're done.
            Debug.Assert(commandCollection != null, "Cannot show a CommandContextMenu without a CommandCollection");
            if (commandCollection == null || commandCollection.Count == 0)
            {
                return(null);
            }

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command collection.
            CommandContextMenu commandContextMenu = new CommandContextMenu(commandCollection, commandBar);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return(command);
        }
 /// <summary>
 /// Initializes a new instance of the CommandEnumerator class.
 /// </summary>
 /// <param name="mappings">The CommandCollection to enumerate.</param>
 public CommandEnumerator(CommandCollection mappings)
 {
     temp = (IEnumerable)mappings;
     baseEnumerator = temp.GetEnumerator();
 }
 /// <summary>
 /// Initializes a new instance of the CommandCollection class.
 /// </summary>
 /// <param name="value">Command collection to initializes this command collection with.</param>
 public CommandCollection(CommandCollection value)
 {
     AddRange(value);
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the CommandEnumerator class.
 /// </summary>
 /// <param name="mappings">The CommandCollection to enumerate.</param>
 public CommandEnumerator(CommandCollection mappings)
 {
     temp           = (IEnumerable)mappings;
     baseEnumerator = temp.GetEnumerator();
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the CommandCollection class.
 /// </summary>
 /// <param name="value">Command collection to initializes this command collection with.</param>
 public CommandCollection(CommandCollection value)
 {
     AddRange(value);
 }
 /// <summary>
 /// Shows a CommandContextMenu modally.
 /// </summary>
 /// <param name="parentWindow">The parent window.</param>
 /// <param name="position">The position to show the menu, in screen coordinates.</param>
 /// <param name="commandCollection">The CommandCollection to show in the menu.  These commands must be present in the CommandManager.</param>
 /// <param name="commandBar">true if this CommandContextMenu is being shown from a CommandBar; false otherwise.</param>
 /// <returns>The command that was selected; or null if no command was selected.</returns>
 public static Command ShowModal(Control parentWindow, Point position, CommandCollection commandCollection, bool commandBar)
 {
     return ShowModal(parentWindow, position, position.X, commandCollection, commandBar);
 }
 /// <summary>
 /// Builds the menu items of this CommandContextMenu from the specified CommandCollection.
 /// </summary>
 /// <param name="commandContextMenuDefinition">The CommandCollection.</param>
 private void BuildMenuItems(CommandCollection commandCollection)
 {
     CommandMenuBuilder commandMenuBuilder = new CommandMenuBuilder(commandBar ? MenuType.CommandBarContext : MenuType.Context);
     foreach (Command command in commandCollection)
         if (command.On)
             commandMenuBuilder.MergeCommand(command);
     MenuItems.AddRange(commandMenuBuilder.CreateMenuItems());
 }
 /// <summary>
 /// Initializes a new instance of the CommandContextMenu class.
 /// </summary>
 /// <param name="container"></param>
 private CommandContextMenu(CommandCollection commandCollection, bool commandBar)
 {
     this.commandBar = commandBar;
     BuildMenuItems(commandCollection);
 }
        /// <summary>
        /// Show the menu (modally) and return the type of the command that was chosen
        /// </summary>
        /// <param name="commandTypes">command types to include in the menu</param>
        /// <param name="point">point to show the menu at</param>
        /// <param name="parentControl">parent control for menu</param>
        /// <param name="menuTextParams">substitution parameters for the menu text</param>
        /// <returns>Type of the command that was chosen (null if no command chosen)</returns>
        public static Type ShowModal(CommandManager commandManager, Control parentWindow, Point position, Type[] commandTypes)
        {
            //	Dynamically construct the collection of commands to be shown.
            CommandCollection commandCollection = new CommandCollection();
            foreach (Type commandType in commandTypes)
            {
                // verify that the type is correct
                if (!typeof(Command).IsAssignableFrom(commandType))
                    throw new ArgumentException(
                        "Type passed is not a subclass of Command!");

                // create an instance of the command and add it to the collection of commands to be shown.
                Command command = Activator.CreateInstance(commandType) as Command;
                commandCollection.Add(command);
            }

            //	Add the commands to the system command manager.
            commandManager.Add(commandCollection);

            //	Show the context menu modally.
            Command commandSelected = ShowModal(parentWindow, position, commandCollection, false);
            Type type = commandSelected == null ? null : commandSelected.GetType();
            commandSelected = null;

            //	Remove the commands from the system command manager.
            commandManager.Remove(commandCollection);

            //	Done!
            return type;
        }
        /// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandCollection">The CommandCollection to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <param name="commandBar">true if this CommandContextMenu is being shown from a CommandBar; false otherwise.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(Control parentWindow, Point position, int alternateXPosition, CommandCollection commandCollection, bool commandBar)
        {
            //	If the command collection was null, or contained no Commands, we're done.
            Debug.Assert(commandCollection != null, "Cannot show a CommandContextMenu without a CommandCollection");
            if (commandCollection == null || commandCollection.Count == 0)
                return null;

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command collection.
            CommandContextMenu commandContextMenu = new CommandContextMenu(commandCollection, commandBar);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return command;
        }