Beispiel #1
0
        // Gets the input gesture text from the command text if it hasn't been explicitly specified
        private static object CoerceInputGestureText(DependencyObject d, object value)
        {
            ButtonBase    button = (ButtonBase)d;
            RoutedCommand routedCommand;

            if (string.IsNullOrEmpty((string)value) && !button.HasNonDefaultValue(InputGestureTextProperty) &&
                (routedCommand = button.Command as RoutedCommand) != null)
            {
                InputGestureCollection col = routedCommand.InputGestures;
                if ((col != null) && (col.Count >= 1))
                {
                    // Search for the first key gesture
                    for (int i = 0; i < col.Count; i++)
                    {
                        KeyGesture keyGesture = ((IList)col)[i] as KeyGesture;
                        if (keyGesture != null)
                        {
                            return(keyGesture.GetDisplayStringForCulture(CultureInfo.CurrentCulture));
                        }
                    }
                }
            }

            return(value);
        }
Beispiel #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ICommandSource commandSource = value as ICommandSource;

            if (commandSource == null)
            {
                return(null);
            }

            RoutedUICommand uiCommand = commandSource.Command as RoutedUICommand;

            if (uiCommand == null)
            {
                return(null);
            }

            string text = uiCommand.Text;

            text = removeUnderScoresPattern.Replace(text, Evaluator);

            foreach (var inputGesture in uiCommand.InputGestures)
            {
                KeyGesture keyGesture = inputGesture as KeyGesture;
                if (keyGesture != null)
                {
                    text = text + " (" + keyGesture.GetDisplayStringForCulture(CultureInfo.InvariantCulture) + ")";
                    break;
                }
            }

            return(text);
        }
        public static string GetDisplayStringForShortcut(KeyGesture kg)
        {
            string old  = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
            string text = KeyCodeConversion.KeyToUnicode(kg.Key.ToKeys());

            if (text != null && !text.Any(ch => char.IsWhiteSpace(ch)))
            {
                if ((kg.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
                {
                    text = StringParser.Format("${res:Global.Shortcuts.Alt}+{0}", text);
                }
                if ((kg.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    text = StringParser.Format("${res:Global.Shortcuts.Shift}+{0}", text);
                }
                if ((kg.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    text = StringParser.Format("${res:Global.Shortcuts.Ctrl}+{0}", text);
                }
                if ((kg.Modifiers & ModifierKeys.Windows) == ModifierKeys.Windows)
                {
                    text = StringParser.Format("${res:Global.Shortcuts.Win}+{0}", text);
                }
                return(text);
            }
            return(old);
        }
        public MenuCheckBox(UIElement inputBindingOwner, Codon codon, object caller, IEnumerable <ICondition> conditions)
            : base(codon, caller, conditions)
        {
            this.Command = CommandWrapper.GetCommand(codon, caller, true, conditions);
            CommandWrapper wrapper = this.Command as CommandWrapper;

            if (wrapper != null)
            {
                ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand;
                if (cmd != null)
                {
                    isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked")
                    {
                        Source = cmd, Mode = BindingMode.OneWay
                    });
                }
            }

            if (!string.IsNullOrEmpty(codon.Properties["shortcut"]))
            {
                KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
                MenuCommand.AddGestureToInputBindingOwner(inputBindingOwner, kg, this.Command, null);
                this.InputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
            }
        }
Beispiel #5
0
 public void AddInputBinding()
 {
     if (GestureText == null)
     {
         GestureText = KeyGesture.GetDisplayStringForCulture(CultureInfo.CurrentUICulture);
     }
 }
Beispiel #6
0
        public ToolBarButton(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, IEnumerable <ICondition> conditions)
        {
            ToolTipService.SetShowOnDisabled(this, true);

            this.codon      = codon;
            this.caller     = caller;
            this.Command    = CommandWrapper.GetCommand(codon, caller, createCommand, conditions);
            this.Content    = ToolBarService.CreateToolBarItemContent(codon);
            this.conditions = conditions;

            if (codon.Properties.Contains("name"))
            {
                this.Name = codon.Properties["name"];
            }

            if (!string.IsNullOrEmpty(codon.Properties["shortcut"]))
            {
                KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
                MenuCommand.AddGestureToInputBindingOwner(inputBindingOwner, kg, this.Command, GetFeatureName());
                this.inputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
            }
            UpdateText();

            SetResourceReference(FrameworkElement.StyleProperty, ToolBar.ButtonStyleKey);
        }
Beispiel #7
0
        public static string GetDisplayStringForShortcut(KeyGesture kg)
        {
            string old  = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
            string text = KeyCodeConversion.KeyToUnicode(kg.Key.ToKeys());

            if (text != null && !text.Any(ch => char.IsWhiteSpace(ch)))
            {
                if ((kg.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)
                {
                    text = "Alt+" + text;
                }
                if ((kg.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                {
                    text = "Shift+" + text;
                }
                if ((kg.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                {
                    text = "Ctrl+" + text;
                }
                if ((kg.Modifiers & ModifierKeys.Windows) == ModifierKeys.Windows)
                {
                    text = "Win+" + text;
                }
                return(text);
            }
            return(old);
        }
            public static KeyGesture GetKeyGesure(Key key, ModifierKeys modifiers)
            {
                KeyGesture k = new KeyGesture(key, modifiers);
                string     s = k.GetDisplayStringForCulture(System.Globalization.CultureInfo.InvariantCulture);

                return(new KeyGesture(key, modifiers));
            }
Beispiel #9
0
        public static string GetInputGestureText(KeyGesture gesture)
        {
            if (gesture == null)
            {
                return(null);
            }
            string ret = gesture.GetDisplayStringForCulture(System.Globalization.CultureInfo.CurrentCulture);

            return(ret.Replace("Return", "Enter").Replace("Up", "↑").Replace("Down", "↓").Replace("Left", "←").Replace("Right", "→"));
        }
Beispiel #10
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"]);
                AddGestureToInputBindingOwner(inputBindingOwner, kg, this.Command, GetFeatureName());
                this.InputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
            }
        }
Beispiel #11
0
 public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand) : base(codon, caller)
 {
     this.Command = new CommandWrapper(codon, caller, createCommand);
     if (!string.IsNullOrEmpty(codon.Properties["shortcut"]))
     {
         KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
         inputBindingOwner.InputBindings.Add(
             new InputBinding(this.Command, kg)
             );
         this.InputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
     }
 }
        private static void HandleItemMenuType(SearchPathDescriptor descriptor, Codon codon, string path, List <string> nextPathChain, List <SearchItem> result)
        {
            SearchItem item = GenerateSearchItem(descriptor, codon, path, nextPathChain);

            item.Label = AddNextPathChainString(codon);
            if (codon.Properties.Contains("shortcut"))
            {
                KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
                item.Shortcut = string.Format("({0})", kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture));
            }
            item.CommandTypeString = codon.Properties["class"];
            result.Add(item);
        }
        public static string GetDisplayString(KeyGesture keyG)
        {
            if (keyG == null)
            {
                return(null);
            }

            string strDisplay = keyG.GetDisplayStringForCulture(CultureInfo.CurrentCulture);

            if (!string.IsNullOrEmpty(strDisplay) &&
                strDisplay.IndexOf("oem", StringComparison.OrdinalIgnoreCase) < 0)
            {
                return(strDisplay);
            }

            //Keys modKey = Keys.None;
            //if ((keyG.Modifiers & ModifierKeys.Shift) != ModifierKeys.None) modKey |= Keys.Shift;
            //if ((keyG.Modifiers & ModifierKeys.Control) != ModifierKeys.None) modKey |= Keys.Control;
            //if ((keyG.Modifiers & ModifierKeys.Alt) != ModifierKeys.None) modKey |= Keys.Alt;
            //if ((keyG.Modifiers & ModifierKeys.Windows) != ModifierKeys.None) modKey |= Keys.LWin;
            //modKey = Keys.None;


            char c = GetDisplayChar(keyG.Key);

            var    converter = new KeyConverter();
            string strKey    = converter.ConvertToString(keyG.Key);

            //string strKey = (string)kc.ConvertTo(keyG.Key, typeof(string));

            if (c == '\0')
            {
#if DEBUG
                Debugger.Break();
#endif
                return(strDisplay);
            }

            return(strDisplay.Replace(strKey, c + ""));
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            RoutedUICommand command = value as RoutedUICommand;

            InputGestureCollection col = command?.InputGestures;

            if (col != null && (col.Count >= 1))
            {
                // Search for the first key gesture
                for (int i = 0; i < col.Count; i++)
                {
                    KeyGesture keyGesture = ((IList)col)[i] as KeyGesture;

                    if (keyGesture != null)
                    {
                        return(String.Format("{0}\n({1})", command.Text, keyGesture.GetDisplayStringForCulture(CultureInfo.CurrentCulture)));
                    }
                }
            }

            return(Binding.DoNothing);
        }