Пример #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // 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);
        }