예제 #1
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length != 6 || !(values[0] is PackageItemType) || !(values[1] is string) || !(values[2] is bool) || !(values[3] is double) || !(values[4] is double) || !(values[5] is DependencyObject))
            {
                return(null);
            }

            int x = (int)(double)values[3];
            int y = (int)(double)values[4];

            if (x < 1)
            {
                x = 1;
            }

            if (y < 1)
            {
                y = 1;
            }

            PackageItemType type = (PackageItemType)values[0];

            if (type == PackageItemType.Folder)
            {
                bool         isExpanded = (bool)values[2];
                ImageMoniker moniker    = isExpanded ? KnownMonikers.FolderOpened : KnownMonikers.FolderClosed;
                return(WpfUtil.ThemeImage((DependencyObject)values[5], WpfUtil.GetIconForImageMoniker(moniker, x, y)));
            }

            string      name = (string)values[1];
            bool        isThemeIcon;
            ImageSource source = WpfUtil.GetIconForFile((DependencyObject)values[5], name, out isThemeIcon);

            return(source);
        }
예제 #2
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length != 4 || !(values[0] is FileTreeModel) || !(values[1] is double) || !(values[2] is double) || !(values[3] is DependencyObject))
            {
                return(null);
            }

            int x = (int)(double)values[1];
            int y = (int)(double)values[2];

            if (x < 1)
            {
                x = 1;
            }

            if (y < 1)
            {
                y = 1;
            }

            FileTreeModel model = (FileTreeModel)values[0];

            if (!model.IsFile)
            {
                bool         isExpanded = model.IsExpanded;
                ImageMoniker moniker    = isExpanded ? KnownMonikers.FolderOpened : KnownMonikers.FolderClosed;
                return(WpfUtil.ThemeImage((DependencyObject)values[3], WpfUtil.GetIconForImageMoniker(moniker, x, y)));
            }

            string      name = model.Name;
            bool        isThemeIcon;
            ImageSource source = WpfUtil.GetIconForFile((DependencyObject)values[3], name, out isThemeIcon);

            return(source);
        }
예제 #3
0
        protected override IEnumerable <JsonCompletionEntry> GetEntries(JsonCompletionContext context)
        {
            MemberNode member = context.ContextNode.FindType <MemberNode>();

            if (member == null || member.UnquotedNameText != "files")
            {
                yield break;
            }

            var parent = member.Parent as ObjectNode;

            if (!JsonHelpers.TryGetInstallationState(parent, out ILibraryInstallationState state))
            {
                yield break;
            }

            if (string.IsNullOrEmpty(state.Name))
            {
                yield break;
            }

            IDependencies   dependencies = _dependenciesFactory.FromConfigFile(ConfigFilePath);
            IProvider       provider     = dependencies.GetProvider(state.ProviderId);
            ILibraryCatalog catalog      = provider?.GetCatalog();

            if (catalog == null)
            {
                yield break;
            }

            Task <ILibrary>      task      = catalog.GetLibraryAsync(state.Name, state.Version, CancellationToken.None);
            FrameworkElement     presenter = GetPresenter(context);
            IEnumerable <string> usedFiles = GetUsedFiles(context);

            if (task.IsCompleted)
            {
                if (!(task.Result is ILibrary library))
                {
                    yield break;
                }

                foreach (string file in library.Files.Keys)
                {
                    if (!usedFiles.Contains(file))
                    {
                        ImageSource glyph = WpfUtil.GetIconForFile(presenter, file, out bool isThemeIcon);
                        yield return(new SimpleCompletionEntry(file, glyph, context.Session));
                    }
                }
            }
            else
            {
                yield return(new SimpleCompletionEntry(Resources.Text.Loading, string.Empty, KnownMonikers.Loading, context.Session));

                _ = task.ContinueWith(async(t) =>
                {
                    await VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    if (!(t.Result is ILibrary library))
                    {
                        return;
                    }

                    if (!context.Session.IsDismissed)
                    {
                        var results = new List <JsonCompletionEntry>();

                        foreach (string file in library.Files.Keys)
                        {
                            if (!usedFiles.Contains(file))
                            {
                                ImageSource glyph = WpfUtil.GetIconForFile(presenter, file, out bool isThemeIcon);
                                results.Add(new SimpleCompletionEntry(file, glyph, context.Session));
                            }
                        }

                        UpdateListEntriesSync(context, results);
                    }
                }, TaskScheduler.Default);
            }
        }