コード例 #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);
        }
コード例 #2
0
ファイル: DataViewModel.cs プロジェクト: viswanathr88/Mirage
        /// <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);
            }
        }
コード例 #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);
            }
        }
コード例 #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));
        }
コード例 #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();
        }
コード例 #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());
        }
コード例 #7
0
ファイル: DataViewModel.cs プロジェクト: viswanathr88/Mirage
        /// <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);
        }
コード例 #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);
        }
コード例 #9
0
ファイル: MenuManager.cs プロジェクト: LiMengliang/PhotoApp
 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);
     }
 }
コード例 #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);
     }
 }
コード例 #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
            });
        }
コード例 #12
0
 public void AddMenuCommand(ICommandEx command)
 {
 }
コード例 #13
0
        public ShellMenuItem(ICommandEx command)
        {
            CommandEx = command;

            Header = CommandEx.LabelTitle;
        }
コード例 #14
0
ファイル: ShellMenuItem.cs プロジェクト: LiMengliang/PhotoApp
        public ShellMenuItem(ICommandEx command)
        {
            CommandEx = command;

            Header = CommandEx.LabelTitle;
        }
コード例 #15
0
        private static ICommandEx ConvertSeparatorMenuItemToCommandEx(IMenuItem separator, ICommandEx previousCommand)
        {
            var separatorCommand = CommandHelpers.CreateAdjacentSeparator(previousCommand);

            separatorCommand.Weight = separator.Weight;

            return(separatorCommand);
        }
コード例 #16
0
ファイル: MenuManager.cs プロジェクト: LiMengliang/PhotoApp
 public void AddMenuCommand(ICommandEx command)
 {
 }
コード例 #17
0
 public override ICommandVisualFactory GetDefaultVisualFactory(ICommandEx command)
 {
     return(ListBoxItemFactory.ForConfigurationPane);
 }