add filepicker
This commit is contained in:
parent
e8e6221200
commit
3456af5101
@ -8,12 +8,24 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
using Tmds.DBus.Protocol;
|
using Tmds.DBus.Protocol;
|
||||||
|
|
||||||
namespace Presence.Desktop.ViewModels
|
namespace Presence.Desktop.ViewModels
|
||||||
{
|
{
|
||||||
public class GroupViewModel : ViewModelBase, IRoutableViewModel
|
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 readonly List<GroupPresenter> _groupPresentersDataSource = new List<GroupPresenter>();
|
||||||
private ObservableCollection<GroupPresenter> _groups;
|
private ObservableCollection<GroupPresenter> _groups;
|
||||||
public ObservableCollection<GroupPresenter> Groups => _groups;
|
public ObservableCollection<GroupPresenter> Groups => _groups;
|
||||||
@ -31,6 +43,8 @@ namespace Presence.Desktop.ViewModels
|
|||||||
public GroupViewModel(IGroupUseCase groupUseCase)
|
public GroupViewModel(IGroupUseCase groupUseCase)
|
||||||
{
|
{
|
||||||
_groupUseCase = groupUseCase;
|
_groupUseCase = groupUseCase;
|
||||||
|
_SelectFileInteraction = new Interaction<string?, string?>();
|
||||||
|
OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile);
|
||||||
_users = new ObservableCollection<UserPresenter>();
|
_users = new ObservableCollection<UserPresenter>();
|
||||||
RefreshGroups();
|
RefreshGroups();
|
||||||
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
||||||
@ -38,7 +52,6 @@ namespace Presence.Desktop.ViewModels
|
|||||||
{ RefreshGroups();
|
{ RefreshGroups();
|
||||||
SetUsers();
|
SetUsers();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetUsers()
|
private void SetUsers()
|
||||||
@ -74,6 +87,12 @@ namespace Presence.Desktop.ViewModels
|
|||||||
}
|
}
|
||||||
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
_groups = new ObservableCollection<GroupPresenter>(_groupPresentersDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SelectFile()
|
||||||
|
{
|
||||||
|
Console.WriteLine("clock");
|
||||||
|
SelectedFile = await _SelectFileInteraction.Handle("Chose csv file");
|
||||||
|
}
|
||||||
public string? UrlPathSegment { get; }
|
public string? UrlPathSegment { get; }
|
||||||
public IScreen HostScreen { get; }
|
public IScreen HostScreen { get; }
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<ComboBox/>
|
<Button Width="100" Command="{Binding OpenFileDialog}"/>
|
||||||
<ComboBox/>
|
<ComboBox/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Border>
|
<Border>
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
using Presence.Desktop.ViewModels;
|
using Presence.Desktop.ViewModels;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
@ -10,8 +14,24 @@ namespace Presence.Desktop.Views
|
|||||||
{
|
{
|
||||||
public GroupView()
|
public GroupView()
|
||||||
{
|
{
|
||||||
this.WhenActivated(disposables => { });
|
this.WhenActivated(action =>
|
||||||
|
{
|
||||||
|
action(ViewModel!.SelectFileInteraction.RegisterHandler(ShowFileDialog));
|
||||||
|
});
|
||||||
AvaloniaXamlLoader.Load(this);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\domain\domain.csproj" />
|
<ProjectReference Include="..\domain\domain.csproj" />
|
||||||
<ProjectReference Include="..\data\data.csproj" />
|
<ProjectReference Include="..\data\data.csproj" />
|
||||||
<ProjectReference Include="..\ui\ui.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -5,8 +5,6 @@ VisualStudioVersion = 17.0.31903.59
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "data", "data\data.csproj", "{FFE39EC0-DDC4-4670-A991-075ADF2B4C95}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "data", "data\data.csproj", "{FFE39EC0-DDC4-4670-A991-075ADF2B4C95}"
|
||||||
EndProject
|
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}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "console_ui", "console_ui\console_ui.csproj", "{1DEBFFB8-8F9B-4E2D-881C-A65AE0A206C3}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "domain", "domain\domain.csproj", "{8B7BA538-FFE9-4A67-A48B-0ECC957B2315}"
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{FFE39EC0-DDC4-4670-A991-075ADF2B4C95}.Release|Any CPU.Build.0 = 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.ActiveCfg = Debug|Any CPU
|
||||||
{1DEBFFB8-8F9B-4E2D-881C-A65AE0A206C3}.Debug|Any CPU.Build.0 = 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
|
{1DEBFFB8-8F9B-4E2D-881C-A65AE0A206C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
Loading…
Reference in New Issue
Block a user