void UpdateSyntaxHighlighting(FileName fileName) { var oldHighlighter = primaryTextEditor.GetService <IHighlighter>(); var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); var highlighter = SD.EditorControlService.CreateHighlighter(document); primaryTextEditor.SyntaxHighlighting = highlighting; primaryTextEditor.TextArea.TextView.LineTransformers.RemoveAll(t => t is HighlightingColorizer); primaryTextEditor.TextArea.TextView.LineTransformers.Insert(0, new HighlightingColorizer(highlighter)); primaryTextEditor.UpdateCustomizedHighlighting(); // Dispose the old highlighter; necessary to avoid memory leaks as // semantic highlighters might attach to global parser events. if (oldHighlighter != null) { oldHighlighter.Dispose(); } }
void CustomizedHighlightingColor_ActiveColorsChanged(object sender, EventArgs e) { // CustomizableHighlightingColorizer loads the new values automatically, we just need // to force a refresh in AvalonEdit. primaryTextEditor.UpdateCustomizedHighlighting(); if (secondaryTextEditor != null) { secondaryTextEditor.UpdateCustomizedHighlighting(); } }
void OnSplitView(object sender, ExecutedRoutedEventArgs e) { if (secondaryTextEditor == null) { // create secondary editor this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight }); secondaryTextEditor = CreateTextEditor(); secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor)); Debug.Assert(primaryTextEditorAdapter != null); secondaryTextEditor.SetBinding(TextEditor.DocumentProperty, new Binding(TextEditor.DocumentProperty.Name) { Source = primaryTextEditor }); secondaryTextEditor.SetBinding(TextEditor.IsReadOnlyProperty, new Binding(TextEditor.IsReadOnlyProperty.Name) { Source = primaryTextEditor }); secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting; secondaryTextEditor.UpdateCustomizedHighlighting(); gridSplitter = new GridSplitter { Height = 4, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top }; SetRow(gridSplitter, 2); this.Children.Add(gridSplitter); secondaryTextEditor.Margin = new Thickness(0, 4, 0, 0); SetRow(secondaryTextEditor, 2); this.Children.Add(secondaryTextEditor); secondaryTextEditorAdapter.FileNameChanged(); FetchParseInformation(); } else { // remove secondary editor this.Children.Remove(secondaryTextEditor); this.Children.Remove(gridSplitter); secondaryTextEditorAdapter.Language.Detach(); DisposeTextEditor(secondaryTextEditor); secondaryTextEditor = null; secondaryTextEditorAdapter = null; gridSplitter = null; this.RowDefinitions.RemoveAt(this.RowDefinitions.Count - 1); this.ActiveTextEditor = primaryTextEditor; } }
void CustomizedHighlightingColor_ActiveColorsChanged(object sender, EventArgs e) { // CustomizableHighlightingColorizer loads the new values automatically, we just need // to force a refresh in AvalonEdit. primaryTextEditor.UpdateCustomizedHighlighting(); if (secondaryTextEditor != null) { secondaryTextEditor.UpdateCustomizedHighlighting(); } foreach (var bookmark in BookmarkManager.GetBookmarks(fileName).OfType <SDMarkerBookmark>()) { bookmark.SetMarker(); } }
void OnSplitView(object sender, ExecutedRoutedEventArgs e) { if (secondaryTextEditor == null) { // create secondary editor this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star), MinHeight = minRowHeight }); secondaryTextEditor = CreateTextEditor(); secondaryTextEditorAdapter = (CodeEditorAdapter)secondaryTextEditor.TextArea.GetService(typeof(ITextEditor)); Debug.Assert(primaryTextEditorAdapter != null); secondaryTextEditor.SetBinding(TextEditor.DocumentProperty, new Binding(TextEditor.DocumentProperty.Name) { Source = primaryTextEditor }); secondaryTextEditor.SetBinding(TextEditor.IsReadOnlyProperty, new Binding(TextEditor.IsReadOnlyProperty.Name) { Source = primaryTextEditor }); secondaryTextEditor.SyntaxHighlighting = primaryTextEditor.SyntaxHighlighting; secondaryTextEditor.UpdateCustomizedHighlighting(); gridSplitter = new GridSplitter { Height = 4, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top }; SetRow(gridSplitter, 2); this.Children.Add(gridSplitter); secondaryTextEditor.Margin = new Thickness(0, 4, 0, 0); SetRow(secondaryTextEditor, 2); this.Children.Add(secondaryTextEditor); secondaryTextEditorAdapter.FileNameChanged(); FetchParseInformation(); } else { // remove secondary editor this.Children.Remove(secondaryTextEditor); this.Children.Remove(gridSplitter); secondaryTextEditorAdapter.Language.Detach(); DisposeTextEditor(secondaryTextEditor); secondaryTextEditor = null; secondaryTextEditorAdapter = null; gridSplitter = null; this.RowDefinitions.RemoveAt(this.RowDefinitions.Count - 1); this.ActiveTextEditor = primaryTextEditor; } }