Пример #1
0
        internal PipEnvironmentView(
            EnvironmentView view,
            PipExtensionProvider provider
            )
        {
            _view     = view;
            _provider = provider;
            _provider.UpdateStarted         += PipExtensionProvider_UpdateStarted;
            _provider.UpdateComplete        += PipExtensionProvider_UpdateComplete;
            _provider.IsPipInstalledChanged += PipExtensionProvider_IsPipInstalledChanged;
            _installCommandView              = new InstallPackageView(this);

            _matcher = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreCase);

            _installed     = new ObservableCollection <PipPackageView>();
            _installedView = new CollectionViewSource {
                Source = _installed
            };
            _installedView.Filter += InstalledView_Filter;
            _installedView.View.CurrentChanged += InstalledView_CurrentChanged;
            _installable         = new List <PackageResultView>();
            _installableFiltered = new List <PackageResultView>();
            _installableView     = new CollectionViewSource {
                Source = _installableFiltered
            };
            _installableView.View.CurrentChanged += InstallableView_CurrentChanged;
            _installableViewRefreshTimer          = new Timer(InstallablePackages_Refresh);

            FinishInitialization();
        }
Пример #2
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var ev = item as EnvironmentView;

            if (ev == null)
            {
                return(base.SelectTemplate(item, container));
            }

            if (EnvironmentView.IsAddNewEnvironmentView(ev) && AddNewEnvironment != null)
            {
                return(AddNewEnvironment);
            }

            if (EnvironmentView.IsCondaEnvironmentView(ev) && CondaEnvironment != null)
            {
                return(CondaEnvironment);
            }

            if (EnvironmentView.IsOnlineHelpView(ev) && OnlineHelp != null)
            {
                return(OnlineHelp);
            }

            if (Environment != null)
            {
                return(Environment);
            }

            return(base.SelectTemplate(item, container));
        }
Пример #3
0
        private async Task StartRefreshDBAsync(EnvironmentView view)
        {
            view.IsRefreshingDB = true;
            view.IsRefreshDBProgressIndeterminate = true;

            var tcs = new TaskCompletionSource <int>();

            ((Interpreter.LegacyDB.IPythonInterpreterFactoryWithDatabase)view.Factory).GenerateDatabase(
                Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) ?
                Interpreter.LegacyDB.GenerateDatabaseOptions.None :
                Interpreter.LegacyDB.GenerateDatabaseOptions.SkipUnchanged,
                tcs.SetResult
                );
            await tcs.Task;

            // Ensure that the factory is added to the list of those currently
            // being refreshed. This ensures that if the task completes before
            // an asynchronous update arrives, we will still reset the state.
            // If an update has arrived, this causes a benign refresh of the
            // command state.
            lock (_environments) {
                if (!_currentlyRefreshing.ContainsKey(view.Factory))
                {
                    _currentlyRefreshing[view.Factory] = default(AnalysisProgress);
                }
            }
        }
Пример #4
0
        public static EnvironmentView CreateAddNewEnvironmentView(IInterpreterOptionsService service)
        {
            var ev = new EnvironmentView(AddNewEnvironmentViewId, Resources.EnvironmentViewCustomAutomationName, null);

            ev.Extensions = new ObservableCollection <object>();
            ev.Extensions.Add(new ConfigurationExtensionProvider(service, alwaysCreateNew: true));
            return(ev);
        }
Пример #5
0
        public static EnvironmentView CreateCondaEnvironmentView(IInterpreterOptionsService service, IInterpreterRegistryService interpreters)
        {
            var ev = new EnvironmentView(CondaEnvironmentViewId, Resources.EnvironmentViewCreateNewCondaEnvironmentAutomationName, null);

            ev.Extensions = new ObservableCollection <object>();
            ev.Extensions.Add(new CondaExtensionProvider(service, interpreters));
            return(ev);
        }
Пример #6
0
        private void UpdateEnvironments(IPythonInterpreterFactory select = null)
        {
            if (_service == null)
            {
                lock (_environmentsLock) {
                    _environments.Clear();
                }
                return;
            }

            lock (_environmentsLock) {
                if (select == null)
                {
                    var selectView = _environmentsView.View.CurrentItem as EnvironmentView;
                    if (selectView != null)
                    {
                        select = selectView.Factory;
                    }
                }

                _environments.Merge(
                    _service.Interpreters
                    .Distinct()
                    .Where(f => f.IsUIVisible())
                    .Select(f => {
                    var view = new EnvironmentView(_service, f, null);
                    OnViewCreated(view);
                    return(view);
                })
                    .Concat(EnvironmentView.AddNewEnvironmentViewOnce.Value)
                    .Concat(EnvironmentView.OnlineHelpViewOnce.Value),
                    EnvironmentComparer.Instance,
                    EnvironmentComparer.Instance
                    );

                if (select != null)
                {
                    var selectView = _environments.FirstOrDefault(v => v.Factory != null &&
                                                                  v.Factory.Id == select.Id && v.Factory.Configuration.Version == select.Configuration.Version);
                    if (selectView == null)
                    {
                        select = null;
                    }
                    else
                    {
                        _environmentsView.View.MoveCurrentTo(selectView);
                    }
                }
                if (select == null)
                {
                    var defaultView = _environments.FirstOrDefault(v => v.IsDefault);
                    if (defaultView != null && _environmentsView.View.CurrentItem == null)
                    {
                        _environmentsView.View.MoveCurrentTo(defaultView);
                    }
                }
            }
        }
Пример #7
0
        private void OnViewCreated(EnvironmentView view)
        {
            var evt = ViewCreated;

            if (evt != null)
            {
                evt(this, new EnvironmentViewEventArgs(view));
            }
        }
Пример #8
0
        public static EnvironmentView CreateAddNewEnvironmentView(IInterpreterOptionsService service)
        {
            var ev = new EnvironmentView();

            ev._addNewEnvironmentView = true;
            ev.Extensions             = new ObservableCollection <object>();
            ev.Extensions.Add(new ConfigurationExtensionProvider(service, alwaysCreateNew: true));
            return(ev);
        }
Пример #9
0
 internal DBEnvironmentView(
     EnvironmentView view,
     DBExtensionProvider provider
     )
 {
     _view     = view;
     _provider = provider;
     _provider.ModulesChanged += Provider_ModulesChanged;
 }
Пример #10
0
            public int Compare(InterpreterConfiguration x, InterpreterConfiguration y)
            {
                if (object.ReferenceEquals(x, y))
                {
                    return(0);
                }
                if (x == null)
                {
                    return(y == null ? 0 : 1);
                }
                else if (y == null)
                {
                    return(-1);
                }

                if (EnvironmentView.IsCondaEnvironmentView(x.Id))
                {
                    return(1);
                }
                else if (EnvironmentView.IsCondaEnvironmentView(y.Id))
                {
                    return(-1);
                }
                if (EnvironmentView.IsAddNewEnvironmentView(x.Id))
                {
                    return(1);
                }
                else if (EnvironmentView.IsAddNewEnvironmentView(y.Id))
                {
                    return(-1);
                }
                if (EnvironmentView.IsOnlineHelpView(x.Id))
                {
                    return(1);
                }
                else if (EnvironmentView.IsOnlineHelpView(y.Id))
                {
                    return(-1);
                }

                int result = StringComparer.CurrentCultureIgnoreCase.Compare(
                    x.Description,
                    y.Description
                    );

                if (result == 0)
                {
                    result = StringComparer.Ordinal.Compare(
                        x.Id,
                        y.Id
                        );
                }

                return(result);
            }
Пример #11
0
        private void UpdateEnvironments(string select = null)
        {
            if (_service == null)
            {
                lock (_environments) {
                    _environments.Clear();
                }
                return;
            }

            lock (_environments) {
                if (select == null)
                {
                    var selectView = _environmentsView.View.CurrentItem as EnvironmentView;
                    select = selectView?.Factory?.Configuration.Id;
                }

                _environments.Merge(
                    _interpreters.Interpreters
                    .Where(f => f.IsUIVisible())
                    .Select(f => {
                    var view = new EnvironmentView(_service, _interpreters, f, null);
                    OnViewCreated(view);
                    return(view);
                })
                    .Concat(_addNewEnvironmentViewOnce ?? Enumerable.Empty <EnvironmentView>())
                    .Concat(EnvironmentView.OnlineHelpViewOnce.Value),
                    EnvironmentComparer.Instance,
                    EnvironmentComparer.Instance
                    );

                if (select != null)
                {
                    var selectView = _environments.FirstOrDefault(v => v.Factory != null &&
                                                                  v.Factory.Configuration.Id == select);
                    if (selectView == null)
                    {
                        select = null;
                    }
                    else
                    {
                        _environmentsView.View.MoveCurrentTo(selectView);
                    }
                }
                if (select == null)
                {
                    var defaultView = _environments.FirstOrDefault(v => v.IsDefault);
                    if (defaultView != null && _environmentsView.View.CurrentItem == null)
                    {
                        _environmentsView.View.MoveCurrentTo(defaultView);
                    }
                }
            }
        }
Пример #12
0
        public void InitializeEnvironments(IInterpreterRegistryService interpreters, IInterpreterOptionsService options, bool synchronous = false)
        {
            if (_interpreters != null)
            {
                _interpreters.InterpretersChanged -= Service_InterpretersChanged;
            }
            _interpreters = interpreters;
            if (_interpreters != null)
            {
                _interpreters.InterpretersChanged += Service_InterpretersChanged;
            }

            if (_options != null)
            {
                _options.DefaultInterpreterChanged -= Service_DefaultInterpreterChanged;
            }
            _options = options;
            if (_options != null)
            {
                _options.DefaultInterpreterChanged += Service_DefaultInterpreterChanged;
            }

            if (_interpreters != null && _options != null)
            {
                _addNewEnvironmentView = EnvironmentView.CreateAddNewEnvironmentView(_options);
                if (ExperimentalOptions.AutoDetectCondaEnvironments)
                {
                    _condaEnvironmentView = EnvironmentView.CreateCondaEnvironmentView(_options, _interpreters);
                    var provider = _condaEnvironmentView.Extensions.FirstOrDefault() as CondaExtensionProvider;
                    OnProviderCreated(provider);
                }
                else
                {
                    _condaEnvironmentView = null;
                }
                _onlineHelpView = EnvironmentView.CreateOnlineHelpEnvironmentView();

                if (synchronous)
                {
                    Dispatcher.Invoke(FirstUpdateEnvironments);
                }
                else
                {
                    Dispatcher.InvokeAsync(FirstUpdateEnvironments).Task.DoNotWait();
                }
            }
            else
            {
                _addNewEnvironmentView = null;
                _condaEnvironmentView  = null;
                _onlineHelpView        = null;
            }
        }
Пример #13
0
        private void PackageExtension_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            EnvironmentView view = e.NewValue as EnvironmentView;

            if (view != null)
            {
                PipEnvironmentView current = Subcontext.DataContext as PipEnvironmentView;
                if (current == null || current.EnvironmentView != view)
                {
                    if (current != null)
                    {
                        current.Dispose();
                    }
                    Subcontext.DataContext = new PipEnvironmentView(view, _provider);
                }
            }
        }
Пример #14
0
        private Style SelectStyle(EnvironmentView ev)
        {
            if (ev == null)
            {
                return(null);
            }

            if (EnvironmentView.IsOnlineHelpView(ev) && OnlineHelp != null)
            {
                return(OnlineHelp);
            }

            if (Environment != null)
            {
                return(Environment);
            }

            return(null);
        }
Пример #15
0
        internal PipEnvironmentView(
            EnvironmentView view,
            PipExtensionProvider provider
            )
        {
            _view     = view;
            _provider = provider;
            _provider.OperationStarted         += PipExtensionProvider_UpdateStarted;
            _provider.OperationFinished        += PipExtensionProvider_UpdateComplete;
            _provider.IsPipInstalledChanged    += PipExtensionProvider_IsPipInstalledChanged;
            _provider.InstalledPackagesChanged += PipExtensionProvider_InstalledPackagesChanged;

            IsPipInstalled      = _provider.IsPipInstalled ?? true;
            ShowSecurityWarning =
                provider._packageManager.UniqueKey == "pip" &&
                view.Configuration.Version != new Version(2, 7) &&
                view.Configuration.Version < new Version(3, 3);

            _installCommandView = new InstallPackageView(this);

            _matcher = new FuzzyStringMatcher(FuzzyMatchMode.FuzzyIgnoreCase);

            _installed     = new ObservableCollection <PipPackageView>();
            _installedView = new CollectionViewSource {
                Source = _installed
            };
            _installedView.Filter += InstalledView_Filter;
            _installedView.View.CurrentChanged += InstalledView_CurrentChanged;
            _installable         = new List <PackageResultView>();
            _installableFiltered = new ObservableCollection <PackageResultView>();
            _installableView     = new CollectionViewSource {
                Source = _installableFiltered
            };
            _installableView.View.CurrentChanged += InstallableView_CurrentChanged;
            _installableViewRefreshTimer          = new Timer(InstallablePackages_Refresh);

            FinishInitialization().DoNotWait();
        }
Пример #16
0
 public static bool IsAddNewEnvironmentView(EnvironmentView view) => AddNewEnvironmentViewId.Equals(view?.Configuration.Id);
Пример #17
0
 public static EnvironmentView CreateAddNewEnvironmentView(IInterpreterOptionsService service) {
     var ev = new EnvironmentView(AddNewEnvironmentViewId);
     ev.Extensions = new ObservableCollection<object>();
     ev.Extensions.Add(new ConfigurationExtensionProvider(service, alwaysCreateNew: true));
     return ev;
 }
Пример #18
0
 public ConfigurationEnvironmentView(EnvironmentView view)
 {
     _view = view;
 }
Пример #19
0
 internal void OnViewSelected(EnvironmentView view)
 {
     ViewSelected?.Invoke(this, new EnvironmentViewEventArgs(view));
 }
Пример #20
0
 private void OnViewCreated(EnvironmentView view)
 {
     ViewCreated?.Invoke(this, new EnvironmentViewEventArgs(view));
 }
Пример #21
0
        private static string GetPathEntries(EnvironmentView view)
        {
            if (!Directory.Exists(view?.PrefixPath)) {
                return null;
            }

            return string.Join(";", PathSuffixes
                .Select(s => PathUtils.GetAbsoluteDirectoryPath(view.PrefixPath, s))
                .Where(Directory.Exists));
        }
Пример #22
0
 public static bool IsOnlineHelpView(EnvironmentView view) => OnlineHelpViewId.Equals(view?.Configuration.Id);
Пример #23
0
        private string GetScriptPath(EnvironmentView view)
        {
            if (view == null) {
                return null;
            }

            return PythonInteractiveEvaluator.GetScriptsPath(
                _site,
                view.Description,
                view.Factory.Configuration,
                false
            );
        }
Пример #24
0
        private void UpdateEnvironments(string select = null)
        {
            if (_service == null)
            {
                lock (_environments) {
                    _environments.Clear();
                }
                return;
            }

            lock (_environments) {
                if (select == null)
                {
                    var selectView = _environmentsView.View.CurrentItem as EnvironmentView;
                    select = selectView?.Configuration?.Id;
                }

                var configs = _interpreters.Configurations.Where(f => f.IsUIVisible());
                configs = configs.Concat(Enumerable.Repeat(EnvironmentView.OnlineHelpView.Configuration, 1));
                if (_addNewEnvironmentView != null)
                {
                    configs = configs.Concat(Enumerable.Repeat(_addNewEnvironmentView.Configuration, 1));
                }

                _environments.Merge(
                    configs,
                    ev => ev.Configuration,
                    c => c,
                    c => {
                    if (EnvironmentView.IsAddNewEnvironmentView(c.Id))
                    {
                        return(_addNewEnvironmentView);
                    }
                    else if (EnvironmentView.IsOnlineHelpView(c.Id))
                    {
                        return(EnvironmentView.OnlineHelpView);
                    }
                    var view = new EnvironmentView(_service, _interpreters, _interpreters.FindInterpreter(c.Id), null);
                    OnViewCreated(view);
                    return(view);
                },
                    InterpreterConfigurationComparer.Instance,
                    InterpreterConfigurationComparer.Instance
                    );

                if (select != null)
                {
                    var selectView = _environments.FirstOrDefault(v => v.Factory != null &&
                                                                  v.Factory.Configuration.Id == select);
                    if (selectView == null)
                    {
                        select = null;
                    }
                    else
                    {
                        _environmentsView.View.MoveCurrentTo(selectView);
                    }
                }
                if (select == null)
                {
                    var defaultView = _environments.FirstOrDefault(v => v.IsDefault);
                    if (defaultView != null && _environmentsView.View.CurrentItem == null)
                    {
                        _environmentsView.View.MoveCurrentTo(defaultView);
                    }
                }
            }
        }
Пример #25
0
 public static bool IsOnlineHelpView(EnvironmentView view) => OnlineHelpViewId.Equals(view?.Configuration.Id);
Пример #26
0
        private void UpdateEnvironments(string select = null)
        {
            if (_options == null)
            {
                lock (_environments) {
                    _environments.Clear();
                }
                return;
            }

            lock (_environments) {
                if (select == null)
                {
                    var selectView = _environmentsView.View.CurrentItem as EnvironmentView;
                    select = selectView?.Configuration?.Id;
                }

                // We allow up to three retries at this process to handle race
                // conditions where an interpreter disappears between the
                // point where we enumerate known configuration IDs and convert
                // them into a view. The first time that happens, we insert a
                // stub entry, and on the subsequent pass it will be removed.
                bool anyMissing = true;
                for (int retries = 3; retries > 0 && anyMissing; --retries)
                {
                    var configs = _interpreters.Configurations.Where(f => f.IsUIVisible()).ToList();

                    anyMissing = false;
                    _environments.Merge(
                        configs,
                        ev => ev.Configuration,
                        c => c,
                        c => {
                        var fact             = _interpreters.FindInterpreter(c.Id);
                        EnvironmentView view = null;
                        try {
                            if (fact != null)
                            {
                                view = new EnvironmentView(_options, _interpreters, fact, null);
                            }
                        } catch (ArgumentException) {
                        }
                        if (view == null)
                        {
                            view       = EnvironmentView.CreateMissingEnvironmentView(c.Id + "+Missing", c.Description);
                            anyMissing = true;
                        }
                        OnViewCreated(view);
                        return(view);
                    },
                        InterpreterConfigurationComparer.Instance,
                        InterpreterConfigurationComparer.Instance
                        );
                }

                if (select != null)
                {
                    var selectView = _environments.FirstOrDefault(v => v.Factory != null &&
                                                                  v.Factory.Configuration.Id == select);
                    if (selectView == null)
                    {
                        select = null;
                    }
                    else
                    {
                        _environmentsView.View.MoveCurrentTo(selectView);
                    }
                }
                if (select == null)
                {
                    var defaultView = _environments.FirstOrDefault(v => v.IsDefault);
                    if (defaultView != null && _environmentsView.View.CurrentItem == null)
                    {
                        _environmentsView.View.MoveCurrentTo(defaultView);
                    }
                }
            }
        }
Пример #27
0
 public static bool IsAddNewEnvironmentView(EnvironmentView view) => AddNewEnvironmentViewId.Equals(view?.Configuration.Id);
Пример #28
0
 public ConfigurationEnvironmentView(EnvironmentView view) {
     _view = view;
 }
Пример #29
0
 public EnvironmentViewEventArgs(EnvironmentView view)
 {
     View = view;
 }
Пример #30
0
 public static bool IsCondaEnvironmentView(EnvironmentView view) => CondaEnvironmentViewId.Equals(view?.Configuration.Id);