Group rename WIP
This commit is contained in:
@@ -7,5 +7,4 @@ public interface IDialogService : IUserCommunicationService
|
||||
{
|
||||
IObservable<ReadInputsViewModel?> ReadInput { get; }
|
||||
IObservable<MessageBoxViewModel?> LastMessageBox { get; }
|
||||
void ReadInputs(IEnumerable<IInputElement> inputs, Action inputHandler, Action? cancelHandler = null);
|
||||
}
|
||||
@@ -1,28 +1,33 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Interactions;
|
||||
using MvvmGen;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
|
||||
namespace FileTime.GuiApp.ViewModels;
|
||||
|
||||
[ViewModel]
|
||||
[Inject(typeof(Action<ReadInputsViewModel>), "_cancel")]
|
||||
[Inject(typeof(Action<ReadInputsViewModel>), "_process")]
|
||||
public partial class ReadInputsViewModel : IModalViewModel
|
||||
public class ReadInputsViewModel : IModalViewModel
|
||||
{
|
||||
public string Name => "ReadInputs";
|
||||
public List<IInputElement> Inputs { get; set; }
|
||||
public Action SuccessHandler { get; set; }
|
||||
public Action? CancelHandler { get; set; }
|
||||
public required List<IInputElement> Inputs { get; init; }
|
||||
public required Action<ReadInputsViewModel> SuccessHandler { get; init; }
|
||||
public required Action<ReadInputsViewModel>? CancelHandler { get; init; }
|
||||
public ObservableCollection<IPreviewElement> Previews { get; } = new();
|
||||
|
||||
[Command]
|
||||
public void Process()
|
||||
public ReadInputsViewModel()
|
||||
{
|
||||
_process.Invoke(this);
|
||||
}
|
||||
|
||||
[Command]
|
||||
public void Cancel()
|
||||
public ReadInputsViewModel(
|
||||
List<IInputElement> inputs,
|
||||
Action<ReadInputsViewModel> successHandler,
|
||||
Action<ReadInputsViewModel>? cancelHandler = null)
|
||||
{
|
||||
_cancel.Invoke(this);
|
||||
Inputs = inputs;
|
||||
SuccessHandler = successHandler;
|
||||
CancelHandler = cancelHandler;
|
||||
}
|
||||
|
||||
public void Process() => SuccessHandler.Invoke(this);
|
||||
|
||||
public void Cancel() => CancelHandler?.Invoke(this);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Globalization;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace FileTime.GuiApp.Converters;
|
||||
|
||||
public class TextDecorationConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool b && b) return TextDecorations.Underline;
|
||||
return null;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="using:FileTime.GuiApp.Converters">
|
||||
<ResourceDictionary
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:converters="using:FileTime.GuiApp.Converters"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceInclude Source="avares://FileTime.GuiApp/Resources/Brushes.axaml"></ResourceInclude>
|
||||
<ResourceInclude Source="avares://FileTime.GuiApp/Resources/Brushes.axaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
@@ -26,18 +27,20 @@
|
||||
x:Key="ItemViewModeToBackgroundConverter" />
|
||||
<converters:NamePartShrinkerConverter x:Key="NamePartShrinkerConverter" />
|
||||
<converters:ItemViewModelIsAttributeTypeConverter x:Key="ItemViewModelIsAttributeTypeConverter" />
|
||||
<converters:ItemViewModelIsAttributeTypeConverter Invert="true"
|
||||
x:Key="ItemViewModelIsNotAttributeTypeConverter" />
|
||||
<converters:ItemViewModelIsAttributeTypeConverter Invert="true" x:Key="ItemViewModelIsNotAttributeTypeConverter" />
|
||||
<converters:GetFileExtensionConverter x:Key="GetFileExtensionConverter" />
|
||||
<converters:FormatSizeConverter x:Key="FormatSizeConverter" />
|
||||
<converters:DateTimeConverter x:Key="DateTimeConverter" />
|
||||
<converters:SplitStringConverter x:Key="SplitStringConverter" />
|
||||
<converters:CompareConverter x:Key="EqualityConverter" />
|
||||
<converters:CompareConverter ComparisonCondition="{x:Static converters:ComparisonCondition.NotEqual}"
|
||||
x:Key="NotEqualsConverter" />
|
||||
<converters:CompareConverter ComparisonCondition="{x:Static converters:ComparisonCondition.NotEqual}" x:Key="NotEqualsConverter" />
|
||||
<converters:ExceptionToStringConverter x:Key="ExceptionToStringConverter" />
|
||||
<converters:CommandToCommandNameConverter x:Key="CommandToCommandNameConverter" />
|
||||
<converters:ItemToImageConverter x:Key="ItemToImageConverter" />
|
||||
<converters:StringReplaceConverter x:Key="PathPreformatter" OldValue="://" NewValue="/"/>
|
||||
<converters:ContextMenuGenerator x:Key="ContextMenuGenerator"/>
|
||||
<converters:StringReplaceConverter
|
||||
NewValue="/"
|
||||
OldValue="://"
|
||||
x:Key="PathPreformatter" />
|
||||
<converters:ContextMenuGenerator x:Key="ContextMenuGenerator" />
|
||||
<converters:TextDecorationConverter x:Key="TextDecorationConverter" />
|
||||
</ResourceDictionary>
|
||||
@@ -37,16 +37,76 @@ public class DialogService : IDialogService
|
||||
.Select(m => m.LastOrDefault());
|
||||
}
|
||||
|
||||
public void ReadInputs(IEnumerable<IInputElement> inputs, Action inputHandler, Action? cancelHandler = null)
|
||||
private void ReadInputs(
|
||||
IEnumerable<IInputElement> inputs,
|
||||
Action inputHandler,
|
||||
Action? cancelHandler = null,
|
||||
IEnumerable<IPreviewElement>? previews = null)
|
||||
{
|
||||
var modalViewModel = new ReadInputsViewModel(HandleReadInputsSuccess, HandleReadInputsCancel)
|
||||
var modalViewModel = new ReadInputsViewModel
|
||||
{
|
||||
Inputs = inputs.ToList(),
|
||||
SuccessHandler = inputHandler,
|
||||
CancelHandler = cancelHandler
|
||||
SuccessHandler = HandleReadInputsSuccess,
|
||||
CancelHandler = HandleReadInputsCancel
|
||||
};
|
||||
|
||||
if (previews is not null)
|
||||
{
|
||||
modalViewModel.Previews.AddRange(previews);
|
||||
}
|
||||
|
||||
_modalService.OpenModal(modalViewModel);
|
||||
|
||||
void HandleReadInputsSuccess(ReadInputsViewModel readInputsViewModel)
|
||||
{
|
||||
_modalService.CloseModal(readInputsViewModel);
|
||||
inputHandler();
|
||||
}
|
||||
|
||||
void HandleReadInputsCancel(ReadInputsViewModel readInputsViewModel)
|
||||
{
|
||||
_modalService.CloseModal(readInputsViewModel);
|
||||
cancelHandler?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public Task<bool> ReadInputs(IEnumerable<IInputElement> fields, IEnumerable<IPreviewElement>? previews = null)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
ReadInputs(
|
||||
fields,
|
||||
() => taskCompletionSource.SetResult(true),
|
||||
() => taskCompletionSource.SetResult(false),
|
||||
previews
|
||||
);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
|
||||
public Task<bool> ReadInputs(params IInputElement[] fields)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
ReadInputs(
|
||||
fields,
|
||||
() => taskCompletionSource.SetResult(true),
|
||||
() => taskCompletionSource.SetResult(false)
|
||||
);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
public Task<bool> ReadInputs(IInputElement field, IEnumerable<IPreviewElement>? previews = null)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
ReadInputs(
|
||||
new[] {field},
|
||||
() => taskCompletionSource.SetResult(true),
|
||||
() => taskCompletionSource.SetResult(false),
|
||||
previews
|
||||
);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
public void ShowToastMessage(string text)
|
||||
@@ -70,24 +130,4 @@ public class DialogService : IDialogService
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
|
||||
private void HandleReadInputsSuccess(ReadInputsViewModel readInputsViewModel)
|
||||
{
|
||||
_modalService.CloseModal(readInputsViewModel);
|
||||
readInputsViewModel.SuccessHandler.Invoke();
|
||||
}
|
||||
|
||||
private void HandleReadInputsCancel(ReadInputsViewModel readInputsViewModel)
|
||||
{
|
||||
_modalService.CloseModal(readInputsViewModel);
|
||||
readInputsViewModel.CancelHandler?.Invoke();
|
||||
}
|
||||
|
||||
public Task<bool> ReadInputs(params IInputElement[] fields)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
ReadInputs(fields, () => taskCompletionSource.SetResult(true), () => taskCompletionSource.SetResult(false));
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
x:DataType="vm:IMainWindowViewModelBase"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:appCoreModels="using:FileTime.App.Core.Models"
|
||||
xmlns:appInteractions="using:FileTime.App.Core.Interactions"
|
||||
xmlns:config="using:FileTime.GuiApp.Configuration"
|
||||
xmlns:corevm="using:FileTime.App.Core.ViewModels"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@@ -578,7 +579,7 @@
|
||||
HorizontalAlignment="Center"
|
||||
Padding="20"
|
||||
VerticalAlignment="Center">
|
||||
<Grid RowDefinitions="Auto,Auto">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto">
|
||||
|
||||
<ItemsControl
|
||||
ItemsSource="{Binding DialogService.ReadInput^.Inputs}"
|
||||
@@ -621,18 +622,92 @@
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ItemsControl Grid.Row="1" ItemsSource="{Binding DialogService.ReadInput^.Previews}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid IsVisible="{Binding PreviewType, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static appInteractions:PreviewType.DoubleTextList}}">
|
||||
<ItemsControl ItemsSource="{Binding Items}" x:DataType="appInteractions:DoubleTextListPreview">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
<ItemsControl ItemsSource="{Binding Text1^}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}" TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl Grid.Column="1" ItemsSource="{Binding Text2^}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}" TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<!--DataGrid ItemsSource="{Binding Items}" x:DataType="appInteractions:DoubleTextListPreview">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ItemsControl
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding Text1^}"
|
||||
Margin="5,0,0,0"
|
||||
VerticalAlignment="Center">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="x:String">
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid-->
|
||||
</Grid>
|
||||
|
||||
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<StackPanel
|
||||
DataContext="{Binding DialogService.ReadInput^}"
|
||||
Grid.Row="1"
|
||||
Grid.Row="2"
|
||||
Margin="0,10,0,0"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
Command="{Binding ProcessCommand}"
|
||||
Command="{Binding Process}"
|
||||
Content="Ok"
|
||||
HorizontalContentAlignment="Center"
|
||||
Width="80" />
|
||||
<Button
|
||||
Command="{Binding CancelCommand}"
|
||||
Command="{Binding Cancel}"
|
||||
Content="Cancel"
|
||||
HorizontalContentAlignment="Center"
|
||||
Margin="10,0,0,0"
|
||||
|
||||
Reference in New Issue
Block a user