public void Dispose()
 {
     markers?.Clear();
     markers.Disconnect(_document);
     markers   = null;
     _document = null;
 }
        public PairedCharacterRenderer()
        {
            highlightBrush = new SolidColorBrush(Colors.LightBlue);
            highlightPen = new Pen(highlightBrush, 1.0);

            PairedCharacters = new TextSegmentCollection<TextSegment>();
        }
 public EditorScript(ITextEditor editor, SDRefactoringContext context, CSharpFormattingOptions formattingOptions)
     : base(editor.Document, formattingOptions, context.TextEditorOptions)
 {
     this.editor  = editor;
     this.context = context;
     this.textSegmentCollection = new TextSegmentCollection <TextSegment>((TextDocument)editor.Document);
 }
 public TextMarkerService(TextDocument document)
 {
     if (document == null)
         throw new ArgumentNullException("document");
     this.document = document;
     this.markers = new TextSegmentCollection<TextMarker>(document);
 }
Exemple #5
0
        private void ModifySelectedLines(Action <int, int> action)
        {
            var selection = TextArea.Selection;

            var startLine = Document.GetLineByOffset(CaretOffset).LineNumber;
            var endLine   = startLine;

            if (selection.Length > 0)
            {
                startLine = selection.StartPosition.Line;
                endLine   = selection.EndPosition.Line;
            }

            var selectionSegment = GetSelectionSegment();
            var caretSegment     = new TextSegment()
            {
                StartOffset = CaretOffset, EndOffset = CaretOffset
            };

            var anchors = new TextSegmentCollection <TextSegment>(Document);

            anchors.Add(selectionSegment);
            anchors.Add(caretSegment);

            action(startLine, endLine);

            SetSelection(selectionSegment);

            CaretOffset = caretSegment.StartOffset;

            Focus();
        }
Exemple #6
0
        public void SetTransformations(SyntaxHighlightDataList highlightData)
        {
            Dispatcher.UIThread.InvokeAsync(() =>
            {
                var transformations = new TextSegmentCollection <TextTransformation>(document);

                foreach (var transform in highlightData)
                {
                    if (transform.Type != HighlightType.None)
                    {
                        transformations.Add(new TextTransformation
                        {
                            Foreground  = GetBrush(transform.Type),
                            StartOffset = transform.Start,
                            EndOffset   = transform.Start + transform.Length
                        });
                    }
                }

                TextTransformations = transformations;

                if (DataChanged != null)
                {
                    DataChanged(this, new EventArgs());
                }
            });
        }
Exemple #7
0
        private void LanguageService_DiagnosticsUpdated(object sender, DiagnosticsUpdatedEventArgs e)
        {
            if (e.AssociatedSourceFile == SourceFile)
            {
                _diagnosticMarkersRenderer?.RemoveAll(marker => Equals(marker.Tag, e.Tag));

                var collection = new TextSegmentCollection <Diagnostic>(Document);

                foreach (var diagnostic in e.Diagnostics)
                {
                    collection.Add(diagnostic);
                }

                if (e.Kind == DiagnosticsUpdatedKind.DiagnosticsCreated)
                {
                    _diagnosticMarkersRenderer?.SetDiagnostics(e.Tag, collection);

                    if (e.DiagnosticHighlights != null)
                    {
                        _textColorizer.SetTransformations(e.Tag, e.DiagnosticHighlights);
                    }
                }

                _contextActionsRenderer.OnDiagnosticsUpdated();
            }

            _shell.UpdateDiagnostics(e);

            TextArea.TextView.Redraw();
        }
Exemple #8
0
        public TextMarkerService(TextDocument document)
        {
            _document = document;
            markers   = new TextSegmentCollection <TextMarker>(document);

            ColorScheme = ColorScheme.Default;
        }
 /// <summary>
 /// Creates a new FoldingManager instance.
 /// </summary>
 public FoldingManager(TextDocument document)
 {
     Document  = document ?? throw new ArgumentNullException(nameof(document));
     _foldings = new TextSegmentCollection <FoldingSection>();
     Dispatcher.UIThread.VerifyAccess();
     TextDocumentWeakEventManager.Changed.AddHandler(document, OnDocumentChanged);
 }
Exemple #10
0
        public void SetDiagnostics(TextSegmentCollection <Diagnostic> diagnostics)
        {
            Clear();

            foreach (var diag in diagnostics)
            {
                Color markerColor;

                switch (diag.Level)
                {
                case DiagnosticLevel.Error:
                case DiagnosticLevel.Fatal:
                    markerColor = Color.FromRgb(253, 45, 45);
                    break;

                case DiagnosticLevel.Warning:
                    markerColor = Color.FromRgb(255, 207, 40);
                    break;

                default:
                    markerColor = Color.FromRgb(0, 42, 74);
                    break;
                }

                Create(diag.StartOffset, diag.Length, diag.Spelling, markerColor);
            }
        }
		public TextMarkerService(TextArea area)
		{
			this.area = area;
			markers = new TextSegmentCollection<TextMarker>(area.Document);
			this.area.TextView.BackgroundRenderers.Add(this);
			this.area.TextView.LineTransformers.Add(this);
		}
Exemple #12
0
		void OnDocumentChanged(object sender, EventArgs e)
		{
			if (textView.Document != null)
				markers = new TextSegmentCollection<TextMarker>(textView.Document);
			else
				markers = null;
		}
Exemple #13
0
 /// <summary>
 /// Called when the <see cref="Markers"/> property changed.
 /// </summary>
 /// <param name="oldValue">The old value.</param>
 /// <param name="newValue">The new value.</param>
 private /* protected virtual */ void OnMarkersChanged(TextSegmentCollection <Marker> oldValue, TextSegmentCollection <Marker> newValue)
 {
     if (_markerRenderer != null)
     {
         _markerRenderer.Markers = newValue;
     }
 }
Exemple #14
0
        internal static bool IsInModifiedAssembly(HashSet <LoadedAssembly> asms, TextSegmentCollection <ReferenceSegment> references)
        {
            var checkedAsmRefs = new HashSet <IAssembly>(AssemblyNameComparer.CompareAll);

            foreach (var refSeg in references)
            {
                var       r      = refSeg.Reference;
                IAssembly asmRef = null;
                if (r is IType)
                {
                    asmRef = (r as IType).DefinitionAssembly;
                }
                if (asmRef == null && r is IMemberRef)
                {
                    var type = ((IMemberRef)r).DeclaringType;
                    if (type != null)
                    {
                        asmRef = type.DefinitionAssembly;
                    }
                }
                if (asmRef != null && !checkedAsmRefs.Contains(asmRef))
                {
                    checkedAsmRefs.Add(asmRef);
                    var asm = MainWindow.Instance.CurrentAssemblyList.FindAssemblyByAssemblyName(asmRef.FullName);
                    if (asm != null && asms.Contains(asm))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
		public EditorScript(ITextEditor editor, SDRefactoringContext context, CSharpFormattingOptions formattingOptions)
			: base(editor.Document, formattingOptions, context.TextEditorOptions)
		{
			this.editor = editor;
			this.context = context;
			this.textSegmentCollection = new TextSegmentCollection<TextSegment>((TextDocument)editor.Document);
		}
		public void SetTransformations(SyntaxHighlightDataList highlightData)
		{
			Dispatcher.UIThread.InvokeAsync(() =>
			{
				var transformations = new TextSegmentCollection<TextTransformation>(document);

				foreach (var transform in highlightData)
				{
                    if (transform.Type != HighlightType.None)
                    {
                        transformations.Add(new TextTransformation
                        {
                            Foreground = GetBrush(transform.Type),
                            StartOffset = transform.Start,
                            EndOffset = transform.Start + transform.Length
                        });
                    }
				}

				TextTransformations = transformations;

				if (DataChanged != null)
				{
					DataChanged(this, new EventArgs());
				}
			});
		}
 public TextMarkerService(TextArea area)
 {
     this.area = area;
     markers   = new TextSegmentCollection <TextMarker>(area.Document);
     this.area.TextView.BackgroundRenderers.Add(this);
     this.area.TextView.LineTransformers.Add(this);
 }
        public PairedCharacterRenderer()
        {
            highlightBrush = new SolidColorBrush(Colors.LightBlue);
            highlightPen   = new Pen(highlightBrush, 1.0);

            PairedCharacters = new TextSegmentCollection <TextSegment>();
        }
Exemple #19
0
        /// <summary>
        /// Shows the given output in the text view.
        /// </summary>
        void ShowOutput(AvaloniaEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null)
        {
            Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength);
            Stopwatch w = Stopwatch.StartNew();

            ClearLocalReferenceMarks();
            textEditor.ScrollToHome();
            if (foldingManager != null)
            {
                FoldingManager.Uninstall(foldingManager);
                foldingManager = null;
            }
            textEditor.Document                  = null; // clear old document while we're changing the highlighting
            uiElementGenerator.UIElements        = textOutput.UIElements;
            referenceElementGenerator.References = textOutput.References;
            references       = textOutput.References;
            definitionLookup = textOutput.DefinitionLookup;
            textEditor.SyntaxHighlighting            = highlighting;
            textEditor.Options.EnableEmailHyperlinks = textOutput.EnableHyperlinks;
            textEditor.Options.EnableHyperlinks      = textOutput.EnableHyperlinks;
            if (activeRichTextColorizer != null)
            {
                textEditor.TextArea.TextView.LineTransformers.Remove(activeRichTextColorizer);
            }
            if (textOutput.HighlightingModel != null)
            {
                activeRichTextColorizer = new RichTextColorizer(textOutput.HighlightingModel);
                textEditor.TextArea.TextView.LineTransformers.Insert(highlighting == null ? 0 : 1, activeRichTextColorizer);
            }

            // Change the set of active element generators:
            foreach (var elementGenerator in activeCustomElementGenerators)
            {
                textEditor.TextArea.TextView.ElementGenerators.Remove(elementGenerator);
            }
            activeCustomElementGenerators.Clear();

            foreach (var elementGenerator in textOutput.elementGenerators)
            {
                textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator);
                activeCustomElementGenerators.Add(elementGenerator);
            }

            Debug.WriteLine("  Set-up: {0}", w.Elapsed); w.Restart();
            textEditor.Document = textOutput.GetDocument();
            Debug.WriteLine("  Assigning document: {0}", w.Elapsed); w.Restart();
            if (textOutput.Foldings.Count > 0)
            {
                if (state != null)
                {
                    state.RestoreFoldings(textOutput.Foldings);
                    textEditor.ScrollToVerticalOffset(state.VerticalOffset);
                    textEditor.ScrollToHorizontalOffset(state.HorizontalOffset);
                }
                foldingManager = FoldingManager.Install(textEditor.TextArea);
                foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1);
                Debug.WriteLine("  Updating folding: {0}", w.Elapsed); w.Restart();
            }
        }
 public TextMarkerService(CodeTextEditor editor)
 {
     if (editor == null) throw new ArgumentNullException(nameof(editor));
     _document = editor.Document;
     _markers = new TextSegmentCollection<TextMarker>(_document);
     _textViews = new List<TextView>();
     editor.ToolTipRequest += EditorOnToolTipRequest;
 }
Exemple #21
0
 public SegmentedDocument(SegmentedDocument templateText)
 {
     textDocument                 = new TextDocument("");
     Segments                     = new TextSegmentCollection <DocumentSegment>(textDocument);
     textDocument.Changing       += onChanging;
     textDocument.UpdateFinished += OnUpdateEnd;
     Load(templateText);
 }
Exemple #22
0
 public TextMarkerService(CodeTextEditor editor)
 {
     if (editor == null) throw new ArgumentNullException(nameof(editor));
     _document = editor.Document;
     _markers = new TextSegmentCollection<TextMarker>(_document);
     _textViews = new List<TextView>();
     editor.ToolTipRequest += EditorOnToolTipRequest;
 }
Exemple #23
0
 public SegmentedDocument(TextDocument textDocument)
 {
     this.textDocument                 = textDocument;
     Segments                          = new TextSegmentCollection <DocumentSegment>(textDocument);
     this.textDocument.Changing       += onChanging;
     this.textDocument.UpdateFinished += OnUpdateEnd;
     ReadOnlySectionProvider           = new TextSegmentReadOnlySectionProvider <TextSegment>(textDocument);
 }
Exemple #24
0
 /// <summary>
 /// Creates a new TextSegmentReadOnlySectionProvider instance using the specified TextSegmentCollection.
 /// </summary>
 public TextSegmentReadOnlySectionProvider(TextSegmentCollection <T> segments)
 {
     if (segments == null)
     {
         throw new ArgumentNullException("segments");
     }
     this.segments = segments;
 }
Exemple #25
0
 public Highlighter(JadeCore.ITextDocument doc)
 {
     if (doc == null)
         throw new ArgumentNullException("doc");
     _document = doc;
     _highlights = new TextSegmentCollection<HighlightedRange>();
     _textViews = new List<TextView>();
 }
Exemple #26
0
        public TextColoringTransformer(TextDocument document)
        {
            this.document = document;

            TextTransformations = new TextSegmentCollection <TextTransformation>(document);

            ColorScheme = ColorScheme.Default;
        }
Exemple #27
0
 /// <summary>
 /// Creates a new FoldingManager instance.
 /// </summary>
 public FoldingManager(TextDocument document)
 {
     if (document == null)
         throw new ArgumentNullException(nameof(document));
     this.document = document;
     foldings = new TextSegmentCollection<FoldingSection>();
     document.VerifyAccess();
     TextDocumentWeakEventManager.Changed.AddListener(document, this);
 }
Exemple #28
0
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (Issues == null)
            {
                return;
            }

            var segments = new TextSegmentCollection <IssueMarker>();

            foreach (var issue in Issues)
            {
                segments.Add(new IssueMarker(Theme, issue));
            }

            var visualLines = textView.VisualLines;

            if (visualLines.Count == 0)
            {
                return;
            }
            int viewStart = visualLines.First().FirstDocumentLine.Offset;
            int viewEnd   = visualLines.Last().LastDocumentLine.EndOffset;

            foreach (var marker in segments.FindOverlappingSegments(viewStart, viewEnd - viewStart))
            {
                var brush   = marker.Brush;
                var usedPen = new Pen(brush, 1);
                usedPen.Freeze();
                if (brush == null)
                {
                    continue;
                }

                foreach (var r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker))
                {
                    var startPoint = r.BottomLeft;
                    var endPoint   = r.BottomRight;

                    double offset = 2.5;

                    int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4);

                    var geometry = new StreamGeometry();

                    using (StreamGeometryContext ctx = geometry.Open())
                    {
                        ctx.BeginFigure(startPoint, false, false);
                        ctx.PolyLineTo(CreatePoints(startPoint, offset, count), true, false);
                    }

                    geometry.Freeze();


                    drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
                }
            }
        }
 void DoTest(TextSegmentCollection<SearchResult> segments, int[] expectedIndexes)
 {
     var result = segments.FirstSegment;
     const string message = "Expected {0} th match : {1}; actually {2}";
     for(int i = 0; i < segments.Count; ++i){
         Assert.AreEqual(expectedIndexes[i], result.StartOffset, message, i + 1, expectedIndexes[i], result.StartOffset);
         result = segments.GetNextSegment(result);
     }
 }
Exemple #30
0
 public TextMarkerService(TextDocument document)
 {
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     this.document = document;
     this.markers  = new TextSegmentCollection <TextMarker>(document);
 }
Exemple #31
0
		/// <summary>
		/// Creates a new FoldingManager instance.
		/// </summary>
		public FoldingManager(TextDocument document)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			this.document = document;
			this.foldings = new TextSegmentCollection<FoldingSection>();
			document.VerifyAccess();
			TextDocumentWeakEventManager.Changed.AddListener(document, this);
		}
		/// <summary>
		/// Creates a new FoldingManager instance.
		/// </summary>
		public FoldingManager(TextView textView, TextDocument document)
		{
			if (textView == null)
				throw new ArgumentNullException("textView");
			if (document == null)
				throw new ArgumentNullException("document");
			this.textView = textView;
			this.document = document;
			this.foldings = new TextSegmentCollection<FoldingSection>(document);
		}
Exemple #33
0
        /// <summary>
        /// Shows the given output in the text view.
        /// </summary>
        void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null)
        {
            Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength);
            Stopwatch w = Stopwatch.StartNew();

            ClearLocalReferenceMarks();
            textEditor.ScrollToHome();
            if (foldingManager != null)
            {
                FoldingManager.Uninstall(foldingManager);
                foldingManager = null;
            }
            textEditor.Document                  = null; // clear old document while we're changing the highlighting
            uiElementGenerator.UIElements        = textOutput.UIElements;
            referenceElementGenerator.References = textOutput.References;
            references       = textOutput.References;
            definitionLookup = textOutput.DefinitionLookup;
            textEditor.SyntaxHighlighting = highlighting;

            // Change the set of active element generators:
            foreach (var elementGenerator in activeCustomElementGenerators)
            {
                textEditor.TextArea.TextView.ElementGenerators.Remove(elementGenerator);
            }
            activeCustomElementGenerators.Clear();

            foreach (var elementGenerator in textOutput.elementGenerators)
            {
                textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator);
                activeCustomElementGenerators.Add(elementGenerator);
            }

            Debug.WriteLine("  Set-up: {0}", w.Elapsed); w.Restart();
            textEditor.Document = textOutput.GetDocument();
            Debug.WriteLine("  Assigning document: {0}", w.Elapsed); w.Restart();
            if (textOutput.Foldings.Count > 0)
            {
                if (state != null)
                {
                    state.RestoreFoldings(textOutput.Foldings);
                    textEditor.ScrollToVerticalOffset(state.VerticalOffset);
                    textEditor.ScrollToHorizontalOffset(state.HorizontalOffset);
                }
                foldingManager = FoldingManager.Install(textEditor.TextArea);
                foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1);
                Debug.WriteLine("  Updating folding: {0}", w.Elapsed); w.Restart();
            }

            // update class bookmarks
            var document = textEditor.Document;

            manager.UpdateClassMemberBookmarks(textOutput.DefinitionLookup.ToDictionary(line => document.GetLineByOffset(line).LineNumber),
                                               typeof(TypeBookmark),
                                               typeof(MemberBookmark));
        }
Exemple #34
0
        public void SetModel(TextDocument document, TMModel model)
        {
            _document        = document;
            _model           = model;
            _transformations = new TextSegmentCollection <TextTransformation>(_document);

            if (_grammar != null)
            {
                _model.SetGrammar(_grammar);
            }
        }
Exemple #35
0
 void OnDocumentChanged(object sender, EventArgs e)
 {
     if (textView.Document != null)
     {
         markers = new TextSegmentCollection <TextMarker>(textView.Document);
     }
     else
     {
         markers = null;
     }
 }
Exemple #36
0
    public TextMarkerService(TextEditor textEd)
    {
        textEditor = textEd;
        markers    = new TextSegmentCollection <TextMarker> (textEd.Document);

        var textView = textEd.TextArea.TextView;

        textView.BackgroundRenderers.Add(this);
        textView.LineTransformers.Add(this);
        textView.Services.AddService(typeof(TextMarkerService), this);
    }
Exemple #37
0
 public void Clear()
 {
     ClearMarkedReferences();
     ClearCustomElementGenerators();
     TextEditor.Document                  = new TextDocument();
     definitionLookup                     = null;
     uiElementGenerator.UIElements        = null;
     referenceElementGenerator.References = null;
     references = new TextSegmentCollection <ReferenceSegment>();
     lastOutput = new LastOutput();
 }
        public TextMarkerService(TextDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            m_document   = document;
            m_markers    = new TextSegmentCollection <TextMarker>(document);
            m_text_views = new List <TextView>();
        }
		void codeEditor_DocumentChanged(object sender, EventArgs e)
		{
			if (markers != null) {
				foreach (TextMarker m in markers.ToArray()) {
					m.Delete();
				}
			}
			if (codeEditor.Document == null)
				markers = null;
			else
				markers = new TextSegmentCollection<TextMarker>(codeEditor.Document);
		}
		/// <summary>
		/// Creates a new FoldingManager instance.
		/// </summary>
		public FoldingManager(TextView textView, TextDocument document)
		{
			if (textView == null)
				throw new ArgumentNullException("textView");
			if (document == null)
				throw new ArgumentNullException("document");
			this.textView = textView;
			this.document = document;
			this.foldings = new TextSegmentCollection<FoldingSection>();
			document.VerifyAccess();
			TextDocumentWeakEventManager.Changed.AddListener(document, this);
		}
Exemple #41
0
 void OnDocumentChanged()
 {
     ClearMarkers();
     if (TextView.Document != null)
     {
         markers = new TextSegmentCollection <TextMarker>(TextView.Document);
     }
     else
     {
         markers = null;
     }
 }
Exemple #42
0
        public void SetOutput(ITextOutput output, IHighlightingDefinition highlighting)
        {
            if (output == null)
            {
                throw new ArgumentNullException();
            }

            HideCancelButton();

            var newLastOutput = new LastOutput(output, highlighting);

            if (lastOutput.Equals(newLastOutput))
            {
                return;
            }
            lastOutput = newLastOutput;

            var avOutput = output as AvalonEditTextOutput;

            Debug.Assert(avOutput != null, "output should be an AvalonEditTextOutput instance");

            TextEditor.LanguageTokens = avOutput == null ? new LanguageTokens() : avOutput.LanguageTokens;
            TextEditor.LanguageTokens.Finish();

            ClearMarkedReferences();
            TextEditor.ScrollToHome();
            TextEditor.Document           = null;
            TextEditor.SyntaxHighlighting = highlighting;
            ClearCustomElementGenerators();

            if (avOutput == null)
            {
                uiElementGenerator.UIElements        = null;
                referenceElementGenerator.References = null;
                references          = new TextSegmentCollection <ReferenceSegment>();
                definitionLookup    = null;
                TextEditor.Document = new TextDocument(output.ToString());
            }
            else
            {
                uiElementGenerator.UIElements        = avOutput.UIElements;
                referenceElementGenerator.References = avOutput.References;
                references       = avOutput.References;
                definitionLookup = avOutput.DefinitionLookup;
                foreach (var elementGenerator in avOutput.ElementGenerators)
                {
                    TextEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator);
                    activeCustomElementGenerators.Add(elementGenerator);
                }

                TextEditor.Document = avOutput.GetDocument();
            }
        }
		/// <summary>
		/// Initializes the marker service and registers itself with the codeEditor
		/// </summary>
		/// <param name="codeEditor"></param>
		public TextMarkerService(TextEditor codeEditor)
		{
			if (codeEditor == null)
				throw new ArgumentNullException("codeEditor");
			this.Editor = codeEditor;
			markers = new TextSegmentCollection<TextMarker>(Editor.Document);

			var tv = Editor.TextArea.TextView;
			tv.Services.AddService(typeof(TextMarkerService),this);
			tv.LineTransformers.Add(this);
			tv.BackgroundRenderers.Add(this);
		}
        /// <summary>
        /// Creates a new FoldingManager instance.
        /// </summary>
        public FoldingManager(TextDocument document)
        {
            // Dirkster99 BugFix for using foldings in AvalonDock 2.0
              this.document = document;
            this.foldings = new TextSegmentCollection<FoldingSection>();

              if (document == null)
            return;
              ////throw new ArgumentNullException("document");

            ////			document.VerifyAccess();
            TextDocumentWeakEventManager.Changed.AddListener(document, this);
        }
Exemple #45
0
        public CyberConsole()
        {
            PreviousCommands = GetCommandsHistory() ?? new List <string>();
            TextSegmentCollection <TextSegment> col = new TextSegmentCollection <TextSegment>();

            TextArea.ReadOnlySectionProvider = new TextSegmentReadOnlySectionProvider <TextSegment>(col);
            TextArea.Caret.PositionChanged  += OnCaretPositionChanged;
            TextArea.TextEntering           += OnTextEntering;
            TextArea.LeftMargins.Add(NewLineMargin.Create());
            TextArea.SelectionBrush      = (Brush) new BrushConverter().ConvertFrom("#4b5e68a1");
            TextArea.SelectionForeground = (Brush) new BrushConverter().ConvertFrom("#579571");
            TextArea.SelectionBorder     = new Pen(Brushes.Transparent, 0);
        }
        public ErrorTextMarkerService(TextEditor textEditor)
        {
            this.textEditor = textEditor;
            this.markers = new TextSegmentCollection<ErrorTextMarker>(textEditor.Document);

            TextView textView = textEditor.TextArea.TextView;
            textView.BackgroundRenderers.Add(this);
            textView.LineTransformers.Add(this);
            textView.Services.AddService(typeof(ErrorTextMarkerService), this);

            textView.MouseHover += TextViewMouseHover;
            textView.MouseHoverStopped += TextViewMouseHoverStopped;
            textView.VisualLinesChanged += TextViewVisualLinesChanged;
        }
        public TextColoringTransformer(TextDocument document)
        {
            this.document = document;

            TextTransformations = new TextSegmentCollection<TextTransformation>(document);

            CommentBrush = Brush.Parse("#559A3F");
            CallExpressionBrush = Brush.Parse("Pink");
            IdentifierBrush = Brush.Parse("#D4D4D4");
            KeywordBrush = Brush.Parse("#569CD6");
            LiteralBrush = Brush.Parse("#D69D85");
            PunctuationBrush = Brush.Parse("#D4D4D4");
            UserTypeBrush = Brush.Parse("#4BB289");
        }
		public TextColoringTransformer(TextDocument document)
		{
			this.document = document;

			TextTransformations = new TextSegmentCollection<TextTransformation>(document);

			CommentBrush = Brush.Parse("#559A3F");
			CallExpressionBrush = Brush.Parse("#DCDCAA");
			IdentifierBrush = Brush.Parse("#C8C8C8");
			KeywordBrush = Brush.Parse("#569CD6");
			LiteralBrush = Brush.Parse("#D69D85");
            NumericLiteralBrush = Brush.Parse("#B5CEA8");
            EnumConstantBrush = Brush.Parse("#B5CEA8");
            EnumTypeNameBrush = Brush.Parse("#B5CEA8");
            InterfaceBrush = Brush.Parse("#B5CEA8");

            PunctuationBrush = Brush.Parse("#C8C8C8");
			UserTypeBrush = Brush.Parse("#4EC9B0");
		}
Exemple #49
0
        public TextDocument(IEditorService editor, DocumentType documentType)
            : base(editor, documentType)
        {
            // Optional services:
            _searchService = editor.Services.GetInstance<ISearchService>().WarnIfMissing();
            _propertiesService = editor.Services.GetInstance<IPropertiesService>().WarnIfMissing();

            AvalonEditDocument = new AvalonEditDocument();
            SelectionMarkers = new TextSegmentCollection<Marker>();
            SearchMarkers = new TextSegmentCollection<Marker>();
            ErrorMarkers = new TextSegmentCollection<Marker>();

            InitializeSearch();

            // The UndoStack indicates whether changes were made to the document.
            AvalonEditDocument.UndoStack.PropertyChanged += OnUndoStackChanged;
            AvalonEditDocument.TextChanged += OnTextChanged;

            Editor.ActiveDockTabItemChanged += OnEditorDockTabItemChanged;

            BeginInvokeUpdateProperties();
        }
Exemple #50
0
        //--------------------------------------------------------------
        private void InitializeSearch()
        {
            if (_searchService == null)
                return;

            // Automatically preview (highlight) all search results in the text editor.
            // The search result markers need to be updated when the search query is changed.
            var query = _searchService.Query;
            var searchQueryChanges =
              Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(h => query.PropertyChanged += h, h => query.PropertyChanged -= h)
                        .Select(e => e.EventArgs)
                        .Where(e => string.IsNullOrEmpty(e.PropertyName)
                                    || e.PropertyName == "FindPattern"
                                    || e.PropertyName == "MatchCase"
                                    || e.PropertyName == "MatchWholeWord"
                                    || e.PropertyName == "Mode"
                                    || e.PropertyName == "Scope")
                        .Select(_ => Unit.Default);

            // Additionally, the search result markers need to be updated when the text document changes.
            var documentChanges =
              Observable.FromEventPattern<DocumentChangeEventArgs>(
                            h => AvalonEditDocument.Changed += h,
                            h => AvalonEditDocument.Changed -= h)
                        .Select(_ => Unit.Default);

            // Throttle the event - the update must not block the UI thread.
            _searchUpdateSubscription =
              searchQueryChanges.Merge(documentChanges)
                                .Throttle(TimeSpan.FromSeconds(0.5))
                                .ObserveOnDispatcher()
                                .Subscribe(_ => PreviewSearchResults());

            // The actual search results are stored in a TextSegmentCollection.
            _searchResults = new TextSegmentCollection<SearchResult>(AvalonEditDocument);

            var messageBus = Editor.Services.GetInstance<IMessageBus>();
            if (messageBus != null)
            {
                _themeMessageSubscription = messageBus.Listen<ThemeMessage>().Subscribe(OnThemeMessage);
            }
        }
 public TextMarkerService(TextEditor textEditor)
 {
     this.textEditor = textEditor;
     markers = new TextSegmentCollection<TextMarker>(textEditor.Document);
 }
        private void TransformSelectedLines(Action<IDocumentLine> transformLine)
        {
            var selection = GetSelectionAsSegment();
            var lines = VisualLineGeometryBuilder.GetLinesForSegmentInDocument(TextDocument, selection);

            if (lines.Count() > 0)
            {
                var anchors = new TextSegmentCollection<TextSegment>(TextDocument);

                anchors.Add(selection);
                // TODO Add an achor to the caret index...

                TextDocument.BeginUpdate();

                foreach (var line in lines)
                {
                    transformLine(line);
                }

                TextDocument.EndUpdate();

                SetSelection(selection);
            }
        }
 void OnDocumentChanged()
 {
     ClearMarkers();
     if (TextView.Document != null)
         markers = new TextSegmentCollection<TextMarker>(TextView.Document);
     else
         markers = null;
 }
Exemple #54
0
 void OnDocumentChanged(object sender, EventArgs e)
 {
     foreach (var bm in BookmarkManager.Bookmarks) {
         var mbm = bm as MarkerBookmark;
         if (mbm != null) {
             ITextMarker marker;
             if (mbm.Markers.TryGetValue(this, out marker))
                 Remove(marker);
             mbm.Markers.Remove(this);
         }
     }
     if (TextView.Document != null)
         markers = new TextSegmentCollection<TextMarker>(TextView.Document);
     else
         markers = null;
 }
Exemple #55
0
 public TextMarkerService(TextEditor codeEditor) {
     this.codeEditor = codeEditor;
     markers = new TextSegmentCollection<TextMarker>(codeEditor.Document);
 }
 public void SetUp()
 {
     segments = new TextSegmentCollection<TextSegment>();
     provider = new TextSegmentReadOnlySectionProvider<TextSegment>(segments);
 }
Exemple #57
0
 public void SetUp()
 {
     tree = new TextSegmentCollection<TestTextSegment>();
     expectedSegments = new List<TestTextSegment>();
 }
 public SpellCheckBackgroundRenderer()
 {
     ErrorSegments = new TextSegmentCollection<TextSegment>();
 }
 public SearchBackgroundRenderer()
 {
     SearchHitsSegments = new TextSegmentCollection<TextSegment>();
 }
Exemple #60
0
 public ErrorMarker(TextEditor textEditor)
 {
     this.textEditor = textEditor;
     markers = new TextSegmentCollection<TextMarker>(textEditor.Document);
 }