Exemplo n.º 1
0
        public AddInstalledEnvironmentView(
            IServiceProvider serviceProvider,
            ProjectView[] projects,
            ProjectView selectedProject
            ) : base(serviceProvider, projects, selectedProject)
        {
            _logger               = Site.GetService(typeof(IPythonToolsLogger)) as IPythonToolsLogger;
            PageName              = Strings.AddInstalledEnvironmentTabHeader;
            AcceptCaption         = Strings.AddInstalledEnvironmentInstallButton;
            AcceptAutomationName  = Strings.AddInstalledEnvironmentInstallButtonAutomationName;
            IsAcceptShieldVisible = true;

            _setupService = Site.GetService(typeof(SVsSetupCompositionService)) as IVsSetupCompositionService;
            _retargeting  = Site.GetService(typeof(SVsTrackProjectRetargeting)) as IVsTrackProjectRetargeting2;

            var packages = GetPackages(_setupService)
                           .Where(p => p.PackageId.StartsWithOrdinal("Component.CPython"))
                           .Select(p => new SetupPackageView(
                                       p.PackageId,
                                       p.Title,
                                       p.CurrentState == (uint)__VsSetupPackageState.INSTALL_PACKAGE_PRESENT,
                                       RefreshAcceptButton
                                       ));

            SetupPackages = new ObservableCollection <SetupPackageView>(packages);

            InstalledView        = new ListCollectionView(SetupPackages);
            InstalledView.Filter = (p => ((SetupPackageView)p).Installed);

            AvailableView        = new ListCollectionView(SetupPackages);
            AvailableView.Filter = (p => !((SetupPackageView)p).Installed);

            RefreshAcceptButton();
        }
 public AddExistingEnvironmentView(
     IServiceProvider serviceProvider,
     ProjectView[] projects,
     ProjectView selectedProject
     ) : base(serviceProvider, projects, selectedProject)
 {
     _logger = Site.GetService(typeof(IPythonToolsLogger)) as IPythonToolsLogger;
     _allGlobalInterpreters = InterpreterView.GetInterpreters(Site, null).ToArray();
     PageName = Strings.AddExistingEnvironmentTabHeader;
     ResetProjectDependentProperties();
 }
 public AddInstalledEnvironmentView(
     IServiceProvider serviceProvider,
     ProjectView[] projects,
     ProjectView selectedProject
     ) : base(serviceProvider, projects, selectedProject)
 {
     _logger               = Site.GetService(typeof(IPythonToolsLogger)) as IPythonToolsLogger;
     PageName              = Strings.AddInstalledEnvironmentTabHeader;
     AcceptCaption         = Strings.AddInstalledEnvironmentLaunch;
     IsAcceptShieldVisible = true;
 }
Exemplo n.º 4
0
        public AddVirtualEnvironmentView(
            IServiceProvider serviceProvider,
            ProjectView[] projects,
            ProjectView selectedProject
            ) : base(serviceProvider, projects, selectedProject)
        {
            PageName                = Strings.AddVirtualEnvironmentTabHeader;
            SetAsCurrent            = SelectedProject != null;
            SetAsDefault            = false;
            ViewInEnvironmentWindow = false;

            ResetProjectDependentProperties();
        }
Exemplo n.º 5
0
        public AddVirtualEnvironmentView(
            IServiceProvider serviceProvider,
            ProjectView[] projects,
            ProjectView selectedProject
            ) : base(serviceProvider, projects, selectedProject)
        {
            PageName                     = Strings.AddVirtualEnvironmentTabHeader;
            SetAsCurrent                 = SelectedProject != null;
            SetAsDefault                 = false;
            ViewInEnvironmentWindow      = false;
            Progress                     = new ProgressControlViewModel();
            Progress.ProgressMessage     = Strings.AddVirtualEnvironmentPreviewInProgress;
            Progress.IsProgressDisplayed = false;

            ResetProjectDependentProperties();
        }
        public AddCondaEnvironmentView(
            IServiceProvider serviceProvider,
            ProjectView[] projects,
            ProjectView selectedProject
            ) : base(serviceProvider, projects, selectedProject)
        {
            _condaMgr           = CondaEnvironmentManager.Create(Site);
            _updatePreviewTimer = new Timer(UpdatePreviewTimerCallback);

            IsCondaMissing  = _condaMgr == null;
            PageName        = Strings.AddCondaEnvironmentTabHeader;
            AcceptCaption   = Strings.AddEnvironmentCreateButton;
            IsAcceptEnabled = !IsCondaMissing;

            SetAsCurrent            = SelectedProject != null;
            SetAsDefault            = false;
            ViewInEnvironmentWindow = false;

            ResetProjectDependentProperties();
        }
Exemplo n.º 7
0
        public EnvironmentViewBase(IServiceProvider serviceProvider, ProjectView[] projects, ProjectView selectedProject)
        {
            if (projects == null)
            {
                throw new ArgumentNullException(nameof(projects));
            }

            _ignoreSelectedProjectChanged = true;

            Site            = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            RegistryService = serviceProvider.GetComponentModel().GetService <IInterpreterRegistryService>();
            OptionsService  = serviceProvider.GetComponentModel().GetService <IInterpreterOptionsService>();

            AcceptCaption   = Strings.AddEnvironmentAddButton;
            IsAcceptEnabled = true;
            Projects        = new ObservableCollection <ProjectView>(projects);
            SelectedProject = selectedProject;

            ProjectsView = new ListCollectionView(Projects);
            ProjectsView.MoveCurrentTo(selectedProject);

            _ignoreSelectedProjectChanged = false;
        }
        private static async Task ShowDialogAsync(
            PageKind activePage,
            IServiceProvider site,
            PythonProjectNode project,
            string existingCondaEnvName = null,
            string environmentYmlPath   = null,
            string requirementsTxtPath  = null,
            CancellationToken ct        = default(CancellationToken)
            )
        {
            if (site == null)
            {
                throw new ArgumentNullException(nameof(site));
            }

            ProjectView[] projectViews;
            ProjectView   selectedProjectView;

            try {
                var sln      = (IVsSolution)site.GetService(typeof(SVsSolution));
                var projects = sln?.EnumerateLoadedPythonProjects().ToArray() ?? new PythonProjectNode[0];

                projectViews = projects
                               .Select((projectNode) => new ProjectView(projectNode))
                               .ToArray();

                selectedProjectView = projectViews.SingleOrDefault(pv => pv.Node == project);
            } catch (InvalidOperationException ex) {
                Debug.Fail(ex.ToUnhandledExceptionMessage(typeof(AddEnvironmentDialog)));
                projectViews        = new ProjectView[0];
                selectedProjectView = null;
            }

            if (selectedProjectView != null)
            {
                if (existingCondaEnvName != null)
                {
                    selectedProjectView.MissingCondaEnvName = existingCondaEnvName;
                }

                if (environmentYmlPath != null)
                {
                    selectedProjectView.EnvironmentYmlPath = environmentYmlPath;
                }

                if (requirementsTxtPath != null)
                {
                    selectedProjectView.RequirementsTxtPath = requirementsTxtPath;
                }
            }

            var addVirtualView = new AddVirtualEnvironmentView(
                site,
                projectViews,
                selectedProjectView
                );

            var addCondaView = new AddCondaEnvironmentView(
                site,
                projectViews,
                selectedProjectView
                );

            var addExistingView = new AddExistingEnvironmentView(
                site,
                projectViews,
                selectedProjectView
                );

            var addInstalledView = new AddInstalledEnvironmentView(
                site,
                projectViews,
                selectedProjectView
                );

            EnvironmentViewBase activeView;

            switch (activePage)
            {
            case PageKind.VirtualEnvironment:
                activeView = addVirtualView;
                break;

            case PageKind.CondaEnvironment:
                activeView = addCondaView;
                break;

            case PageKind.ExistingEnvironment:
                activeView = addExistingView;
                break;

            case PageKind.InstalledEnvironment:
                activeView = addInstalledView;
                break;

            default:
                Debug.Assert(false, string.Format("Unknown page kind '{0}'", activePage));
                activeView = null;
                break;
            }

            using (var dlg = new AddEnvironmentDialog(
                       new EnvironmentViewBase[] {
                addVirtualView,
                addCondaView,
                addExistingView,
                addInstalledView,
            },
                       activeView
                       )) {
                try {
                    WindowHelper.ShowModal(dlg);
                } catch (Exception) {
                    dlg.Close();
                    throw;
                }

                if (dlg.DialogResult ?? false)
                {
                    var view = dlg.View.PagesView.CurrentItem as EnvironmentViewBase;
                    Debug.Assert(view != null);
                    if (view != null)
                    {
                        try {
                            await view.ApplyAsync();
                        } catch (Exception ex) when(!ex.IsCriticalException())
                        {
                            Debug.Fail(ex.ToUnhandledExceptionMessage(typeof(AddEnvironmentDialog)), Strings.ProductTitle);
                        }
                    }
                }
            }
        }