Exemple #1
0
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, 
                                             CanExecuteRoutedEventHandler canExecuteRoutedEventHandler,
                                             InputGesture inputGesture, InputGesture inputGesture2, InputGesture inputGesture3, InputGesture inputGesture4) 
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler,
                                   inputGesture, inputGesture2, inputGesture3, inputGesture4);
 } 
        /// <summary>
        /// Adds the elements of the given collection to the end of this list. If
        /// required, the capacity of the list is increased to twice the previous
        /// capacity or the new size, whichever is larger.
        /// </summary>
        /// <param name="collection">collection to append</param>
        public void AddRange(ICollection collection)
        {
            if (IsReadOnly)
            {
                throw new NotSupportedException(SR.Get(SRID.ReadOnlyInputGesturesCollection));
            }

            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            if (collection.Count > 0)
            {
                if (_innerGestureList == null)
                {
                    _innerGestureList = new System.Collections.Generic.List <InputGesture>(collection.Count);
                }

                IEnumerator collectionEnum = collection.GetEnumerator();
                while (collectionEnum.MoveNext())
                {
                    InputGesture inputGesture = collectionEnum.Current as InputGesture;
                    if (inputGesture != null)
                    {
                        _innerGestureList.Add(inputGesture);
                    }
                    else
                    {
                        throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputGestures));
                    }
                }
            }
        }
 public FullscreenCommand(string name, MainWindow wnd, InputGesture inputGesture)
     : base(name, inputGesture)
 {
     this.wnd = wnd;
     this.wnd.PreviewKeyDown += wnd_PreviewKeyDown;
     this.fullscreenHandler = new FullscreenHandler(wnd);
     this.fullscreenHandler.FullscreenChanged += fullscreenHandler_FullscreenChanged;
 }
 /// <summary>
 /// Contains
 /// </summary>
 /// <param name="key">key</param>
 /// <returns>true - if found, false - otherwise</returns>
 public bool Contains(InputGesture key)
 {
     if (_innerGestureList != null && key != null)
     {
         return(_innerGestureList.Contains(key));
     }
     return(false);
 }
        //------------------------------------------------------
        //
        //  Protected Methods
        //
        //------------------------------------------------------

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
        #region Internal

        internal InputGesture FindMatch(object targetElement, InputEventArgs inputEventArgs)
        {
            for (int i = 0; i < Count; i++)
            {
                InputGesture inputGesture = this[i];
                if (inputGesture.Matches(targetElement, inputEventArgs))
                {
                    return(inputGesture);
                }
            }

            return(null);
        }
        public InputBinding(ICommand command, InputGesture gesture) 
        {   
            if (command == null)
                throw new ArgumentNullException("command");

            if (gesture == null)
                throw new ArgumentNullException("gesture");

            // Check before assignment to avoid continuation
            CheckSecureCommand(command, gesture);

            Command = command;
            _gesture = gesture;
        }
Exemple #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="command">Command</param>
        /// <param name="gesture">Input Gesture</param>
        public InputBinding(ICommand command, InputGesture gesture)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (gesture == null)
            {
                throw new ArgumentNullException("gesture");
            }

            Command  = command;
            _gesture = gesture;
        }
		void CommandTest (RoutedUICommand cmd,
				  string text, string name, InputGesture[] gestures)
		{
			Assert.AreEqual (cmd.OwnerType, typeof (ApplicationCommands));
			Assert.AreEqual (text, cmd.Text);
			Assert.AreEqual (name, cmd.Name);
			if (gestures == null) {
				Assert.AreEqual (0, cmd.InputGestures.Count);
			}
			else {
				Assert.AreEqual (gestures.Length, cmd.InputGestures.Count);
				for (int i = 0; i < gestures.Length; i ++) {
					Assert.AreEqual (gestures[i].GetType(), cmd.InputGestures[i].GetType());
				}
			}
		}
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="inputGesture"></param>
        public int Add(InputGesture inputGesture)
        {
            if (IsReadOnly)
            {
                throw new NotSupportedException(SR.Get(SRID.ReadOnlyInputGesturesCollection));
            }

            if (inputGesture == null)
            {
                throw new ArgumentNullException("inputGesture");
            }

            EnsureList();
            _innerGestureList.Add(inputGesture);
            return(0); // ICollection.Add no longer returns the indice
        }
Exemple #10
0
        void CheckSecureCommand(ICommand command, InputGesture gesture)
        {
            // In v3.5, only ApplicationCommands.Paste was treated as ISecureCommand,
            // causing the below demand to fail if a binding for it was created. As
            // there's no provable security vulnerability and for backwards compat
            // reasons, we special-case Cut and Copy not to be subject to this check
            // even though they have been promoted to ISecureCommand in v4.0.
            ISecureCommand secure = command as ISecureCommand;

            if (secure != null &&
                command != ApplicationCommands.Cut &&
                command != ApplicationCommands.Copy)
            {
                secure.UserInitiatedPermission.Demand();
            }
        }
Exemple #11
0
        protected BaseCommand(string name, InputGesture inputGesture)
        {
            this.Name = name;

            if (inputGesture != null)
            {
                this.InputBinding = new System.Windows.Input.InputBinding(this, inputGesture);

                if (inputGesture is KeyGesture)
                {
                    var kg = (KeyGesture)inputGesture;
                    var keyText = keyReplacements.ContainsKey(kg.Key) ? keyReplacements[kg.Key] : kg.Key.ToString();

                    this.GestureText = modifierText[kg.Modifiers] + keyText;
                }
            }
        }
        /// <summary>
        /// Indexing operator
        /// </summary>
        object IList.this[int index]
        {
            get
            {
                return(this[index]);
            }
            set
            {
                InputGesture inputGesture = value as InputGesture;
                if (inputGesture == null)
                {
                    throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputGestures));
                }

                this[index] = inputGesture;
            }
        }
        /// <summary>
        ///  Insert
        /// </summary>
        /// <param name="index">index at which to insert the item</param>
        /// <param name="inputGesture">item value to insert</param>
        public void Insert(int index, InputGesture inputGesture)
        {
            if (IsReadOnly)
            {
                throw new NotSupportedException(SR.Get(SRID.ReadOnlyInputGesturesCollection));
            }

            if (inputGesture == null)
            {
                throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputGestures));
            }

            if (_innerGestureList != null)
            {
                _innerGestureList.Insert(index, inputGesture);
            }
        }
        /// <summary>
        /// Remove
        /// </summary>
        /// <param name="inputGesture"></param>
        public void Remove(InputGesture inputGesture)
        {
            if (IsReadOnly)
            {
                throw new NotSupportedException(SR.Get(SRID.ReadOnlyInputGesturesCollection));
            }

            if (inputGesture == null)
            {
                throw new ArgumentNullException("inputGesture");
            }

            if (_innerGestureList != null && _innerGestureList.Contains(inputGesture))
            {
                _innerGestureList.Remove(inputGesture as InputGesture);
            }
        }
Exemple #15
0
        public InputBinding(ICommand command, InputGesture gesture)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (gesture == null)
            {
                throw new ArgumentNullException("gesture");
            }

            // Check before assignment to avoid continuation
            CheckSecureCommand(command, gesture);

            Command  = command;
            _gesture = gesture;
        }
Exemple #16
0
        void CheckSecureCommand(ICommand command, InputGesture gesture)
        {
            // In v3.5, only ApplicationCommands.Paste was treated as ISecureCommand,
            // causing the below demand to fail if a binding for it was created. As
            // there's no provable security vulnerability and for backwards compat
            // reasons, we special-case Cut and Copy not to be subject to this check
            // even though they have been promoted to ISecureCommand in v4.0.
            //
            // See Dev10 bug 815844 on reevaluating the threat model around protection
            // of key bindings. The following demand may be unnecessary or misguided.
            ISecureCommand secure = command as ISecureCommand;

            if (secure != null &&
                command != ApplicationCommands.Cut &&
                command != ApplicationCommands.Copy)
            {
                secure.UserInitiatedPermission.Demand();
            }
        }
Exemple #17
0
        /// <summary>
        /// Constructor with parameters</summary>
        /// <param name="commandTag">Command ID</param>
        /// <param name="menuTag">Unique ID for menu command attached to</param>
        /// <param name="groupTag">Unique ID for command's group</param>
        /// <param name="text">User visible command text, as on menu item</param>
        /// <param name="menuPath">String array describing menu path</param>
        /// <param name="description">Command description</param>
        /// <param name="imageSourceKey">Image resource for command</param>
        /// <param name="inputGestures">Sequence of input device gestures to execute command</param>
        /// <param name="visibility">Flags indicating where command is visible: on toolbar, menus, etc.</param>
        public CommandDef(
            object commandTag,
            object menuTag,
            object groupTag,
            string text,
            string[] menuPath,
            string description,
            object imageSourceKey,
            InputGesture[] inputGestures,
            CommandVisibility visibility)
            : this(commandTag, menuTag, groupTag, text, description)
        {

            ImageSourceKey = imageSourceKey;
            if(menuPath != null)
                MenuPath = menuPath;
            if (inputGestures != null)
                InputGestures = inputGestures;
            
            Visibility = visibility;
        }
 public void CopyTo(InputGesture[] inputGestures, int index)
 {
 }
 public int IndexOf(InputGesture value)
 {
   return default(int);
 }
 /// <summary>
 /// CopyTo - to copy the collection starting from given index into an array
 /// </summary>
 /// <param name="inputGestures">Array of InputGesture</param>
 /// <param name="index">start index of items to copy</param>
 public void CopyTo(InputGesture[] inputGestures, int index) 
 {
     if (_innerGestureList != null)
         _innerGestureList.CopyTo(inputGestures, index);
 }
        /// <summary>
        /// Remove
        /// </summary>
        /// <param name="inputGesture"></param>
        public void Remove(InputGesture inputGesture) 
        {
            if (IsReadOnly)
            {
                 throw new NotSupportedException(SR.Get(SRID.ReadOnlyInputGesturesCollection));
            }

            if (inputGesture == null)
 	        {
                throw new ArgumentNullException("inputGesture");
	        }

            if (_innerGestureList != null && _innerGestureList.Contains(inputGesture))
            {
                _innerGestureList.Remove(inputGesture as InputGesture);
            }
        }
        /// <summary>
        /// Add
        /// </summary>
        /// <param name="inputGesture"></param>
        public int Add(InputGesture inputGesture) 
        {
            if (IsReadOnly)
            {
                throw new NotSupportedException(SR.Get(SRID.ReadOnlyInputGesturesCollection));
            }

	    if (inputGesture == null)
            {
		throw new ArgumentNullException("inputGesture");
            }

            EnsureList();
            _innerGestureList.Add(inputGesture);
            return 0; // ICollection.Add no longer returns the indice
        }
        private static RoutedCommand DeclareCommand(ref RoutedCommand command,
                                string commandDebugName, InputGesture gesture)
        {
            if (command == null)
            {
                InputGestureCollection collection = null;

                if (gesture != null)
                {
                    collection = new InputGestureCollection();
                    collection.Add(gesture);
                }

                command = new RoutedCommand(commandDebugName,
                                            typeof(ThumbViewer), collection);
            }
            return command;
        }// end:DeclareCommand()
 public int IndexOf(InputGesture value)
 {
     return(default(int));
 }
 public void Insert(int index, InputGesture inputGesture)
 {
 }
 public int Add(InputGesture inputGesture)
 {
     return(default(int));
 }
 public bool Contains(InputGesture key)
 {
     return(default(bool));
 }
 public void Remove(InputGesture inputGesture)
 {
 }
        private GestureCommand FindOrCreateLookup(UIElement uiElement, InputGesture gesture)
        {
            foreach(var item in uiElement.InputBindings)
            {
                var binding = (InputBinding)item;
                var command = binding.Command as GestureCommand;

                if(command != null
                   && AreGestureEqual(gesture, command.Gesture))
                {
                    return command;
                }
            }

            var lookup = new GestureCommand(gesture);

            uiElement.InputBindings.Add(
                new InputBinding(lookup, gesture)
                );

            return lookup;
        }
Exemple #30
0
 public static void SetInputBinding(InputBindingCollection inputCollection, ICommand command, InputGesture gesture)
 {
     var binding = new InputBinding(command, gesture);
     inputCollection.Remove(binding);
     inputCollection.Add(binding);
 }
 public bool Contains(InputGesture key)
 {
   return default(bool);
 }
 public void Remove(InputGesture inputGesture)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GestureCommand"/> class.
 /// </summary>
 /// <param name="gesture">The gesture.</param>
 public GestureCommand(InputGesture gesture)
 {
     _gesture = gesture;
 }
Exemple #34
0
 public int IndexOf(InputGesture value)
 {
     throw new NotImplementedException();
 }
 //http://wekempf.spaces.live.com/blog/cns!D18C3EC06EA971CF!255.entry?wa=wsignin1.0
 public static void Register(Type hostType, SimpleRoutedCommand simpleRoutedCommand, InputGesture inputGesture)
 {
     CommandManager.RegisterClassCommandBinding(hostType, simpleRoutedCommand.CommandBinding);
     CommandManager.RegisterClassInputBinding(hostType, new InputBinding(simpleRoutedCommand, inputGesture));
     simpleRoutedCommand._routedCommand.InputGestures.Add(inputGesture);
 }
Exemple #36
0
 public bool Contains(InputGesture key)
 {
     return(list.Contains(key));
 }
 /// <summary>
 /// IndexOf
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public int IndexOf(InputGesture value)
 {
     return (_innerGestureList != null) ? _innerGestureList.IndexOf(value) : -1;
 }
Exemple #38
0
 public InputBinding(ICommand command, InputGesture gesture)
 {
 }
        /// <summary>
        ///  Insert
        /// </summary>
        /// <param name="index">index at which to insert the item</param>
        /// <param name="inputGesture">item value to insert</param>
        public void Insert(int index, InputGesture inputGesture)
        {
            if (IsReadOnly)
                 throw new NotSupportedException(SR.Get(SRID.ReadOnlyInputGesturesCollection));    

            if (inputGesture == null)
                throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsInputGestures));

            if (_innerGestureList != null)
                _innerGestureList.Insert(index, inputGesture);
        }
 public void Insert(int index, InputGesture inputGesture)
 {
 }
 /// <summary>
 /// Contains
 /// </summary>
 /// <param name="key">key</param>
 /// <returns>true - if found, false - otherwise</returns>
 public bool Contains(InputGesture key) 
 {
     if (_innerGestureList != null && key != null)
     {
        return _innerGestureList.Contains(key) ;
     }
     return false;
 }
 public int Add(InputGesture inputGesture)
 {
   return default(int);
 }
        /// <summary>
        /// IndexOf
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        int IList.IndexOf(object value)
        {
            InputGesture inputGesture = value as InputGesture;

            return((inputGesture != null) ? this.IndexOf(inputGesture) : -1);
        }
Exemple #44
0
		private static Func<InputBinding, bool> GestureEquals(InputGesture gesture)
		{
			return existingBinding => InputGestureEqualityComparer.Instance.Equals(gesture, existingBinding.Gesture);
		}
 /// <summary>
 /// IndexOf
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public int IndexOf(InputGesture value)
 {
     return((_innerGestureList != null) ? _innerGestureList.IndexOf(value) : -1);
 }
        /// <summary>
        /// Perform the binding operation for any kind of button
        /// </summary>
        private static void GenericBinder(UIElement a_element, InputGesture a_gesture, ICommand a_newCommand, ICommand a_oldCommand)
        {
            if ( a_oldCommand != null )
            {
                var existingBindings = a_element.InputBindings.Cast<InputBinding>().Where(a_binding => a_binding.Command == a_oldCommand).ToList();
                existingBindings.ForEach(a_element.InputBindings.Remove);
            }

            if ( a_newCommand != null )
            {
                if ( a_gesture is MouseGesture )
                    a_element.InputBindings.Add(new MouseBinding(a_newCommand, a_gesture as MouseGesture));
                else
                    a_element.InputBindings.Add(new InputBinding(a_newCommand, a_gesture));

            }
        }
Exemple #47
0
 public static void AddShortcut(this UIElement element, InputGesture gesture, Action action)
 {
     element.CommandBindings.Add(new CommandBinding(new RoutedCommand() { InputGestures = { gesture } }, (o, e) => action()));
 }
Exemple #48
0
		public InputBinding (ICommand command, InputGesture gesture)
		{
		}
Exemple #49
0
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, 
                                             InputGesture inputGesture, InputGesture inputGesture2)
 { 
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, null, inputGesture, inputGesture2); 
 }
        private bool AreGestureEqual(InputGesture left, InputGesture right)
        {
            if(left.GetType() != right.GetType()) return false;

            var leftKeyGesture = left as UnrestrictedKeyGesture;
            if(leftKeyGesture != null)
            {
                var rightKeyGesture = (UnrestrictedKeyGesture)right;

                return rightKeyGesture.Key == leftKeyGesture.Key
                       && rightKeyGesture.Modifiers == leftKeyGesture.Modifiers;
            }

            var leftMouseGesture = left as MouseGesture;
            if(leftMouseGesture != null)
            {
                var rightMouseGesture = (MouseGesture)right;

                return rightMouseGesture.MouseAction == leftMouseGesture.MouseAction
                       && rightMouseGesture.Modifiers == leftMouseGesture.Modifiers;
            }

            return false;
        }
 public DelegateCommand(string name, Action<object> executeAction, Predicate<object> canExecuteFunc, InputGesture inputGesture)
     : base(name, inputGesture)
 {
     this.executeAction = executeAction;
     this.canExecuteFunc = canExecuteFunc;
 }
Exemple #52
0
 public int Add(InputGesture inputGesture)
 {
     return(list.Add(inputGesture));
 }