/// <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 void UnregisterCommand(object commandTag, Sce.Atf.Applications.ICommandClient client) { // TODO: is this sequence of operations thread safe? var clientAdapter = GetOrCreateClientAdapter(client); var command = clientAdapter.RemoveCommand(commandTag); if (command != null) { m_commandService.UnregisterCommand(command, clientAdapter); } }
/// <summary> /// Registers a command for a command client. /// NOTE: CommandInfo.MenuItem and CommandInfo.Button will not be valid. /// Shortcut related properties and methods on CommandInfo will have no effect.</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 void RegisterCommand(Sce.Atf.Applications.CommandInfo info, Sce.Atf.Applications.ICommandClient client) { // Embedded image resources will not be available as WPF app resources // If image resource does not exist we need to create it and add it to app resources object imageResourceKey = null; if (!string.IsNullOrEmpty(info.ImageName)) { var embeddedImage = ResourceUtil.GetImage(info.ImageName); if (embeddedImage == null) { throw new InvalidOperationException("Could not find embedded image: " + info.ImageName); } Util.GetOrCreateResourceForEmbeddedImage(embeddedImage); imageResourceKey = embeddedImage; } // Convert text and path string displayText = GetDisplayMenuText(info.MenuText); info.DisplayedMenuText = displayText; string[] menuPath = GetMenuPath(info.MenuText); // Convert shortcuts var inputGestures = new List <InputGesture>(); foreach (var formsKey in info.Shortcuts) { inputGestures.Add(Util.ConvertKey(formsKey)); } // Create and register command passing this as command client var def = new CommandDef( info.CommandTag, info.MenuTag, info.GroupTag, displayText, menuPath, info.Description, imageResourceKey, inputGestures.ToArray <InputGesture>(), info.Visibility); var clientAdapter = GetOrCreateClientAdapter(client); var command = m_commandService.RegisterCommand(def, clientAdapter); clientAdapter.AddCommand(command); }
private CommandClientAdapter GetOrCreateClientAdapter(Sce.Atf.Applications.ICommandClient client) { CommandClientAdapter adapter; if (!m_clientAdapters.TryGetValue(client, out adapter)) { adapter = new CommandClientAdapter(client); lock (m_clientAdapters) { m_clientAdapters.Add(client, adapter); } } return(adapter); }
public CommandClientAdapter(Sce.Atf.Applications.ICommandClient adaptee) { m_adaptee = adaptee; }
/// <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(Sce.Atf.Applications.ICommandClient client) { var clientAdapter = GetOrCreateClientAdapter(client); m_commandService.SetActiveClient(clientAdapter); }