Add output folder selector
This commit is contained in:
		| @@ -15,47 +15,47 @@ | |||||||
|     </Window.DataContext> |     </Window.DataContext> | ||||||
|     <Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="Auto,Auto,*"> |     <Grid ColumnDefinitions="Auto,*,Auto" RowDefinitions="Auto,Auto,*"> | ||||||
|         <Grid.Styles> |         <Grid.Styles> | ||||||
|             <Style Selector="TemplatedControl.space"> |             <Style Selector=":is(TemplatedControl)"> | ||||||
|                 <Setter Property="Margin" Value="5" /> |                 <Setter Property="Margin" Value="0,5" /> | ||||||
|             </Style> |             </Style> | ||||||
|         </Grid.Styles> |         </Grid.Styles> | ||||||
|         <Label |         <Label | ||||||
|             Classes="space" |  | ||||||
|             Content="Input Folder" |             Content="Input Folder" | ||||||
|             Grid.Column="0" |             Grid.Column="0" | ||||||
|             Grid.Row="0" |             Grid.Row="0" | ||||||
|             VerticalAlignment="Center" /> |             VerticalAlignment="Center" | ||||||
|  |             VerticalContentAlignment="Center" /> | ||||||
|         <Label |         <Label | ||||||
|             Classes="space" |  | ||||||
|             Content="Output Folder" |             Content="Output Folder" | ||||||
|             Grid.Column="0" |             Grid.Column="0" | ||||||
|             Grid.Row="1" |             Grid.Row="1" | ||||||
|             VerticalAlignment="Center" /> |             VerticalAlignment="Center" | ||||||
|  |             VerticalContentAlignment="Center" /> | ||||||
|         <TextBox |         <TextBox | ||||||
|             Classes="space" |  | ||||||
|             Grid.Column="1" |             Grid.Column="1" | ||||||
|             Grid.Row="0" |             Grid.Row="0" | ||||||
|             Text="{Binding InputFolder}" |             Text="{Binding InputFolder}" | ||||||
|             Watermark="Input" /> |             Watermark="Input"> | ||||||
|  |             <TextBox.InnerRightContent> | ||||||
|  |                 <Button | ||||||
|  |                     Command="{Binding SelectInputFolderCommand}" | ||||||
|  |                     Content="..." | ||||||
|  |                     Margin="0,5,5,5" | ||||||
|  |                     VerticalAlignment="Stretch" /> | ||||||
|  |             </TextBox.InnerRightContent> | ||||||
|  |         </TextBox> | ||||||
|         <TextBox |         <TextBox | ||||||
|             Classes="space" |  | ||||||
|             Grid.Column="1" |             Grid.Column="1" | ||||||
|             Grid.Row="1" |             Grid.Row="1" | ||||||
|             Text="{Binding OutputFolder}" |             Text="{Binding OutputFolder}" | ||||||
|             Watermark="Output" /> |             Watermark="Output"> | ||||||
|         <Button |             <TextBox.InnerRightContent> | ||||||
|             Classes="space" |                 <Button | ||||||
|             Grid.Column="2" |                     Command="{Binding SelectOutputFolderCommand}" | ||||||
|             Grid.Row="0" |                     Content="..." | ||||||
|             VerticalAlignment="Stretch"> |                     Margin="0,5,5,5" | ||||||
|             ... |                     VerticalAlignment="Stretch" /> | ||||||
|         </Button> |             </TextBox.InnerRightContent> | ||||||
|         <Button |         </TextBox> | ||||||
|             Classes="space" |  | ||||||
|             Grid.Column="2" |  | ||||||
|             Grid.Row="1" |  | ||||||
|             VerticalAlignment="Stretch"> |  | ||||||
|             ... |  | ||||||
|         </Button> |  | ||||||
|     </Grid> |     </Grid> | ||||||
| </Window> | </Window> | ||||||
|   | |||||||
| @@ -1,4 +1,9 @@ | |||||||
|  | using System.Linq; | ||||||
|  | using System.Threading.Tasks; | ||||||
|  | using Avalonia.Controls.ApplicationLifetimes; | ||||||
|  | using Avalonia.Platform.Storage; | ||||||
| using CommunityToolkit.Mvvm.ComponentModel; | using CommunityToolkit.Mvvm.ComponentModel; | ||||||
|  | using CommunityToolkit.Mvvm.Input; | ||||||
|  |  | ||||||
| namespace PhotoRenamerGui; | namespace PhotoRenamerGui; | ||||||
|  |  | ||||||
| @@ -6,4 +11,24 @@ public partial class MainWindowViewModel : ObservableObject | |||||||
| { | { | ||||||
|     [ObservableProperty] private string? _inputFolder; |     [ObservableProperty] private string? _inputFolder; | ||||||
|     [ObservableProperty] private string? _outputFolder; |     [ObservableProperty] private string? _outputFolder; | ||||||
|  |  | ||||||
|  |     [RelayCommand] | ||||||
|  |     private async Task SelectInputFolder() | ||||||
|  |     { | ||||||
|  |         InputFolder = await SearchFolder(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     [RelayCommand] | ||||||
|  |     private async Task SelectOutputFolder() | ||||||
|  |     { | ||||||
|  |         OutputFolder = await SearchFolder(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private async Task<string?> SearchFolder() | ||||||
|  |     { | ||||||
|  |         var storageProvider = (App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).MainWindow | ||||||
|  |             .StorageProvider; | ||||||
|  |         var result  =await storageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions()); | ||||||
|  |         return result.FirstOrDefault()?.TryGetLocalPath(); | ||||||
|  |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user