예제 #1
0
        private static Dictionary <string, string> GetGestureTable(FrameworkElement Source)
        {
            Dictionary <string, string> GestureTable = new Dictionary <string, string>();
            FrameworkElement            Element      = Source;
            IGestureTranslator          Translator   = null;

            for (; ;)
            {
                IGestureSource AsGestureSource;
                if ((AsGestureSource = Element as IGestureSource) != null)
                {
                    Translator = AsGestureSource.GestureTranslator;
                }

                ParseKeyBindings(Element.InputBindings, Translator, GestureTable);

                FrameworkElement AsParentElement;
                if ((AsParentElement = Element.Parent as FrameworkElement) != null)
                {
                    Element = AsParentElement;
                }
                else
                {
                    break;
                }
            }

            return(GestureTable);
        }
예제 #2
0
        private static void ParseKeyBinding(KeyBinding Binding, IGestureTranslator Translator, Dictionary <string, string> GestureTable)
        {
            string Key;
            ExtendedRoutedCommand AsExtendedCommand;
            RoutedUICommand       AsUICommand;

            if ((AsExtendedCommand = Binding.Command as ExtendedRoutedCommand) != null)
            {
                Key = AsExtendedCommand.MenuHeader;
            }

            else if ((AsUICommand = Binding.Command as RoutedUICommand) != null)
            {
                Key = GestureHelper.ApplicationCommandName(AsUICommand);
            }

            else
            {
                Key = null;
            }

            if (Key != null && !GestureTable.ContainsKey(Key))
            {
                string GestureText;
                if (GestureToText(Binding.Gesture, Translator, out GestureText))
                {
                    GestureTable.Add(Key, GestureText);
                }
            }
        }
예제 #3
0
 private static string PostTranslateText(IGestureTranslator Translator, string Text)
 {
     if (Translator == null)
     {
         return(Text);
     }
     else
     {
         return(Translator.PostTranslate(Text));
     }
 }
예제 #4
0
 private static void ParseKeyBindings(InputBindingCollection InputBindings, IGestureTranslator Translator, Dictionary <string, string> GestureTable)
 {
     foreach (InputBinding Binding in InputBindings)
     {
         KeyBinding AsKeyBinding;
         if ((AsKeyBinding = Binding as KeyBinding) != null)
         {
             ParseKeyBinding(AsKeyBinding, Translator, GestureTable);
         }
     }
 }
예제 #5
0
        private static bool GetSystemGestureText(RoutedUICommand Command, FrameworkElement Source, out string DisplayString)
        {
            IGestureSource AsGestureSource;

            if ((AsGestureSource = Source as IGestureSource) != null)
            {
                IGestureTranslator Translator = AsGestureSource.GestureTranslator;
                if (Translator != null)
                {
                    foreach (InputGesture Gesture in Command.InputGestures)
                    {
                        if (GestureToText(Gesture, Translator, out DisplayString))
                        {
                            return(true);
                        }
                    }
                }
            }

            DisplayString = null;
            return(false);
        }
예제 #6
0
        private static bool GestureToText(InputGesture Gesture, IGestureTranslator Translator, out string GestureText)
        {
            KeyGesture AsKeyGesture;

            if ((AsKeyGesture = Gesture as KeyGesture) != null)
            {
                string LocalizedText = AsKeyGesture.GetDisplayStringForCulture(CultureInfo.CurrentCulture);
                if (LocalizedText != null && LocalizedText.Length > 0)
                {
                    GestureText = PostTranslateText(Translator, LocalizedText);
                    return(true);
                }

                if (AsKeyGesture.DisplayString != null && AsKeyGesture.DisplayString.Length > 0)
                {
                    GestureText = PostTranslateText(Translator, AsKeyGesture.DisplayString);
                    return(true);
                }
            }

            GestureText = null;
            return(false);
        }