Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions FileItem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
using System.Linq;
using MetadataExtractor;
using MetadataExtractor.Formats.Exif;
using SkiaSharp;

namespace SelectSight;

using System;
Expand All @@ -8,30 +13,19 @@ namespace SelectSight;
using System.Threading.Tasks;
using Avalonia.Media.Imaging;

public class FileItem : INotifyPropertyChanged
public class FileItem(string fullPath) : INotifyPropertyChanged
{
public string FullPath { get; }
public string Name { get; }
public string SizeString { get; }

public string FullPath { get; } = fullPath;
public string Name { get; } = Path.GetFileName(fullPath);

private Bitmap? _thumbnail;
public Bitmap? Thumbnail
{
get => _thumbnail;
private set => SetField(ref _thumbnail, value);
}

public FileItem(string fullPath)
{
FullPath = fullPath;
Name = Path.GetFileName(fullPath);
SizeString = new FileInfo(fullPath).Length.ToString("N0") + " bytes";

// Start loading thumbnail asynchronously
_ = LoadThumbnailAsync();
}

private async Task LoadThumbnailAsync()
public async Task LoadThumbnailAsync()
{
try
{
Expand All @@ -40,10 +34,7 @@ private async Task LoadThumbnailAsync()
{
// Attempt to load image thumbnail
await using var stream = new FileStream(FullPath, FileMode.Open, FileAccess.Read);

// Decode to a specific width for performance (e.g., 100 pixels)
Thumbnail = await Task.Run(() => Bitmap.DecodeToWidth(stream, 300));
return;
Thumbnail = await ThumbnailUtils.GenerateBitmap(stream);
}
}
catch (Exception ex)
Expand All @@ -53,7 +44,7 @@ private async Task LoadThumbnailAsync()

Thumbnail ??= GetDefaultIcon();
}

private static Bitmap? _defaultIcon;
private static Bitmap GetDefaultIcon()
{
Expand Down
11 changes: 6 additions & 5 deletions MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
Icon="avares://SelectSight/Assets/icon.ico">

<Grid RowDefinitions="*,Auto" Background="WhiteSmoke">
<Grid Grid.Row="0" ColumnDefinitions="5*,1*">
<Grid Grid.Row="0" ColumnDefinitions="8*,1*">
<Border Grid.Column="0" BorderBrush="LightGray" BorderThickness="0,0,1,0" Background="Transparent">
<Grid RowDefinitions="Auto,*">
<ListBox Grid.Row="1"
x:Name="AllFilesListBox"
Background="Transparent"
AutoScrollToSelectedItem="False"
SelectionMode="Multiple">

<ListBox.ItemsPanel>
Expand Down Expand Up @@ -73,15 +74,15 @@
Background="Transparent" Padding="10">
<Grid ColumnDefinitions="*,*">
<Grid Grid.Column="0" ColumnDefinitions="Auto,*" HorizontalAlignment="Stretch">
<TextBlock Grid.Column="0" x:Name="SelectedFilesText" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Grid.Column="0" x:Name="FilesInfoText" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Grid.Column="1" x:Name="FeedbackText" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
<StackPanel Grid.Column="1"
Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="Select All"
HorizontalContentAlignment="Left"
Background="DeepSkyBlue"
Click="SelectAllFiles"
Click="SelectAllBtnClick"
x:Name="SelectAllButton"
Padding="15,8" Margin="0,0,10,0">
<Button.Styles>
Expand All @@ -93,7 +94,7 @@
<Button Content="Copy Selected"
Background="YellowGreen"
IsEnabled="False"
Click="CopySelectedFiles"
Click="CopySelectedBtnClick"
x:Name="CopyButton"
Padding="15,8" Margin="0,0,10,0">
<Button.Styles>
Expand All @@ -104,7 +105,7 @@
</Button>
<Button Content="Clear Selected"
Background="DarkRed"
Click="ClearSelectedFiles"
Click="ClearSelectedBtnClick"
IsEnabled="False"
x:Name="ClearButton"
Padding="15,8">
Expand Down
Loading