Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update nuget support #21

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NatashaPad.Core/NatashaPad.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="$(RoslyncPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(RoslyncPackageVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="$(RoslyncPackageVersion)" />
<PackageReference Include="ReferenceResolver" Version="0.16.0" />
<PackageReference Include="ReferenceResolver" Version="0.17.0-preview-20240117-161410" />
</ItemGroup>

</Project>
35 changes: 30 additions & 5 deletions src/NatashaPad/ViewModels/NugetManageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ namespace NatashaPad.ViewModels;
//TODO: 界面加载后即激活搜索框
internal partial class NugetManageViewModel : DialogViewModelBase
{
// TODO: get it via dependency injection
private readonly INuGetHelper _nugetHelper = new NuGetHelper(NullLoggerFactory.Instance);

public NugetManageViewModel(CommonParam commonParam,
IEnumerable<InstalledPackage> installedPackages) : base(commonParam)
{
Expand All @@ -25,6 +27,7 @@ internal partial class NugetManageViewModel : DialogViewModelBase

SearchedPackages = new ObservableCollection<SearchedPackage>();

Sources = _nugetHelper.GetSources().Select(x => x.Name.GetValueOrDefault(x.Source)).ToArray();
SearchCommand = new DelegateCommand(async () => await SearchAsync());
}

Expand All @@ -44,6 +47,22 @@ await InstalledPackages.Select(p => _nugetHelper.DownloadPackage(p.Name, NuGetVe
public ObservableCollection<SearchedPackage> SearchedPackages { get; }

private string _searchText;
private bool _includePrerelease = true;
private string _selectedSource;

public string[] Sources { get; }

public string SelectedSource
{
get => _selectedSource;
set => SetProperty(ref _selectedSource, value);
}

public bool IncludePrerelease
{
get => _includePrerelease;
set => SetProperty(ref _includePrerelease, value);
}

public string SearchText
{
Expand All @@ -55,18 +74,24 @@ public string SearchText

private async Task SearchAsync()
{
var text = _searchText;
if (string.IsNullOrWhiteSpace(text))
var text = _searchText?.Trim();
if (string.IsNullOrEmpty(text))
return;
text = text.Trim();

//TODO: 这边都给了默认值。需要在界面上支持用户选择
var packagesNames = await _nugetHelper.GetPackages(text, true, default).ToArrayAsync();
var packagesNames = (
await _nugetHelper.SearchPackages(text, _includePrerelease, source: _selectedSource).ToArrayAsync()
)
.SelectMany(x => x.SearchResult.Select(r=> r.Identity.Id))
.Distinct()
;

SearchedPackages.Clear();
foreach (var name in packagesNames)
{
var versions = await _nugetHelper.GetPackageVersions(name, default).ToArrayAsync();
var versions = await _nugetHelper.GetPackageVersions(
name, _includePrerelease, null, _selectedSource
).ToArrayAsync();
// TODO: we may want to show the source where the version comes from
var pkg = new SearchedPackage(name,
versions.Select(x => x.Version.ToString()).ToArray());
Expand Down
4 changes: 2 additions & 2 deletions src/NatashaPad/ViewModels/UsingManageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace NatashaPad.ViewModels;

//TODO: 添加时,1. 获取光标;2. 滚动到空处;3. 空处红框显示;
internal class UsingManageViewModel : DialogViewModelBase
internal sealed class UsingManageViewModel : DialogViewModelBase
{
public UsingManageViewModel(CommonParam commonParam,
IEnumerable<string> namespaces) : base(commonParam)
Expand Down Expand Up @@ -45,7 +45,7 @@ protected override Task OkAsync()
}
}

internal class NamespaceItem : CollectionItem
internal sealed class NamespaceItem : CollectionItem
{
public NamespaceItem(string @namespace)
{
Expand Down
13 changes: 11 additions & 2 deletions src/NatashaPad/Views/NugetManageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@
</GroupBox>
<Grid Grid.Column="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid>
<StackPanel Margin="10 0 0 10" Orientation="Horizontal">
<!-- 这里放置一个 source 选项和显示 prerelease 版本的选项
<TextBlock>Source</TextBlock>
<ComboBox Name="CbSource" Padding="3 0">
<ComboBoxItem IsSelected="True">All</ComboBoxItem>
</ComboBox>
-->
</StackPanel>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
Expand All @@ -89,7 +98,7 @@
Foreground="White" />
</Button>
</Grid>
<ScrollViewer Grid.Row="1"
<ScrollViewer Grid.Row="2"
Margin="0 10 0 0"
Padding="0 0 15 0"
VerticalScrollBarVisibility="Visible">
Expand Down