Ejemplo n.º 1
0
 /// <summary>
 /// Searches for an <see cref="UIActionHandler"/> to convert a user command key to a <see cref="UIAction"/>
 /// and then perform the action.
 /// </summary>
 /// <param name="shortcut">
 /// The shortcut key pressed by the user.
 /// </param>
 /// <param name="bottomLevelControl">
 /// The <see cref="Control"/> from which to initiate searching for a handler for the shortcut key.
 /// Generally this is the control which has the keyboard focus.
 /// </param>
 /// <returns>
 /// Whether or not a <see cref="UIActionHandler"/> was found which processed the key successfully.
 /// </returns>
 public static bool TryExecute(Keys shortcut, Control bottomLevelControl)
 {
     // Try to find an action with given shortcut.
     return((from actionHandler in EnumerateUIActionHandlers(bottomLevelControl)
             from interfaceActionPair in actionHandler.InterfaceSets
             let shortcuts = interfaceActionPair.Item1.Get <IShortcutKeysUIActionInterface>()?.Shortcuts
                             where shortcuts != null
                             from registeredShortcut in shortcuts
                             // If the shortcut matches, then try to perform the action.
                             // If the handler does not return UIActionVisibility.Parent, then swallow the key by returning true.
                             where KeyUtilities.IsMatch(registeredShortcut, shortcut)
                             select actionHandler.TryPerformAction(interfaceActionPair.Item2, true).UIActionVisibility)
            .Any(x => x != UIActionVisibility.Parent));
 }