/// <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> /// Closes the CommandContextManager, ensuring that all commands have been removed from /// the CommandManager. /// </summary> public void Close() { // Begin the batch update. BeginUpdate(); // If entered, leave. if (entered) { Leave(); } // If activated, deactivate. if (activated) { Deactivate(); } // Remove normal commands. commandManager.Remove(normalCommandCollection); // End the batch update. EndUpdate(); // Clear our internal tables. normalCommandCollection.Clear(); activatedCommandCollection.Clear(); enteredCommandCollection.Clear(); commandContextTable.Clear(); }
public void Dispose() { try { _commandManager.BeginUpdate(); foreach (Command command in _loadedCommands) { _commandManager.Remove(command); } _loadedCommands.Clear(); } finally { _commandManager.EndUpdate(); } }
/// <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; }