Working on the gui
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="PhotoRenamerGui.App"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
<Application
|
||||
RequestedThemeVariant="Default"
|
||||
x:Class="PhotoRenamerGui.App"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
|
||||
</Application.Styles>
|
||||
</Application>
|
@ -57,5 +57,23 @@
|
||||
VerticalAlignment="Stretch" />
|
||||
</TextBox.InnerRightContent>
|
||||
</TextBox>
|
||||
|
||||
|
||||
<DataGrid
|
||||
AutoGenerateColumns="False"
|
||||
BorderBrush="Gray"
|
||||
BorderThickness="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Grid.Row="2"
|
||||
GridLinesVisibility="All"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding MediaFiles}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridCheckBoxColumn Binding="{Binding IsSelected}" />
|
||||
<DataGridTextColumn Binding="{Binding SourceDirectory}" Header="Source" />
|
||||
<DataGridTextColumn Binding="{Binding TargetDirectory}" Header="Target" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -1,9 +1,13 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Platform.Storage;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using PhotoRenamer;
|
||||
|
||||
namespace PhotoRenamerGui;
|
||||
|
||||
@ -11,24 +15,64 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private string? _inputFolder;
|
||||
[ObservableProperty] private string? _outputFolder;
|
||||
public ObservableCollection<MediaFile> MediaFiles { get; } = new();
|
||||
|
||||
[RelayCommand]
|
||||
private async Task SelectInputFolder()
|
||||
private async Task SelectInputFolderAsync()
|
||||
{
|
||||
InputFolder = await SearchFolder();
|
||||
InputFolder = await SearchFolderAsync();
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
private async Task SelectOutputFolder()
|
||||
private async Task SelectOutputFolderAsync()
|
||||
{
|
||||
OutputFolder = await SearchFolder();
|
||||
OutputFolder = await SearchFolderAsync();
|
||||
}
|
||||
|
||||
private async Task<string?> SearchFolder()
|
||||
|
||||
private static async Task<string?> SearchFolderAsync()
|
||||
{
|
||||
var storageProvider = (App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).MainWindow
|
||||
var storageProvider = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)
|
||||
?.MainWindow?
|
||||
.StorageProvider;
|
||||
var result =await storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions());
|
||||
return result.FirstOrDefault()?.TryGetLocalPath();
|
||||
if (storageProvider is null) return "<not accessible>";
|
||||
var result = await storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions());
|
||||
return result.Count > 0 ? result[0].TryGetLocalPath() : null;
|
||||
}
|
||||
|
||||
partial void OnInputFolderChanged(string? value)
|
||||
{
|
||||
UpdatePreviewList();
|
||||
}
|
||||
|
||||
partial void OnOutputFolderChanged(string? value)
|
||||
{
|
||||
UpdatePreviewList();
|
||||
}
|
||||
|
||||
private void UpdatePreviewList()
|
||||
{
|
||||
MediaFiles.Clear();
|
||||
if (string.IsNullOrWhiteSpace(InputFolder)) return;
|
||||
if (string.IsNullOrWhiteSpace(OutputFolder)) return;
|
||||
var allFiles = FolderExtension.GetAllFiles(InputFolder);
|
||||
foreach (var file in allFiles)
|
||||
{
|
||||
var source = Path.GetRelativePath(InputFolder, file);
|
||||
var date = MediaFileExtension.GetDateTimeFromSourceFile(file);
|
||||
var target = FolderExtension.BuildTargetDirectoryByDate(OutputFolder, DateOnly.FromDateTime(date));
|
||||
|
||||
MediaFiles.Add(new MediaFile(true, source, Path.GetRelativePath(OutputFolder, target)));
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
public class MediaFile(bool isSelected, string? sourceDirectory, string? targetDirectory) : ObservableObject
|
||||
{
|
||||
public bool IsSelected { get=> isSelected;
|
||||
set => SetProperty(ref isSelected, value);
|
||||
}
|
||||
public string? SourceDirectory { get; } = sourceDirectory;
|
||||
public string? TargetDirectory { get; } = targetDirectory;
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
@ -10,12 +10,18 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.0.4" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.0.4" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.4" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.4" />
|
||||
<PackageReference Include="Avalonia" Version="11.0.5" />
|
||||
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.5" />
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.0.5" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.5" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.5" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.4" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.5" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PhotoRenamer\PhotoRenamer.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user