Esempio n. 1
0
        private Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
        {
            if (document == null)
            {
                throw new System.ArgumentNullException("document");
            }
            Paragraph paragraph = new Paragraph();

            foreach (DocumentLine current in document.Lines)
            {
                int lineNumber = current.LineNumber;
                HighlightedInlineBuilder highlightedInlineBuilder = new HighlightedInlineBuilder(document.GetText(current));
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    int             offset          = current.Offset;
                    foreach (HighlightedSection current2 in highlightedLine.Sections)
                    {
                        highlightedInlineBuilder.SetHighlighting(current2.Offset - offset, current2.Length, current2.Color);
                    }
                }
                paragraph.Inlines.AddRange(highlightedInlineBuilder.CreateRuns());
                paragraph.Inlines.Add(new LineBreak());
            }
            return(paragraph);
        }
 /// <summary>
 /// Creates a new HighlightingColorizer instance that uses a fixed highlighter instance.
 /// The colorizer can only be used with text views that show the document for which
 /// the highlighter was created.
 /// </summary>
 /// <param name="highlighter">The highlighter to be used.</param>
 public HighlightingColorizer(IHighlighter highlighter)
 {
     if (highlighter == null)
         throw new ArgumentNullException("highlighter");
     this.highlighter = highlighter;
     this.isFixedHighlighter = true;
 }
        SearchedFile SearchForIssues(FileName fileName, ITextSource fileContent, IEnumerable <IssueManager.IssueProvider> providers, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var context = SDRefactoringContext.Create(fileName, fileContent, TextLocation.Empty, cancellationToken);
            ReadOnlyDocument document    = null;
            IHighlighter     highlighter = null;
            var results = new List <SearchResultMatch>();

            foreach (var provider in providers)
            {
                cancellationToken.ThrowIfCancellationRequested();
                foreach (var issue in provider.GetIssues(context))
                {
                    if (document == null)
                    {
                        document    = new ReadOnlyDocument(fileContent, fileName);
                        highlighter = SD.EditorControlService.CreateHighlighter(document);
                        highlighter.BeginHighlighting();
                    }
                    results.Add(SearchResultMatch.Create(document, issue.Start, issue.End, highlighter));
                }
            }
            if (highlighter != null)
            {
                highlighter.Dispose();
            }
            if (results.Count > 0)
            {
                return(new SearchedFile(fileName, results));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
		/// <summary>
		/// Converts a readonly TextDocument to a Block and applies the provided highlighter.
		/// </summary>
		public static Block ConvertTextDocumentToBlock(IDocument document, IHighlighter highlighter)
		{
			if (document == null)
				throw new ArgumentNullException("document");
//			Table table = new Table();
//			table.Columns.Add(new TableColumn { Width = GridLength.Auto });
//			table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
//			TableRowGroup trg = new TableRowGroup();
//			table.RowGroups.Add(trg);
			Paragraph p = new Paragraph();
			p.TextAlignment = TextAlignment.Left;
			for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
				if (lineNumber > 1)
					p.Inlines.Add(new LineBreak());
				var line = document.GetLineByNumber(lineNumber);
//				TableRow row = new TableRow();
//				trg.Rows.Add(row);
//				row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
//				Paragraph p = new Paragraph();
//				row.Cells.Add(new TableCell(p));
				if (highlighter != null) {
					HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
					p.Inlines.AddRange(highlightedLine.ToRichText().CreateRuns());
				} else {
					p.Inlines.Add(document.GetText(line));
				}
			}
			return p;
		}
Esempio n. 5
0
        private void OnParse(MatchItem SelectedItem)
        {
            if (SelectedItem != null)
            {
                MatchItem m = SelectedItem;

                textEditor.ScrollTo(m.CurrentLine, 0);

                if (_colorizerCollection.Count > 0 && textEditor.Document.LineCount > 1)
                {
                    textEditor.TextArea.TextView.LineTransformers.Remove(_colorizerCollection[0]);
                    IHighlighter    documentHighlighter = textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;
                    HighlightedLine result = documentHighlighter.HighlightLine(textEditor.Document.GetLineByNumber(_prevHighlightedLine).LineNumber);

                    // invalidate specific Line
                    textEditor.TextArea.TextView.Redraw(result.DocumentLine);
                    _colorizerCollection.Clear();
                }


                // Add Colors
                LineColorizer currentHighligtedLine = new LineColorizer(m.CurrentLine);

                textEditor.TextArea.TextView.LineTransformers.Add(currentHighligtedLine);

                _colorizerCollection.Add(currentHighligtedLine);

                // invalidate specific Line
                textEditor.TextArea.TextView.Redraw();

                //Keep track of previous line
                _prevHighlightedLine = m.CurrentLine;
            }
        }
Esempio n. 6
0
        private static IdentifierTooltipContent TryGetIdentifierTooltipContent([NotNull] IHighlighter highlighter, [NotNull] PsiLanguageType languageType,
                                                                               [NotNull] ISolution solution, [NotNull] IContextBoundSettingsStore settings)
        {
            var contentProvider = solution.GetComponent <IdentifierTooltipContentProvider>();

            return(contentProvider.TryGetIdentifierContent(highlighter, languageType, settings));
        }
        public IEnumerator HighlightWithColor()
        {
            foreach (Type highlighterImplementation in ReflectionUtils.GetConcreteImplementationsOf <IHighlighter>())
            {
                // Given a GameObject with at least one Renderer
                GameObject   cube         = GameObject.CreatePrimitive(PrimitiveType.Cube);
                IHighlighter highlighter  = cube.AddComponent(highlighterImplementation) as IHighlighter;
                Material     testMaterial = CreateHighlightMaterial();
                Color        testColor    = Color.green;

                testMaterial.color = testColor;

                Assert.That(highlighter != null);
                Assert.IsFalse(highlighter.IsHighlighting);

                // When StartHighlighting
                highlighter.StartHighlighting(testMaterial);

                yield return(null);

                // Then the object is highlighted with provided color
                Material highlightMaterial = highlighter.GetHighlightMaterial();

                Assert.IsTrue(highlighter.IsHighlighting);
                Assert.That(highlightMaterial.color == testColor);
            }
        }
        public IEnumerator StopHighlight()
        {
            foreach (Type highlighterImplementation in ReflectionUtils.GetConcreteImplementationsOf <IHighlighter>())
            {
                // Given a GameObject with at least one Renderer
                GameObject   cube        = GameObject.CreatePrimitive(PrimitiveType.Cube);
                IHighlighter highlighter = cube.AddComponent(highlighterImplementation) as IHighlighter;;

                Assert.That(highlighter != null);
                Assert.IsFalse(highlighter.IsHighlighting);

                // When StartHighlighting
                highlighter.StartHighlighting(CreateHighlightMaterial());

                yield return(null);

                // Then the object is highlighted and then stopped.
                Assert.IsTrue(highlighter.IsHighlighting);
                highlighter.StopHighlighting();

                yield return(null);

                Assert.IsFalse(highlighter.IsHighlighting);
            }
        }
Esempio n. 9
0
        public void FindLocalReferences(ParseInformation parseInfo, ITextSource fileContent, IVariable variable, ICompilation compilation, Action <SearchResultMatch> callback, CancellationToken cancellationToken)
        {
            var csParseInfo = parseInfo as CSharpFullParseInformation;

            if (csParseInfo == null)
            {
                throw new ArgumentException("Parse info does not have SyntaxTree");
            }

            ReadOnlyDocument document    = null;
            IHighlighter     highlighter = null;

            new FindReferences().FindLocalReferences(
                variable, csParseInfo.UnresolvedFile, csParseInfo.SyntaxTree, compilation,
                delegate(AstNode node, ResolveResult result) {
                if (document == null)
                {
                    document    = new ReadOnlyDocument(fileContent, parseInfo.FileName);
                    highlighter = SD.EditorControlService.CreateHighlighter(document);
                    highlighter.BeginHighlighting();
                }
                var region           = new DomRegion(parseInfo.FileName, node.StartLocation, node.EndLocation);
                int offset           = document.GetOffset(node.StartLocation);
                int length           = document.GetOffset(node.EndLocation) - offset;
                var builder          = SearchResultsPad.CreateInlineBuilder(node.StartLocation, node.EndLocation, document, highlighter);
                var defaultTextColor = highlighter != null ? highlighter.DefaultTextColor : null;
                callback(new SearchResultMatch(parseInfo.FileName, node.StartLocation, node.EndLocation, offset, length, builder, defaultTextColor));
            }, cancellationToken);

            if (highlighter != null)
            {
                highlighter.Dispose();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new <see cref="FixedHighlighter"/> for a copy of a portion
        /// of the input document (including the original highlighting).
        /// </summary>
        public static FixedHighlighter CreateView(IHighlighter highlighter, int offset, int endOffset)
        {
            var oldDocument = highlighter.Document;
            // ReadOnlyDocument would be better; but displaying the view in AvalonEdit
            // requires a TextDocument
            var newDocument = new TextDocument(oldDocument.CreateSnapshot(offset, endOffset - offset));

            var oldStartLine       = oldDocument.GetLineByOffset(offset);
            var oldEndLine         = oldDocument.GetLineByOffset(endOffset);
            int oldStartLineNumber = oldStartLine.LineNumber;

            HighlightedLine[] newLines = new HighlightedLine[oldEndLine.LineNumber - oldStartLineNumber + 1];
            highlighter.BeginHighlighting();
            try {
                for (int i = 0; i < newLines.Length; i++)
                {
                    HighlightedLine oldHighlightedLine = highlighter.HighlightLine(oldStartLineNumber + i);
                    IDocumentLine   newLine            = newDocument.GetLineByNumber(1 + i);
                    HighlightedLine newHighlightedLine = new HighlightedLine(newDocument, newLine);
                    MoveSections(oldHighlightedLine.Sections, -offset, newLine.Offset, newLine.EndOffset, newHighlightedLine.Sections);
                    newHighlightedLine.ValidateInvariants();
                    newLines[i] = newHighlightedLine;
                }
            } finally {
                highlighter.EndHighlighting();
            }
            return(new FixedHighlighter(newDocument, newLines));
        }
Esempio n. 11
0
		/// <summary>
		/// Creates a new <see cref="FixedHighlighter"/> for a copy of a portion
		/// of the input document (including the original highlighting).
		/// </summary>
		public static FixedHighlighter CreateView(IHighlighter highlighter, int offset, int endOffset)
		{
			var oldDocument = highlighter.Document;
			// ReadOnlyDocument would be better; but displaying the view in AvalonEdit
			// requires a TextDocument
			var newDocument = new TextDocument(oldDocument.CreateSnapshot(offset, endOffset - offset));
			
			var oldStartLine = oldDocument.GetLineByOffset(offset);
			var oldEndLine = oldDocument.GetLineByOffset(endOffset);
			int oldStartLineNumber = oldStartLine.LineNumber;
			HighlightedLine[] newLines = new HighlightedLine[oldEndLine.LineNumber - oldStartLineNumber + 1];
			highlighter.BeginHighlighting();
			try {
				for (int i = 0; i < newLines.Length; i++) {
					HighlightedLine oldHighlightedLine = highlighter.HighlightLine(oldStartLineNumber + i);
					IDocumentLine newLine = newDocument.GetLineByNumber(1 + i);
					HighlightedLine newHighlightedLine = new HighlightedLine(newDocument, newLine);
					MoveSections(oldHighlightedLine.Sections, -offset, newLine.Offset, newLine.EndOffset, newHighlightedLine.Sections);
					newHighlightedLine.ValidateInvariants();
					newLines[i] = newHighlightedLine;
				}
			} finally {
				highlighter.EndHighlighting();
			}
			return new FixedHighlighter(newDocument, newLines);
		}
Esempio n. 12
0
        /// <summary>
        /// Creates a HTML fragment for the selected text.
        /// </summary>
        public string CreateHtmlFragment(TextArea textArea, HtmlOptions options)
        {
            if (textArea == null)
            {
                throw new ArgumentNullException("textArea");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            IHighlighter  highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;
            StringBuilder html        = new StringBuilder();
            bool          first       = true;

            foreach (ISegment selectedSegment in this.Segments)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    html.AppendLine("<br>");
                }
                html.Append(HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, selectedSegment, options));
            }
            return(html.ToString());
        }
Esempio n. 13
0
		public static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
		{
			if (document == null)
				throw new ArgumentNullException("document");
//			Table table = new Table();
//			table.Columns.Add(new TableColumn { Width = GridLength.Auto });
//			table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
//			TableRowGroup trg = new TableRowGroup();
//			table.RowGroups.Add(trg);
			Paragraph p = new Paragraph();
			foreach (DocumentLine line in document.Lines) {
				int lineNumber = line.LineNumber;
//				TableRow row = new TableRow();
//				trg.Rows.Add(row);
//				row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
				HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
				if (highlighter != null) {
					HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
					int lineStartOffset = line.Offset;
					foreach (HighlightedSection section in highlightedLine.Sections)
						inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
				}
//				Paragraph p = new Paragraph();
//				row.Cells.Add(new TableCell(p));
				p.Inlines.AddRange(inlineBuilder.CreateRuns());
				p.Inlines.Add(new LineBreak());
			}
			return p;
		}
Esempio n. 14
0
        /// <summary>
        /// Converts a TextDocument to Block.
        /// </summary>
        /// <remarks>
        /// This portion of code by Daniel Grunwald from an AvalonEdit related <a href="http://community.sharpdevelop.net/forums/t/12012.aspx">forum post</a>
        /// </remarks>
        static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            Paragraph p = new Paragraph();

            foreach (DocumentLine line in document.Lines)
            {
                int lineNumber = line.LineNumber;
                HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    int             lineStartOffset = line.Offset;

                    foreach (HighlightedSection section in highlightedLine.Sections)
                    {
                        inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
                    }
                }
                p.Inlines.AddRange(inlineBuilder.CreateRuns());
                p.Inlines.Add(new LineBreak());
            }

            return(p);
        }
Esempio n. 15
0
        public void Remove(IHighlighter highlighter)
        {
            var service = ServiceLocator.Instance.Get<IHighlightingService<IHighlighter>>();
            if (service == null)
            {
                return;
            }

            var prompt = string.Format(
                "Are you sure you want to remove the selected highlighter?\r\n\r\n" +
                "Highlighter Name = \"{0}\"",
                highlighter.Name);

            var result = MessageBox.Show(
                prompt,
                "Remove Highlighter",
                MessageBoxButton.YesNo,
                MessageBoxImage.Question,
                MessageBoxResult.No);

            if (result == MessageBoxResult.Yes)
            {
                service.Highlighters.Remove(highlighter);
            }
        }
        public void Remove(IHighlighter highlighter)
        {
            var service = ServiceLocator.Instance.Get <IHighlightingService <IHighlighter> >();

            if (service == null)
            {
                return;
            }

            var prompt = string.Format(
                "Are you sure you want to remove the selected highlighter?\r\n\r\n" +
                "Highlighter Name = \"{0}\"",
                highlighter.Name);

            var result = MessageBox.Show(
                prompt,
                "Remove Highlighter",
                MessageBoxButton.YesNo,
                MessageBoxImage.Question,
                MessageBoxResult.No);

            if (result == MessageBoxResult.Yes)
            {
                service.Highlighters.Remove(highlighter);
            }
        }
Esempio n. 17
0
 private static IdentifierContentGroup GetIdentifierContentGroup(
     [NotNull] IHighlighter highlighter,
     [NotNull] ISolution solution,
     [NotNull] IContextBoundSettingsStore settings)
 => solution
 .GetComponent <IdentifierTooltipContentProvider>()
 .GetIdentifierContentGroup(highlighter, settings);
Esempio n. 18
0
 public static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
 {
     if (document == null)
         throw new ArgumentNullException("document");
     //			Table table = new Table();
     //			table.Columns.Add(new TableColumn { Width = GridLength.Auto });
     //			table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
     //			TableRowGroup trg = new TableRowGroup();
     //			table.RowGroups.Add(trg);
     Paragraph p = new Paragraph();
     foreach (DocumentLine line in document.Lines) {
         int lineNumber = line.LineNumber;
     //				TableRow row = new TableRow();
     //				trg.Rows.Add(row);
     //				row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
         HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
         if (highlighter != null) {
             HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
             int lineStartOffset = line.Offset;
             foreach (HighlightedSection section in highlightedLine.Sections)
                 inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
         }
     //				Paragraph p = new Paragraph();
     //				row.Cells.Add(new TableCell(p));
         p.Inlines.AddRange(inlineBuilder.CreateRuns());
         p.Inlines.Add(new LineBreak());
     }
     return p;
 }
Esempio n. 19
0
 public void Higlight(IHighlighter h)
 {
     UseWaitCursor = true;
     Highlighter   = h;
     h.Highlight(rtb);
     UseWaitCursor = false;
 }
        private void ShowRefactoringAdvice(IHighlighter highlighter, InplaceRefactoringInfo refactoringInfo)
        {
            sequentialLifetimes.Next(refactoringLifetime =>
            {
                var message = GetMessage();
                var options = GetOptions(refactoringInfo);
                agent.ShowBalloon(refactoringLifetime, string.Empty, message, options, new[] { "Cancel" }, false,
                                  balloonLifetime =>
                {
                    currentHighlighter = highlighter;

                    agent.ButtonClicked.Advise(balloonLifetime, _ => sequentialLifetimes.TerminateCurrent());
                    agent.BalloonOptionClicked.Advise(balloonLifetime, tag =>
                    {
                        // Terminate first. This kills the balloon window before we start
                        // the refactoring UI. If we start the refactoring UI first, I think
                        // it picks up the balloon window as its parent, and it closes when
                        // the balloon closes
                        sequentialLifetimes.TerminateCurrent();

                        var action = tag as Action;
                        if (action != null)
                        {
                            action();
                        }
                    });
                });
            });
        }
Esempio n. 21
0
        const string LineSelectedType = "MSDEVLineSelect";  // This is the type VS 2003 and 2005 use for flagging a whole line copy

        static void CopyWholeLine(TextArea textArea, DocumentLine line)
        {
            ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
            string   text      = textArea.Document.GetText(wholeLine);

            // Ensure we use the appropriate newline sequence for the OS
            text = TextUtilities.NormalizeNewLines(text, Environment.NewLine);
            DataObject data = new DataObject(text);

            // Also copy text in HTML format to clipboard - good for pasting text into Word
            // or to the SharpDevelop forums.
            IHighlighter highlighter = textArea.GetService(typeof(IHighlighter)) as IHighlighter;

            HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, wholeLine, new HtmlOptions(textArea.Options)));

            MemoryStream lineSelected = new MemoryStream(1);

            lineSelected.WriteByte(1);
            data.SetData(LineSelectedType, lineSelected, false);

            try
            {
                Clipboard.SetDataObject(data, true);
            }
            catch (ExternalException)
            {
                // Apparently this exception sometimes happens randomly.
                // The MS controls just ignore it, so we'll do the same.
                return;
            }
            textArea.OnTextCopied(new TextEventArgs(text));
        }
 /// <summary>
 /// This method is called when a text view is removed from this HighlightingColorizer,
 /// and also when the TextDocument on any associated text view changes.
 /// </summary>
 protected virtual void DeregisterServices(TextView textView)
 {
     if (highlighter != null)
     {
         if (isInHighlightingGroup)
         {
             highlighter.EndHighlighting();
             isInHighlightingGroup = false;
         }
         highlighter.HighlightingStateChanged -= OnHighlightStateChanged;
         // remove highlighter if it is registered
         if (textView.Services.GetService(typeof(IHighlighter)) == highlighter)
         {
             textView.Services.RemoveService(typeof(IHighlighter));
         }
         if (!isFixedHighlighter)
         {
             if (highlighter != null)
             {
                 highlighter.Dispose();
             }
             highlighter = null;
         }
     }
 }
Esempio n. 23
0
        /// <summary>
        /// Creates a FlowDocument from TextEditor text.
        /// </summary>
        /// <remarks>
        /// This portion of code by Daniel Grunwald from an AvalonEdit related <a href="http://community.sharpdevelop.net/forums/t/12012.aspx">forum post</a>
        /// </remarks>
        static FlowDocument CreateFlowDocumentForEditor(TextEditor editor, bool withHighlighting)
        {
            IHighlighter highlighter = (withHighlighting) ? editor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter : null;
            FlowDocument doc         = new FlowDocument(ConvertTextDocumentToBlock(editor.Document, highlighter));

            return(doc);
        }
Esempio n. 24
0
        /// <summary>
        /// Converts an IDocument to a Block and applies the provided highlighter.
        /// </summary>
        public static Block ConvertTextDocumentToBlock(IDocument document, IHighlighter highlighter)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            Paragraph p = new Paragraph();

            p.TextAlignment = TextAlignment.Left;
            for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++)
            {
                if (lineNumber > 1)
                {
                    p.Inlines.Add(new LineBreak());
                }
                var line = document.GetLineByNumber(lineNumber);
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    p.Inlines.AddRange(highlightedLine.ToRichText().CreateRuns());
                }
                else
                {
                    p.Inlines.Add(document.GetText(line));
                }
            }
            return(p);
        }
Esempio n. 25
0
        /// <summary>
        /// Converts an IDocument to a RichText and applies the provided highlighter.
        /// </summary>
        public static RichText ConvertTextDocumentToRichText(IDocument document, IHighlighter highlighter)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            var texts = new List <RichText>();

            for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++)
            {
                var line = document.GetLineByNumber(lineNumber);
                if (lineNumber > 1)
                {
                    texts.Add(line.PreviousLine.DelimiterLength == 2 ? "\r\n" : "\n");
                }
                if (highlighter != null)
                {
                    HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
                    texts.Add(highlightedLine.ToRichText());
                }
                else
                {
                    texts.Add(document.GetText(line));
                }
            }
            return(RichText.Concat(texts.ToArray()));
        }
Esempio n. 26
0
        private Block ConvertTextDocumentToBlock()
        {
            TextDocument document    = textEditor.Document;
            IHighlighter highlighter =
                textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;

            return(DocumentPrinter.ConvertTextDocumentToBlock(document, highlighter));

            //Paragraph p = new Paragraph();
            //foreach (DocumentLine line in document.Lines)
            //{
            //    int lineNumber = line.LineNumber;
            //    HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
            //    if (highlighter != null)
            //    {
            //        HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
            //        int lineStartOffset = line.Offset;
            //        foreach (HighlightedSection section in highlightedLine.Sections)
            //            inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
            //    }
            //    p.Inlines.AddRange(inlineBuilder.CreateRuns());
            //    p.Inlines.Add(new LineBreak());
            //}

            //return p;
        }
Esempio n. 27
0
        private IdentifierTooltipContent TryPresentNonColorized(
            [CanBeNull] IHighlighter highlighter,
            [CanBeNull] IDeclaredElement element,
            [NotNull] IContextBoundSettingsStore settings)
        {
            RichTextBlock richTextToolTip = highlighter?.RichTextToolTip;

            if (richTextToolTip == null)
            {
                return(null);
            }

            RichText richText = richTextToolTip.RichText;

            if (richText.IsNullOrEmpty())
            {
                return(null);
            }

            var identifierContent = new IdentifierTooltipContent(richText, highlighter.Range);

            if (element != null && settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                identifierContent.Icon = TryGetIcon(element);
            }
            return(identifierContent);
        }
Esempio n. 28
0
        public override IEnumerable <BulbMenuItem> GetBulbMenuItems(IHighlighter highlighter)
        {
            if (!(highlighter.UserData is UnityRunMarkerHighlighting runMarker))
            {
                yield break;
            }

            var solution = Shell.Instance.GetComponent <SolutionsManager>().Solution;

            if (solution == null)
            {
                yield break;
            }

            switch (runMarker.AttributeId)
            {
            case UnityRunMarkerAttributeIds.RUN_METHOD_MARKER_ID:
                foreach (var item in GetRunMethodItems(solution, runMarker))
                {
                    yield return(item);
                }
                yield break;

            default:
                yield break;
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Creates a HTML fragment from a part of a document.
        /// </summary>
        /// <param name="document">The document to create HTML from.</param>
        /// <param name="highlighter">The highlighter used to highlight the document. <c>null</c> is valid and will create HTML without any highlighting.</param>
        /// <param name="segment">The part of the document to create HTML for. You can pass <c>null</c> to create HTML for the whole document.</param>
        /// <param name="options">The options for the HTML creation.</param>
        /// <returns>HTML code for the document part.</returns>
        public static string CreateHtmlFragment(TextDocument document, IHighlighter highlighter, ISegment segment, HtmlOptions options)
        {
            if (document == null)
                throw new ArgumentNullException("document");
            if (options == null)
                throw new ArgumentNullException("options");
            if (highlighter != null && highlighter.Document != document)
                throw new ArgumentException("Highlighter does not belong to the specified document.");
            if (segment == null)
                segment = new SimpleSegment(0, document.TextLength);

            StringBuilder html = new StringBuilder();
            int segmentEndOffset = segment.EndOffset;
            DocumentLine line = document.GetLineByOffset(segment.Offset);
            while (line != null && line.Offset < segmentEndOffset) {
                HighlightedLine highlightedLine;
                if (highlighter != null)
                    highlightedLine = highlighter.HighlightLine(line.LineNumber);
                else
                    highlightedLine = new HighlightedLine(document, line);
                SimpleSegment s = segment.GetOverlap(line);
                if (html.Length > 0)
                    html.AppendLine("<br>");
                html.Append(highlightedLine.ToHtml(s.Offset, s.EndOffset, options));
                line = line.NextLine;
            }
            return html.ToString();
        }
Esempio n. 30
0
        private Block ConvertTextDocumentToBlock()
        {
            TextDocument document    = textEditor.Document;
            IHighlighter highlighter =
                textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;

            return(DocumentPrinter.ConvertTextDocumentToBlock(document, highlighter));
        }
Esempio n. 31
0
        /// <summary>
        /// Returns a file highlighter capable of highlighting the specified file.
        /// </summary>
        /// <param name="filePath">Path to the file, for which a valid highlighter should be found.</param>
        /// <returns>IHighlighter instance capable of highlighting the specified file, or null if no was found.</returns>
        public static IHighlighter GetFileHighlighterForPath(string filePath)
        {
            string       extension           = System.IO.Path.GetExtension(filePath);
            IHighlighter matchingHighlighter = null;

            sFileHighlighters.TryGetValue(extension, out matchingHighlighter);
            return(matchingHighlighter);
        }
        /// <summary>
        /// ActionFilter that implements the Highlight functionality
        /// </summary>
        public HighlightSearch()
        {
            var container = (IUnityContainer)GlobalConfiguration.
                            Configuration.DependencyResolver.GetService(typeof(IUnityContainer));

            _highlighter = container.Resolve <IHighlighter>();;
            _helper      = container.Resolve <IJokesHelper>();;
        }
Esempio n. 33
0
 public static FlowDocument CreateFlowDocumentForEditor(TextEditor editor)
 {
     IHighlighter highlighter = editor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;
     FlowDocument doc = new FlowDocument(ConvertTextDocumentToBlock(editor.Document, highlighter));
     doc.FontFamily = editor.FontFamily;
     doc.FontSize = editor.FontSize;
     return doc;
 }
Esempio n. 34
0
 public EditableSourceCode()
 {
     this.highlighter = new C99Highlighter();
     this.DefaultStyleKey = typeof(EditableSourceCode);
     this.ApplyTemplate();
     this.Background = new SolidColorBrush(colorBackground);
     this.Unloaded += EditableSourceCode_Unloaded;
     this.oldlen = 0;
 }
Esempio n. 35
0
        /// <summary>
        /// Creates a flow document from the editor's contents.
        /// </summary>
        public static FlowDocument CreateFlowDocumentForEditor(TextEditor editor, List <VisualLineElementGenerator> visualLineElementGenerators)
        {
            IHighlighter highlighter = editor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;
            FlowDocument doc         = new FlowDocument(ConvertTextDocumentToBlock(editor.Document, highlighter, visualLineElementGenerators));

            doc.FontFamily = editor.FontFamily;
            doc.FontSize   = editor.FontSize;
            return(doc);
        }
Esempio n. 36
0
        /// <summary>
        /// Creates a FlowDocument from TextEditor text.
        /// </summary>
        static FlowDocument CreateFlowDocumentForEditor(TextEditor editor)
        {
            // ref.:  http://community.sharpdevelop.net/forums/t/12012.aspx
            IHighlighter highlighter = editor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;

            FlowDocument doc = new FlowDocument(ConvertTextDocumentToBlock(editor.Document, highlighter));

            return(doc);
        }
 /// <summary>
 /// Creates a new HighlightingColorizer instance that uses a fixed highlighter instance.
 /// The colorizer can only be used with text views that show the document for which
 /// the highlighter was created.
 /// </summary>
 /// <param name="highlighter">The highlighter to be used.</param>
 public HighlightingColorizer(IHighlighter highlighter)
 {
     if (highlighter == null)
     {
         throw new ArgumentNullException("highlighter");
     }
     this.highlighter        = highlighter;
     this.isFixedHighlighter = true;
 }
Esempio n. 38
0
        public string GenerateHtml(TextDocument document, IHighlighter highlighter)
        {
            string myMainStyle = MainStyle;
            string LineNumberStyle = "color: #606060;";

            StringWriter output = new StringWriter();
            if (ShowLineNumbers || AlternateLineBackground) {
                output.Write("<div");
                WriteStyle(output, myMainStyle);
                output.WriteLine(">");

                int longestNumberLength = 1 + (int)Math.Log10(document.LineCount);

                for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
                    HighlightedLine line = highlighter.HighlightLine(lineNumber);
                    output.Write("<pre");
                    if (AlternateLineBackground && (lineNumber % 2) == 0) {
                        WriteStyle(output, AlternateLineStyle);
                    } else {
                        WriteStyle(output, LineStyle);
                    }
                    output.Write(">");

                    if (ShowLineNumbers) {
                        output.Write("<span");
                        WriteStyle(output, LineNumberStyle);
                        output.Write('>');
                        output.Write(lineNumber.ToString().PadLeft(longestNumberLength));
                        output.Write(":  ");
                        output.Write("</span>");
                    }

                    PrintWords(output, line);
                    output.WriteLine("</pre>");
                }
                output.WriteLine("</div>");
            } else {
                output.Write("<pre");
                WriteStyle(output, myMainStyle + LineStyle);
                output.WriteLine(">");
                for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
                    HighlightedLine line = highlighter.HighlightLine(lineNumber);
                    PrintWords(output, line);
                    output.WriteLine();
                }
                output.WriteLine("</pre>");
            }
            if (CreateStylesheet && stylesheet.Length > 0) {
                string result = "<style type=\"text/css\">" + stylesheet.ToString() + "</style>" + output.ToString();
                stylesheet = new StringBuilder();
                return result;
            } else {
                return output.ToString();
            }
        }
Esempio n. 39
0
        public override IEnumerable<BulbMenuItem> GetBulbMenuItems(IHighlighter highlighter)
        {
            yield return new BulbMenuItem(new ExecutableItem(() =>
            {
                ISolution solution = GetCurrentSolution();

                var clickable = solution?.GetComponent<IDaemon>().GetHighlighting(highlighter) as IClickableGutterHighlighting;
                clickable?.OnClick();

            }), highlighter.ToolTip, IconId, BulbMenuAnchors.PermanentBackgroundItems, true);
        }
Esempio n. 40
0
		public static SearchResultMatch Create(IDocument document, TextLocation startLocation, TextLocation endLocation, IHighlighter highlighter)
		{
			int startOffset = document.GetOffset(startLocation);
			int endOffset = document.GetOffset(endLocation);
			var inlineBuilder = SearchResultsPad.CreateInlineBuilder(startLocation, endLocation, document, highlighter);
			var defaultTextColor = highlighter.DefaultTextColor;
			return new SearchResultMatch(FileName.Create(document.FileName),
			                             startLocation, endLocation,
			                             startOffset, endOffset - startOffset,
			                             inlineBuilder, defaultTextColor);
		}
Esempio n. 41
0
        public SearchPager(IndexSearcher indexSearcher, IISearcher[] searchers, IHighlighter highlighter, int hitsPerPage)
        {
            if (searchers == null || searchers.Length == 0) throw new ArgumentNullException("searchers", "No searcher specified.");

            this.indexSearcher = indexSearcher;
            this.searchers = searchers;
            this.hitsPerPage = hitsPerPage;
            this.highlighter = highlighter;

            Initialize();
        }
Esempio n. 42
0
        public override void OnClick(IHighlighter highlighter)
        {
            ISolution currentSolution = Shell.Instance.GetComponent<ISolutionManager>().CurrentSolution;
            if (currentSolution == null)
            {
                return;
            }

            var clickable = JetBrains.ReSharper.Daemon.Daemon.GetInstance(currentSolution).GetHighlighting(highlighter) as IClickableGutterHighlighting;
            if (clickable != null)
            {
                clickable.OnClick();
            }
        }
Esempio n. 43
0
        public override IEnumerable<BulbMenuItem> GetBulbMenuItems(IHighlighter highlighter)
        {
            var solution = Shell.Instance.GetComponent<SolutionsManager>().Solution;
            if (solution == null)
                return EmptyList<BulbMenuItem>.InstanceList;

            var textControlManager = solution.GetComponent<ITextControlManager>();
            var textControl = textControlManager.FocusedTextControl.Value;

            var daemon = solution.GetComponent<IDaemon>();
            var highlighting = daemon.GetHighlighting(highlighter) as UnityMarkOnGutter;
            if (highlighting != null)
                return highlighting.GetBulbMenuItems(solution, textControl);

            return EmptyList<BulbMenuItem>.InstanceList;
        }
		/// <summary>
		/// This method is called when a text view is removed from this HighlightingColorizer,
		/// and also when the TextDocument on any associated text view changes.
		/// </summary>
		protected virtual void DeregisterServices(TextView textView)
		{
			if (highlighter != null) {
				if (isInHighlightingGroup) {
					highlighter.EndHighlighting();
					isInHighlightingGroup = false;
				}
				highlighter.HighlightingStateChanged -= OnHighlightStateChanged;
				// remove highlighter if it is registered
				if (textView.Services.GetService(typeof(IHighlighter)) == highlighter)
					textView.Services.RemoveService(typeof(IHighlighter));
				if (!isFixedHighlighter) {
					if (highlighter != null)
						highlighter.Dispose();
					highlighter = null;
				}
			}
		}
Esempio n. 45
0
		/// <summary>
		/// Converts an IDocument to a RichText and applies the provided highlighter.
		/// </summary>
		public static RichText ConvertTextDocumentToRichText(IDocument document, IHighlighter highlighter)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			var texts = new List<RichText>();
			for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
				var line = document.GetLineByNumber(lineNumber);
				if (lineNumber > 1)
					texts.Add(line.PreviousLine.DelimiterLength == 2 ? "\r\n" : "\n");
				if (highlighter != null) {
					HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
					texts.Add(highlightedLine.ToRichText());
				} else {
					texts.Add(document.GetText(line));
				}
			}
			return RichText.Concat(texts.ToArray());
		}
Esempio n. 46
0
		/// <summary>
		/// Converts an IDocument to a Block and applies the provided highlighter.
		/// </summary>
		public static Block ConvertTextDocumentToBlock(IDocument document, IHighlighter highlighter)
		{
			if (document == null)
				throw new ArgumentNullException("document");
			Paragraph p = new Paragraph();
			p.TextAlignment = TextAlignment.Left;
			for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
				if (lineNumber > 1)
					p.Inlines.Add(new LineBreak());
				var line = document.GetLineByNumber(lineNumber);
				if (highlighter != null) {
					HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
					p.Inlines.AddRange(highlightedLine.ToRichText().CreateRuns());
				} else {
					p.Inlines.Add(document.GetText(line));
				}
			}
			return p;
		}
Esempio n. 47
0
 public HighlightedRange(IHighlighter highlighter, int startOffset, int length)
 {
     _highlighter = highlighter;
     StartOffset = startOffset;
     Length = length;
 }
			public CustomizingHighlighter(IEnumerable<CustomizedHighlightingColor> customizations, IHighlighter baseHighlighter)
			{
				Debug.Assert(customizations != null);
				this.customizations = customizations;
				this.baseHighlighter = baseHighlighter;
			}
Esempio n. 49
0
 /// <summary>
 /// This method is called when a new text view is added to this HighlightingColorizer,
 /// and also when the TextDocument on any associated text view changes.
 /// </summary>
 protected virtual void RegisterServices(TextView textView)
 {
     if (textView.Document != null) {
         if (!isFixedHighlighter)
             highlighter = textView.Document != null ? CreateHighlighter(textView, textView.Document) : null;
         if (highlighter != null && highlighter.Document == textView.Document) {
             // add service only if it doesn't already exist
             if (textView.Services.GetService(typeof(IHighlighter)) == null) {
                 textView.Services.AddService(typeof(IHighlighter), highlighter);
             }
             highlighter.HighlightingStateChanged += OnHighlightStateChanged;
         }
     }
 }
Esempio n. 50
0
 private Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
 {
     if (document == null)
     {
         throw new System.ArgumentNullException("document");
     }
     Paragraph paragraph = new Paragraph();
     foreach (DocumentLine current in document.Lines)
     {
         int lineNumber = current.LineNumber;
         HighlightedInlineBuilder highlightedInlineBuilder = new HighlightedInlineBuilder(document.GetText(current));
         if (highlighter != null)
         {
             HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
             int offset = current.Offset;
             foreach (HighlightedSection current2 in highlightedLine.Sections)
             {
                 highlightedInlineBuilder.SetHighlighting(current2.Offset - offset, current2.Length, current2.Color);
             }
         }
         paragraph.Inlines.AddRange(highlightedInlineBuilder.CreateRuns());
         paragraph.Inlines.Add(new LineBreak());
     }
     return paragraph;
 }
 public override string GetTooltip(IHighlighter highlighter)
 {
     // method overrided for debug only
     // TODO static tooltip for predefined elements: appender, looger, root, appender-ref, level
     return base.GetTooltip(highlighter);
 }
 public override void OnClick(IHighlighter highlighter)
 {
 }
Esempio n. 53
0
 private void DaxEditor_DocumentChanged(object sender, EventArgs e)
 {
     if (this.Document == null ) return;
     if (this.SyntaxHighlighting == null) return;
     documentHighlighter = new DocumentHighlighter( this.Document, this.SyntaxHighlighting);
 }
Esempio n. 54
0
		public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, IHighlighter highlighter)
		{
			if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) {
				var matchedLine = document.GetLineByNumber(startPosition.Line);
				HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(matchedLine));
				if (highlighter != null) {
					HighlightedLine highlightedLine = highlighter.HighlightLine(startPosition.Line);
					int startOffset = highlightedLine.DocumentLine.Offset;
					// copy only the foreground color
					foreach (HighlightedSection section in highlightedLine.Sections) {
						if (section.Color.Foreground != null) {
							inlineBuilder.SetForeground(section.Offset - startOffset, section.Length, section.Color.Foreground.GetBrush(null));
						}
					}
				}
				
				// now highlight the match in bold
				if (startPosition.Column >= 1) {
					if (endPosition.Line == startPosition.Line && endPosition.Column > startPosition.Column) {
						// subtract one from the column to get the offset inside the line's text
						int startOffset = startPosition.Column - 1;
						int endOffset = Math.Min(inlineBuilder.Text.Length, endPosition.Column - 1);
						inlineBuilder.SetFontWeight(startOffset, endOffset - startOffset, FontWeights.Bold);
					}
				}
				return inlineBuilder;
			}
			return null;
		}
Esempio n. 55
0
 public HighlighterConverter(IHighlighter highlighter)
 {
     this.highlighter = highlighter;
 }
Esempio n. 56
0
		public static RichText CreateInlineBuilder(TextLocation startPosition, TextLocation endPosition, IDocument document, IHighlighter highlighter)
		{
			if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) {
				var highlightedLine = highlighter.HighlightLine(startPosition.Line);
				var documentLine = highlightedLine.DocumentLine;
				var inlineBuilder = highlightedLine.ToRichTextModel();
				// reset bold/italics
				inlineBuilder.SetFontWeight(0, documentLine.Length, FontWeights.Normal);
				inlineBuilder.SetFontStyle(0, documentLine.Length, FontStyles.Normal);
				
				// now highlight the match in bold
				if (startPosition.Column >= 1) {
					if (endPosition.Line == startPosition.Line && endPosition.Column > startPosition.Column) {
						// subtract one from the column to get the offset inside the line's text
						int startOffset = startPosition.Column - 1;
						int endOffset = Math.Min(documentLine.Length, endPosition.Column - 1);
						inlineBuilder.SetFontWeight(startOffset, endOffset - startOffset, FontWeights.Bold);
					}
				}
				return new RichText(document.GetText(documentLine), inlineBuilder);
			}
			return null;
		}
 private static TextStyle GetVisualStudioForeColour(IHighlighterCustomization highlighterCustomization, IHighlighter highlighter)
 {
     var highlighterAttributes = highlighterCustomization.GetCustomizedHighlighterAttributes(highlighter);
     return TextStyle.FromForeColor(highlighterAttributes.Color);
 }
Esempio n. 58
0
        /// <summary>
        /// Converts a TextDocument to Block.
        /// </summary>
        static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
        {
            // ref.:  http://community.sharpdevelop.net/forums/t/12012.aspx
              if (document == null)
            throw new ArgumentNullException("document");

              Paragraph p = new Paragraph();

              foreach (DocumentLine line in document.Lines)
              {
            int lineNumber = line.LineNumber;

            HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));

            if (highlighter != null)
            {
              HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);

              int lineStartOffset = line.Offset;

              foreach (HighlightedSection section in highlightedLine.Sections)
            inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
            }

            p.Inlines.AddRange(inlineBuilder.CreateRuns());
            p.Inlines.Add(new LineBreak());
              }

              return p;
        }
		public CustomizingHighlighter(IHighlighter baseHighlighter, IEnumerable<CustomizedHighlightingColor> customizations)
		{
			if (baseHighlighter == null)
				throw new ArgumentNullException("baseHighlighter");
			if (customizations == null)
				throw new ArgumentNullException("customizations");
			
			this.customizations = customizations;
			this.baseHighlighter = baseHighlighter;
		}
Esempio n. 60
0
        public void Edit(IHighlighter highlighter)
        {
            Debug.Assert(highlighter != null, "Highligher must be supplied for editing.");

            AddEditHighlighterWindow window = new AddEditHighlighterWindow();
            AddEditHighlighter data = new AddEditHighlighter(window, false);
            window.DataContext = data;
            window.Owner = Application.Current.MainWindow;

            data.Name = highlighter.Name;
            data.Pattern = highlighter.Pattern;
            data.Mode = highlighter.Mode;
            data.Field = highlighter.Field;

            if (highlighter.Style != null && highlighter.Style.Background != null)
            {
                data.OverrideBackgroundColour = true;
                data.BackgroundColour = (Color)highlighter.Style.Background;
            }
            else
            {
                data.OverrideBackgroundColour = false;
                data.BackgroundColourIndex = 1;
            }

            if (highlighter.Style != null && highlighter.Style.Foreground != null)
            {
                data.OverrideForegroundColour = true;
                data.ForegroundColour = (Color)highlighter.Style.Foreground;
            }
            else
            {
                data.OverrideForegroundColour = false;
                data.ForegroundColourIndex = 0;
            }

            bool? dialogResult = window.ShowDialog();

            if (dialogResult != null && (bool)dialogResult)
            {
                highlighter.Name = data.Name;
                highlighter.Pattern = data.Pattern;
                highlighter.Mode = data.Mode;
                highlighter.Field = data.Field;

                if (highlighter.Style == null && (data.OverrideBackgroundColour || data.OverrideForegroundColour))
                {
                    highlighter.Style = new HighlighterStyle();
                }

                if (highlighter.Style != null)
                {
                    highlighter.Style.Background = data.OverrideBackgroundColour
                                                       ? (Color?)data.BackgroundColour
                                                       : null;
                    highlighter.Style.Foreground = data.OverrideForegroundColour
                                                       ? (Color?)data.ForegroundColour
                                                       : null;
                }
            }
        }