Esempio n. 1
0
 internal static void AddGestureToInputBindingOwner(UIElement inputBindingOwner, KeyGesture kg, System.Windows.Input.ICommand shortcutCommand, string featureName)
 {
     if (inputBindingOwner != null && kg != null && shortcutCommand != null)
     {
         // wrap the shortcut command so that it can report to UDC with
         // different activation method
         if (!string.IsNullOrEmpty(featureName))
         {
             shortcutCommand = new ShortcutCommandWrapper(shortcutCommand, featureName);
         }
         // try to find an existing input binding which conflicts with this shortcut
         var existingInputBinding =
             (from InputBinding b in inputBindingOwner.InputBindings
              let gesture = b.Gesture as KeyGesture
                            where gesture != null &&
                            gesture.Key == kg.Key &&
                            gesture.Modifiers == kg.Modifiers
                            select b
             ).FirstOrDefault();
         if (existingInputBinding != null)
         {
             // modify the existing input binding to allow calling both commands
             existingInputBinding.Command = new AmbiguousCommandWrapper(existingInputBinding.Command, shortcutCommand);
         }
         else
         {
             inputBindingOwner.InputBindings.Add(new InputBinding(shortcutCommand, kg));
         }
     }
 }
Esempio n. 2
0
 internal static void AddGestureToInputBindingOwner(UIElement inputBindingOwner, KeyGesture kg, System.Windows.Input.ICommand shortcutCommand, string featureName)
 {
     if (inputBindingOwner != null && kg != null && shortcutCommand != null) {
         // wrap the shortcut command so that it can report to UDC with
         // different activation method
         if (!string.IsNullOrEmpty(featureName))
             shortcutCommand = new ShortcutCommandWrapper(shortcutCommand, featureName);
         // try to find an existing input binding which conflicts with this shortcut
         var existingInputBinding =
             (from InputBinding b in inputBindingOwner.InputBindings
              let gesture = b.Gesture as KeyGesture
              where gesture != null
              && gesture.Key == kg.Key
              && gesture.Modifiers == kg.Modifiers
              select b
             ).FirstOrDefault();
         if (existingInputBinding != null) {
             // modify the existing input binding to allow calling both commands
             existingInputBinding.Command = new AmbiguousCommandWrapper(existingInputBinding.Command, shortcutCommand);
         } else {
             inputBindingOwner.InputBindings.Add(new InputBinding(shortcutCommand, kg));
         }
     }
 }
Esempio n. 3
0
		public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, string activationMethod) : base(codon, caller)
		{
			this.ActivationMethod = activationMethod;
			this.Command = CommandWrapper.GetCommand(codon, caller, createCommand);
			if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) {
				KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
				if (inputBindingOwner != null) {
					var shortcutCommand = this.Command;
					string featureName = GetFeatureName();
					// wrap the shortcut command so that it can report to UDC with
					// different activation method
					if (shortcutCommand != null && !string.IsNullOrEmpty(featureName))
						shortcutCommand = new ShortcutCommandWrapper(shortcutCommand, featureName);
					// try to find an existing input binding which conflicts with this shortcut
					var existingInputBinding =
						(from InputBinding b in inputBindingOwner.InputBindings
						 let gesture = b.Gesture as KeyGesture
						 where gesture != null
						 && gesture.Key == kg.Key
						 && gesture.Modifiers == kg.Modifiers
						 select b
						).FirstOrDefault();
					if (existingInputBinding != null) {
						// modify the existing input binding to allow calling both commands
						existingInputBinding.Command = new AmbiguousCommandWrapper(existingInputBinding.Command, shortcutCommand);
					} else {
						inputBindingOwner.InputBindings.Add(new InputBinding(shortcutCommand, kg));
					}
				}
				this.InputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
			}
		}