/// <summary> /// Occurs when the button is clicked. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">A <see cref="RoutedEventArgs"/> that contains the event data.</param> private void OnToggleBreakpointButtonClick(object sender, RoutedEventArgs e) { // Toggle a breakpoint DebuggingHelper.ToggleBreakpoint(editor.ActiveView.Selection.EndSnapshotOffset, true); // Focus the editor editor.Focus(); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // OBJECT ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes an instance of the <c>MainControl</c> class. /// </summary> public MainControl() { InitializeComponent(); // Register display item classification types (so breakpoint indicator styles are registered) new DisplayItemClassificationTypeProvider().RegisterAll(); // Set the header/footer text to make the editor work as a method body editor.Document.SetHeaderAndFooterText("using System; using System.Diagnostics; using System.IO; private class Program { private void Execute() {\r\n", "\r\n}}"); // // NOTE: Make sure that you've read through the add-on language's 'Getting Started' topic // since it tells you how to set up an ambient parse request dispatcher and an ambient // code repository within your application OnStartup code, and add related cleanup in your // application OnExit code. These steps are essential to having the add-on perform well. // // Initialize the project assembly (enables support for automated IntelliPrompt features) projectAssembly = new CSharpProjectAssembly("SampleBrowser"); var assemblyLoader = new BackgroundWorker(); assemblyLoader.DoWork += DotNetProjectAssemblyReferenceLoader; assemblyLoader.RunWorkerAsync(); // Load the .NET Languages Add-on C# language and register the project assembly on it var language = new CSharpSyntaxLanguage(); language.RegisterProjectAssembly(projectAssembly); // Register an indicator quick info provider language.RegisterService(new IndicatorQuickInfoProvider()); // Register an event sink that allows for handling of clicks in the indicator margin language.RegisterService(new DebuggingPointerInputEventSink()); // Assign the language editor.Document.Language = language; this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (DispatcherOperationCallback) delegate(object arg) { // Since we are initializing some default breakpoints, make sure the document parse completes in the worker thread first AmbientParseRequestDispatcherProvider.Dispatcher.WaitForParse(ParseRequest.GetParseHashKey(editor.Document)); // Add some indicators (this is dispatched since this sample relies on the document's AST being available and parsing occurs asynchronously) DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[19].StartOffset), true); DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[23].StartOffset), false); DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(editor.ActiveView.CurrentSnapshot, editor.ActiveView.CurrentSnapshot.Lines[28].StartOffset), true); return(null); }, null); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Occurs when a pointer button is pressed over the specified <see cref="IEditorView"/>. /// </summary> /// <param name="view">The <see cref="IEditorView"/> that received the event.</param> /// <param name="e">The <see cref="InputPointerButtonEventArgs"/> that contains the event data.</param> protected virtual void OnViewPointerPressed(IEditorView view, InputPointerButtonEventArgs e) { if ((e != null) && (!e.Handled)) { // Get a hit test result var hitTestResult = view.SyntaxEditor.HitTest(e.GetPosition(view.VisualElement)); if ((hitTestResult.Type == HitTestResultType.ViewMargin) && (hitTestResult.ViewMargin.Key == EditorViewMarginKeys.Indicator) && (hitTestResult.ViewLine != null)) { // Remove all breakpoints that start on the view line if (view.SyntaxEditor.Document.IndicatorManager.Breakpoints.RemoveAll( tr => hitTestResult.ViewLine.TextRange.IntersectsWith(tr.VersionRange.Translate(view.CurrentSnapshot).StartOffset)) == 0) { // No breakpoints were removed so add one DebuggingHelper.ToggleBreakpoint(new TextSnapshotOffset(hitTestResult.Snapshot, hitTestResult.Offset), true); } } } }