예제 #1
0
        protected override void OnCreate()
        {
            base.OnCreate();

            _pyService = _site.GetPythonToolsService();
            _uiThread  = _site.GetUIThread();

            _pyService.InteractiveOptions.Changed += InteractiveOptions_Changed;

            // TODO: Get PYEnvironment added to image list
            BitmapImageMoniker = KnownMonikers.DockPanel;
            Caption            = Strings.Environments;

            _outputWindow = OutputWindowRedirector.GetGeneral(_site);
            Debug.Assert(_outputWindow != null);
            _statusBar = _site.GetService(typeof(SVsStatusbar)) as IVsStatusbar;

            var list = new ToolWindow();

            list.ViewCreated  += List_ViewCreated;
            list.ViewSelected += List_ViewSelected;
            list.Site          = _site;
            try {
                list.TelemetryLogger = _pyService.Logger;
            } catch (Exception ex) {
                Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
            }

            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentView.OpenInteractiveWindow,
                                         OpenInteractiveWindow_Executed,
                                         OpenInteractiveWindow_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentView.OpenInteractiveScripts,
                                         OpenInteractiveScripts_Executed,
                                         OpenInteractiveScripts_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentPathsExtension.StartInterpreter,
                                         StartInterpreter_Executed,
                                         StartInterpreter_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentPathsExtension.StartWindowsInterpreter,
                                         StartInterpreter_Executed,
                                         StartInterpreter_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         ApplicationCommands.Help,
                                         OnlineHelp_Executed,
                                         OnlineHelp_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         ToolWindow.UnhandledException,
                                         UnhandledException_Executed,
                                         UnhandledException_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentView.OpenInPowerShell,
                                         OpenInPowerShell_Executed,
                                         OpenInPowerShell_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentView.OpenInCommandPrompt,
                                         OpenInCommandPrompt_Executed,
                                         OpenInCommandPrompt_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentPathsExtension.OpenInBrowser,
                                         OpenInBrowser_Executed,
                                         OpenInBrowser_CanExecute
                                         ));
            list.CommandBindings.Add(new CommandBinding(
                                         EnvironmentView.Delete,
                                         DeleteEnvironment_Executed,
                                         DeleteEnvironment_CanExecute
                                         ));

            RegisterCommands(
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(CommonGuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.cmdidAddEnvironment, new AddEnvironmentCommand(this))
                );

            Content = list;
        }
예제 #2
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            Trace.WriteLine("Entering InitializeAsync() of: {0}".FormatUI(this));

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await base.InitializeAsync(cancellationToken, progress);

            AddService <IClipboardService>(new ClipboardService(), true);
            AddService <IPythonToolsToolWindowService>(this, true);
            AddService <PythonLanguageInfo>((container, serviceType) => new PythonLanguageInfo(this), promote: true);
            AddService <CustomDebuggerEventHandler>((container, serviceType) => new CustomDebuggerEventHandler(this), promote: true);
            AddService <IPythonToolsOptionsService>(PythonToolsOptionsService.CreateService, promote: true);
            AddService <IPythonToolsLogger>(PythonToolsLogger.CreateService, promote: true);
            AddService <PythonToolsService>(PythonToolsService.CreateService, promote: true);
            AddService <ErrorTaskProvider>(ErrorTaskProvider.CreateService, promote: true);
            AddService <CommentTaskProvider>(CommentTaskProvider.CreateService, promote: true);
            AddService <IPythonDebugOptionsService>((container, serviceType) => new PythonDebugOptionsService(this), promote: true);

            var solutionEventListener = new SolutionEventsListener(this);

            solutionEventListener.StartListeningForChanges();
            AddService <SolutionEventsListener>(solutionEventListener, true);

            // Enable the mixed-mode debugger UI context
            UIContext.FromUIContextGuid(DkmEngineId.NativeEng).IsActive = true;

            // Add our command handlers for menu (commands must exist in the .vsct file)
            RegisterCommands(GuidList.guidPythonToolsCmdSet,
                             new OpenReplCommand(this, (int)PkgCmdIDList.cmdidReplWindow),
                             new OpenReplCommand(this, PythonConstants.OpenInteractiveForEnvironment),
                             new OpenDebugReplCommand(this),
                             new ExecuteInReplCommand(this),
                             new SendToReplCommand(this),
                             new FillParagraphCommand(this),
                             new DiagnosticsCommand(this),
                             new RemoveImportsCommand(this, true),
                             new RemoveImportsCommand(this, false),
                             new OpenInterpreterListCommand(this),
                             new ImportWizardCommand(this),
                             new ImportCoverageCommand(this),
                             new ShowPythonViewCommand(this),
                             new ShowCppViewCommand(this),
                             new ShowNativePythonFrames(this),
                             new UsePythonStepping(this),
                             new ViewAllEnvironmentsCommand(this),
                             new OpenWebUrlCommand(this, "https://go.microsoft.com/fwlink/?linkid=832525", PkgCmdIDList.cmdidWebPythonAtMicrosoft),
                             new OpenWebUrlCommand(this, Strings.IssueTrackerUrl, PkgCmdIDList.cmdidWebPTVSSupport),
                             new OpenWebUrlCommand(this, "https://go.microsoft.com/fwlink/?linkid=832517", PkgCmdIDList.cmdidWebDGProducts));

            RegisterCommands(
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(GuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.cmdidAddEnvironment, new AddEnvironmentCommand(this)),
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(GuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.cmdidAddVirtualEnv, new AddEnvironmentCommand(this, Environments.AddEnvironmentDialog.PageKind.VirtualEnvironment)),
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(GuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.cmdidAddExistingEnv, new AddEnvironmentCommand(this, Environments.AddEnvironmentDialog.PageKind.ExistingEnvironment)),
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(GuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.cmdidAddCondaEnv, new AddEnvironmentCommand(this, Environments.AddEnvironmentDialog.PageKind.CondaEnvironment)),
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(GuidList.guidPythonToolsCmdSet, PythonConstants.InstallPythonPackage, new ManagePackagesCommand(this)),
                new CurrentEnvironmentCommand(this),
                new CurrentEnvironmentListCommand(this)
                );

            // Enable the Python debugger UI context
            UIContext.FromUIContextGuid(AD7Engine.DebugEngineGuid).IsActive = true;

            // The variable is inherited by child processes backing Test Explorer, and is used in PTVS
            // test discoverer and test executor to connect back to VS.
            Environment.SetEnvironmentVariable("_PTVS_PID", Process.GetCurrentProcess().Id.ToString());

            Trace.WriteLine("Leaving Initialize() of: {0}".FormatUI(this));
        }