void IVsPython.OpenInteractive(string description) { int?commandId = null; lock (PythonToolsPackage.CommandsLock) { foreach (var command in PythonToolsPackage.Commands) { OpenReplCommand replCommand = command.Key as OpenReplCommand; if (replCommand != null && replCommand.Description == description) { commandId = replCommand.CommandId; break; } } } if (commandId.HasValue) { var dte = (EnvDTE.DTE)_serviceProvider.GetService(typeof(EnvDTE.DTE)); object inObj = null, outObj = null; dte.Commands.Raise(GuidList.guidPythonToolsCmdSet.ToString("B"), commandId.Value, ref inObj, ref outObj); } else { throw new KeyNotFoundException("Could not find interactive window with name: " + description); } }
private void RefreshReplCommands(object sender, EventArgs e) { OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs == null) { return; } List <OpenReplCommand> replCommands = new List <OpenReplCommand>(); lock (CommandsLock) { foreach (var keyValue in Commands) { var command = keyValue.Key; OpenReplCommand openRepl = command as OpenReplCommand; if (openRepl != null) { replCommands.Add(openRepl); mcs.RemoveCommand(keyValue.Value); } } foreach (var command in replCommands) { Commands.Remove(command); } RegisterCommands(GetReplCommands(), GuidList.guidPythonToolsCmdSet); } }
private List <OpenReplCommand> GetReplCommands() { var replCommands = new List <OpenReplCommand>(); var compModel = ComponentModel; if (compModel == null) { return(replCommands); } var interpreters = compModel.GetService <IInterpreterRegistryService>(); if (interpreters == null) { return(replCommands); } var factories = interpreters.Configurations.ToList(); if (factories.Count == 0) { return(replCommands); } var interpreterService = compModel.GetService <IInterpreterOptionsService>(); if (interpreterService == null) { return(replCommands); } var defaultFactory = interpreterService.DefaultInterpreter; if (defaultFactory != null) { factories.Remove(defaultFactory.Configuration); factories.Insert(0, defaultFactory.Configuration); } for (int i = 0; i < (PkgCmdIDList.cmdidReplWindowF - PkgCmdIDList.cmdidReplWindow) && i < factories.Count; i++) { var factory = factories[i]; var cmd = new OpenReplCommand(this, (int)PkgCmdIDList.cmdidReplWindow + i, factory); replCommands.Add(cmd); } if (defaultFactory != null) { // This command is a fallback for the Python.Interactive command // If no project is selected, the default environment will be // used. replCommands.Add(new OpenReplCommand(this, (int)PythonConstants.OpenInteractiveForEnvironment, defaultFactory.Configuration)); } return(replCommands); }