Exemple #1
0
        void HighlightSelectedTab()
        {
            foreach (var vm in CurrentNavPath())
            {
                var selected = AllChildren.OfType <Tab>().FirstOrDefault(tab => tab.VM == vm);

                if (selected != null)
                {
                    selected.Highlight();
                    return;
                }
            }
        }
Exemple #2
0
        private async Task RefreshPackagesAsync(IPackageManager packageManager)
        {
            if (_suppressPackageRefresh || packageManager == null)
            {
                return;
            }

            bool prevChecked = _checkedItems;

            // Use _checkingItems to prevent the expanded state from
            // disappearing too quickly.
            _checkingItems = true;
            _checkedItems  = true;

            var packages = new Dictionary <string, PackageSpec>();

            foreach (var p in await packageManager.GetInstalledPackagesAsync(CancellationToken.None))
            {
                packages[p.FullSpec] = p;
            }

            await ProjectMgr.Site.GetUIThread().InvokeAsync(() => {
                if (ProjectMgr == null || ProjectMgr.IsClosed)
                {
                    return;
                }

                try {
                    var logger = ProjectMgr.Site.GetPythonToolsService().Logger;
                    if (logger != null)
                    {
                        foreach (var p in packages)
                        {
                            logger.LogEvent(PythonLogEvent.PythonPackage,
                                            new PackageInfo {
                                Name = p.Value.Name.ToLowerInvariant()
                            });
                        }
                    }
                } catch (Exception ex) {
                    Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
                }

                bool anyChanges = false;
                var existing    = AllChildren.OfType <InterpretersPackageNode>().ToDictionary(c => c.Url);

                // remove the nodes which were uninstalled.
                foreach (var keyValue in existing)
                {
                    if (!packages.Remove(keyValue.Key))
                    {
                        RemoveChild(keyValue.Value);
                        anyChanges = true;
                    }
                }

                // add the new nodes
                foreach (var p in packages.OrderBy(kv => kv.Key))
                {
                    AddChild(new InterpretersPackageNode(ProjectMgr, p.Value));
                    anyChanges = true;
                }
                _checkingItems = false;

                ProjectMgr.OnInvalidateItems(this);
                if (!prevChecked)
                {
                    if (anyChanges)
                    {
                        ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Expandable, 0);
                    }
                    if (ProjectMgr.ParentHierarchy != null)
                    {
                        ExpandItem(EXPANDFLAGS.EXPF_CollapseFolder);
                    }
                }
            });
        }
Exemple #3
0
        private async Task RefreshPackagesAsync(IPackageManager packageManager)
        {
            if (_suppressPackageRefresh || packageManager == null)
            {
                return;
            }

            bool prevChecked = _checkedItems;

            // Use _checkingItems to prevent the expanded state from
            // disappearing too quickly.
            _checkingItems = true;
            _checkedItems  = true;

            var packages = new Dictionary <string, PackageSpec>();

            foreach (var p in await packageManager.GetInstalledPackagesAsync(CancellationToken.None))
            {
                packages[p.FullSpec] = p;
            }

            await ProjectMgr.Site.GetUIThread().InvokeAsync(() => {
                if (ProjectMgr == null || ProjectMgr.IsClosed)
                {
                    return;
                }

                bool anyChanges = false;
                var existing    = AllChildren.OfType <InterpretersPackageNode>().ToDictionary(c => c.Url);

                // remove the nodes which were uninstalled.
                foreach (var keyValue in existing)
                {
                    if (!packages.Remove(keyValue.Key))
                    {
                        RemoveChild(keyValue.Value);
                        anyChanges = true;
                    }
                }

                // add the new nodes
                foreach (var p in packages.OrderBy(kv => kv.Key))
                {
                    AddChild(new InterpretersPackageNode(ProjectMgr, p.Value));
                    anyChanges = true;
                }
                _checkingItems = false;

                ProjectMgr.OnInvalidateItems(this);
                if (!prevChecked)
                {
                    if (anyChanges)
                    {
                        ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Expandable, 0);
                    }
                    if (ProjectMgr.ParentHierarchy != null)
                    {
                        ExpandItem(EXPANDFLAGS.EXPF_CollapseFolder);
                    }
                }

                if (prevChecked && anyChanges)
                {
                    var withDb = _factory as IPythonInterpreterFactoryWithDatabase;
                    if (withDb != null)
                    {
                        withDb.GenerateDatabase(GenerateDatabaseOptions.SkipUnchanged);
                    }
                }
            });
        }