Ejemplo n.º 1
0
        private void ResaltarError(DocumentLine Linea, System.Windows.Media.Color Color)
        {
            ITextMarker marker = this.TextMarkerService.Create(Linea.Offset, Linea.Length);

            marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
            marker.MarkerColor = Color;
        }
Ejemplo n.º 2
0
        private void HighlightObjectRef(TextViewPosition?position)
        {
            if (position == null)
            {
                return;
            }

            if (_objectRefMarker != null)
            {
                _colorTransformer.Remove(_objectRefMarker);
            }
            var line    = Editor.Document.GetLineByNumber(position.Value.Line);
            var regex   = new Regex(@"[^a-zA-Z0-9]\d+\s\d+\sR[^a-zA-Z0-9]");
            var matches = regex.Matches(Editor.Document.GetText(line));

            foreach (Match match in matches)
            {
                if (match.Index < position.Value.Location.Column &&
                    match.Index + match.Length > position.Value.Location.Column)
                {
                    _objectRefMarker = _colorTransformer.Create(line.Offset + match.Index + 1,
                                                                match.Length - 2);
                    _objectRefMarker.MarkerTypes = TextMarkerTypes.NormalUnderline;
                    _objectRefMarker.MarkerColor = Colors.Blue;
                }
            }
        }
Ejemplo n.º 3
0
        void AddMarkerFromSelectionClick(object sender, RoutedEventArgs e)
        {
            ITextMarker marker = textMarkerService.Create(textEditor.SelectionStart, textEditor.SelectionLength);

            marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
            marker.MarkerColor = Colors.Red;
        }
Ejemplo n.º 4
0
        public void HandleToolTipRequest(ToolTipRequestEventArgs args)
        {
            if (args.InDocument)
            {
                int offset = args.Editor.Document.GetOffset(args.LogicalPosition);

                FoldingManager foldings = args.Editor.GetService(typeof(FoldingManager)) as FoldingManager;
                if (foldings != null)
                {
                    var            foldingsAtOffset = foldings.GetFoldingsAt(offset);
                    FoldingSection collapsedSection = foldingsAtOffset.FirstOrDefault(section => section.IsFolded);

                    if (collapsedSection != null)
                    {
                        args.SetToolTip(GetTooltipTextForCollapsedSection(args, collapsedSection));
                    }
                }

                TextMarkerService textMarkerService = args.Editor.GetService(typeof(ITextMarkerService)) as TextMarkerService;
                if (textMarkerService != null)
                {
                    var         markersAtOffset   = textMarkerService.GetMarkersAtOffset(offset);
                    ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

                    if (markerWithToolTip != null)
                    {
                        args.SetToolTip(markerWithToolTip.ToolTip);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void TE_TextChanged(object sender, EventArgs e)
        {
            toolTipService.RemoveAll();
            textMarkerService.RemoveAll(delegate(ITextMarker marker) { return(true); });

            var textEditor = sender as TextEditor;
            var text       = textEditor.Text;
            var tuple      = Controller.Check(text);

            Errors = tuple.Item2;
            tree   = tuple.Item1;

            Debug.WriteLine("\n");
            Errors.ForEach((VoltaCompilerError error) => {
                int offset         = textEditor.Document.GetOffset(error.Line, error.Column);
                ITextMarker marker = textMarkerService.Create(offset, 0);
                marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                marker.MarkerColor = Colors.Red;

                toolTipService.CreateErrorToolTip(error, marker as TextMarker);
            });

            OnErrorListUpdated?.Invoke(Errors);

            if (e != null)
            {
                CodeFile.HasUnsavedChanges = true;
            }
        }
Ejemplo n.º 6
0
		public virtual void RemoveMarker()
		{
			if (marker != null) {
				marker.Delete();
				marker = null;
			}
		}
Ejemplo n.º 7
0
            ITextMarker FindNextMarker(Point mousePos)
            {
                var    renderSize     = this.RenderSize;
                var    document       = editor.Document;
                var    textView       = editor.TextArea.TextView;
                double documentHeight = textView.DocumentHeight;

                ITextMarker bestMarker   = null;
                double      bestDistance = double.PositiveInfinity;

                foreach (var marker in textMarkerService.TextMarkers)
                {
                    if (!IsVisibleInAdorner(marker))
                    {
                        continue;
                    }
                    var    location  = document.GetLocation(marker.StartOffset);
                    double visualTop = textView.GetVisualTopByDocumentLine(location.Line);
                    double renderPos = visualTop / documentHeight * renderSize.Height;

                    double distance = Math.Abs(renderPos - mousePos.Y);
                    if (distance < bestDistance)
                    {
                        bestDistance = distance;
                        bestMarker   = marker;
                    }
                }
                return(bestMarker);
            }
Ejemplo n.º 8
0
        private void MouseHover(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var pos = m_textEditor.GetPositionFromPoint(e.GetPosition(m_textEditor));

            if (pos.HasValue)
            {
                var markersAtOffset = MarkerService.GetMarkersAtOffset(m_textEditor.Document, m_textEditor.Document.GetOffset(new TextLocation(pos.Value.Line, pos.Value.Column)));
                if (markersAtOffset == null)
                {
                    return;
                }
                ITextMarker markerWithToolTip = markersAtOffset.FirstOrDefault(marker => marker.ToolTip != null);

                if (markerWithToolTip != null && markerWithToolTip.ToolTip != null)
                {
                    if (toolTip == null)
                    {
                        toolTip         = new System.Windows.Controls.ToolTip();
                        toolTip.Closed += ToolTipClosed;
                    }
                    toolTip.PlacementTarget = m_textEditor; // required for property inheritance
                    toolTip.Content         = markerWithToolTip.ToolTip;
                    toolTip.IsOpen          = true;
                    e.Handled = true;
                }
            }
        }
Ejemplo n.º 9
0
        void AddErrorHighlight(int start, int length)
        {
            ITextMarker marker = textMarkerService.Create(start, length);

            marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
            marker.MarkerColor = Colors.Red;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Function writes diagnostic information to DiagnosticListView
        /// </summary>
        /// <param name="diagnostics">Diagnostic to be written</param>
        private void WriteDiagnostic(IEnumerable <DiagnosticHelper> diagnostics)
        {
            foreach (DiagnosticHelper diagnostic in diagnostics)
            {
                lastDiagnostics_.Add(diagnostic);

                // Create and display markers in document
                if (diagnostic.Location.Location == CodeLocation.LocationType.InSource)
                {
                    DocumentLine line = SourceCodeTextBox.Document.GetLineByNumber(diagnostic.Location.Line);

                    ITextMarker marker = textMarkerService_.Create(line.Offset, line.Length);
                    marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                    if (diagnostic.Severity == DiagnosticHelper.SeverityType.Error)
                    {
                        marker.MarkerColor = Colors.Red;
                    }
                    else if (diagnostic.Severity == DiagnosticHelper.SeverityType.Warning)
                    {
                        marker.MarkerColor = Colors.Yellow;
                    }
                    else if (diagnostic.Severity == DiagnosticHelper.SeverityType.Info)
                    {
                        marker.MarkerColor = Colors.Blue;
                    }
                }
            }
        }
        public void ShowExample(TextArea exampleTextArea)
        {
            string exampleText            = StringParser.Parse(color.ExampleText, GetXshdProperties().ToArray());
            int    semanticHighlightStart = exampleText.IndexOf("#{#", StringComparison.OrdinalIgnoreCase);
            int    semanticHighlightEnd   = exampleText.IndexOf("#}#", StringComparison.OrdinalIgnoreCase);

            if (semanticHighlightStart > -1 && semanticHighlightEnd >= semanticHighlightStart + 3)
            {
                semanticHighlightEnd -= 3;
                exampleText           = exampleText.Remove(semanticHighlightStart, 3).Remove(semanticHighlightEnd, 3);
                ITextMarkerService svc = exampleTextArea.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
                exampleTextArea.Document.Text = exampleText;
                if (svc != null)
                {
                    ITextMarker m = svc.Create(semanticHighlightStart, semanticHighlightEnd - semanticHighlightStart);
                    m.Tag = (Action <IHighlightingItem, ITextMarker>)(
                        (IHighlightingItem item, ITextMarker marker) => {
                        marker.BackgroundColor = item.Background;
                        marker.ForegroundColor = item.Foreground;
                        marker.FontStyle       = item.Italic ? FontStyles.Italic : FontStyles.Normal;
                        marker.FontWeight      = item.Bold ? FontWeights.Bold : FontWeights.Normal;
                        if (item.Underline)
                        {
                            marker.MarkerColor = item.Foreground;
                            marker.MarkerTypes = TextMarkerTypes.NormalUnderline;
                        }
                    });
                }
            }
            else
            {
                exampleTextArea.Document.Text = exampleText;
            }
        }
Ejemplo n.º 12
0
 public virtual void RemoveMarker()
 {
     if (marker != null)
     {
         marker.Delete();
         marker = null;
     }
 }
Ejemplo n.º 13
0
        protected override ITextMarker CreateMarker(ITextMarkerService markerService)
        {
            ITextMarker marker = null;

            marker.BackgroundColor = System.Windows.Media.Color.FromRgb(180, 38, 38);
            marker.ForegroundColor = Colors.White;
            return(marker);
        }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CSharpCodeProvider provider   = new CSharpCodeProvider();
                CompilerParameters parameters = new CompilerParameters();
                parameters.ReferencedAssemblies.Add("System.dll");
                parameters.ReferencedAssemblies.Add("System.Net.Http.dll");
                //parameters.ReferencedAssemblies.Add("PresentationFramework.dll");
                //parameters.ReferencedAssemblies.Add("PresentationCore.dll");
                //parameters.ReferencedAssemblies.Add("System.dll");
                parameters.ReferencedAssemblies.Add("FacebookIDE.exe");
                parameters.GenerateInMemory   = true;
                parameters.GenerateExecutable = false;


                CompilerResults results = provider.CompileAssemblyFromSource(parameters, editor.Document.Text);

                ErrorList.Clear();
                textMarkerService.RemoveAll(m => true);
                if (results.Errors.Count > 0)
                {
                    foreach (CompilerError err in results.Errors)
                    {
                        ErrorList.Add(err);

                        var         line   = editor.Document.GetLineByNumber(err.Line);
                        ITextMarker marker = textMarkerService.Create(line.Offset + err.Column, line.Length);
                        marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline;
                        marker.MarkerColor = Colors.Red;
                    }
                    return;
                }

                Assembly assembly = results.CompiledAssembly;
                Type     program  = assembly.GetType("Script");
                var      method   = program.GetMethod("GetSeries");
                var      method2  = program.GetMethod("GetCollection");
                var      instance = assembly.CreateInstance("Script");

                method.Invoke(instance, null);

                SeriesCollection s = (SeriesCollection)method2.Invoke(instance, null);

                chart.Series = s;

                tab_control.SelectedIndex = 1;
            }
            catch (TargetInvocationException tie)
            {
                MessageBox.Show(tie.Message + "\r\n\r\n" + tie.InnerException.Message, "Script Error", MessageBoxButton.OK, MessageBoxImage.Error);;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 15
0
        protected override ITextMarker CreateMarker(ITextMarkerService markerService)
        {
            IDocumentLine line   = this.Document.GetLine(this.LineNumber);
            ITextMarker   marker = markerService.Create(line.Offset, line.Length);

            marker.BackgroundColor = Color.FromRgb(180, 38, 38);
            marker.ForegroundColor = Colors.White;
            return(marker);
        }
Ejemplo n.º 16
0
        protected override ITextMarker CreateMarker(ITextMarkerService markerService)
        {
            IDocumentLine line   = this.Document.GetLine(startLine);
            ITextMarker   marker = markerService.Create(line.Offset + startColumn - 1, Math.Max(endColumn - startColumn, 1));

            marker.BackgroundColor = Colors.Yellow;
            marker.ForegroundColor = Colors.Blue;
            return(marker);
        }
		public void SetUpFixture()
		{
			try {
				string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
				PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
			} catch (Exception) {}
			
			document = MockTextMarkerService.CreateDocumentWithMockService();
			string code = "\t\t{\r\n" +
				"\t\t\tint count = 0;\r\n" +
				"\t\t}\r\n";
			document.Text = code;
			markerStrategy = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			
			string xml = "<CoverageSession xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" +
				"\t<Modules>\r\n" +
				"\t\t<Module hash=\"44-54-B6-13-97-49-45-F8-6A-74-9E-49-0C-77-87-C6-9C-54-47-7A\">\r\n" +
				"\t\t\t<FullName>C:\\Projects\\Test\\Foo.Tests\\bin\\Foo.Tests.DLL</FullName>\r\n" +
				"\t\t\t<ModuleName>Foo.Tests</ModuleName>\r\n" +
				"\t\t\t<Files>\r\n" +
				"\t\t\t\t<File uid=\"1\" fullPath=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" +
				"\t\t\t</Files>\r\n" +
				"\t\t\t<Classes>\r\n" +
				"\t\t\t\t<Class>\r\n" +
				"\t\t\t\t\t<FullName>Foo.Tests.FooTestFixture</FullName>\r\n" +
				"\t\t\t\t\t<Methods>\r\n" +
				"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"false\" isStatic=\"false\" isGetter=\"false\" isSetter=\"false\">\r\n" +
				"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
				"\t\t\t\t\t\t\t<Name>System.Void Foo.Tests.FooTestFixture::SimpleTest()</Name>\r\n" +
				"\t\t\t\t\t\t\t<FileRef uid=\"1\" />\r\n" +
				"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
				"\t\t\t\t\t\t\t\t<SequencePoint vc=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"4\" />\r\n" +
				"\t\t\t\t\t\t\t\t<SequencePoint vc=\"1\" sl=\"2\" sc=\"4\" el=\"2\" ec=\"18\" />\r\n" +
				"\t\t\t\t\t\t\t\t<SequencePoint vc=\"0\" sl=\"3\" sc=\"3\" el=\"3\" ec=\"4\" />\r\n" +
				"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
				"\t\t\t\t\t\t</Method>\r\n" +
				"\t\t\t\t\t</Methods>\r\n" +
				"\t\t\t\t</Class>\r\n" +
				"\t\t\t</Classes>\r\n" +
				"\t\t</Module>\r\n" +
				"\t</Modules>\r\n" +
				"</CoverageSession>";
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(document, method.SequencePoints);
			
			foreach (ITextMarker marker in markerStrategy.TextMarkers) {
				if (markerOne == null) {
					markerOne = marker;
				} else if (markerTwo == null) {
					markerTwo = marker;
				} else if (markerThree == null) {
					markerThree = marker;
				}
			}
		}
Ejemplo n.º 18
0
        void AddTask(SDTask task)
        {
            if (!isEnabled)
            {
                return;
            }
            if (!CheckTask(task))
            {
                return;
            }

            if (task.Line >= 1 && task.Line <= textEditor.Document.LineCount)
            {
                LoggingService.Debug(task.ToString());
                int offset    = textEditor.Document.GetOffset(task.Line, task.Column);
                int endOffset = TextUtilities.GetNextCaretPosition(textEditor.Document, offset, System.Windows.Documents.LogicalDirection.Forward, CaretPositioningMode.WordBorderOrSymbol);
                if (endOffset < 0)
                {
                    endOffset = textEditor.Document.TextLength;
                }
                int length = endOffset - offset;

                if (length < 1)
                {
                    // marker should be at least 1 characters long,
                    // but take care that we don't make it longer than the document
                    length = Math.Min(1, textEditor.Document.TextLength - offset);
                }

                ITextMarker marker = this.markerService.Create(offset, length);

                Color markerColor = Colors.Transparent;

                switch (task.TaskType)
                {
                case TaskType.Error:
                    markerColor = ErrorColor;
                    break;

                case TaskType.Message:
                    markerColor = MessageColor;
                    break;

                case TaskType.Warning:
                    markerColor = WarningColor;
                    break;
                }

                marker.MarkerColor = markerColor;
                marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline | TextMarkerTypes.LineInScrollBar;

                marker.ToolTip = task.Description;

                marker.Tag = task;
            }
        }
Ejemplo n.º 19
0
        void AddTask(Task task)
        {
            if (!isEnabled)
            {
                return;
            }
            if (!CheckTask(task))
            {
                return;
            }

            if (task.Line >= 1 && task.Line <= textEditor.Document.TotalNumberOfLines)
            {
                LoggingService.Debug(task.ToString());
                int offset    = textEditor.Document.PositionToOffset(task.Line, task.Column);
                int endOffset = TextUtilities.GetNextCaretPosition(DocumentUtilitites.GetTextSource(textEditor.Document), offset, System.Windows.Documents.LogicalDirection.Forward, CaretPositioningMode.WordBorderOrSymbol);
                if (endOffset < 0)
                {
                    endOffset = textEditor.Document.TextLength;
                }
                int length = endOffset - offset;

                if (length < 2)
                {
                    // marker should be at least 2 characters long, but take care that we don't make
                    // it longer than the document
                    length = Math.Min(2, textEditor.Document.TextLength - offset);
                }

                ITextMarker marker = this.markerService.Create(offset, length);

                Color markerColor = Colors.Transparent;

                switch (task.TaskType)
                {
                case TaskType.Error:
                    markerColor = Colors.Red;
                    break;

                case TaskType.Message:
                    markerColor = Colors.Blue;
                    break;

                case TaskType.Warning:
                    markerColor = Colors.Orange;
                    break;
                }

                marker.MarkerColor = markerColor;
                marker.MarkerType  = TextMarkerType.SquigglyUnderline;

                marker.ToolTip = task.Description;

                marker.Tag = task;
            }
        }
Ejemplo n.º 20
0
        public void CodeCoverageHighlighterRemoveMarkersDoesNotThrowInvalidCastExceptionWhenOneMarkerTagIsTask()
        {
            ITextMarker textMarker = markerService.Create(0, 2);

            textMarker.Tag = new Task(null, String.Empty, 1, 1, TaskType.Error);

            CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();

            Assert.DoesNotThrow(delegate { highlighter.RemoveMarkers(document); });
        }
Ejemplo n.º 21
0
		public void SetMarker()
		{
			RemoveMarker();
			if (this.Document != null) {
				ITextMarkerService markerService = this.Document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
				if (markerService != null) {
					marker = CreateMarker(markerService);
				}
			}
		}
Ejemplo n.º 22
0
		public void Remove(ITextMarker marker)
		{
			if (marker == null)
				throw new ArgumentNullException("marker");
			TextMarker m = marker as TextMarker;
			if (markers.Remove(m)) {
				Redraw(m);
				m.OnDeleted();
			}
		}
		public void SetUpFixture()
		{
			IDocument document = MockTextMarkerService.CreateDocumentWithMockService();
			ITextMarkerService markerStrategy = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			string code = "\t\t{\r\n" +
				"\t\t\tAssert.AreEqual(0, childElementCompletionData.Length, \"\" +\r\n" +
				"\t\t\t                \"Not expecting any child elements.\");\r\n" +
				"\t\t}\r\n";
			document.Text = code;

			string xml = "<CoverageSession xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n" +
				"\t<Modules>\r\n" +
				"\t\t<Module hash=\"44-54-B6-13-97-49-45-F8-6A-74-9E-49-0C-77-87-C6-9C-54-47-7A\">\r\n" +
				"\t\t\t<FullName>C:\\Projects\\Test\\Foo.Tests\\bin\\Foo.Tests.DLL</FullName>\r\n" +
				"\t\t\t<ModuleName>Foo.Tests</ModuleName>\r\n" +
				"\t\t\t<Files>\r\n" +
				"\t\t\t\t<File uid=\"1\" fullPath=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" +
				"\t\t\t</Files>\r\n" +
				"\t\t\t<Classes>\r\n" +
				"\t\t\t\t<Class>\r\n" +
				"\t\t\t\t\t<FullName>Foo.Tests.FooTestFixture</FullName>\r\n" +
				"\t\t\t\t\t<Methods>\r\n" +
				"\t\t\t\t\t\t<Method visited=\"true\" cyclomaticComplexity=\"1\" sequenceCoverage=\"100\" branchCoverage=\"100\" isConstructor=\"false\" isStatic=\"false\" isGetter=\"false\" isSetter=\"false\">\r\n" +
				"\t\t\t\t\t\t\t<MetadataToken>100663297</MetadataToken>\r\n" +
				"\t\t\t\t\t\t\t<Name>System.Void Foo.Tests.FooTestFixture::SimpleTest()</Name>\r\n" +
				"\t\t\t\t\t\t\t<FileRef uid=\"1\" />\r\n" +
				"\t\t\t\t\t\t\t<SequencePoints>\r\n" +
				"\t\t\t\t\t\t\t\t<SequencePoint vc=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"4\" />\r\n" +
				"\t\t\t\t\t\t\t\t<SequencePoint vc=\"1\"  sl=\"2\" sc=\"4\" el=\"3\" ec=\"57\" />\r\n" +
				"\t\t\t\t\t\t\t\t<SequencePoint vc=\"1\" sl=\"4\" sc=\"3\" el=\"4\" ec=\"4\" />\r\n" +
				"\t\t\t\t\t\t\t</SequencePoints>\r\n" +
				"\t\t\t\t\t\t</Method>\r\n" +
				"\t\t\t\t\t</Methods>\r\n" +
				"\t\t\t\t</Class>\r\n" +
				"\t\t\t</Classes>\r\n" +
				"\t\t</Module>\r\n" +
				"\t</Modules>\r\n" +
				"</CoverageSession>";
			
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(document, method.SequencePoints);
			
			foreach (ITextMarker marker in markerStrategy.TextMarkers) {
				if (markerOne == null) {
					markerOne = marker;
				} else if (markerTwo == null) {
					markerTwo = marker;
				} else if (markerThree == null) {
					markerThree = marker;
				}
			}
		}
Ejemplo n.º 24
0
        private void AddTask(Task task)
        {
            if (!CheckTask(task))
            {
                return;
            }

            ISourceEditor editor = Document as ISourceEditor;

            if (task.Line >= 1 && task.Line <= editor.TextEditor.LineCount)
            {
                int offset = editor.TextEditor.Document.GetOffset(new TextLocation(task.Line, task.Column));
                int length = task.Length == 0 ? EditorHelper.GetWordAt(editor.TextEditor.Document, offset).Length : task.Length;

                if (length < 2)
                {
                    // marker should be at least 2 characters long, but take care that we don't make
                    // it longer than the document
                    length = Math.Min(2, editor.TextEditor.Document.TextLength - offset);
                }

                ITextMarker marker = MarkerService.Create(editor, offset, length);

                marker.PropertyChanged += (sender, args) =>
                {
                    ITextMarker m = sender as ITextMarker;
                    editor.TextEditor.TextArea.TextView.Redraw(m, DispatcherPriority.Normal);
                };

                Color markerColor = Colors.Transparent;

                switch (task.TaskType)
                {
                case TaskType.Error:
                    markerColor = Colors.Red;
                    break;

                case TaskType.Message:
                    markerColor = Colors.Blue;
                    break;

                case TaskType.Warning:
                    markerColor = Colors.Orange;
                    break;
                }

                marker.MarkerColor = markerColor;
                marker.MarkerType  = task.Underline ? TextMarkerType.SquigglyUnderline : TextMarkerType.None;

                marker.ToolTip = task.Description;

                marker.Tag = task;
            }
        }
Ejemplo n.º 25
0
        public override ITextMarker CreateMarker(ITextMarkerService markerService, DecompilerTextView textView)
        {
            ITextMarker marker = CreateMarkerInternal(markerService, textView);
            var         cm     = textView == null ? null : textView.CodeMappings;

            marker.ZOrder            = ZOrder;
            marker.HighlightingColor = () => IsEnabled ? HighlightingColor : DisabledHighlightingColor;
            marker.IsVisible         = b => cm != null && b is BreakpointBookmark && cm.ContainsKey(((BreakpointBookmark)b).MethodKey);
            marker.Bookmark          = this;
            return(marker);
        }
Ejemplo n.º 26
0
 private void SetMarker()
 {
     RemoveMarker();
     if (this.Document != null)
     {
         ITextMarkerService markerService = this.Document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
         if (markerService != null)
         {
             marker = CreateMarker(markerService);
         }
     }
 }
Ejemplo n.º 27
0
        public override ITextMarker CreateMarker(ITextMarkerService markerService, int offset, int length)
        {
            ITextMarker marker = markerService.Create(offset + startColumn - 1, length + 1);

            marker.BackgroundColor = Colors.Yellow;
            marker.ForegroundColor = Colors.Blue;
            marker.IsVisible       = b => b is MarkerBookmark && DebugInformation.CodeMappings != null &&
                                     DebugInformation.CodeMappings.ContainsKey(((MarkerBookmark)b).MemberReference.MDToken.ToInt32());
            marker.Bookmark = this;
            this.Marker     = marker;
            return(marker);
        }
Ejemplo n.º 28
0
        /// <summary>Remove a specific marker</summary>
        public void Remove(ITextMarker marker)
        {
            if (marker == null)
            {
                throw new ArgumentNullException("marker");
            }

            if (marker is TextMarker m && m_markers.Remove(m))
            {
                Redraw(m);
                m.OnDeleted();
            }
        }
Ejemplo n.º 29
0
        public void Remove(ITextMarker marker)
        {
            TextMarker m = marker as TextMarker;

            if (m != null)
            {
                if (m_Markers != null && m_Markers.Remove(m))
                {
                    Redraw(m);
                    m.OnDeleted();
                }
            }
        }
Ejemplo n.º 30
0
 public void AddMarker(XPathNodeMatch node)
 {
     if (node.HasLineInfo() && node.Value.Length > 0)
     {
         int offset = document.PositionToOffset(node.LineNumber + 1, node.LinePosition + 1);
         if (markerService != null)
         {
             ITextMarker marker = markerService.Create(offset, node.Value.Length);
             marker.Tag             = typeof(XPathNodeTextMarker);
             marker.BackgroundColor = MarkerBackColor;
         }
     }
 }
Ejemplo n.º 31
0
        public override ITextMarker CreateMarker(ITextMarkerService markerService, int offset, int length)
        {
            ITextMarker marker = markerService.Create(offset, length);

            marker.BackgroundColor = Color.FromRgb(180, 38, 38);
            marker.ForegroundColor = Colors.White;
            marker.IsVisible       = b => b is BreakpointBookmark && DebugInformation.CodeMappings != null &&
                                     DebugInformation.CodeMappings.ContainsKey(((BreakpointBookmark)b).FunctionToken);
            marker.Bookmark = this;
            this.Marker     = marker;

            return(marker);
        }
Ejemplo n.º 32
0
        public override ITextMarker CreateMarker(ITextMarkerService markerService, int offset, int length)
        {
            ITextMarker marker = markerService.Create(offset, length);

            marker.BackgroundColor = Color.FromRgb(180, 38, 38);
            marker.ForegroundColor = Colors.White;
            marker.IsVisible       = b => b is MarkerBookmark && DebugInformation.DecompiledMemberReferences != null &&
                                     DebugInformation.DecompiledMemberReferences.ContainsKey(((MarkerBookmark)b).MemberReference.MetadataToken.ToInt32());
            marker.Bookmark = this;
            this.Marker     = marker;

            return(marker);
        }
Ejemplo n.º 33
0
        bool IsSelected(ITextMarker marker)
        {
            int selectionEndOffset = textEditor.SelectionStart + textEditor.SelectionLength;

            if (marker.StartOffset >= textEditor.SelectionStart && marker.StartOffset <= selectionEndOffset)
            {
                return(true);
            }
            if (marker.EndOffset >= textEditor.SelectionStart && marker.EndOffset <= selectionEndOffset)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 34
0
        public void Remove(ITextMarker marker)
        {
            if (marker == null)
            {
                throw new ArgumentNullException(nameof(marker));
            }
            TextMarker m = marker as TextMarker;

            if (markers != null && markers.Remove(m))
            {
                Redraw(m);
                m.OnDeleted();
            }
        }
Ejemplo n.º 35
0
		protected override void Initialize(DecompilerTextView textView, ITextMarkerService markerService, ITextMarker marker) {
			marker.HighlightingColor = () => {
				switch (type) {
				case StackFrameLineType.CurrentStatement:
					return DebuggerColors.StackFrameCurrentHighlightingColor;
				case StackFrameLineType.SelectedReturnStatement:
					return DebuggerColors.StackFrameSelectedHighlightingColor;
				case StackFrameLineType.ReturnStatement:
					return DebuggerColors.StackFrameReturnHighlightingColor;
				default:
					throw new InvalidOperationException();
				}
			};
		}
Ejemplo n.º 36
0
        public void SetUpFixture()
        {
            try {
                string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
                PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
            } catch (Exception) {}

            IDocument          document       = MockTextMarkerService.CreateDocumentWithMockService();
            ITextMarkerService markerStrategy = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
            string             code           = "\t\t{\r\n" +
                                                "\t\t\tAssert.AreEqual(0, childElementCompletionData.Length, \"\" +\r\n" +
                                                "\t\t\t                \"Not expecting any child elements.\");\r\n" +
                                                "\t\t}\r\n";

            document.Text = code;

            string xml = "<PartCoverReport>\r\n" +
                         "\t<file id=\"1\" url=\"c:\\Projects\\XmlEditor\\Test\\Schema\\SingleElementSchemaTestFixture.cs\" />\r\n" +
                         "\t<Assembly id=\"1\" name=\"XmlEditor.Tests\" module=\"C:\\Projects\\Test\\XmlEditor.Tests\\bin\\XmlEditor.Tests.DLL\" domain=\"test-domain-XmlEditor.Tests.dll\" domainIdx=\"1\" />\r\n" +
                         "\t<Type asmref=\"1\" name=\"XmlEditor.Tests.Schema.SingleElementSchemaTestFixture\">\r\n" +
                         "\t\t<Method name=\"NoteElementHasNoChildElements\">\r\n" +
                         "\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"4\" />\r\n" +
                         "\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"2\" sc=\"4\" el=\"3\" ec=\"57\" />\r\n" +
                         "\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"4\" sc=\"3\" el=\"4\" ec=\"4\" />\r\n" +
                         "\t\t</Method>\r\n" +
                         "\t</Type>\r\n" +
                         "</PartCoverReport>";

            CodeCoverageResults     results     = new CodeCoverageResults(new StringReader(xml));
            CodeCoverageMethod      method      = results.Modules[0].Methods[0];
            CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();

            highlighter.AddMarkers(document, method.SequencePoints);

            foreach (ITextMarker marker in markerStrategy.TextMarkers)
            {
                if (markerOne == null)
                {
                    markerOne = marker;
                }
                else if (markerTwo == null)
                {
                    markerTwo = marker;
                }
                else if (markerThree == null)
                {
                    markerThree = marker;
                }
            }
        }
		public void SetUpFixture()
		{
			try {
				string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
				PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
			} catch (Exception) {}
			
			IDocument document = MockTextMarkerService.CreateDocumentWithMockService();
			ITextMarkerService markerStrategy = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			string code = "\t\t{\r\n" +
				"\t\t\tAssert.AreEqual(0, childElementCompletionData.Length, \"\" +\r\n" +
				"\t\t\t                \"Not expecting any child elements.\");\r\n" +
				"\t\t}\r\n";
			document.Text = code;

			string xml = "<PartCoverReport>\r\n" +
				"\t<file id=\"1\" url=\"c:\\Projects\\XmlEditor\\Test\\Schema\\SingleElementSchemaTestFixture.cs\" />\r\n" +
				"\t<Assembly id=\"1\" name=\"XmlEditor.Tests\" module=\"C:\\Projects\\Test\\XmlEditor.Tests\\bin\\XmlEditor.Tests.DLL\" domain=\"test-domain-XmlEditor.Tests.dll\" domainIdx=\"1\" />\r\n" +
				"\t<Type asmref=\"1\" name=\"XmlEditor.Tests.Schema.SingleElementSchemaTestFixture\">\r\n" +
				"\t\t<Method name=\"NoteElementHasNoChildElements\">\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"1\" sc=\"3\" el=\"1\" ec=\"4\" />\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"2\" sc=\"4\" el=\"3\" ec=\"57\" />\r\n" +
				"\t\t\t<pt visit=\"1\" fid=\"1\" sl=\"4\" sc=\"3\" el=\"4\" ec=\"4\" />\r\n" +
				"\t\t</Method>\r\n" +
				"\t</Type>\r\n" +
				"</PartCoverReport>";
			
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(document, method.SequencePoints);
			
			foreach (ITextMarker marker in markerStrategy.TextMarkers) {
				if (markerOne == null) {
					markerOne = marker;
				} else if (markerTwo == null) {
					markerTwo = marker;
				} else if (markerThree == null) {
					markerThree = marker;
				}
			}
		}
		public void Init()
		{
			string xml = "<root><foo/></root>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//root");
			
			IDocument doc = MockTextMarkerService.CreateDocumentWithMockService();
			doc.Text = xml;
			XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
			xpathNodeMarker.AddMarkers(nodes);
			
			ITextMarkerService service = doc.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			markers = new List<ITextMarker>(service.TextMarkers);
			
			// Remove markers.
			XPathNodeTextMarker.RemoveMarkers(doc);
			markersAfterRemove = new List<ITextMarker>(service.TextMarkers);
			
			xpathNodeTextMarker = markers[0];
		}
		public void SetUpFixture()
		{
			try {
				string configFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NCoverAddIn.Tests");
				PropertyService.InitializeService(configFolder, Path.Combine(configFolder, "data"), "NCoverAddIn.Tests");
			} catch (Exception) {}
			
			document = MockTextMarkerService.CreateDocumentWithMockService();
			string code = "\t\t{\r\n" +
				"\t\t\tint count = 0;\r\n" +
				"\t\t}\r\n";
			document.Text = code;
			markerStrategy = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			
			string xml = "<PartCoverReport>\r\n" +
				"<File id=\"1\" url=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" +
				"<Assembly id=\"1\" name=\"Foo.Tests\" module=\"C:\\Projects\\Test\\Foo.Tests\\bin\\Foo.Tests.DLL\" domain=\"test-domain-Foo.Tests.dll\" domainIdx=\"1\" />\r\n" +
				"\t<Type asmref=\"1\" name=\"Foo.Tests.FooTestFixture\" flags=\"1232592\">\r\n" +
				"\t\t<Method name=\"SimpleTest\">\r\n" +
				"\t\t\t<pt visit=\"1\" sl=\"1\" fid=\"1\" sc=\"3\" el=\"1\" ec=\"4\" document=\"c:\\Projects\\Foo\\Foo1TestFixture.cs\" />\r\n" +
				"\t\t\t<pt visit=\"1\" sl=\"2\" fid=\"1\" sc=\"4\" el=\"2\" ec=\"18\" document=\"c:\\Projects\\Foo\\Foo1TestFixture.cs\" />\r\n" +
				"\t\t\t<pt visit=\"0\" sl=\"3\" fid=\"1\" sc=\"3\" el=\"3\" ec=\"4\" document=\"c:\\Projects\\Foo\\Foo1TestFixture.cs\" />\r\n" +
				"\t\t</Method>\r\n" +
				"\t</Type>\r\n" +
				"</PartCoverReport>";
			CodeCoverageResults results = new CodeCoverageResults(new StringReader(xml));
			CodeCoverageMethod method = results.Modules[0].Methods[0];
			CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter();
			highlighter.AddMarkers(document, method.SequencePoints);
			
			foreach (ITextMarker marker in markerStrategy.TextMarkers) {
				if (markerOne == null) {
					markerOne = marker;
				} else if (markerTwo == null) {
					markerTwo = marker;
				} else if (markerThree == null) {
					markerThree = marker;
				}
			}
		}
		public void Remove(ITextMarker marker)
		{
			marker.Delete();
		}
Ejemplo n.º 41
0
			protected override void Initialize(DecompilerTextView textView, ITextMarkerService markerService, ITextMarker marker) {
				marker.HighlightingColor = () => ilbp.IsEnabled ? DebuggerColors.CodeBreakpointHighlightingColor : DebuggerColors.CodeBreakpointDisabledHighlightingColor;
			}
		bool IsCodeCoverageTextMarker(ITextMarker marker)
		{
			Type type = marker.Tag as Type;
			return type == typeof(CodeCoverageHighlighter);
		}
Ejemplo n.º 43
0
 static bool IsXPathNodeTextMarker(ITextMarker marker)
 {
     return (Type)marker.Tag == typeof(XPathNodeTextMarker);
 }
Ejemplo n.º 44
0
		public void Remove(ITextMarker marker)
		{
			if (marker == null)
				return;
			
			TextMarker m = marker as TextMarker;
			if (markers.Remove(m)) {
				Redraw(m);
				m.OnDeleted();
			}
		}
		protected override void OnMouseMove(MouseEventArgs e)
		{
			int line = GetLineFromMousePosition(e);
			
			if (line == 0)
				return;
			
			int startLine;
			bool added;
			string oldText = changeWatcher.GetOldVersionFromLine(line, out startLine, out added);
			
			TextEditor editor = this.TextView.Services.GetService(typeof(TextEditor)) as TextEditor;
			markerService = this.TextView.Services.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			
			int offset, length;
			bool hasNewVersion = changeWatcher.GetNewVersionFromLine(line, out offset, out length);
			
			if (hasNewVersion) {
				if (marker != null)
					markerService.Remove(marker);
				if (length <= 0) {
					marker = null;
					length = 0;
				} else {
					marker = markerService.Create(offset, length);
					marker.BackgroundColor = Colors.LightGreen;
				}
			}
			
			if (oldText != null) {
				DiffControl differ = new DiffControl();
				differ.editor.SyntaxHighlighting = editor.SyntaxHighlighting;
				differ.editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
				differ.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
				differ.editor.Document.Text = oldText;
				differ.Background = Brushes.White;
				
				// TODO : deletions on line 0 cannot be displayed.
				
				LineChangeInfo prevLineInfo = changeWatcher.GetChange(startLine - 1);
				LineChangeInfo lineInfo = changeWatcher.GetChange(startLine);
				
				if (prevLineInfo.Change == ChangeType.Deleted) {
					var docLine = editor.Document.GetLineByNumber(startLine - 1);
					differ.editor.Document.Insert(0, editor.Document.GetText(docLine.Offset, docLine.TotalLength));
				}
				
				if (oldText == string.Empty) {
					differ.editor.Visibility = Visibility.Collapsed;
					differ.copyButton.Visibility = Visibility.Collapsed;
				} else {
					var baseDocument = new TextDocument(changeWatcher.BaseDocument.Text);
					var mainHighlighter = new DocumentHighlighter(baseDocument, differ.editor.SyntaxHighlighting.MainRuleSet);
					var popupHighlighter = differ.editor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter;
					
					if (prevLineInfo.Change == ChangeType.Deleted)
						popupHighlighter.InitialSpanStack = mainHighlighter.GetSpanStack(prevLineInfo.OldStartLineNumber);
					else
						popupHighlighter.InitialSpanStack = mainHighlighter.GetSpanStack(lineInfo.OldStartLineNumber);
				}
				
				differ.revertButton.Click += delegate {
					if (hasNewVersion) {
						int delimiter = 0;
						DocumentLine l = Document.GetLineByOffset(offset + length);
						if (added)
							delimiter = l.DelimiterLength;
						if (length == 0)
							oldText += DocumentUtilitites.GetLineTerminator(new AvalonEditDocumentAdapter(Document, null), l.LineNumber);
						Document.Replace(offset, length + delimiter, oldText);
						tooltip.IsOpen = false;
					}
				};
				
				tooltip.Child = new Border() {
					Child = differ,
					BorderBrush = Brushes.Black,
					BorderThickness = new Thickness(1)
				};
				
				if (tooltip.IsOpen)
					tooltip.IsOpen = false;
				
				tooltip.IsOpen = true;
				
				tooltip.Closed += delegate {
					if (marker != null) markerService.Remove(marker);
				};
				
				tooltip.HorizontalOffset = -10;
				tooltip.VerticalOffset =
					TextView.GetVisualTopByDocumentLine(startLine) - TextView.ScrollOffset.Y;
				tooltip.Placement = PlacementMode.Top;
				tooltip.PlacementTarget = this.TextView;
			}
			
			base.OnMouseMove(e);
		}
Ejemplo n.º 46
0
		protected abstract void Initialize(DecompilerTextView textView, ITextMarkerService markerService, ITextMarker marker);
Ejemplo n.º 47
0
		protected abstract void Initialize(ITextEditorUIContext uiContext, ITextMarkerService markerService, ITextMarker marker);
Ejemplo n.º 48
0
			protected override void Initialize(ITextEditorUIContext uiContext, ITextMarkerService markerService, ITextMarker marker) {
				marker.HighlightingColor = () => ilbp.IsEnabled ? DebuggerColors.CodeBreakpointHighlightingColor : DebuggerColors.CodeBreakpointDisabledHighlightingColor;
			}
Ejemplo n.º 49
0
			public void CreateMarker(IDocument document, ITextMarkerService markerService)
			{
				int startOffset = InspectedVersion.MoveOffsetTo(document.Version, this.StartOffset, AnchorMovementType.Default);
				int endOffset = InspectedVersion.MoveOffsetTo(document.Version, this.EndOffset, AnchorMovementType.Default);
				if (this.StartOffset != this.EndOffset && startOffset >= endOffset)
					return;
				marker = markerService.Create(startOffset, endOffset - startOffset);
				marker.ToolTip = this.Description;
				
				Color color = GetColor(this.Severity);
				color.A = 186;
				marker.MarkerColor = color;
				if (!Provider.IsRedundancy)
					marker.MarkerTypes = TextMarkerTypes.ScrollBarRightTriangle;
				switch (MarkerType) {
					case IssueMarker.WavedLine:
						marker.MarkerTypes |= TextMarkerTypes.SquigglyUnderline;
						break;
					case IssueMarker.DottedLine:
						marker.MarkerTypes |= TextMarkerTypes.DottedUnderline;
						break;
					case IssueMarker.GrayOut:
						marker.ForegroundColor = SystemColors.GrayTextColor;
						break;
				}
				marker.Tag = this;
			}
Ejemplo n.º 50
0
        private void HighlightObjectRef(TextViewPosition? position)
        {
            if (position == null)
                return;

            if (_objectRefMarker != null)
                _colorTransformer.Remove(_objectRefMarker);
            var line = Editor.Document.GetLineByNumber(position.Value.Line);
            var regex = new Regex(@"[^a-zA-Z0-9]\d+\s\d+\sR[^a-zA-Z0-9]");
            var matches = regex.Matches(Editor.Document.GetText(line));

            foreach (Match match in matches)
            {
                if (match.Index < position.Value.Location.Column &&
                    match.Index + match.Length > position.Value.Location.Column)
                {
                    _objectRefMarker = _colorTransformer.Create(line.Offset + match.Index + 1,
                        match.Length - 2);
                    _objectRefMarker.MarkerTypes = TextMarkerTypes.NormalUnderline;
                    _objectRefMarker.MarkerColor = Colors.Blue;
                }
            }
        }
		protected override void OnMouseMove(MouseEventArgs e)
		{
			int line = GetLineFromMousePosition(e);
			
			if (line == 0)
				return;
			
			int startLine;
			string oldText = changeWatcher.GetOldVersionFromLine(line, out startLine);
			
			int offset, length;
			
			TextEditor editor = this.TextView.Services.GetService(typeof(TextEditor)) as TextEditor;
			markerService = this.TextView.Services.GetService(typeof(ITextMarkerService)) as ITextMarkerService;

			
			if (changeWatcher.GetNewVersionFromLine(line, out offset, out length)) {
				if (marker != null)
					markerService.Remove(marker);
				marker = markerService.Create(offset, length);
				marker.BackgroundColor = Colors.LightGreen;
			}
			
			if (oldText != null) {
				DiffControl differ = new DiffControl();
				differ.editor.SyntaxHighlighting = editor.SyntaxHighlighting;
				differ.editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
				differ.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
				differ.editor.Document.Text = oldText;
				differ.Background = Brushes.White;
				
				DocumentHighlighter mainHighlighter = TextView.Services.GetService(typeof(IHighlighter)) as DocumentHighlighter;
				DocumentHighlighter popupHighlighter = differ.editor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter;
				
//				popupHighlighter.InitialSpanStack = mainHighlighter.GetSpanStack(
				
				if (oldText == string.Empty) {
					differ.editor.Visibility = Visibility.Collapsed;
				}
				
				differ.undoButton.Click += delegate {
					if (marker != null) {
						int delimiter = 0;
						if (oldText == string.Empty)
							delimiter = Document.GetLineByOffset(offset + length).DelimiterLength;
						Document.Replace(offset, length + delimiter, oldText);
						tooltip.IsOpen = false;
					}
				};
				
				tooltip.Child = new Border() {
					Child = differ,
					BorderBrush = Brushes.Black,
					BorderThickness = new Thickness(1)
				};
				
				if (tooltip.IsOpen)
					tooltip.IsOpen = false;
				
				tooltip.IsOpen = true;
				
				tooltip.Closed += delegate {
					if (marker != null) markerService.Remove(marker);
				};
				
				tooltip.HorizontalOffset = -10;
				tooltip.VerticalOffset =
					TextView.GetVisualTopByDocumentLine(startLine) - TextView.ScrollOffset.Y;
				tooltip.Placement = PlacementMode.Top;
				tooltip.PlacementTarget = this.TextView;
			}
			
			base.OnMouseMove(e);
		}
		void CreateDefaultEntries(string language, out IHighlightingItem defaultText, IList<IHighlightingItem> items)
		{
			// Create entry for "default text/background"
			defaultText = new SimpleHighlightingItem(CustomizableHighlightingColorizer.DefaultTextAndBackground, ta => ta.Document.Text = "Normal text") {
				Foreground = SystemColors.WindowTextColor,
				Background = SystemColors.WindowColor
			};
			defaultText = new CustomizedHighlightingItem(customizationList, defaultText, language, canSetFont: false);
			defaultText.PropertyChanged += item_PropertyChanged;
			items.Add(defaultText);
			
			// Create entry for "Selected text"
			IHighlightingItem selectedText = new SimpleHighlightingItem(
				CustomizableHighlightingColorizer.SelectedText,
				ta => {
					ta.Document.Text = "Selected text";
					ta.Selection = Selection.Create(ta, 0, 13);
				})
			{
				Foreground = SystemColors.HighlightTextColor,
				Background = SystemColors.HighlightColor
			};
			selectedText = new CustomizedHighlightingItem(customizationList, selectedText, language, canSetFont: false);
			selectedText.PropertyChanged += item_PropertyChanged;
			items.Add(selectedText);
			
			// Create entry for "Non-printable characters"
			IHighlightingItem nonPrintChars = new SimpleHighlightingItem(
				CustomizableHighlightingColorizer.NonPrintableCharacters,
				ta => {
					ta.Document.Text = "	    \r \r\n \n";
				})
			{
				Foreground = Colors.LightGray
			};
			nonPrintChars = new CustomizedHighlightingItem(customizationList, nonPrintChars, language, canSetFont: false, canSetBackground: false);
			nonPrintChars.PropertyChanged += item_PropertyChanged;
			items.Add(nonPrintChars);
			
			// Create entry for "Line numbers"
			IHighlightingItem lineNumbers = new SimpleHighlightingItem(
				CustomizableHighlightingColorizer.LineNumbers,
				ta => {
					ta.Document.Text = "These are just" + Environment.NewLine +
						"multiple" + Environment.NewLine +
						"lines of" + Environment.NewLine +
						"text";
				})
			{
				Foreground = Colors.Gray
			};
			lineNumbers = new CustomizedHighlightingItem(customizationList, lineNumbers, language, canSetFont: false, canSetBackground: false);
			lineNumbers.PropertyChanged += item_PropertyChanged;
			items.Add(lineNumbers);
			
			// Create entry for "Bracket highlight"
			IHighlightingItem bracketHighlight = new SimpleHighlightingItem(
				BracketHighlightRenderer.BracketHighlight,
				ta => {
					ta.Document.Text = "(simple) example";
					XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
					if (xshd == null)
						return;
					var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name);
					BracketHighlightRenderer.ApplyCustomizationsToRendering(bracketHighlighter, customizationsForCurrentLanguage);
					bracketHighlighter.SetHighlight(new BracketSearchResult(0, 1, 7, 1));
				})
			{
				Foreground = BracketHighlightRenderer.DefaultBorder,
				Background = BracketHighlightRenderer.DefaultBackground
			};
			bracketHighlight = new CustomizedHighlightingItem(customizationList, bracketHighlight, language, canSetFont: false);
			bracketHighlight.PropertyChanged += item_PropertyChanged;
			items.Add(bracketHighlight);
			
			// Create entry for "Folding controls"
			IHighlightingItem foldingControls = new SimpleHighlightingItem(
				FoldingControls,
				ta => {
					ta.Document.Text = "This" + Environment.NewLine +
						"is a folding" + Environment.NewLine +
						"example";
					foldingManager.CreateFolding(0, 10);
				})
			{
				Foreground = Colors.Gray,
				Background = Colors.White
			};
			foldingControls = new CustomizedHighlightingItem(customizationList, foldingControls, language, canSetFont: false);
			foldingControls.PropertyChanged += item_PropertyChanged;
			items.Add(foldingControls);
			
			// Create entry for "Selected folding controls"
			IHighlightingItem selectedFoldingControls = new SimpleHighlightingItem(
				FoldingSelectedControls,
				ta => {
					ta.Document.Text = "This" + Environment.NewLine +
						"is a folding" + Environment.NewLine +
						"example";
					foldingManager.CreateFolding(0, 10);
				})
			{
				Foreground = Colors.Black,
				Background = Colors.White
			};
			selectedFoldingControls = new CustomizedHighlightingItem(customizationList, selectedFoldingControls, language, canSetFont: false);
			selectedFoldingControls.PropertyChanged += item_PropertyChanged;
			items.Add(selectedFoldingControls);
			
			// Create entry for "Folding text markers"
			IHighlightingItem foldingTextMarker = new SimpleHighlightingItem(
				FoldingTextMarkers,
				ta => {
					ta.Document.Text = "This" + Environment.NewLine +
						"is a folding" + Environment.NewLine +
						"example";
					foldingManager.CreateFolding(0, 10).IsFolded = true;
				})
			{
				Foreground = Colors.Gray
			};
			foldingTextMarker = new CustomizedHighlightingItem(customizationList, foldingTextMarker, language, canSetFont: false, canSetBackground: false);
			foldingTextMarker.PropertyChanged += item_PropertyChanged;
			items.Add(foldingTextMarker);
			
			IHighlightingItem linkText = new SimpleHighlightingItem(
				CustomizableHighlightingColorizer.LinkText,
				ta => {
					ta.Document.Text = "http://icsharpcode.net" + Environment.NewLine + "*****@*****.**";
				})
			{
				Foreground = Colors.Blue,
				Background = Colors.Transparent
			};
			linkText = new CustomizedHighlightingItem(customizationList, linkText, language, canSetFont: false);
			linkText.PropertyChanged += item_PropertyChanged;
			items.Add(linkText);
			
			IHighlightingItem errorMarker = new SimpleHighlightingItem(
				ErrorPainter.ErrorColorName,
				ta => {
					ta.Document.Text = "some error";
					marker = textMarkerService.Create(0, 5);
				})
			{
				Foreground = Colors.Red
			};
			errorMarker = new CustomizedHighlightingItem(customizationList, errorMarker, language, canSetFont: false, canSetBackground: false);
			errorMarker.PropertyChanged += item_PropertyChanged;
			items.Add(errorMarker);
			
			IHighlightingItem warningMarker = new SimpleHighlightingItem(
				ErrorPainter.WarningColorName,
				ta => {
					ta.Document.Text = "some warning";
					marker = textMarkerService.Create(0, 5);
				})
			{
				Foreground = Colors.Orange
			};
			warningMarker = new CustomizedHighlightingItem(customizationList, warningMarker, language, canSetFont: false, canSetBackground: false);
			warningMarker.PropertyChanged += item_PropertyChanged;
			items.Add(warningMarker);
			
			IHighlightingItem messageMarker = new SimpleHighlightingItem(
				ErrorPainter.MessageColorName,
				ta => {
					ta.Document.Text = "some message";
					marker = textMarkerService.Create(0, 5);
				})
			{
				Foreground = Colors.Blue
			};
			messageMarker = new CustomizedHighlightingItem(customizationList, messageMarker, language, canSetFont: false, canSetBackground: false);
			messageMarker.PropertyChanged += item_PropertyChanged;
			items.Add(messageMarker);
			
			IHighlightingItem breakpointMarker = new SimpleHighlightingItem(
				BreakpointBookmark.BreakpointMarker,
				ta => {
					ta.Document.Text = "some code with a breakpoint";
					marker = textMarkerService.Create(0, ta.Document.TextLength);
				})
			{
				Background = BreakpointBookmark.DefaultBackground,
				Foreground = BreakpointBookmark.DefaultForeground
			};
			breakpointMarker = new CustomizedHighlightingItem(customizationList, breakpointMarker, language, canSetFont: false);
			breakpointMarker.PropertyChanged += item_PropertyChanged;
			items.Add(breakpointMarker);
			
			IHighlightingItem currentStatementMarker = new SimpleHighlightingItem(
				CurrentLineBookmark.Name,
				ta => {
					ta.Document.Text = "current statement line";
					marker = textMarkerService.Create(0, ta.Document.TextLength);
				})
			{
				Background = CurrentLineBookmark.DefaultBackground,
				Foreground = CurrentLineBookmark.DefaultForeground
			};
			currentStatementMarker = new CustomizedHighlightingItem(customizationList, currentStatementMarker, language, canSetFont: false);
			currentStatementMarker.PropertyChanged += item_PropertyChanged;
			items.Add(currentStatementMarker);
			
			IHighlightingItem columnRuler = new SimpleHighlightingItem(
				CustomizableHighlightingColorizer.ColumnRuler,
				ta => {
					ta.Document.Text = "some line with a lot of text";
					ta.TextView.Options.ColumnRulerPosition = 15;
					ta.TextView.Options.ShowColumnRuler = true;
				})
			{
				Foreground = Colors.LightGray
			};
			columnRuler = new CustomizedHighlightingItem(customizationList, columnRuler, language, canSetFont: false, canSetBackground: false);
			columnRuler.PropertyChanged += item_PropertyChanged;
			items.Add(columnRuler);
		}
Ejemplo n.º 53
0
			bool IsVisibleInAdorner(ITextMarker marker)
			{
				return (marker.MarkerTypes & (TextMarkerTypes.ScrollBarLeftTriangle | TextMarkerTypes.ScrollBarRightTriangle | TextMarkerTypes.LineInScrollBar | TextMarkerTypes.CircleInScrollBar)) != 0;
			}
		void UpdatePreview()
		{
			XshdSyntaxDefinition xshd = (XshdSyntaxDefinition)languageComboBox.SelectedItem;
			if (xshd != null) {
				var customizationsForCurrentLanguage = customizationList.Where(c => c.Language == null || c.Language == xshd.Name);
				CustomizableHighlightingColorizer.ApplyCustomizationsToDefaultElements(textEditor, customizationsForCurrentLanguage);
				ApplyToRendering(textEditor, customizationsForCurrentLanguage);
				var item = (IHighlightingItem)listBox.SelectedItem;
				TextView textView = textEditor.TextArea.TextView;
				foldingManager.Clear();
				textMarkerService.RemoveAll(m => true);
				marker = null;
				textView.LineTransformers.Remove(colorizer);
				colorizer = null;
				if (item != null) {
					if (item.ParentDefinition != null) {
						colorizer = new CustomizableHighlightingColorizer(item.ParentDefinition.MainRuleSet, customizationsForCurrentLanguage);
						textView.LineTransformers.Add(colorizer);
					}
					textEditor.Select(0, 0);
					bracketHighlighter.SetHighlight(null);
					item.ShowExample(textEditor.TextArea);
					if (marker != null) {
						switch (item.Name) {
							case ErrorPainter.ErrorColorName:
							case ErrorPainter.WarningColorName:
							case ErrorPainter.MessageColorName:
								marker.MarkerType = TextMarkerType.SquigglyUnderline;
								marker.ForegroundColor = item.Foreground;
								marker.BackgroundColor = item.Background;
								break;
							default:
								marker.MarkerType = TextMarkerType.None;
								marker.ForegroundColor = item.Foreground;
								marker.BackgroundColor = item.Background;
								break;
						}
					}
				}
			}
		}
Ejemplo n.º 55
0
		void DisplayTooltip(MouseEventArgs e)
		{
			int line = GetLineFromMousePosition(e);
			
			if (line == 0)
				return;
			
			int startLine;
			bool added;
			string oldText = changeWatcher.GetOldVersionFromLine(line, out startLine, out added);
			
			TextEditor editor = this.TextView.Services.GetService(typeof(TextEditor)) as TextEditor;
			markerService = this.TextView.Services.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			
			LineChangeInfo zeroLineInfo = changeWatcher.GetChange(0);
			
			int offset, length;
			bool hasNewVersion = changeWatcher.GetNewVersionFromLine(line, out offset, out length);
			
			if (line == 1 && zeroLineInfo.Change == ChangeType.Deleted) {
				int zeroStartLine; bool zeroAdded;
				startLine = 1;
				string deletedText = changeWatcher.GetOldVersionFromLine(0, out zeroStartLine, out zeroAdded);
				var docLine = editor.Document.GetLineByNumber(line);
				string newLine = DocumentUtilitites.GetLineTerminator(changeWatcher.CurrentDocument, 1);
				deletedText += newLine;
				deletedText += editor.Document.GetText(docLine.Offset, docLine.Length);
				if (oldText != null)
					oldText = deletedText + newLine + oldText;
				else
					oldText = deletedText;
				
				if (!hasNewVersion) {
					offset = 0;
					length = docLine.Length;
					hasNewVersion = true;
				}
			}
			
			if (hasNewVersion) {
				if (marker != null)
					markerService.Remove(marker);
				if (length <= 0) {
					marker = null;
					length = 0;
				} else {
					marker = markerService.Create(offset, length);
					marker.BackgroundColor = Colors.LightGreen;
				}
			}
			
			if (oldText != null) {
				LineChangeInfo currLineInfo = changeWatcher.GetChange(startLine);
				
				if (currLineInfo.Change == ChangeType.Deleted && !(line == 1 && zeroLineInfo.Change == ChangeType.Deleted)) {
					var docLine = editor.Document.GetLineByNumber(startLine);
					if (docLine.DelimiterLength == 0)
						oldText = DocumentUtilitites.GetLineTerminator(changeWatcher.CurrentDocument, startLine) + oldText;
					oldText = editor.Document.GetText(docLine.Offset, docLine.TotalLength) + oldText;
				}
				
				DiffControl differ = new DiffControl();
				differ.editor.SyntaxHighlighting = editor.SyntaxHighlighting;
				differ.editor.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
				differ.editor.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
				differ.editor.Document.Text = oldText;
				differ.Background = Brushes.White;
				
				if (oldText == string.Empty) {
					differ.editor.Visibility = Visibility.Collapsed;
					differ.copyButton.Visibility = Visibility.Collapsed;
				} else {
					var baseDocument = new TextDocument(DocumentUtilitites.GetTextSource(changeWatcher.BaseDocument));
					if (differ.editor.SyntaxHighlighting != null) {
						var mainHighlighter = new DocumentHighlighter(baseDocument, differ.editor.SyntaxHighlighting.MainRuleSet);
						var popupHighlighter = differ.editor.TextArea.GetService(typeof(IHighlighter)) as DocumentHighlighter;
						
						popupHighlighter.InitialSpanStack = mainHighlighter.GetSpanStack(currLineInfo.OldStartLineNumber);
					}
				}
				
				differ.revertButton.Click += delegate {
					if (hasNewVersion) {
						Document.Replace(offset, length, oldText);
						tooltip.IsOpen = false;
					}
				};
				
				tooltip.Child = new Border() {
					Child = differ,
					BorderBrush = Brushes.Black,
					BorderThickness = new Thickness(1)
				};
				
				if (tooltip.IsOpen)
					tooltip.IsOpen = false;
				
				tooltip.IsOpen = true;
				
				tooltip.Closed += delegate {
					if (marker != null) markerService.Remove(marker);
				};
				tooltip.HorizontalOffset = -10;
				tooltip.VerticalOffset =
					TextView.GetVisualTopByDocumentLine(startLine) - TextView.ScrollOffset.Y;
				tooltip.Placement = PlacementMode.Top;
				tooltip.PlacementTarget = this.TextView;
			}
		}