|
4 | 4 | using System.Threading.Tasks; |
5 | 5 |
|
6 | 6 | using ExtensionManager.Manifest; |
| 7 | +using ExtensionManager.UI.Utils; |
7 | 8 | using ExtensionManager.UI.ViewModels; |
8 | 9 | using ExtensionManager.UI.Views; |
| 10 | +using ExtensionManager.UI.Worker; |
9 | 11 | using ExtensionManager.VisualStudio; |
10 | 12 | using ExtensionManager.VisualStudio.Extensions; |
11 | 13 |
|
@@ -43,86 +45,58 @@ internal sealed class DialogService : IDialogService |
43 | 45 | } |
44 | 46 | } |
45 | 47 |
|
46 | | - public Task<bool> ShowExportDialogAsync(IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
47 | | - => ShowExportDialogAsync(manifest, installedExtensions, forSolution: false); |
48 | | - public Task<bool> ShowExportForSolutionDialogAsync(IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
49 | | - => ShowExportDialogAsync(manifest, installedExtensions, forSolution: true); |
50 | | - private async Task<bool> ShowExportDialogAsync(IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions, bool forSolution) |
| 48 | + public Task ShowExportDialogAsync(IExportWorker worker, IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
| 49 | + => ShowExportDialogAsync(worker, manifest, installedExtensions, forSolution: false); |
| 50 | + public Task ShowExportForSolutionDialogAsync(IExportWorker worker, IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
| 51 | + => ShowExportDialogAsync(worker, manifest, installedExtensions, forSolution: true); |
| 52 | + private async Task ShowExportDialogAsync(IExportWorker worker, IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions, bool forSolution) |
51 | 53 | { |
52 | | - var vm = new InstallExportDialogViewModel(forSolution ? InstallExportDialogType.ExportSolution : InstallExportDialogType.Export); |
| 54 | + var vm = new ExportDialogViewModel(worker, manifest, forSolution); |
53 | 55 |
|
54 | 56 | foreach (var ext in installedExtensions) |
55 | 57 | vm.Extensions.Add(new(ext)); |
56 | 58 |
|
57 | | - var accept = await ShowInstallExportDialogAsync(vm).ConfigureAwait(false); |
58 | | - |
59 | | - if (accept) |
60 | | - { |
61 | | - manifest.Extensions.Clear(); |
62 | | - |
63 | | - foreach (var ext in vm.SelectedExtensions) |
64 | | - manifest.Extensions.Add(ext.Model); |
65 | | - } |
66 | | - |
67 | | - return accept; |
| 59 | + await ShowInstallExportDialogAsync(vm); |
68 | 60 | } |
69 | 61 |
|
70 | | - public Task<InstallExtensionsDialogResult?> ShowInstallDialogAsync(IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
71 | | - => ShowInstallForSolutionDialogAsync(manifest, installedExtensions, forSolution: false); |
72 | | - public Task<InstallExtensionsDialogResult?> ShowInstallForSolutionDialogAsync(IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
73 | | - => ShowInstallForSolutionDialogAsync(manifest, installedExtensions, forSolution: true); |
74 | | - private async Task<InstallExtensionsDialogResult?> ShowInstallForSolutionDialogAsync(IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions, bool forSolution) |
| 62 | + public Task ShowInstallDialogAsync(IInstallWorker worker, IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
| 63 | + => ShowInstallForSolutionDialogAsync(worker, manifest, installedExtensions, forSolution: false); |
| 64 | + public Task ShowInstallForSolutionDialogAsync(IInstallWorker worker, IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions) |
| 65 | + => ShowInstallForSolutionDialogAsync(worker, manifest, installedExtensions, forSolution: true); |
| 66 | + private async Task ShowInstallForSolutionDialogAsync(IInstallWorker worker, IManifest manifest, IReadOnlyCollection<IVSExtension> installedExtensions, bool forSolution) |
75 | 67 | { |
76 | | - var vm = new InstallExportDialogViewModel(forSolution ? InstallExportDialogType.InstallSolution : InstallExportDialogType.Install); |
| 68 | + var vm = new InstallDialogViewModel(worker, manifest, forSolution); |
77 | 69 |
|
78 | 70 | foreach (var ext in manifest.Extensions) |
79 | 71 | { |
80 | | - var isInstalled = installedExtensions.Contains(ext, ExtensionEqualityComparer.Instance); |
| 72 | + var isInstalled = installedExtensions.Contains(ext, ExtensionEqualityComparerById.Instance); |
81 | 73 |
|
82 | | - vm.Extensions.Add(new(ext) |
83 | | - { |
84 | | - CanBeSelected = !isInstalled, |
85 | | - Group = isInstalled ? "Already installed" : "Extensions", |
86 | | - }); |
| 74 | + vm.AddExtension(ext, isInstalled); |
87 | 75 | } |
88 | 76 |
|
89 | | - var accept = await ShowInstallExportDialogAsync(vm).ConfigureAwait(false); |
90 | | - |
91 | | - if (accept) |
92 | | - return new(vm.SystemWide, vm.SelectedExtensions.Select(x => x.Model).ToArray()); |
93 | | - |
94 | | - return null; |
| 77 | + await ShowInstallExportDialogAsync(vm); |
95 | 78 | } |
96 | 79 |
|
97 | | - private Task<bool> ShowInstallExportDialogAsync(object viewModel) |
| 80 | + private Task ShowInstallExportDialogAsync(object viewModel) |
98 | 81 | { |
99 | 82 | if (VSFacade.Threads.CheckUIThreadAccess()) |
100 | | - return Task.FromResult(OnUIThread(viewModel)); |
| 83 | + { |
| 84 | + OnUIThread(viewModel); |
| 85 | + |
| 86 | + return Task.CompletedTask; |
| 87 | + } |
101 | 88 |
|
102 | 89 | return VSFacade.Threads.RunOnUIThreadAsync(() => OnUIThread(viewModel)); |
103 | 90 |
|
104 | | - static bool OnUIThread(object viewModel) |
| 91 | + static void OnUIThread(object viewModel) |
105 | 92 | { |
106 | 93 | var window = new InstallExportDialogWindow |
107 | 94 | { |
108 | 95 | Owner = WpfApplication.Current.MainWindow, |
109 | 96 | DataContext = viewModel |
110 | 97 | }; |
111 | 98 |
|
112 | | - var result = window.ShowDialog(); |
113 | | - |
114 | | - return result == true; |
| 99 | + window.ShowDialog(); |
115 | 100 | } |
116 | 101 | } |
117 | 102 | } |
118 | | - |
119 | | -file sealed class ExtensionEqualityComparer : IEqualityComparer<IVSExtension> |
120 | | -{ |
121 | | - public static ExtensionEqualityComparer Instance { get; } = new(); |
122 | | - |
123 | | - public bool Equals(IVSExtension x, IVSExtension y) |
124 | | - => x?.Id == y?.Id; |
125 | | - |
126 | | - public int GetHashCode(IVSExtension obj) |
127 | | - => obj?.Id?.GetHashCode() ?? 0; |
128 | | -} |
0 commit comments