//static InputBindings()
		//{
		//}

		//public InputBindings(InputBindingCollection bindingsOwner)
		//{
		//	_inputBindings = bindingsOwner;
		//	_stash = new Stack<KeyBinding>();
		//}

		public static void Initialize(InputBindingCollection inputBindings, ActionBinding[] entries)
		{
			_inputBindings = inputBindings;
			_entriesAll = entries;

			_stash = new Stack<KeyBinding>();
		}
Esempio n. 2
0
        /// <summary>
        ///     Register class level InputBindings.
        /// </summary>
        /// <param name="type">Owner type</param>
        /// <param name="inputBinding">InputBinding to register</param>
        public static void RegisterClassInputBinding(Type type, InputBinding inputBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (inputBinding == null)
            {
                throw new ArgumentNullException("inputBinding");
            }

            lock (_classInputBindings.SyncRoot)
            {
                InputBindingCollection inputBindings = _classInputBindings[type] as InputBindingCollection;

                if (inputBindings == null)
                {
                    inputBindings             = new InputBindingCollection();
                    _classInputBindings[type] = inputBindings;
                }

                inputBindings.Add(inputBinding);

                if (!inputBinding.IsFrozen)
                {
                    inputBinding.Freeze();
                }
            }
        }
Esempio n. 3
0
 public static void RemoveKeyBindings(this swi.InputBindingCollection bindings, swc.ItemCollection items)
 {
     foreach (var item in items.OfType <sw.UIElement>())
     {
         bindings.RemoveKeyBindings(item);
     }
 }
Esempio n. 4
0
        public MainPage()
        {
            InitializeComponent();

            OpenHelpPageCommand = new DelegateCommand(ExecuteOpenHelpPage);
            this.DataContext = OpenHelpPageCommand;
            InputBindingCollection inputBindCollection = new InputBindingCollection();
            inputBindCollection.Add(new KeyBinding(this.OpenHelpPageCommand, new KeyGesture(Key.F1)));
            CommandManager.SetInputBindings(this, inputBindCollection);
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the value of the Menu attached property to a given DependencyObject. 
        /// </summary>
        /// <param name="element">The element on which to set the property value.</param>
        /// <param name="value">The property value to set.</param>
        public static void SetInputBindings(UIElement control, InputBindingCollection value)
        {
            // preconditions

            Argument.IsNotNull("control", control);

            // implementation

            control.SetValue(InputBindingsProperty, value);
        }
Esempio n. 6
0
        public static void AddKeyBindings(this swi.InputBindingCollection bindings, sw.UIElement item)
        {
            if (item == null)
            {
                return;
            }
            bindings.AddRange(item.InputBindings);
            var itemsControl = item as swc.ItemsControl;

            if (itemsControl != null && itemsControl.HasItems)
            {
                AddKeyBindings(bindings, itemsControl.Items);
            }
        }
Esempio n. 7
0
        public static void RemoveKeyBindings(this swi.InputBindingCollection bindings, sw.UIElement item)
        {
            if (item == null)
            {
                return;
            }
            foreach (var binding in item.InputBindings.OfType <swi.InputBinding>())
            {
                bindings.Remove(binding);
            }

            var itemsControl = item as swc.ItemsControl;

            if (itemsControl != null && itemsControl.HasItems)
            {
                RemoveKeyBindings(bindings, itemsControl.Items);
            }
        }
 public InputBindings(Window bindingsOwner)
 {
     _inputBindings = bindingsOwner.InputBindings;
     _stash = new Stack<KeyBinding>();
 }
Esempio n. 9
0
        /// <summary>
        /// コマンドを操作にバインディングします。
        /// </summary>
        public static void Binding(InputBindingCollection inputs)
        {
            inputs.Add(
                new KeyBinding(MoveUndo,
                    new KeyGesture(Key.Left)));
            inputs.Add(
                new KeyBinding(MoveRedo,
                    new KeyGesture(Key.Right)));

            inputs.Add(
                new KeyBinding(LoadKifFile,
                    new KeyGesture(Key.O, ModifierKeys.Control)));
            inputs.Add(
                new KeyBinding(SaveKifFile,
                    new KeyGesture(Key.A, ModifierKeys.Control)));

            inputs.Add(
                new KeyBinding(PasteKifFile,
                    new KeyGesture(Key.V, ModifierKeys.Control)));
            inputs.Add(
                new KeyBinding(CopyKifFile,
                    new KeyGesture(Key.C, ModifierKeys.Control)));
        }
Esempio n. 10
0
 public InputBindings(Window bindingsOwner)
 {
     this.inputBindings = bindingsOwner.InputBindings;
       this.stash = new Stack<KeyBinding>();
 }
Esempio n. 11
0
        public void BindCommands(CommandBindingCollection bindings, InputBindingCollection inputBindings)
        {
            //Switch View
            bindings.Add(new CommandBinding(Commands.SwitchView,
                                        delegate(object target, ExecutedRoutedEventArgs args)
                                        {
                                            OnSwitchView();
                                            args.Handled = true;
                                        }));
            inputBindings.Add(new InputBinding(Commands.SwitchView, new KeyGesture(Key.Enter)));
            
            //Display Next
            bindings.Add(new CommandBinding(Commands.DisplayNext,
                                        delegate(object target, ExecutedRoutedEventArgs args)
                                        {
                                            OnDisplayNext();
                                            args.Handled = true;
                                        }));
            inputBindings.Add(new InputBinding(Commands.DisplayNext, new KeyGesture(Key.PageDown)));

            //Display Prev
            bindings.Add(new CommandBinding(Commands.DisplayPrev,
                                        delegate(object target, ExecutedRoutedEventArgs args)
                                        {
                                            OnDisplayPrev();
                                            args.Handled = true;
                                        }));
            inputBindings.Add(new InputBinding(Commands.DisplayPrev, new KeyGesture(Key.PageUp)));

            //Display First
            bindings.Add(new CommandBinding(Commands.DisplayFirst,
                                        delegate(object target, ExecutedRoutedEventArgs args)
                                        {
                                            OnDisplayFirst();
                                            args.Handled = true;
                                        }));
            inputBindings.Add(new InputBinding(Commands.DisplayFirst, new KeyGesture(Key.Home)));

            //Display Last
            bindings.Add(new CommandBinding(Commands.DisplayLast,
                                        delegate(object target, ExecutedRoutedEventArgs args)
                                        {
                                            OnDisplayLast();
                                            args.Handled = true;
                                        }));
            inputBindings.Add(new InputBinding(Commands.DisplayLast, new KeyGesture(Key.End)));

            //Zoom To Fit
            bindings.Add(new CommandBinding(Commands.ZoomToFit,
                                        delegate(object target, ExecutedRoutedEventArgs args)
                                        {
                                            OnZoomToFit();
                                            args.Handled = true;
                                        }));
            inputBindings.Add(new InputBinding(Commands.ZoomToFit, new KeyGesture(Key.Insert)));
        }
Esempio n. 12
0
        /// <summary>
        ///     Scans input and command bindings for matching gestures and executes the appropriate command
        /// </summary>
        /// <remarks>
        ///     Scans for command to execute in the following order:
        ///     - input bindings associated with the targetElement instance
        ///     - input bindings associated with the targetElement class
        ///     - command bindings associated with the targetElement instance
        ///     - command bindings associated with the targetElement class
        /// </remarks>
        /// <param name="targetElement">UIElement/ContentElement to be scanned for input and command bindings</param>
        /// <param name="inputEventArgs">InputEventArgs to be matched against for gestures</param>
        internal static void TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs)
        {
            if ((targetElement == null) || (inputEventArgs == null))
            {
                return;
            }

            ICommand      command   = null;
            IInputElement target    = null;
            object        parameter = null;

            // Determine UIElement/ContentElement/Neither type
            DependencyObject targetElementAsDO = targetElement as DependencyObject;
            bool             isUIElement       = InputElement.IsUIElement(targetElementAsDO);
            bool             isContentElement  = !isUIElement && InputElement.IsContentElement(targetElementAsDO);
            bool             isUIElement3D     = !isUIElement && !isContentElement && InputElement.IsUIElement3D(targetElementAsDO);

            // Step 1: Check local input bindings
            InputBindingCollection localInputBindings = null;

            if (isUIElement)
            {
                localInputBindings = ((UIElement)targetElement).InputBindingsInternal;
            }
            else if (isContentElement)
            {
                localInputBindings = ((ContentElement)targetElement).InputBindingsInternal;
            }
            else if (isUIElement3D)
            {
                localInputBindings = ((UIElement3D)targetElement).InputBindingsInternal;
            }
            if (localInputBindings != null)
            {
                InputBinding inputBinding = localInputBindings.FindMatch(targetElement, inputEventArgs);
                if (inputBinding != null)
                {
                    command   = inputBinding.Command;
                    target    = inputBinding.CommandTarget;
                    parameter = inputBinding.CommandParameter;
                }
            }

            // Step 2: If no command, check class input bindings
            if (command == null)
            {
                lock (_classInputBindings.SyncRoot)
                {
                    Type classType = targetElement.GetType();
                    while (classType != null)
                    {
                        InputBindingCollection classInputBindings = _classInputBindings[classType] as InputBindingCollection;
                        if (classInputBindings != null)
                        {
                            InputBinding inputBinding = classInputBindings.FindMatch(targetElement, inputEventArgs);
                            if (inputBinding != null)
                            {
                                command   = inputBinding.Command;
                                target    = inputBinding.CommandTarget;
                                parameter = inputBinding.CommandParameter;
                                break;
                            }
                        }
                        classType = classType.BaseType;
                    }
                }
            }

            // Step 3: If no command, check local command bindings
            if (command == null)
            {
                // Check for the instance level ones Next
                CommandBindingCollection localCommandBindings = null;
                if (isUIElement)
                {
                    localCommandBindings = ((UIElement)targetElement).CommandBindingsInternal;
                }
                else if (isContentElement)
                {
                    localCommandBindings = ((ContentElement)targetElement).CommandBindingsInternal;
                }
                else if (isUIElement3D)
                {
                    localCommandBindings = ((UIElement3D)targetElement).CommandBindingsInternal;
                }
                if (localCommandBindings != null)
                {
                    command = localCommandBindings.FindMatch(targetElement, inputEventArgs);
                }
            }

            // Step 4: If no command, look at class command bindings
            if (command == null)
            {
                lock (_classCommandBindings.SyncRoot)
                {
                    Type classType = targetElement.GetType();
                    while (classType != null)
                    {
                        CommandBindingCollection classCommandBindings = _classCommandBindings[classType] as CommandBindingCollection;
                        if (classCommandBindings != null)
                        {
                            command = classCommandBindings.FindMatch(targetElement, inputEventArgs);
                            if (command != null)
                            {
                                break;
                            }
                        }
                        classType = classType.BaseType;
                    }
                }
            }

            // Step 5: If found a command, then execute it (unless it is
            // the special "NotACommand" command, which we simply ignore without
            // setting Handled=true, so that the input bubbles up to the parent)
            if (command != null && command != ApplicationCommands.NotACommand)
            {
                // We currently do not support declaring the element with focus as the target
                // element by setting target == null.  Instead, we interpret a null target to indicate
                // the element that we are routing the event through, e.g. the targetElement parameter.
                if (target == null)
                {
                    target = targetElement;
                }

                bool continueRouting = false;

                RoutedCommand routedCommand = command as RoutedCommand;
                if (routedCommand != null)
                {
                    if (routedCommand.CriticalCanExecute(parameter,
                                                         target,
                                                         inputEventArgs.UserInitiated /*trusted*/,
                                                         out continueRouting))
                    {
                        // If the command can be executed, we never continue to route the
                        // input event.
                        continueRouting = false;

                        ExecuteCommand(routedCommand, parameter, target, inputEventArgs);
                    }
                }
                else
                {
                    if (command.CanExecute(parameter))
                    {
                        command.Execute(parameter);
                    }
                }

                // If we mapped an input event to a command, we should always
                // handle the input event - regardless of whether the command
                // was executed or not.  Unless the CanExecute handler told us
                // to continue the route.
                inputEventArgs.Handled = !continueRouting;
            }
        }
Esempio n. 13
0
        /// <summary>
        ///     Register class level InputBindings.
        /// </summary>
        /// <param name="type">Owner type</param>
        /// <param name="inputBinding">InputBinding to register</param>
        public static void RegisterClassInputBinding(Type type, InputBinding inputBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (inputBinding == null)
            {
                throw new ArgumentNullException("inputBinding");
            }

            lock (_classInputBindings.SyncRoot)
            {
                InputBindingCollection inputBindings = _classInputBindings[type] as InputBindingCollection;

                if (inputBindings == null)
                {
                    inputBindings = new InputBindingCollection();
                    _classInputBindings[type] = inputBindings;
                }

                inputBindings.Add(inputBinding);

                if (!inputBinding.IsFrozen)
                {
                    inputBinding.Freeze();
                }
            }
        }
Esempio n. 14
0
 public static void SetInputBinding(InputBindingCollection inputCollection, ICommand command, InputGesture gesture)
 {
     var binding = new InputBinding(command, gesture);
     inputCollection.Remove(binding);
     inputCollection.Add(binding);
 }
 public static void SetInputBindingsCollection(DependencyObject obj, InputBindingCollection value)
 {
     obj.SetValue(InputBindingsProperty, value);
 }
Esempio n. 16
0
 public static InputBindingCollection IBC(params InputBinding[] inputBindings)
 {
     InputBindingCollection collection = new InputBindingCollection(inputBindings);
     return collection;
 }
Esempio n. 17
0
 public static void SetAttachedInputBindings(DependencyObject obj, InputBindingCollection value)
 {
     obj.SetValue(FocusHelper.AttachedInputBindingsProperty, (object)value);
 }
 public static void SetInputBindings( UIElement element, InputBindingCollection inputBindings )
 {
     element.SetValue( InputBindingsProperty, inputBindings );
 }
 private void EditInputBinding(MenuItem menu, ModifierKeys modifier) {
     KeyConverter k = new KeyConverter();
     Key key = (Key)k.ConvertFromString(menu.InputGestureText);
     InputBindingCollection InputBindingsCopy = new InputBindingCollection(InputBindings);
     foreach (KeyBinding item in InputBindingsCopy) {
         if (item.Key == key) {
             if (modifier == ModifierKeys.None)
                 InputBindings.Remove(item);
             else {
                 item.Modifiers = modifier;
                 if (modifier == ModifierKeys.Control)
                     menu.InputGestureText = "CTRL+" + menu.InputGestureText;
             }
             break;
         }
     }
 }