Beispiel #1
0
        public TEditor()
        {
            InitializeComponent();
            (this.Content as FrameworkElement).DataContext = this;
            spellingErrorColorizer = new SpellingErrorColorizer();
            //textEditor.TextArea.TextView.LineTransformers.Add(spellingErrorColorizer);
            textEditor.TextArea.LostFocus += TextArea_LostFocus;
            var converter = new System.Windows.Media.BrushConverter();

            textEditor.TextArea.TextView.LinkTextForegroundBrush = (Brush)converter.ConvertFromString("#007acc");

            //setTestText();
            // Load our custom highlighting definition
            IHighlightingDefinition customHighlighting = null;

            try
            {
                using (XmlReader reader = new XmlTextReader("CustomHighlighting.xshd"))
                {
                    customHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.
                                         HighlightingLoader.Load(reader, HighlightingManager.Instance);
                }
                HighlightingManager.Instance.RegisterHighlighting("Custom Highlighting", new string[] { ".cool" }, customHighlighting);
            }
            catch (Exception ex)
            {
            }



#if DOTNET4
            this.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display);
#endif

            //textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
            textEditor.SyntaxHighlighting = customHighlighting;
            // initial highlighting now set by XAML

            textEditor.TextArea.TextEntering   += textEditor_TextArea_TextEntering;
            textEditor.TextArea.TextEntered    += textEditor_TextArea_TextEntered;
            textEditor.TextArea.PreviewKeyDown += TextArea_PreviewKeyDown;

            DispatcherTimer foldingUpdateTimer = new DispatcherTimer();
            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(1);
            foldingUpdateTimer.Tick    += delegate { UpdateFoldings(); };
            foldingUpdateTimer.Start();


            if (textEditor.SyntaxHighlighting == null)
            {
                foldingStrategy = null;
            }
            else
            {
                textEditor.Options.HighlightCurrentLine = true;
                //textEditor.Options.ShowColumnRuler = true;
                //textEditor.Options.ShowTabs = true;
                textEditor.Options.EnableEmailHyperlinks       = true;
                textEditor.Options.EnableHyperlinks            = true;
                textEditor.Options.EnableTextDragDrop          = true;
                textEditor.Options.ShowBoxForControlCharacters = true;
                //textEditor.Options.ShowEndOfLine = true;
                //textEditor.Options.ShowSpaces = true;
                //textEditor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(textEditor.Options);
                textEditor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.DefaultIndentationStrategy();
                foldingStrategy = new BraceFoldingStrategy();
            }
            if (foldingStrategy != null)
            {
                if (foldingManager == null)
                {
                    foldingManager = FoldingManager.Install(textEditor.TextArea);
                }
                UpdateFoldings();
            }
            else
            {
                if (foldingManager != null)
                {
                    FoldingManager.Uninstall(foldingManager);
                    foldingManager = null;
                }
            }
        }
Beispiel #2
0
        public TEditor()
        {
            InitializeComponent();
            (this.Content as FrameworkElement).DataContext = this;
            spellingErrorColorizer = new SpellingErrorColorizer();
            textEditor.TextArea.TextView.LineTransformers.Add(spellingErrorColorizer);


            // Load our custom highlighting definition
            IHighlightingDefinition customHighlighting;

            try
            {
                using (XmlReader reader = new XmlTextReader("CustomHighlighting.xshd"))
                {
                    customHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.
                                         HighlightingLoader.Load(reader, HighlightingManager.Instance);
                }
                HighlightingManager.Instance.RegisterHighlighting("Custom Highlighting", new string[] { ".cool" }, customHighlighting);
            }
            catch (Exception ex)
            {
            }



#if DOTNET4
            this.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display);
#endif

            //textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
            //textEditor.SyntaxHighlighting = customHighlighting;
            // initial highlighting now set by XAML

            textEditor.TextArea.TextEntering += textEditor_TextArea_TextEntering;
            textEditor.TextArea.TextEntered  += textEditor_TextArea_TextEntered;

            DispatcherTimer foldingUpdateTimer = new DispatcherTimer();
            foldingUpdateTimer.Interval = TimeSpan.FromSeconds(2);
            foldingUpdateTimer.Tick    += delegate { UpdateFoldings(); };
            foldingUpdateTimer.Start();


            if (textEditor.SyntaxHighlighting == null)
            {
                foldingStrategy = null;
            }
            else
            {
                //textEditor.TextArea.IndentationStrategy = new ICSharpCode.AvalonEdit.Indentation.CSharp.CSharpIndentationStrategy(textEditor.Options);
                foldingStrategy = new BraceFoldingStrategy();
            }
            if (foldingStrategy != null)
            {
                if (foldingManager == null)
                {
                    foldingManager = FoldingManager.Install(textEditor.TextArea);
                }
                UpdateFoldings();
            }
            else
            {
                if (foldingManager != null)
                {
                    FoldingManager.Uninstall(foldingManager);
                    foldingManager = null;
                }
            }
        }