internal static IReplWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project)
        {
            var compModel = serviceProvider.GetComponentModel();
            var provider  = compModel.GetService <IReplWindowProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(factory, project);
            var    window = provider.FindReplWindow(replId);

            if (window == null)
            {
                window = provider.CreateReplWindow(
                    serviceProvider.GetPythonContentType(),
                    factory.Description + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                    );

                var pyService = serviceProvider.GetPythonToolsService();
                window.SetOptionValue(
                    ReplOptions.UseSmartUpDown,
                    pyService.GetInteractiveOptions(factory).ReplSmartHistory
                    );
            }

            if (project != null && project.Interpreters.IsProjectSpecific(factory))
            {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return(window);
        }
        internal static IReplWindow /*!*/ EnsureReplWindow(IPythonInterpreterFactory factory)
        {
            var compModel = PythonToolsPackage.ComponentModel;
            var provider  = compModel.GetExtensions <IReplWindowProvider>().First();

            string replId = PythonReplEvaluatorProvider.GetReplId(factory);
            var    window = provider.FindReplWindow(replId);

            if (window == null)
            {
                window = provider.CreateReplWindow(
                    PythonToolsPackage.Instance.ContentType,
                    factory.GetInterpreterDisplay() + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                    );

                window.SetOptionValue(ReplOptions.UseSmartUpDown, PythonToolsPackage.Instance.InteractiveOptionsPage.GetOptions(factory).ReplSmartHistory);
            }
            return(window);
        }
Exemple #3
0
        internal static IReplWindowToolWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, IPythonInterpreterFactory factory, PythonProjectNode project)
        {
            var compModel = serviceProvider.GetComponentModel();
            var provider  = compModel.GetService <IReplWindowProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(factory, project);
            var    window = provider.FindReplWindow(replId);

            if (window == null)
            {
                window = provider.CreateReplWindow(
                    serviceProvider.GetPythonContentType(),
                    factory.Description + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                    );

                var toolWindow = window as ToolWindowPane;
                if (toolWindow != null)
                {
#if DEV14_OR_LATER
                    toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow;
#else
                    // TODO: Add image here for VS 2013
#endif
                }

                var pyService = serviceProvider.GetPythonToolsService();
                window.SetSmartUpDown(pyService.GetInteractiveOptions(factory).ReplSmartHistory);
            }

            if (project != null && project.Interpreters.IsProjectSpecific(factory))
            {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return(window);
        }
        internal static IVsInteractiveWindow /*!*/ EnsureReplWindow(IServiceProvider serviceProvider, InterpreterConfiguration config, PythonProjectNode project)
        {
            var compModel        = serviceProvider.GetComponentModel();
            var provider         = compModel.GetService <InteractiveWindowProvider>();
            var vsProjectContext = compModel.GetService <VsProjectContextProvider>();

            string replId = PythonReplEvaluatorProvider.GetReplId(config.Id, project);
            var    window = provider.FindReplWindow(replId);

            if (window == null)
            {
                window = provider.CreateInteractiveWindow(
                    serviceProvider.GetPythonContentType(),
                    config.FullDescription + " Interactive",
                    typeof(PythonLanguageInfo).GUID,
                    replId
                    );

#if DEV14
                var toolWindow = window as ToolWindowPane;
                if (toolWindow != null)
                {
                    toolWindow.BitmapImageMoniker = KnownMonikers.PYInteractiveWindow;
                }
#endif

                var pyService = serviceProvider.GetPythonToolsService();
                window.InteractiveWindow.SetSmartUpDown(pyService.GetInteractiveOptions(config).ReplSmartHistory);
            }


            if (project != null && vsProjectContext.IsProjectSpecific(config))
            {
                project.AddActionOnClose(window, BasePythonReplEvaluator.CloseReplWindow);
            }

            return(window);
        }
Exemple #5
0
        public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode)
        {
            string description = null;

            if (Version.IsCPython)
            {
                description = string.Format("{0} {1}",
                                            Version.Isx64 ? CPythonInterpreterFactoryConstants.Description64 : CPythonInterpreterFactoryConstants.Description32,
                                            Version.Version.ToVersion()
                                            );
            }
            else if (Version.IsIronPython)
            {
                description = string.Format("{0} {1}",
                                            Version.Isx64 ? "IronPython 64-bit" : "IronPython",
                                            Version.Version.ToVersion()
                                            );
            }
            Assert.IsNotNull(description, "Unknown interpreter");

            var automation  = (IVsPython)app.Dte.GetObject("VsPython");
            var options     = (IPythonOptions)automation;
            var replOptions = options.GetInteractiveOptions(description);

            Assert.IsNotNull(replOptions, "Could not find options for " + description);

            replOptions.InlinePrompts         = InlinePrompts;
            replOptions.UseInterpreterPrompts = UseInterpreterPrompts;
            replOptions.PrimaryPrompt         = PrimaryPrompt;
            replOptions.SecondaryPrompt       = SecondaryPrompt;
            replOptions.EnableAttach          = EnableAttach;

            var oldExecutionMode = replOptions.ExecutionMode;

            app.OnDispose(() => replOptions.ExecutionMode = oldExecutionMode);
            replOptions.ExecutionMode = executionMode;

            var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord;

            app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord);
            options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord;

            bool success = false;

            for (int retries = 1; retries < 20; ++retries)
            {
                try {
                    app.ExecuteCommand("Python.Interactive", "/e:\"" + description + "\"");
                    success = true;
                    break;
                } catch (AggregateException) {
                }
                app.DismissAllDialogs();
                app.SetFocus();
                Thread.Sleep(retries * 100);
            }
            Assert.IsTrue(success, "Unable to open " + description + " through DTE");
            var interpreters = app.ComponentModel.GetService <IInterpreterOptionsService>();
            var replId       = PythonReplEvaluatorProvider.GetReplId(
                interpreters.FindInterpreter(Version.Id, Version.Version.ToVersion())
                );

            var provider = app.ComponentModel.GetService <InteractiveWindowProvider>();

            return((ToolWindowPane)provider.FindReplWindow(replId));
        }
        private static ReplWindow OpenInteractive(
            PythonVisualStudioApp app,
            ReplWindowProxySettings settings,
            string executionMode
            )
        {
            string description = null;

            if (settings.Version.IsCPython)
            {
                description = string.Format("{0} {1}",
                                            settings.Version.Isx64 ? CPythonInterpreterFactoryConstants.Description64 : CPythonInterpreterFactoryConstants.Description32,
                                            settings.Version.Version.ToVersion()
                                            );
            }
            else if (settings.Version.IsIronPython)
            {
                description = string.Format("{0} {1}",
                                            settings.Version.Isx64 ? "IronPython 64-bit" : "IronPython",
                                            settings.Version.Version.ToVersion()
                                            );
            }
            Assert.IsNotNull(description, "Unknown interpreter");

            var automation = (IVsPython)app.Dte.GetObject("VsPython");
            var options    = ((IPythonOptions)automation).GetInteractiveOptions(description);

            Assert.IsNotNull(options, "Could not find options for " + description);

            options.InlinePrompts         = settings.InlinePrompts;
            options.UseInterpreterPrompts = settings.UseInterpreterPrompts;
            options.PrimaryPrompt         = settings.PrimaryPrompt;
            options.SecondaryPrompt       = settings.SecondaryPrompt;
            options.EnableAttach          = settings.EnableAttach;

            var oldExecutionMode = options.ExecutionMode;

            app.OnDispose(() => options.ExecutionMode = oldExecutionMode);
            options.ExecutionMode = executionMode;

            bool success = false;

            for (int retries = 1; retries < 20; ++retries)
            {
                try {
                    app.ExecuteCommand("Python.Interactive", "/e:\"" + description + "\"");
                    success = true;
                    break;
                } catch (AggregateException) {
                }
                app.DismissAllDialogs();
                app.SetFocus();
                Thread.Sleep(retries * 100);
            }
            Assert.IsTrue(success, "Unable to open " + description + " through DTE");
            var provider     = app.ComponentModel.GetService <IReplWindowProvider>();
            var interpreters = app.ComponentModel.GetService <IInterpreterOptionsService>();
            var replId       = PythonReplEvaluatorProvider.GetReplId(
                interpreters.FindInterpreter(settings.Version.Id, settings.Version.Version.ToVersion())
                );

            var interactive = provider.FindReplWindow(replId) as ReplWindow;

            if (interactive == null)
            {
                // This is a failure, since we check if the environment is
                // installed in TestInitialize().
                Assert.Fail("Need " + description);
            }

            return(interactive);
        }