コード例 #1
0
ファイル: Command.cs プロジェクト: DraTeots/gemini
 public Command(CommandDefinitionBase commandDefinition)
 {
     _commandDefinition = commandDefinition;
     Text = commandDefinition.Text;
     ToolTip = commandDefinition.ToolTip;
     IconSource = commandDefinition.IconSource;
 }
コード例 #2
0
ファイル: CommandService.cs プロジェクト: DraTeots/gemini
 public Command GetCommand(CommandDefinitionBase commandDefinition)
 {
     Command command;
     if (!_commands.TryGetValue(commandDefinition, out command))
         command = _commands[commandDefinition] = new Command(commandDefinition);
     return command;
 }
コード例 #3
0
 public Command(CommandDefinitionBase commandDefinition)
 {
     _commandDefinition = commandDefinition;
     Text       = commandDefinition.Text;
     ToolTip    = commandDefinition.ToolTip;
     IconSource = commandDefinition.IconSource;
 }
コード例 #4
0
ファイル: CommandRouter.cs プロジェクト: DraTeots/gemini
        public CommandHandlerWrapper GetCommandHandler(CommandDefinitionBase commandDefinition)
        {
            CommandHandlerWrapper commandHandler;

            var shell = IoC.Get<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;
        }
コード例 #5
0
 public KeyGesture GetPrimaryKeyGesture(CommandDefinitionBase commandDefinition)
 {
     var keyboardShortcut = _keyboardShortcuts.FirstOrDefault(x => x.CommandDefinition == commandDefinition);
     return (keyboardShortcut != null)
         ? keyboardShortcut.KeyGesture
         : null;
 }
コード例 #6
0
ファイル: CommandRouter.cs プロジェクト: danjmackay/gemini
        public CommandHandlerWrapper GetCommandHandler(CommandDefinitionBase commandDefinition)
        {
            CommandHandlerWrapper commandHandler;

            var activeItemViewModel = IoC.Get<IShell>().ActiveLayoutItem;
            if (activeItemViewModel != null)
            {
                var activeItemView = ViewLocator.LocateForModel(activeItemViewModel, null, null);
                var activeItemWindow = Window.GetWindow(activeItemView);
                if (activeItemWindow != null)
                {
                    var startElement = FocusManager.GetFocusedElement(activeItemWindow);

                    // First, we look at the currently focused element, and iterate up through
                    // the tree, giving each DataContext a chance to handle the command.
                    commandHandler = FindCommandHandlerInVisualTree(commandDefinition, startElement);
                    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;
        }
コード例 #7
0
ファイル: CommandRouter.cs プロジェクト: zhangf911/gemini
        public CommandHandlerWrapper GetCommandHandler(CommandDefinitionBase commandDefinition)
        {
            CommandHandlerWrapper commandHandler;

            var activeItemViewModel = IoC.Get <IShell>().ActiveLayoutItem;

            if (activeItemViewModel != null)
            {
                var activeItemView   = ViewLocator.LocateForModel(activeItemViewModel, null, null);
                var activeItemWindow = Window.GetWindow(activeItemView);
                if (activeItemWindow != null)
                {
                    var startElement = FocusManager.GetFocusedElement(activeItemWindow);

                    // First, we look at the currently focused element, and iterate up through
                    // the tree, giving each DataContext a chance to handle the command.
                    commandHandler = FindCommandHandlerInVisualTree(commandDefinition, startElement);
                    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);
        }
コード例 #8
0
        public KeyGesture GetPrimaryKeyGesture(CommandDefinitionBase commandDefinition)
        {
            var keyboardShortcut = _keyboardShortcuts.FirstOrDefault(x => x.CommandDefinition == commandDefinition);

            return((keyboardShortcut != null)
                ? keyboardShortcut.KeyGesture
                : null);
        }
コード例 #9
0
ファイル: CommandService.cs プロジェクト: yvanvds/gemini
        public Command GetCommand(CommandDefinitionBase commandDefinition)
        {
            Command command;

            if (!_commands.TryGetValue(commandDefinition, out command))
            {
                command = _commands[commandDefinition] = new Command(commandDefinition);
            }
            return(command);
        }
コード例 #10
0
        object ICommandRerouter.GetHandler(CommandDefinitionBase commandDefinition)
        {
            if (commandDefinition is UndoCommandDefinition ||
                commandDefinition is RedoCommandDefinition)
            {
                return _shell.ActiveItem;
            }

            return null;
        }
コード例 #11
0
ファイル: CommandRouter.cs プロジェクト: yvanvds/gemini
        private CommandHandlerWrapper GetCommandHandlerForLayoutItem(CommandDefinitionBase commandDefinition, object activeItemViewModel)
        {
            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));
        }
コード例 #12
0
ファイル: CommandRouter.cs プロジェクト: yvanvds/gemini
        private CommandHandlerWrapper FindCommandHandlerInVisualTree(CommandDefinitionBase commandDefinition, IInputElement target)
        {
            var visualObject = target as DependencyObject;

            if (visualObject == null)
            {
                return(null);
            }

            object previousDataContext = null;

            do
            {
                var frameworkElement = visualObject as FrameworkElement;
                if (frameworkElement != null)
                {
                    var dataContext = frameworkElement.DataContext;
                    if (dataContext != null && !ReferenceEquals(dataContext, previousDataContext))
                    {
                        if (dataContext is ICommandRerouter)
                        {
                            var commandRerouter = (ICommandRerouter)dataContext;
                            var 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);
        }
コード例 #13
0
ファイル: CommandRouter.cs プロジェクト: yvanvds/gemini
        public CommandHandlerWrapper GetCommandHandler(CommandDefinitionBase commandDefinition)
        {
            CommandHandlerWrapper commandHandler;

            var shell = IoC.Get <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);
        }
コード例 #14
0
ファイル: CommandRouter.cs プロジェクト: DraTeots/gemini
        private CommandHandlerWrapper GetCommandHandlerForLayoutItem(CommandDefinitionBase commandDefinition, object activeItemViewModel)
        {
            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);
        }
コード例 #15
0
ファイル: CommandRouter.cs プロジェクト: DraTeots/gemini
        private CommandHandlerWrapper FindCommandHandlerInVisualTree(CommandDefinitionBase commandDefinition, IInputElement target)
        {
            var visualObject = target as DependencyObject;
            if (visualObject == null)
                return null;

            object previousDataContext = null;
            do
            {
                var frameworkElement = visualObject as FrameworkElement;
                if (frameworkElement != null)
                {
                    var dataContext = frameworkElement.DataContext;
                    if (dataContext != null && !ReferenceEquals(dataContext, previousDataContext))
                    {
                        if (dataContext is ICommandRerouter)
                        {
                            var commandRerouter = (ICommandRerouter) dataContext;
                            var 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;
        }