public override void Attach(ICommandEx command, PlatformVisual visual, ICommandAttachContext context) { var listBoxItem = (ListBoxItem)GetCommandSourceForVisual(visual); listBoxItem.Command = command; listBoxItem.CommandParameter = new ChoiceCommandParameter(command); base.Attach(command, visual, context); }
/// <summary> /// Deregister a command /// </summary> /// <param name="command"></param> protected void DeregisterCommand(ICommandEx command) { if (this.commands.ContainsKey(command)) { command.Executing -= OnCommandExecuting; command.Executed -= OnCommandExecuted; this.commands.Remove(command); } }
internal void RegisterCommandsByPropertyNames(ICommandEx command, Expression body, string[] additionalProperties) { var propertyNames = ExtractPropertyNames(body); foreach (var pn in propertyNames.Union(additionalProperties)) { if (!commands.TryGetValue(pn, out var data)) { data = ImmutableArray <ICommandEx> .Empty; } data = data.Add(command); commands = commands.SetItem(pn, data); } }
/// <summary> /// Override to disable or hide any menu command. Can also change it's text. /// </summary> /// <param name="command">The command. We usually identify by the UniqueId, though they are defined all over the place.</param> /// <param name="sender">generally unused</param> /// <param name="commandParameter">The commandParameter, usually casted to ICommandParameter to do work</param> /// <param name="editSite">The DocumentEditSite</param> /// <param name="handled">set to true if you handle(prevent further processing)</param> /// <returns>true if the command can execute. Returning false will show it as disabled</returns> public override bool CanExecuteCommand(ICommandEx command, object sender, object commandParameter, DocumentEditSite editSite, ref bool handled) { if (ExamplePreferencePageController.HideEditor) { if (commandParameter is ICommandParameter parameter && !_allowedCommands.Contains(command.UniqueId)) { parameter.Visible = false; return(false); } } return(base.CanExecuteCommand(command, sender, commandParameter, editSite, ref handled)); }
public async Task<bool> ProcessAsync(ICommandEx command) { lock (this) { if (command.RemoveIdentifier != null) { foreach (var cmd in _commands.Where(c => c.RemoveIdentifier == command.RemoveIdentifier)) _commands.Remove(cmd); } _commands.Add(command); } return await ProcessAsync(); }
public async Task <bool> ProcessAsync(ICommandEx command) { lock (this) { if (command.RemoveIdentifier != null) { foreach (var cmd in _commands.Where(c => c.RemoveIdentifier == command.RemoveIdentifier)) { _commands.Remove(cmd); } } _commands.Add(command); } return(await ProcessAsync()); }
/// <summary> /// Register a command /// </summary> /// <param name="command">command to register</param> /// <param name="callback">callback when command execution completes</param> protected void RegisterCommand(ICommandEx command, Action <ExecutedEventArgs> callback) { if (command == null || callback == null) { throw new ArgumentNullException("command or callback"); } if (this.commands.ContainsKey(command)) { return; } command.Executing += OnCommandExecuting; command.Executed += OnCommandExecuted; this.commands.Add(command, callback); }
/// <summary> /// Utility method to convert an enumerable of IMenuItems to an enumerable of ICommandEx. /// </summary> /// <param name="menuItems">A list of IMenuItems to convert.</param> public static IEnumerable <ICommandEx> ConvertMenuItemsToCommands(IEnumerable <IMenuItem> menuItems) { var commands = new List <ICommandEx>(); ICommandEx previousCommand = null; foreach (var menuItem in menuItems) { if (menuItem.Type == MenuType.Separator) { commands.Add(ConvertSeparatorMenuItemToCommandEx(menuItem, previousCommand)); continue; } previousCommand = ConvertMenuItemToCommandEx(menuItem); commands.Add(previousCommand); } return(commands); }
private void BuildMenuCommandHierarchy(ICommandEx parentCommand, ICommandSourceParent commandVisual, ShellMenu shellMenu) { if (parentCommand != null) { ICommandSourceParent parentCommandVisual; if (_commandInformations.TryGetValue(parentCommand, out parentCommandVisual)) { parentCommandVisual.AddItem(commandVisual); return; } parentCommandVisual = new ShellMenuItem(parentCommand); parentCommandVisual.AddItem(commandVisual); _commandInformations.Add(parentCommand, parentCommandVisual); parentCommand = parentCommand.MenuCommandParent; BuildMenuCommandHierarchy(parentCommand, parentCommandVisual, shellMenu); } else { shellMenu.AddItem(commandVisual); } }
private static ShellCommandInstance AddGroupCommands(ICommandEx parentCommand, List <ICommandEx> subMenuCommands, double weight) { var subMenuShellCommandInstanceList = new List <ShellCommandInstance>(); foreach (var subMenuCommand in subMenuCommands) { var subMenuShellCommandInstance = subMenuCommand as ShellCommandInstance; subMenuShellCommandInstanceList.Add(subMenuShellCommandInstance ?? new ShellCommandInstance(subMenuCommand)); } var itemsEnumerableCommandParameter = new ItemsEnumerableCommandParameter(parentCommand) { Items = subMenuShellCommandInstanceList }; return(new ShellCommandInstance(parentCommand) { CommandParameter = itemsEnumerableCommandParameter, Weight = weight }); }
public void AddMenuCommand(ICommandEx command) { }
public ShellMenuItem(ICommandEx command) { CommandEx = command; Header = CommandEx.LabelTitle; }
private static ICommandEx ConvertSeparatorMenuItemToCommandEx(IMenuItem separator, ICommandEx previousCommand) { var separatorCommand = CommandHelpers.CreateAdjacentSeparator(previousCommand); separatorCommand.Weight = separator.Weight; return(separatorCommand); }
public override ICommandVisualFactory GetDefaultVisualFactory(ICommandEx command) { return(ListBoxItemFactory.ForConfigurationPane); }