private static bool TrySetCommandBinding <T>(object control, CommandInterface command) where T : Control { var commandSource = control as T; commandSource.DataBindings.Add("Enabled", command, "CanExecute"); commandSource.Click += delegate { command.Execute(); }; return(true); }
protected string ExecuteCommandInternal(string commandString) { // notify any listeners that a command was entered OnCommandEntered.Invoke(commandString); // add the new command to the history and ensure the length remains below the maximum CommandHistory.Add(commandString); while (CommandHistory.Count > MaxHistory) { CommandHistory.RemoveAt(0); } // update the history index HistoryIndex = CommandHistory.Count - 1; // tokenise the command string List <string> tokens = TokeniseString(commandString); // early out if there was no data if (tokens.Count == 0) { return("[Error] Tried to execute a blank command."); } // extract the command string commandId = tokens[0].ToLower(); tokens.RemoveAt(0); // does the command exist? if (AlternateCommandNames.ContainsKey(commandId)) { CommandInterface command = Commands[AlternateCommandNames[commandId]]; if (command.IsAvailable) { return(command.Execute(tokens)); } } return("[Error] The command \'" + commandId + "\' could not be found."); }
public void Process() { Command.Execute(); }