//this runs as a glib idle handler so it can add/remove text editor markers
			//in order to to block the GUI thread, we batch them in UPDATE_COUNT
			bool IdleHandler ()
			{
				if (cancellationToken.IsCancellationRequested)
					return false;
				var editor = ext.Editor;
				if (editor == null || editor.Document == null)
					return false;
				//clear the old results out at the same rate we add in the new ones
				for (int i = 0; oldMarkers > 0 && i < UPDATE_COUNT; i++) {
					if (cancellationToken.IsCancellationRequested)
						return false;
					editor.Document.RemoveMarker (ext.markers.Dequeue ());
					oldMarkers--;
				}
				//add in the new markers
				for (int i = 0; i < UPDATE_COUNT; i++) {
					if (!enumerator.MoveNext ()) {
						ext.OnTasksUpdated (EventArgs.Empty);
						return false;
					}
					if (cancellationToken.IsCancellationRequested)
						return false;
					var currentResult = (Result)enumerator.Current;
					
					if (currentResult.InspectionMark != IssueMarker.None) {
						int start = editor.LocationToOffset (currentResult.Region.Begin);
						int end = editor.LocationToOffset (currentResult.Region.End);
						if (start >= end)
							continue;
						if (currentResult.InspectionMark == IssueMarker.GrayOut) {
							var marker = new GrayOutMarker (currentResult, TextSegment.FromBounds (start, end));
							marker.IsVisible = currentResult.Underline;
							editor.Document.AddMarker (marker);
							ext.markers.Enqueue (marker);
							editor.Parent.TextViewMargin.RemoveCachedLine (editor.GetLineByOffset (start));
							editor.Parent.QueueDraw ();
						} else {
							var marker = new ResultMarker (currentResult, TextSegment.FromBounds (start, end));
							marker.IsVisible = currentResult.Underline;
							editor.Document.AddMarker (marker);
							ext.markers.Enqueue (marker);
						}
					}
					
					ext.tasks.Add (new QuickTask (currentResult.Message, currentResult.Region.Begin, currentResult.Level));
				}
				
				return true;
			}
Example #2
0
            //this runs as a glib idle handler so it can add/remove text editor markers
            //in order to to block the GUI thread, we batch them in UPDATE_COUNT
            bool IdleHandler()
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(false);
                }
                var editor = ext.Editor;

                if (editor == null || editor.Document == null)
                {
                    return(false);
                }
                //clear the old results out at the same rate we add in the new ones
                for (int i = 0; oldMarkers > 0 && i < UPDATE_COUNT; i++)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return(false);
                    }
                    editor.Document.RemoveMarker(ext.markers.Dequeue());
                    oldMarkers--;
                }
                //add in the new markers
                for (int i = 0; i < UPDATE_COUNT; i++)
                {
                    if (!enumerator.MoveNext())
                    {
                        ext.OnTasksUpdated(EventArgs.Empty);
                        return(false);
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return(false);
                    }
                    var currentResult = (Result)enumerator.Current;

                    if (currentResult.InspectionMark != IssueMarker.None)
                    {
                        int start = editor.LocationToOffset(currentResult.Region.Begin);
                        int end   = editor.LocationToOffset(currentResult.Region.End);
                        if (start >= end)
                        {
                            continue;
                        }
                        if (currentResult.InspectionMark == IssueMarker.GrayOut)
                        {
                            var marker = new GrayOutMarker(currentResult, TextSegment.FromBounds(start, end));
                            marker.IsVisible = currentResult.Underline;
                            editor.Document.AddMarker(marker);
                            ext.markers.Enqueue(marker);
                            editor.Parent.TextViewMargin.RemoveCachedLine(editor.GetLineByOffset(start));
                            editor.Parent.QueueDraw();
                        }
                        else
                        {
                            var marker = new ResultMarker(currentResult, TextSegment.FromBounds(start, end));
                            marker.IsVisible = currentResult.Underline;
                            editor.Document.AddMarker(marker);
                            ext.markers.Enqueue(marker);
                        }
                    }

                    ext.tasks.Add(new QuickTask(currentResult.Message, currentResult.Region.Begin, currentResult.Level));
                }

                return(true);
            }