add filepicker

This commit is contained in:
KP9lKk 2024-12-06 11:04:11 +03:00
parent e8e6221200
commit 3456af5101
5 changed files with 43 additions and 11 deletions

View File

@ -8,16 +8,28 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Tmds.DBus.Protocol;
namespace Presence.Desktop.ViewModels
{
public class GroupViewModel : ViewModelBase, IRoutableViewModel
{
public ICommand OpenFileDialog { get; }
public Interaction<string?, string?> SelectFileInteraction => _SelectFileInteraction;
public readonly Interaction<string?, string?> _SelectFileInteraction;
private string? _selectedFile;
public string? SelectedFile
{
get => _selectedFile;
set => this.RaiseAndSetIfChanged(ref _selectedFile, value);
}
private readonly List<GroupPresenter> _groupPresentersDataSource = new List<GroupPresenter>();
private ObservableCollection<GroupPresenter> _groups;
public ObservableCollection<GroupPresenter> Groups => _groups;
public GroupPresenter? SelectedGroupItem {
get => _selectedGroupItem;
set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); }
@ -31,6 +43,8 @@ namespace Presence.Desktop.ViewModels
public GroupViewModel(IGroupUseCase groupUseCase)
{
_groupUseCase = groupUseCase;
_SelectFileInteraction = new Interaction<string?, string?>();
OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile);
_users = new ObservableCollection<UserPresenter>();
RefreshGroups();
this.WhenAnyValue(vm => vm.SelectedGroupItem)
@ -38,7 +52,6 @@ namespace Presence.Desktop.ViewModels
{ RefreshGroups();
SetUsers();
});
}
private void SetUsers()
@ -74,6 +87,12 @@ namespace Presence.Desktop.ViewModels
}
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
}
private async Task SelectFile()
{
Console.WriteLine("clock");
SelectedFile = await _SelectFileInteraction.Handle("Chose csv file");
}
public string? UrlPathSegment { get; }
public IScreen HostScreen { get; }
}

View File

@ -27,7 +27,7 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox/>
<Button Width="100" Command="{Binding OpenFileDialog}"/>
<ComboBox/>
</StackPanel>
<Border>

View File

@ -1,5 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Platform.Storage;
using Avalonia.ReactiveUI;
using Presence.Desktop.ViewModels;
using ReactiveUI;
@ -10,8 +14,24 @@ namespace Presence.Desktop.Views
{
public GroupView()
{
this.WhenActivated(disposables => { });
this.WhenActivated(action =>
{
action(ViewModel!.SelectFileInteraction.RegisterHandler(ShowFileDialog));
});
AvaloniaXamlLoader.Load(this);
}
private async Task ShowFileDialog(IInteractionContext<string?, string?> context)
{
var topLevel = TopLevel.GetTopLevel(this);
var storageFile = await topLevel.StorageProvider.OpenFilePickerAsync(
new FilePickerOpenOptions()
{
AllowMultiple = false,
Title = context.Input
}
);
context.SetOutput(storageFile.First().Path.ToString());
}
}
}

View File

@ -3,7 +3,6 @@
<ItemGroup>
<ProjectReference Include="..\domain\domain.csproj" />
<ProjectReference Include="..\data\data.csproj" />
<ProjectReference Include="..\ui\ui.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -5,8 +5,6 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "data", "data\data.csproj", "{FFE39EC0-DDC4-4670-A991-075ADF2B4C95}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ui", "ui\ui.csproj", "{2CDB8D72-14C6-47D8-9DA0-852E72FE1663}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "console_ui", "console_ui\console_ui.csproj", "{1DEBFFB8-8F9B-4E2D-881C-A65AE0A206C3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "domain", "domain\domain.csproj", "{8B7BA538-FFE9-4A67-A48B-0ECC957B2315}"
@ -25,10 +23,6 @@ Global
{FFE39EC0-DDC4-4670-A991-075ADF2B4C95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FFE39EC0-DDC4-4670-A991-075ADF2B4C95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FFE39EC0-DDC4-4670-A991-075ADF2B4C95}.Release|Any CPU.Build.0 = Release|Any CPU
{2CDB8D72-14C6-47D8-9DA0-852E72FE1663}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CDB8D72-14C6-47D8-9DA0-852E72FE1663}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CDB8D72-14C6-47D8-9DA0-852E72FE1663}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CDB8D72-14C6-47D8-9DA0-852E72FE1663}.Release|Any CPU.Build.0 = Release|Any CPU
{1DEBFFB8-8F9B-4E2D-881C-A65AE0A206C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1DEBFFB8-8F9B-4E2D-881C-A65AE0A206C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DEBFFB8-8F9B-4E2D-881C-A65AE0A206C3}.Release|Any CPU.ActiveCfg = Release|Any CPU