internal static bool Execute(string actionName, CommandHint hint, params object[] args) { // Call some command/shortcut actions to execute the current action actionName = actionName.ToLower(); var executeHandlers = GetModeDataSection(currentIndex, ModeDescriptor.ExecuteHandlersKey) as JSONObject; if (executeHandlers == null) { return(false); } if (!executeHandlers.Contains(actionName)) { return(false); } string commandId = (string)executeHandlers[actionName]; if (!CommandService.Exists(commandId)) { return(false); } var result = CommandService.Execute(commandId, hint, args); return(result == null || (bool)result); }
private static object ExecuteCommand(string id, CommandHint hint, object[] args) { if (!Exists(id)) { throw new ArgumentException($"Command {id} does not exist", nameof(id)); } var command = s_Commands[id]; if ((command.hint & hint) == 0) { throw new ArgumentException($"Command ({id}, {command.hint}) does not match the hinting {hint}", nameof(id)); } var context = new CommandExecuteContext { hint = hint, args = args, result = null }; command.handler(context); return(context.result); }
internal static bool Execute(ModeAction builtinAction, CommandHint hint, params object[] args) { return(Execute(builtinAction.ToString(), hint, args)); }
public CommandHandlerAttribute(string id, CommandHint hint) : this(id, id, hint) { }
public CommandHandlerAttribute(string id, string label, CommandHint hint) { this.id = id; this.label = label; this.hint = hint; }
public static object Execute(string id, CommandHint hint, params object[] args) { var contextArgs = args != null && args.Length > 0 ? args : k_DefaultArgs; return(ExecuteCommand(id, hint, contextArgs)); }
public static object Execute(string id, CommandHint hint) { return(ExecuteCommand(id, hint, k_DefaultArgs)); }
public static void RegisterCommand(string id, CommandHandler handler, CommandHint hint = CommandHint.Any) { RegisterCommand(id, id, handler, hint); }
public static void RegisterCommand(string id, string label, CommandHandler handler, CommandHint hint = CommandHint.Any) { if (Exists(id)) { throw new ArgumentException($"A command with id {id} already exists", nameof(id)); } s_Commands[id] = new Command { id = id, label = label ?? id, hint = hint, handler = handler, managed = false }; }