示例#1
0
        public override void OnToolWindowCreated()
        {
            // Register key bindings to use in the editor
            var  windowFrame = (IVsWindowFrame)Frame;
            Guid cmdUi       = VSConstants.GUID_TextEditorFactory;

            windowFrame.SetGuidProperty((int)__VSFPROPID.VSFPROPID_InheritKeyBindings, ref cmdUi);

            // pause for a tiny moment to let the tool window open before initializing the host
            var timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromMilliseconds(0);
            timer.Tick    += (o, e) =>
            {
                timer.Stop();

                // all exceptions from the timer thread should be caught to avoid crashing VS
                try
                {
                    LoadConsoleEditor();
                }
                catch (Exception x)
                {
                    // hide the text "initialize host" when an error occurs.
                    ConsoleParentPane.NotifyInitializationCompleted();

                    ExceptionHelper.WriteToActivityLog(x);
                }
            };
            timer.Start();

            base.OnToolWindowCreated();
        }
示例#2
0
        private async Task LoadConsoleEditorAsync()
        {
            try
            {
                if (WpfConsole != null)
                {
                    // allow the console to start writing output
                    WpfConsole.StartWritingOutput();

                    var consolePane = WpfConsole.Content as FrameworkElement;

                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    ConsoleParentPane.AddConsoleEditor(consolePane);

                    // WPF doesn't handle input focus automatically in this scenario. We
                    // have to set the focus manually, otherwise the editor is displayed but
                    // not focused and not receiving keyboard inputs until clicked.
                    if (consolePane != null)
                    {
                        PendingMoveFocus(consolePane);
                    }
                }
            }
            catch (Exception x)
            {
                ExceptionHelper.WriteErrorToActivityLog(x);
            }
        }
示例#3
0
        private void StartConsoleSession(FrameworkElement consolePane)
        {
            if (WpfConsole != null && WpfConsole.Content == consolePane && WpfConsole.Host != null)
            {
                try
                {
                    if (WpfConsole.Dispatcher.IsStartCompleted)
                    {
                        OnDispatcherStartCompleted();
                        // if the dispatcher was started before we reach here,
                        // it means the dispatcher has been in read-only mode (due to _startedWritingOutput = false).
                        // enable key input now.
                        WpfConsole.Dispatcher.AcceptKeyInput();
                    }
                    else
                    {
                        WpfConsole.Dispatcher.StartCompleted  += (sender, args) => OnDispatcherStartCompleted();
                        WpfConsole.Dispatcher.StartWaitingKey += OnDispatcherStartWaitingKey;
                        WpfConsole.Dispatcher.Start();
                    }
                }
                catch (Exception x)
                {
                    // hide the text "initialize host" when an error occurs.
                    ConsoleParentPane.NotifyInitializationCompleted();

                    WpfConsole.WriteLine(x.GetBaseException().ToString());
                    ExceptionHelper.WriteToActivityLog(x);
                }
            }
            else
            {
                ConsoleParentPane.NotifyInitializationCompleted();
            }
        }
示例#4
0
        private void OnDispatcherStartCompleted()
        {
            ConsoleParentPane.NotifyInitializationCompleted();

            // force the UI to update the toolbar
            VsUIShell.UpdateCommandUI(0 /* false = update UI asynchronously */);
        }
示例#5
0
        private void OnDispatcherStartCompleted()
        {
            WpfConsole.Dispatcher.StartWaitingKey -= OnDispatcherStartWaitingKey;

            ConsoleParentPane.NotifyInitializationCompleted();

            // force the UI to update the toolbar
            VsUIShell.UpdateCommandUI(0 /* false = update UI asynchronously */);

            NuGetEventTrigger.Instance.TriggerEvent(NuGetEvent.PackageManagerConsoleLoaded);
        }
示例#6
0
        private async Task OnDispatcherStartCompletedAsync()
        {
            WpfConsole.Dispatcher.StartWaitingKey -= OnDispatcherStartWaitingKey;

            ConsoleParentPane.NotifyInitializationCompleted();

            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            // force the UI to update the toolbar
            IVsUIShell vsUIShell = await AsyncServiceProvider.GlobalProvider.GetServiceAsync <IVsUIShell, IVsUIShell>(throwOnFailure : false);

            vsUIShell.UpdateCommandUI(0 /* false = update UI asynchronously */);
        }
示例#7
0
        private async Task OnDispatcherStartCompletedAsync()
        {
            WpfConsole.Dispatcher.StartWaitingKey -= OnDispatcherStartWaitingKey;

            ConsoleParentPane.NotifyInitializationCompleted();

            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            // force the UI to update the toolbar
            IVsUIShell vsUIShell = await AsyncServiceProvider.GlobalProvider.GetServiceAsync <IVsUIShell>();

            vsUIShell.UpdateCommandUI(0 /* false = update UI asynchronously */);

            NuGetEventTrigger.Instance.TriggerEvent(NuGetEvent.PackageManagerConsoleLoaded);
        }
示例#8
0
        private void OnDispatcherStartCompleted()
        {
            WpfConsole.Dispatcher.StartWaitingKey -= OnDispatcherStartWaitingKey;

            ConsoleParentPane.NotifyInitializationCompleted();

            NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // force the UI to update the toolbar
                VsUIShell.UpdateCommandUI(0 /* false = update UI asynchronously */);
            });

            NuGetEventTrigger.Instance.TriggerEvent(NuGetEvent.PackageManagerConsoleLoaded);
        }
示例#9
0
        private void LoadConsoleEditor()
        {
            if (WpfConsole != null)
            {
                FrameworkElement consolePane = WpfConsole.Content as FrameworkElement;
                ConsoleParentPane.AddConsoleEditor(consolePane);

                // WPF doesn't handle input focus automatically in this scenario. We
                // have to set the focus manually, otherwise the editor is displayed but
                // not focused and not receiving keyboard inputs until clicked.
                if (consolePane != null)
                {
                    PendingMoveFocus(consolePane);
                }
            }
        }
示例#10
0
        private void StartConsoleSession(FrameworkElement consolePane)
        {
            if (WpfConsole != null && WpfConsole.Content == consolePane && WpfConsole.Host != null)
            {
                try
                {
                    if (WpfConsole.Dispatcher.IsStartCompleted)
                    {
                        OnDispatcherStartCompleted();
                    }
                    else
                    {
                        WpfConsole.Dispatcher.StartCompleted += (sender, args) => OnDispatcherStartCompleted();
                        WpfConsole.Dispatcher.Start();
                    }
                } catch (Exception x)
                {
                    // hide the text "initialize host" when an error occurs.
                    ConsoleParentPane.NotifyInitializationCompleted();

                    WpfConsole.WriteLine(x.ToString());
                }
            }
        }
示例#11
0
 private void OnDispatcherStartWaitingKey(object sender, EventArgs args)
 {
     WpfConsole.Dispatcher.StartWaitingKey -= OnDispatcherStartWaitingKey;
     // we want to hide the text "initialize host..." when waiting for key input
     ConsoleParentPane.NotifyInitializationCompleted();
 }