/// <summary> /// Unregisters an existing EditorCommand based on its registered name. /// </summary> /// <param name="commandName">The name of the command to be unregistered.</param> public void UnregisterCommand(string commandName) { EditorCommand existingCommand = null; if (this.editorCommands.TryGetValue(commandName, out existingCommand)) { this.editorCommands.Remove(commandName); this.OnCommandRemoved(existingCommand); } else { throw new KeyNotFoundException( string.Format( "Command '{0}' is not registered", commandName)); } }
/// <summary> /// Registers a new EditorCommand with the ExtensionService and /// causes its details to be sent to the host editor. /// </summary> /// <param name="editorCommand">The details about the editor command to be registered.</param> /// <returns>True if the command is newly registered, false if the command already exists.</returns> public bool RegisterCommand(EditorCommand editorCommand) { bool commandExists = this.editorCommands.ContainsKey( editorCommand.Name); // Add or replace the editor command this.editorCommands[editorCommand.Name] = editorCommand; if (!commandExists) { this.OnCommandAdded(editorCommand); } else { this.OnCommandUpdated(editorCommand); } return(!commandExists); }
private void OnCommandRemoved(EditorCommand command) { this.CommandRemoved?.Invoke(this, command); }
/// <summary> /// Returns all registered EditorCommands. /// </summary> /// <returns>An Array of all registered EditorCommands.</returns> public EditorCommand[] GetCommands() { EditorCommand[] commands = new EditorCommand[this.editorCommands.Count]; this.editorCommands.Values.CopyTo(commands, 0); return(commands); }
/// <summary> /// Registers a new command in the editor. /// </summary> /// <param name="editorCommand">The EditorCommand to be registered.</param> /// <returns>True if the command is newly registered, false if the command already exists.</returns> public bool RegisterCommand(EditorCommand editorCommand) { return(this.extensionService.RegisterCommand(editorCommand)); }