Esempio n. 1
0
        public MesCommand GetCommand(MesCommandDefinitionBase commandDefinition)
        {
            MesCommand command;

            if (!_commands.TryGetValue(commandDefinition, out command))
            {
                command = _commands[commandDefinition] = new MesCommand(commandDefinition);
            }
            return(command);
        }
Esempio n. 2
0
        private MesCommandHandlerWrapper FindCommandHandlerInVisualTree(MesCommandDefinitionBase commandDefinition, IInputElement target)
        {
            if (!(target is DependencyObject visualObject))
            {
                return(null);
            }

            Object previousDataContext = null;

            do
            {
                if (visualObject is FrameworkElement frameworkElement)
                {
                    Object dataContext = frameworkElement.DataContext;
                    if (dataContext != null && !ReferenceEquals(dataContext, previousDataContext))
                    {
                        if (dataContext is IMesCommandRerouter commandRerouter)
                        {
                            Object commandTarget = commandRerouter.GetHandler(commandDefinition);
                            if (commandTarget != null)
                            {
                                if (IsCommandHandlerForCommandDefinitionType(commandTarget, commandDefinition.GetType()))
                                {
                                    return(CreateCommandHandlerWrapper(commandDefinition.GetType(), commandTarget));
                                }

                                throw new InvalidOperationException("This object does not handle the specified command definition.");
                            }
                        }

                        if (IsCommandHandlerForCommandDefinitionType(dataContext, commandDefinition.GetType()))
                        {
                            return(CreateCommandHandlerWrapper(commandDefinition.GetType(), dataContext));
                        }

                        previousDataContext = dataContext;
                    }
                }
                visualObject = VisualTreeHelper.GetParent(visualObject);
            } while (visualObject != null);

            return(null);
        }
Esempio n. 3
0
        private MesCommandHandlerWrapper GetCommandHandlerForLayoutItem(MesCommandDefinitionBase commandDefinition, object activeItemViewModel)
        {
#warning GetCommandHendlerForLayoutItem
#if false
            var activeItemView   = ViewLocator.LocateForModel(activeItemViewModel, null, null);
            var activeItemWindow = Window.GetWindow(activeItemView);
            if (activeItemWindow == null)
            {
                return(null);
            }

            var startElement = FocusManager.GetFocusedElement(activeItemView) ?? activeItemView;

            // First, we look at the currently focused element, and iterate up through
            // the tree, giving each DataContext a chance to handle the command.
            return(FindCommandHandlerInVisualTree(commandDefinition, startElement));
#endif
            throw new NotImplementedException();
        }
Esempio n. 4
0
        public MesCommandHandlerWrapper GetCommandHandler(MesCommandDefinitionBase commandDefinition)
        {
#warning GetCommandHandler
#if false
            CommandHandlerWrapper commandHandler;

            var shell = Mvx.IoCProvider.Resolve <IShell>();

            var activeItemViewModel = shell.ActiveLayoutItem;
            if (activeItemViewModel != null)
            {
                commandHandler = GetCommandHandlerForLayoutItem(commandDefinition, activeItemViewModel);
                if (commandHandler != null)
                {
                    return(commandHandler);
                }
            }

            var activeDocumentViewModel = shell.ActiveItem;
            if (activeDocumentViewModel != null && !Equals(activeDocumentViewModel, activeItemViewModel))
            {
                commandHandler = GetCommandHandlerForLayoutItem(commandDefinition, activeDocumentViewModel);
                if (commandHandler != null)
                {
                    return(commandHandler);
                }
            }

            // If none of the objects in the DataContext hierarchy handle the command,
            // fallback to the global handler.
            if (!_globalCommandHandlerWrappers.TryGetValue(commandDefinition.GetType(), out commandHandler))
            {
                return(null);
            }

            return(commandHandler);
#endif
            throw new NotImplementedException();
        }
        public KeyGesture GetPrimaryKeyGesture(MesCommandDefinitionBase commandDefinition)
        {
            var keyboardShortcut = _keyboardShortcuts.FirstOrDefault(x => x.CommandDefinition == commandDefinition);

            return(keyboardShortcut?.KeyGesture);
        }
 public MesCommandToolBarItemDefinition(MesToolBarItemGroupDefinition group, int sortOrder, ToolBarItemDisplay display = ToolBarItemDisplay.IconOnly)
     : base(group, sortOrder, display)
 {
     _commandDefinition = Mvx.IoCProvider.Resolve <IMesCommandService>().GetCommandDefinition(typeof(TCommandDefinition));
     _keyGesture        = Mvx.IoCProvider.Resolve <IMesCommandKeyGestureService>().GetPrimaryKeyGesture(_commandDefinition);
 }
 public MesCommandMenuItemDefinition(MesMenuItemGroupDefinition group, int sortOrder)
     : base(group, sortOrder)
 {
     _commandDefinition = Mvx.IoCProvider.Resolve <IMesCommandService>().GetCommandDefinition(typeof(TCommandDefinition));
     _keyGesture        = Mvx.IoCProvider.Resolve <IMesCommandKeyGestureService>().GetPrimaryKeyGesture(_commandDefinition);
 }