Esempio n. 1
0
        public override void OnWindowLoaded()
        {
            bool requiresCompiler = false;

            foreach (var snippet in SnippetsAddinConfiguration.Current.Snippets)
            {
                if (!requiresCompiler && snippet.SnippetText.Contains("{{") || snippet.SnippetText.Contains("@"))
                {
                    requiresCompiler = true;
                }


                if (!string.IsNullOrEmpty(snippet.KeyboardShortcut))
                {
                    var        ksc = snippet.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;
                    }

                    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 = new CommandBase((s, e) => InsertSnippet(snippet),
                                                 (s, e) => Model.IsEditorActive);

                    Model.Window.InputBindings.Add(kb);
                }
            }

            if (requiresCompiler)
            {
                RoslynLifetimeManager.WarmupRoslyn();
            }
        }
 public override void OnApplicationShutdown()
 {
     // if Roslyn is running shut it down
     RoslynLifetimeManager.ShutdownRoslyn();
     snippetsWindow?.Close();
 }