コード例 #1
0
 /// <summary>
 /// By default hook up Execute/ExecuteConfiguration/CanExecute
 /// handlers to the On Handlers in the Addin class.
 /// </summary>
 /// <param name="addin"></param>
 public AddInMenuItem(MarkdownMonsterAddin addin = null)
 {
     if (addin != null)
     {
         Execute = addin.OnExecute;
         ExecuteConfiguration = addin.OnExecuteConfiguration;
         CanExecute           = addin.OnCanExecute;
     }
 }
コード例 #2
0
 /// <summary>
 /// adds a keyboard
 /// </summary>
 /// <param name="menuItem"></param>
 /// <param name="addin"></param>
 private static void AddKeyboardShortcut(AddInMenuItem menuItem, MarkdownMonsterAddin addin)
 {
     if (!string.IsNullOrEmpty(menuItem.KeyboardShortcut))
     {
         KeyBinding kb = WindowUtilities.CreateKeyboardShortcutBinding(
             menuItem.KeyboardShortcut,
             menuItem.Command);
         if (kb != null)
         {
             addin.Model.Window.InputBindings.Add(kb);
         }
     }
 }
コード例 #3
0
        private static void AddKeyboardShortcut(AddInMenuItem menuItem, MarkdownMonsterAddin addin)
        {
            if (!string.IsNullOrEmpty(menuItem.KeyboardShortcut))
            {
                var        ksc = menuItem.KeyboardShortcut.ToLower();
                KeyBinding kb  = new KeyBinding();

                if (ksc.Contains("alt"))
                {
                    kb.Modifiers = ModifierKeys.Alt;
                }
                if (ksc.Contains("shift"))
                {
                    kb.Modifiers |= ModifierKeys.Shift;
                }
                if (ksc.Contains("ctrl") || ksc.Contains("ctl"))
                {
                    kb.Modifiers |= ModifierKeys.Control;
                }
                if (ksc.Contains("win"))
                {
                    kb.Modifiers |= ModifierKeys.Windows;
                }

                string key =
                    ksc.Replace("+", "")
                    .Replace("-", "")
                    .Replace("_", "")
                    .Replace(" ", "")
                    .Replace("alt", "")
                    .Replace("shift", "")
                    .Replace("ctrl", "")
                    .Replace("ctl", "");

                key = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(key);
                if (!string.IsNullOrEmpty(key))
                {
                    KeyConverter k = new KeyConverter();
                    kb.Key = (Key)k.ConvertFromString(key);
                }

                // Whatever command you need to bind to
                kb.Command = menuItem.Command;
                addin.Model.Window.InputBindings.Add(kb);
            }
        }