Exemplo n.º 1
0
        /// <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));
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
 private void OnCommandRemoved(EditorCommand command)
 {
     this.CommandRemoved?.Invoke(this, command);
 }
Exemplo n.º 4
0
 /// <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));
 }