Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        /// <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));
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        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());
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
 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);
     }
 }
Ejemplo n.º 10
0
 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);
     }
 }
Ejemplo n.º 11
0
        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
            });
        }
Ejemplo n.º 12
0
 public void AddMenuCommand(ICommandEx command)
 {
 }
Ejemplo n.º 13
0
        public ShellMenuItem(ICommandEx command)
        {
            CommandEx = command;

            Header = CommandEx.LabelTitle;
        }
Ejemplo n.º 14
0
        public ShellMenuItem(ICommandEx command)
        {
            CommandEx = command;

            Header = CommandEx.LabelTitle;
        }
Ejemplo n.º 15
0
        private static ICommandEx ConvertSeparatorMenuItemToCommandEx(IMenuItem separator, ICommandEx previousCommand)
        {
            var separatorCommand = CommandHelpers.CreateAdjacentSeparator(previousCommand);

            separatorCommand.Weight = separator.Weight;

            return(separatorCommand);
        }
Ejemplo n.º 16
0
 public void AddMenuCommand(ICommandEx command)
 {
 }
Ejemplo n.º 17
0
 public override ICommandVisualFactory GetDefaultVisualFactory(ICommandEx command)
 {
     return(ListBoxItemFactory.ForConfigurationPane);
 }