IEnumerable <object> IContextMenuCommandProvider.GetCommands(object context, object target) { ICommandClient cmdclient = (ICommandClient)this; if (context == this.TreeView) { if (Adapters.Is <IGame>(target) || Adapters.Is <GameReference>(target) || Adapters.Is <IResolveable>(target)) { foreach (Command command in Enum.GetValues(typeof(Command))) { if (cmdclient.CanDoCommand(command)) { yield return(command); } } } // Some nodes can provide extra context menu commands // Nodes that can will have an adapter derived from // IContextMenuCommandProvider var subProvider = target.As <IContextMenuCommandProvider>(); if (subProvider != null) { var subClient = target.Cast <ICommandClient>(); var registeredCommands = GetRegisteredCommands(subProvider); foreach (var command in registeredCommands.m_commands) { if (subClient.CanDoCommand(command)) { yield return(command); } } } } }
private static void RegisterDebugCommands(ICommandService commandService, ICommandClient client) { // Enable these two commands if you want to log the SCMP, and libscriptdebugger.cpp also has some logging you can // enable. commandService.RegisterCommand( Command.ScmpLogging, Menu.Debug, CommandGroup.Debug, Localization.SledDebugMenuScmpProtocolLogging, Localization.SledDebugMenuScmpProtocolLoggingComment, Keys.None, null, CommandVisibility.Menu, client); //m_commandService.RegisterCommand( // Command.ScmpSendMark, // Menu.Debug, // CommandGroup.Debug, // Localization.SledDebugMenuScmpProtocolMark, // Localization.SledDebugMenuScmpProtocolMarkComment, // Keys.None, // null, // CommandVisibility.Menu, // this); }
/// <summary> /// Sets the active client that receives a command, for the case when multiple /// ICommandClient objects have registered for the same command tag (such as the /// StandardCommand.EditCopy enum, for example). Set to null to reduce the priority /// of the previously active client.</summary> /// <param name="client">Command client, null if client is deactivated</param> public void SetActiveClient(ICommandClient client) { List <object> commandTags = new List <object>(m_commandClients.Keys); // 'client' being null is an indication to pop the most recently active client if (client == null && m_activeClient != null) { // make sure previous client will NOT be the last registered for its command tags foreach (object commandTag in commandTags) { if (m_commandClients.ContainsKeyValue(commandTag, m_activeClient)) { m_commandClients.AddFirst(commandTag, m_activeClient); } } } m_activeClient = client; if (m_activeClient != null) { // make sure client will be the last registered for its command tags foreach (object commandTag in commandTags) { if (m_commandClients.ContainsKeyValue(commandTag, client)) { m_commandClients.Add(commandTag, client); } } } }
/// <summary> /// Registers a command for a command client</summary> /// <param name="info">Command description; standard commands are defined as static /// members of the CommandInfo class</param> /// <param name="client">Client that handles the command</param> public virtual void RegisterCommand(CommandInfo info, ICommandClient client) { if (client == null) { throw new InvalidOperationException("Command has no client"); } CommandInfo duplicate = GetCommandInfo(info.CommandTag); if (duplicate == null) { if (!CommandIsUnique(info.MenuTag, info.MenuText)) { throw new InvalidOperationException( string.Format( "Duplicate menu/command combination. CommandTag: {0}, MenuTag: {1}, GroupTag: {2}, MenuText: {3}", info.CommandTag, info.MenuTag, info.GroupTag, info.MenuText)); } RegisterCommandInfo(info); // Only increment the menu count for unique commands, because it's legal to // call RegisterCommand multiple times with the same CommandInfo. IncrementMenuCommandCount(info.MenuTag); } m_commandClients.Add(info.CommandTag, client); }
private void item_Click(object sender, EventArgs e) { // See if the user clicked the icon portion of the menu item and set the IconClicked property that // interested commands can check. IconClicked = IsMouseOverIcon(sender as ToolStripItem); // clear status text if (m_statusService != null) { m_statusService.ShowStatus(string.Empty); } ToolStripItem item = sender as ToolStripItem; object tag = item.Tag; if (tag != null) { ICommandClient client = GetClient(tag); if (client == null) { client = m_activeClient; } if (client != null && client.CanDoCommand(tag)) { client.DoCommand(tag); } } IconClicked = false; }
/// <summary> /// Unregisters a command for a command client</summary> /// <param name="commandTag">Command tag that identifies CommandInfo used to register /// the command</param> /// <param name="client">Client that handles the command</param> public virtual void UnregisterCommand(object commandTag, ICommandClient client) { if (client == null) { m_commandClients.Remove(commandTag); } else { m_commandClients.Remove(commandTag, client); } CommandInfo info = GetCommandInfo(commandTag); if (info == null) { return; } UnregisterCommandInfo(info); if (info.MenuTag != null) { MenuInfo menuInfo = GetMenuInfo(info.MenuTag); if (menuInfo != null) { DecrementMenuCommandCount(menuInfo); } } }
/// <summary> /// Creates and registers a command for a command client</summary> /// <param name="def">Command definition</param> /// <param name="client">Command client</param> /// <returns>ICommandItem for command</returns> public ICommandItem RegisterCommand(CommandDef def, ICommandClient client) { Requires.NotNull(client, "client"); // Problem - what about same command tag registered in several places with different shortcuts // submenus etc? ICommandItem command; if (!m_commandsLookup.TryGetValue(def.CommandTag, out command)) { if (!CommandIsUnique(def.MenuTag, def.CommandTag)) { throw new InvalidOperationException( string.Format( "Duplicate menu/command combination. CommandTag: {0}, MenuTag: {1}, GroupTag: {2}, MenuText: {3}", def.CommandTag, def.GroupTag, def.MenuTag, def.Text)); } command = new CommandItem(def, CanDoCommand, CommandExecuted); m_commands.Add(command); m_commands.Sort(new CommandComparer()); m_commandsLookup.Add(command.CommandTag, command); int index = m_commands.IndexOf(command); CommandAdded.Raise<ItemInsertedEventArgs<ICommandItem>>(this, new ItemInsertedEventArgs<ICommandItem>(index, command)); } m_commandClients.Add(def.CommandTag, client); return command; }
public bool SendCommand(CommandInfo ci) { Control focusedControl = Sce.Atf.WinFormsUtil.GetFocusedControl(); while (focusedControl != null && !(focusedControl is ICommandClient)) { focusedControl = focusedControl.Parent; } ICommandClient focusedCmdClient = focusedControl as ICommandClient; if (focusedCmdClient != null) { if (focusedCmdClient.CanDoCommand(ci.CommandTag)) { focusedCmdClient.DoCommand(ci.CommandTag); return(true); } } focusedCmdClient = DocumentManager.GetInst().ActiveDocument as ICommandClient; if (focusedCmdClient != null) { if (focusedCmdClient.CanDoCommand(ci.CommandTag)) { focusedCmdClient.DoCommand(ci.CommandTag); return(true); } } return(false); }
public static Task _DispatchCommandInternalAsync(ICommand message, Type messageType, bool requireAffirmation) { ICommandClient client = null; Type messageBaseType = messageType; while (client == null && messageBaseType != null) { if (commandClients.TryGetValue(messageBaseType, out client)) { if (requireAffirmation) { return(client.DispatchAsyncAwait(message)); } else { return(client.DispatchAsync(message)); } } messageBaseType = messageBaseType.BaseType; } if (requireAffirmation) { return(HandleCommandAsync((ICommand)message, messageType, true)); } else { //Task.Run execues on shared principal which can mess things up return(TaskSafePrincipal.Run(async() => { await HandleCommandAsync((ICommand)message, messageType, true); })); } }
/// <summary> /// Registers a command for a command client</summary> /// <param name="info">Command description; standard commands are defined as static /// members of the CommandInfo class</param> /// <param name="client">Client that handles the command</param> public virtual void RegisterCommand(CommandInfo info, ICommandClient client) { if (client == null) { throw new InvalidOperationException("Command has no client"); } CommandInfo duplicate = GetCommandInfo(info.CommandTag); if (duplicate == null) { if (!CommandIsUnique(info.MenuTag, info.MenuText)) { throw new InvalidOperationException( string.Format( "Duplicate menu/command combination. CommandTag: {0}, MenuTag: {1}, GroupTag: {2}, MenuText: {3}", info.CommandTag, info.GroupTag, info.MenuTag, info.MenuText)); } RegisterCommandInfo(info); } IncrementMenuCommandCount(info.MenuTag); m_commandClients.Add(info.CommandTag, client); }
/// <summary> /// Creates and registers a command for a command client</summary> /// <param name="def">Command definition</param> /// <param name="client">Command client</param> /// <returns>ICommandItem for command</returns> public ICommandItem RegisterCommand(CommandDef def, ICommandClient client) { Requires.NotNull(client, "client"); // Problem - what about same command tag registered in several places with different shortcuts // submenus etc? ICommandItem command; if (!m_commandsLookup.TryGetValue(def.CommandTag, out command)) { if (!CommandIsUnique(def.MenuTag, def.CommandTag)) { throw new InvalidOperationException( string.Format( "Duplicate menu/command combination. CommandTag: {0}, MenuTag: {1}, GroupTag: {2}, MenuText: {3}", def.CommandTag, def.GroupTag, def.MenuTag, def.Text)); } command = new CommandItem(def, CanDoCommand, CommandExecuted); m_commands.Add(command); m_commands.Sort(new CommandComparer()); m_commandsLookup.Add(command.CommandTag, command); int index = m_commands.IndexOf(command); CommandAdded.Raise <ItemInsertedEventArgs <ICommandItem> >(this, new ItemInsertedEventArgs <ICommandItem>(index, command)); } m_commandClients.Add(def.CommandTag, client); return(command); }
/// <summary> /// Raises the CheckCanDo event. ICommandClients can call EnableCheckCanDoEvent before /// registering this CommandInfo and then can call this method for greatly improved performance.</summary> /// <param name="client">Command client that registered this CommandInfo</param> /// <remarks>This method is only applicable to WinForms version of CommandService.</remarks> public void OnCheckCanDo(ICommandClient client) { if (!m_checkCanDoClients.Contains(client)) { throw new InvalidOperationException("Call EnableCheckCanDoEvent before calling OnCheckCanDo"); } CheckCanDo.Raise(this, EventArgs.Empty); }
public GitFileService(IOptions <ApiOptions> apiOption, ILogger <GitFileService> logger, ICommandClient commandClient, IFileRepository fileRepository) { _logger = logger; _commandClient = commandClient; _apiOptions = apiOption.Value; _fileRepository = fileRepository; }
public RedirectedProcess( ITerminal ClientTerminal, ICommandClient CommandClient ) { _InputHandler = new InputHandler(); _TerminalClient = ClientTerminal; _ProcessExit = new ManualResetEvent( false ); _CommandClient = CommandClient; }
public void Disconnect() { if ( null != _CommandClient ) { lock( _CommandClient ) { _CommandClient = null; } } }
/// <summary> /// Registers a command for a command client</summary> /// <param name="info">Command description; standard commands are defined as static /// members on the CommandInfo class</param> /// <param name="client">Client that handles the command</param> public override void RegisterCommand(CommandInfo info, ICommandClient client) { base.RegisterCommand(info, client); if (info != null && client != null && info.CheckCanDoClients.Contains(client)) { m_checkCanDoClients.Add(info, client); m_checkCanDoClientsToUpdate.Add(info); } m_commandsSorted = false; }
/// <summary> /// Unregisters a command for a command client</summary> /// <param name="commandTag">Command tag that identifies CommandInfo used to register /// the command</param> /// <param name="client">Client that handles the command</param> public override void UnregisterCommand(object commandTag, ICommandClient client) { CommandInfo info = GetCommandInfo(commandTag); if (info != null && client != null && info.CheckCanDoClients.Contains(client)) { m_checkCanDoClients.Remove(info, client); m_checkCanDoClientsToUpdate.Remove(info); } base.UnregisterCommand(commandTag, client); RemoveToolStripItem(commandTag); }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="visibility">Whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>Menu/Toolbar command information</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, CommandInfo commandInfo, CommandVisibility visibility, ICommandClient client) { CommandInfo info = commandInfo.Clone(); commandService.RegisterCommand(info, client); info.Visibility = visibility; return(info); }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="visibility">Whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>Menu/Toolbar command information</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, StandardCommand commandTag, CommandVisibility visibility, ICommandClient client) { CommandInfo info = CommandInfo.GetStandardCommand(commandTag); commandService.RegisterCommand(info, client); info.Visibility = visibility; return(info); }
public StatefulBot( ITransactionsClient transactionsClient, ICommandClient commandClient, TState initial, Func <TState, Transaction, TState> update, Func <TState, Commands> handler) { _transactionsClient = transactionsClient; _commandClient = commandClient; _state = initial; _update = update; _handler = handler; }
/// <summary> /// Utility function to get the command's client and call UpdateCommand.</summary> /// <param name="commandTag">The command to update</param> /// <param name="state">Command's state</param> private void UpdatePinnableCommand(object commandTag, CommandState state) { ICommandClient client = GetClient(commandTag); if (client == null) { client = m_activeClient; } if (client != null && client.CanDoCommand(commandTag)) { client.UpdateCommand(commandTag, state); } }
private void LegacyUpdateCommand(ICommandItem item) { ICommandClient client = GetClientOrActiveClient(item.CommandTag); if (client != null) { var commandState = new CommandState { Text = item.Text, Check = item.IsChecked }; client.UpdateCommand(item.CommandTag, commandState); item.Text = commandState.Text.Trim(); item.IsChecked = commandState.Check; } }
/// <summary> /// Creates and registers a command</summary> /// <param name="commandRegistry">ICommandService</param> /// <param name="commandTag">Unique command ID</param> /// <param name="menuTag">Unique ID for menu command attached to</param> /// <param name="groupTag">Unique ID for command's group</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="client">ICommandClient</param> /// <returns>ICommandItem for command</returns> public static ICommandItem RegisterCommand( this ICommandService commandRegistry, object commandTag, object menuTag, object groupTag, string menuText, string description, ICommandClient client) { Requires.NotNull(commandRegistry, "commandRegistry"); var def = new CommandDef(commandTag, menuTag, groupTag, menuText, description); return(commandRegistry.RegisterCommand(def, client)); }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description); commandService.RegisterCommand(info, client); return(info); }
/// <summary> /// Gets tags for context menu (right click) commands</summary> /// <param name="context">Context containing target object</param> /// <param name="target">Right clicked object, or null if none</param> IEnumerable <object> IContextMenuCommandProvider.GetCommands(object context, object target) { ICommandClient cmdclient = (ICommandClient)this; if (context == m_paletteService.TreeView) { foreach (Command command in Enum.GetValues(typeof(Command))) { if (cmdclient.CanDoCommand(command)) { yield return(command); } } } }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut, or Keys.None if none</param> /// <param name="imageName">Text identifying image, or null if none</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, System.Windows.Forms.Keys shortcut, string imageName, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description, KeysInterop.ToAtf(shortcut), imageName); commandService.RegisterCommand(info, client); return(info); }
IEnumerable <object> IContextMenuCommandProvider.GetCommands(object context, object target) { ICommandClient cmdclient = (ICommandClient)this; if (context == this.TreeView && (Adapters.Is <IGame>(target) || Adapters.Is <GameReference>(target))) { foreach (Command command in Enum.GetValues(typeof(Command))) { if (cmdclient.CanDoCommand(command)) { yield return(command); } } } }
private void OscServiceMessageReceived(object sender, OscMessageReceivedArgs e) { CommandInfo cmdInfo; if (m_addressesToCommands.TryGetValue(e.Address, out cmdInfo)) { ICommandClient cmdClient = m_commandService.GetClient(cmdInfo.CommandTag); if (cmdClient != null) { if (cmdClient.CanDoCommand(cmdInfo.CommandTag)) { cmdClient.DoCommand(cmdInfo.CommandTag); } } e.Handled = true; } }
/// <summary> /// Creates and registers a command</summary> /// <param name="commandRegistry">ICommandService</param> /// <param name="commandTag">Unique command ID</param> /// <param name="menuTag">Unique ID for menu command attached to</param> /// <param name="groupTag">Unique ID for command's group</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut</param> /// <param name="imageSourceKey">Image resource for command</param> /// <param name="client">ICommandClient</param> /// <returns>ICommandItem for command</returns> public static ICommandItem RegisterCommand( this ICommandService commandRegistry, object commandTag, object menuTag, object groupTag, string menuText, string description, KeyGesture shortcut, object imageSourceKey, ICommandClient client) { Requires.NotNull(commandRegistry, "commandRegistry"); var gestures = shortcut != null ? new InputGesture[] { shortcut } : null; var def = new CommandDef(commandTag, menuTag, groupTag, menuText, null, description, imageSourceKey, gestures, CommandVisibility.Default); return(commandRegistry.RegisterCommand(def, client)); }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut, or Keys.None if none</param> /// <param name="imageKey">Object identifying image, or null if none</param> /// <param name="visibility">Whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, Keys shortcut, object imageKey, CommandVisibility visibility, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description, shortcut, imageKey, visibility); commandService.RegisterCommand(info, client); return(info); }
/// <summary> /// Unregisters a command for a command client</summary> /// <param name="command">ICommandItem for command</param> /// <param name="client">Client that handles the command</param> public void UnregisterCommand(ICommandItem command, ICommandClient client) { if (command.CommandTag is StandardCommand) return; if (client == null) m_commandClients.Remove(command.CommandTag); else m_commandClients.Remove(command.CommandTag, client); if (!m_commandClients.TryGetFirst(command.CommandTag, out client)) { m_commandsLookup.Remove(command.CommandTag); int index = m_commands.IndexOf(command); m_commands.Remove(command); CommandRemoved.Raise<ItemRemovedEventArgs<ICommandItem>>(this, new ItemRemovedEventArgs<ICommandItem>(index, command)); } }
/// <summary> /// Processes the key as a command shortcut</summary> /// <param name="key">Key to process</param> /// <returns>True iff the key was processed as a command shortcut</returns> public virtual bool ProcessKey(Keys key) { KeyEventArgs keyEventArgs = new KeyEventArgs(key); ProcessingKey.Raise(this, keyEventArgs); if (keyEventArgs.Handled) { return(true); } Keys shortcut = KeysUtil.NumPadToNum(key); //if there is no key, return if (shortcut == Keys.None) { return(false); } //if the key is not a registered shortcut, return object tag; if (!m_shortcuts.TryGetValue(shortcut, out tag)) { return(false); } //Is there a client, and if so, can the client do the command? ICommandClient client = GetClient(tag); if (client == null) { client = m_activeClient; } if (client == null || !client.CanDoCommand(tag)) { return(false); } // do the command client.DoCommand(tag); return(true); }
/// <summary> /// Force an update on a particular command</summary> /// <param name="info">Command to update</param> public void UpdateCommand(CommandInfo info) { if (m_mainForm.InvokeRequired) { m_mainForm.BeginInvoke(new Action <CommandInfo>(UpdateCommand), info); return; } ToolStripMenuItem menuItem; ToolStripButton menuButton; info.GetMenuItemAndButton(out menuItem, out menuButton); CommandState commandState = new CommandState(); commandState.Text = info.DisplayedMenuText; commandState.Check = menuItem.Checked; ICommandClient client = GetClient(info.CommandTag); if (client == null) { client = m_activeClient; } bool enabled = false; if (client != null) { enabled = client.CanDoCommand(info.CommandTag); if (enabled) { client.UpdateCommand(info.CommandTag, commandState); } } string menuText = commandState.Text.Trim(); menuItem.Text = menuButton.Text = menuText; menuItem.Checked = menuButton.Checked = commandState.Check; menuItem.Enabled = menuButton.Enabled = enabled; }
public override void UnregisterCommand(object commandTag, ICommandClient client) { base.UnregisterCommand(commandTag, client); // If there are no more clients associated with this command // then remove it if (!m_commandClients.TryGetFirst(commandTag, out client)) { ICommandItem command = m_commandsLookup[commandTag]; m_commandsLookup.Remove(commandTag); // Remove from composition var commandItem = command as CommandItem; if (commandItem != null && commandItem.ComposablePart != null) { m_composer.RemovePart(commandItem.ComposablePart); commandItem.ComposablePart = null; } } }
public static void AddCommandClient <TInterface>(ICommandClient commandClient) where TInterface : IBaseProvider { lock (serviceLock) { Type type = typeof(TInterface); var commandTypes = GetCommandTypesFromInterface(type); foreach (var commandType in commandTypes) { if (commandServerTypes.Contains(commandType)) { throw new InvalidOperationException($"Cannot create loopback. Command Server already registered for type {commandType.GetNiceName()}"); } if (commandClients.Keys.Contains(commandType)) { throw new InvalidOperationException($"Command Client already registered for type {commandType.GetNiceName()}"); } commandClients.TryAdd(commandType, commandClient); //_ = Log.InfoAsync($"{nameof(Bus)} Added Command Client For {commandType.GetNiceName()}"); } } }
public RegisteredSubProvider( IContextMenuCommandProvider subProvider, ICommandService commandService, ICommandClient client) { m_commands = subProvider.GetCommands(null, null); foreach (var c in m_commands) { var description = GetAnnotatedDescription(c).Localize(); commandService.RegisterCommand( c, StandardMenu.File, CustomCommandGroups.NodeSpecific, description, description, Sce.Atf.Input.Keys.None, null, CommandVisibility.ContextMenu, client); } }
/// <summary> /// Sets the active client that receives a command, for the case when multiple /// ICommandClient objects have registered for the same command tag (such as the /// StandardCommand.EditCopy enum, for example). Set to null to reduce the priority /// of the previously active client.</summary> /// <param name="client">Command client, null if client is deactivated</param> public void SetActiveClient(ICommandClient client) { List<object> commandTags = new List<object>(m_commandClients.Keys); // 'client' being null is an indication to pop the most recently active client if (client == null && m_activeClient != null) { // make sure previous client will NOT be the last registered for its command tags foreach (object commandTag in commandTags) { if (m_commandClients.ContainsKeyValue(commandTag, m_activeClient)) m_commandClients.AddFirst(commandTag, m_activeClient); } } m_activeClient = client; if (m_activeClient != null) { // make sure client will be the last registered for its command tags foreach (object commandTag in commandTags) { if (m_commandClients.ContainsKeyValue(commandTag, client)) m_commandClients.Add(commandTag, client); } } }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut, or Keys.None if none</param> /// <param name="imageKey">Object identifying image, or null if none</param> /// <param name="visibility">Whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, Keys shortcut, object imageKey, CommandVisibility visibility, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description, shortcut, imageKey, visibility); commandService.RegisterCommand(info, client); return info; }
/// <summary> /// Creates and registers a command</summary> /// <param name="commandRegistry">ICommandService</param> /// <param name="commandTag">Unique command ID</param> /// <param name="menuTag">Unique ID for menu command attached to</param> /// <param name="groupTag">Unique ID for command's group</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="client">ICommandClient</param> /// <returns>ICommandItem for command</returns> public static ICommandItem RegisterCommand( this ICommandService commandRegistry, object commandTag, object menuTag, object groupTag, string menuText, string description, ICommandClient client) { Requires.NotNull(commandRegistry, "commandRegistry"); var def = new CommandDef(commandTag, menuTag, groupTag, menuText, description); return commandRegistry.RegisterCommand(def, client); }
/// <summary> /// Registers a command for a command client</summary> /// <param name="info">Command description; standard commands are defined as static /// members on the CommandInfo class</param> /// <param name="client">Client that handles the command</param> public override void RegisterCommand(CommandInfo info, ICommandClient client) { base.RegisterCommand(info, client); m_commandsSorted = false; }
private void UpdateCommand(CommandInfo info, ICommandClient client) { if (m_mainForm.InvokeRequired) { m_mainForm.BeginInvoke(new Action<CommandInfo>(UpdateCommand), info); return; } ToolStripMenuItem menuItem; ToolStripButton menuButton; info.GetMenuItemAndButton(out menuItem, out menuButton); CommandState commandState = new CommandState(); commandState.Text = info.DisplayedMenuText; commandState.Check = menuItem.Checked; bool enabled = false; if (client != null) { enabled = client.CanDoCommand(info.CommandTag); if (enabled) client.UpdateCommand(info.CommandTag, commandState); } string menuText = commandState.Text.Trim(); menuItem.Text = menuButton.Text = menuText; menuItem.Checked = menuButton.Checked = commandState.Check; menuItem.Enabled = menuButton.Enabled = enabled; }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="visibility">Whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>Menu/Toolbar command information</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, StandardCommand commandTag, CommandVisibility visibility, ICommandClient client) { CommandInfo info = CommandInfo.GetStandardCommand(commandTag); commandService.RegisterCommand(info, client); info.Visibility = visibility; return info; }
/// <summary> /// Unregisters a command for a command client</summary> /// <param name="commandTag">Command tag that identifies CommandInfo used to register /// the command</param> /// <param name="client">Client that handles the command</param> public override void UnregisterCommand(object commandTag, ICommandClient client) { base.UnregisterCommand(commandTag, client); RemoveToolStripItem(commandTag); }
/// <summary> /// Indicates whether or not the CheckCanDo event is supported. Call this before /// this CommandInfo is registered with a command service to have improved performance /// by saving the command service from having to poll the command client.</summary> /// <param name="client">Command client that will register this CommandInfo</param> /// <remarks>This method is only applicable to WinForms version of CommandService.</remarks> public void EnableCheckCanDoEvent(ICommandClient client) { m_checkCanDoClients.Add(client); }
/// <summary> /// Raises the CheckCanDo event. ICommandClients can call EnableCheckCanDoEvent before /// registering this CommandInfo and then can call this method for greatly improved performance.</summary> /// <param name="client">Command client that registered this CommandInfo</param> /// <remarks>This method is only applicable to WinForms version of CommandService.</remarks> public void OnCheckCanDo(ICommandClient client) { if (!m_checkCanDoClients.Contains(client)) throw new InvalidOperationException("Call EnableCheckCanDoEvent before calling OnCheckCanDo"); CheckCanDo.Raise(this, EventArgs.Empty); }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description); commandService.RegisterCommand(info, client); return info; }
/// <summary> /// Registers a command for the command client</summary> /// <param name="commandService">Command service</param> /// <param name="commandTag">Command's unique ID</param> /// <param name="menuTag">Containing menu's unique ID, or null</param> /// <param name="groupTag">Containing menu group's unique ID, or null</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut, or Keys.None if none</param> /// <param name="imageName">Text identifying image, or null if none</param> /// <param name="visibility">Value describing whether command is visible in menus and toolbars</param> /// <param name="client">Client that performs command</param> /// <returns>CommandInfo object describing command</returns> public static CommandInfo RegisterCommand( this ICommandService commandService, object commandTag, object menuTag, object groupTag, string menuText, string description, System.Windows.Forms.Keys shortcut, string imageName, CommandVisibility visibility, ICommandClient client) { CommandInfo info = new CommandInfo(commandTag, menuTag, groupTag, menuText, description, KeysInterop.ToAtf(shortcut), imageName, visibility); commandService.RegisterCommand(info, client); return info; }
/// <summary> /// Creates and registers a command</summary> /// <param name="commandRegistry">ICommandService</param> /// <param name="commandTag">Unique command ID</param> /// <param name="menuTag">Unique ID for menu command attached to</param> /// <param name="groupTag">Unique ID for command's group</param> /// <param name="menuText">Command text as it appears in menu</param> /// <param name="description">Command description</param> /// <param name="shortcut">Command shortcut</param> /// <param name="imageSourceKey">Image resource for command</param> /// <param name="visibility">Flags indicating where command is visible: on toolbar, menus, etc.</param> /// <param name="client">ICommandClient</param> /// <returns>ICommandItem for command</returns> public static ICommandItem RegisterCommand( this ICommandService commandRegistry, object commandTag, object menuTag, object groupTag, string menuText, string description, KeyGesture shortcut, object imageSourceKey, CommandVisibility visibility, ICommandClient client) { Requires.NotNull(commandRegistry, "commandRegistry"); var gestures = shortcut != null ? new InputGesture[] { shortcut } : null; var def = new CommandDef(commandTag, menuTag, groupTag, menuText, null, description, imageSourceKey, gestures, visibility); return commandRegistry.RegisterCommand(def, client); }