Esempio n. 1
0
 void OnBreakEventRemoved(BreakEvent be)
 {
     OnChanged();
     BreakEventRemoved?.Invoke(this, new BreakEventArgs(be));
     if (be is Breakpoint bp)
     {
         BreakpointRemoved?.Invoke(this, new BreakpointEventArgs(bp));
     }
     else if (be is Catchpoint ce)
     {
         CatchpointRemoved?.Invoke(this, new CatchpointEventArgs(ce));
     }
 }
        /// <summary>
        /// Sets up a breakpoint when the user taps on the breakpoints area
        /// </summary>
        /// <param name="sender">The <see cref="Canvas"/> instance in use</param>
        /// <param name="e">The <see cref="TappedRoutedEventArgs"/> instance for the event</param>
        private void BreakpointsCanvas_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Calculate the target vertical offset for the tap
            double yOffset =
                e.GetPosition((Border)sender).Y - 8 -         // Tap Y offset and adjustment
                CodeEditBox.VerticalScrollBarMargin.Top +     // Top internal padding
                CodeEditBox.ContentScroller !.VerticalOffset; // Vertical scroll offset

            // Get the range aligned to the left edge of the tapped line
            ITextRange range = CodeEditBox.Document.GetRangeFromPoint(new Point(0, yOffset), PointOptions.ClientCoordinates);

            range.GetRect(PointOptions.Transform, out Rect line, out _);

            // Get the line number
            int lineNumber = CodeEditBox.Text.AsSpan(0, range.StartPosition).Count(Characters.CarriageReturn) + 1;

            if (lineNumber == 1)
            {
                return;
            }

            // Store or remove the breakpoint
            if (BreakpointIndicators.ContainsKey(lineNumber))
            {
                BreakpointIndicators.Remove(lineNumber);

                if (BreakpointIndicators.Count == 0)
                {
                    BreakpointsBorder.ContextFlyout = null;
                }

                BreakpointRemoved?.Invoke(this, new BreakpointToggleEventArgs(lineNumber, BreakpointIndicators.Count));
            }
            else
            {
                if (BreakpointIndicators.Count == 0)
                {
                    BreakpointsBorder.ContextFlyout = BreakpointsMenuFlyout;
                }

                BreakpointIndicators.GetOrAddValueRef(lineNumber) = (float)line.Top;

                BreakpointAdded?.Invoke(this, new BreakpointToggleEventArgs(lineNumber, BreakpointIndicators.Count));
            }

            UpdateBreakpointsInfo();

            IdeOverlaysCanvas.Invalidate();
            CodeEditBox.InvalidateOverlays();
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a breakpoint to the debugger.
        /// </summary>
        /// <param name="line">The line to add the breakpoint to.</param>
        /// <returns>The breakpoint.</returns>
        public DebuggerBreakpoint SetBreakpoint(int line)
        {
            if (_breakpoints.Any(x => x.Line == line))
            {
                throw new InvalidOperationException($"A breakpoint is already set at line {line}.");
            }

            var bp = new DebuggerBreakpoint(this, line);

            bp.Destroyed.Event += () =>
            {
                _breakpoints.Remove(bp);
                BreakpointRemoved.Fire(bp);
            };

            _breakpoints.Add(bp);
            BreakpointAdded.Fire(bp);

            return(bp);
        }