Add option to select directories in archive browsers

This commit is contained in:
Pat Hartl 2023-03-27 01:17:44 -05:00
parent c2dd624cec
commit e2a28a57ea
3 changed files with 22 additions and 5 deletions

View file

@ -22,14 +22,14 @@
DataSource="CurrentPathEntries"
HidePagination="true"
Loading="Entries == null"
RowSelectable="@(x => x.FullName != null && !x.FullName.EndsWith('/'))"
RowSelectable="@(x => CanSelect(x))"
OnRowClick="OnRowClicked"
SelectedRowsChanged="SelectedFilesChanged"
ScrollY="calc(100vh - 55px - 55px - 53px)">
@if (Select)
{
<Selection Key="@context.FullName" Type="@(Multiple ? "checkbox" : "radio")" Disabled="@(context.FullName != null && context.FullName.EndsWith('/'))" />
<Selection Key="@context.FullName" Type="@(Multiple ? "checkbox" : "radio")" Disabled="@(!CanSelect(context))" />
}
<Column TData="string" Width="32">
<Icon Type="@GetIcon(context)" Theme="outline" />
@ -60,7 +60,8 @@
@code {
[Parameter] public Guid ArchiveId { get; set; }
[Parameter] public bool Select { get; set; }
[Parameter] public bool Multiple { get; set; }
[Parameter] public bool Multiple { get; set; } = false;
[Parameter] public bool AllowDirectories { get; set; } = false;
[Parameter] public IEnumerable<ZipArchiveEntry> SelectedFiles { get; set; }
[Parameter] public EventCallback<IEnumerable<ZipArchiveEntry>> SelectedFilesChanged { get; set; }
@ -186,6 +187,21 @@
}
}
private bool CanSelect(ZipArchiveEntry entry)
{
if (entry == null || entry.FullName == null)
return false;
var isDirectory = entry.FullName.EndsWith('/');
if (isDirectory && AllowDirectories)
return true;
else if (!isDirectory)
return true;
else
return false;
}
public class ArchiveDirectory
{
public string Name { get; set; }

View file

@ -2,7 +2,7 @@
@using System.IO.Compression;
@using LANCommander.Models;
<ArchiveBrowser ArchiveId="Options.ArchiveId" @bind-SelectedFiles="SelectedFiles" Select="Options.Select" Multiple="Options.Multiple" />
<ArchiveBrowser ArchiveId="Options.ArchiveId" @bind-SelectedFiles="SelectedFiles" Select="Options.Select" Multiple="Options.Multiple" AllowDirectories="Options.AllowDirectories" />
@code {
private IEnumerable<ZipArchiveEntry> SelectedFiles { get; set; }

View file

@ -4,6 +4,7 @@
{
public Guid ArchiveId { get; set; }
public bool Select { get; set; }
public bool Multiple { get; set; }
public bool Multiple { get; set; } = false;
public bool AllowDirectories { get; set; } = false;
}
}