Command status
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<AvaloniaResource Include="Assets\**" />
|
||||
<Folder Include="ViewModels\" />
|
||||
<None Remove=".gitignore" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
[Property]
|
||||
private ObservableCollection<string> _popupTexts = new ObservableCollection<string>();
|
||||
|
||||
public IReadOnlyList<ReadOnlyParallelCommands> TimelineCommands => _timeRunner.ParallelCommands;
|
||||
public ObservableCollection<ParallelCommandsViewModel> TimelineCommands { get; } = new();
|
||||
|
||||
async partial void OnInitialize()
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
inputInterface.InputHandler = ReadInputs;
|
||||
App.ServiceProvider.GetService<TopContainer>();
|
||||
|
||||
_timeRunner.CommandsChanged += (o, e) => OnPropertyChanged(nameof(TimelineCommands));
|
||||
_timeRunner.CommandsChanged += UpdateParalellCommands;
|
||||
InitCommandBindings();
|
||||
|
||||
_keysToSkip.Add(new KeyWithModifiers[] { new KeyWithModifiers(Key.Up) });
|
||||
@@ -179,6 +179,31 @@ namespace FileTime.Avalonia.ViewModels
|
||||
Places = places;
|
||||
}
|
||||
|
||||
private void UpdateParalellCommands(object? sender, EventArgs e)
|
||||
{
|
||||
foreach (var parallelCommand in _timeRunner.ParallelCommands)
|
||||
{
|
||||
if (!TimelineCommands.Any(c => c.Id == parallelCommand.Id))
|
||||
{
|
||||
TimelineCommands.Add(new ParallelCommandsViewModel(parallelCommand));
|
||||
}
|
||||
}
|
||||
var itemsToRemove = new List<ParallelCommandsViewModel>();
|
||||
foreach (var parallelCommandVm in TimelineCommands)
|
||||
{
|
||||
if (!_timeRunner.ParallelCommands.Any(c => c.Id == parallelCommandVm.Id))
|
||||
{
|
||||
itemsToRemove.Add(parallelCommandVm);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < itemsToRemove.Count; i++)
|
||||
{
|
||||
itemsToRemove[i].Dispose();
|
||||
TimelineCommands.Remove(itemsToRemove[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<IContainer?> GetContainerForWindowsDrive(DriveInfo drive)
|
||||
{
|
||||
return (await LocalContentProvider.GetRootContainers()).FirstOrDefault(d => d.Name == drive.Name.TrimEnd(Path.DirectorySeparatorChar));
|
||||
@@ -625,14 +650,10 @@ namespace FileTime.Avalonia.ViewModels
|
||||
[Command]
|
||||
public async void ProcessInputs()
|
||||
{
|
||||
try
|
||||
if (_inputHandler != null)
|
||||
{
|
||||
if (_inputHandler != null)
|
||||
{
|
||||
await _inputHandler.Invoke();
|
||||
}
|
||||
await _inputHandler.Invoke();
|
||||
}
|
||||
catch { }
|
||||
|
||||
Inputs = null;
|
||||
_inputHandler = null;
|
||||
@@ -781,7 +802,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
|
||||
var selectedItemName = AppState.SelectedTab.SelectedItem?.Item.Name;
|
||||
var currentLocationItems = await AppState.SelectedTab.CurrentLocation.GetItems();
|
||||
if(currentLocationItems.FirstOrDefault(i => i.Item.Name.ToLower() == AppState.RapidTravelText.ToLower()) is IItemViewModel matchItem)
|
||||
if (currentLocationItems.FirstOrDefault(i => i.Item.Name.ToLower() == AppState.RapidTravelText.ToLower()) is IItemViewModel matchItem)
|
||||
{
|
||||
await AppState.SelectedTab.SetCurrentSelectedItem(matchItem.Item);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Avalonia.ViewModels
|
||||
{
|
||||
public class ParallelCommandsViewModel : IDisposable
|
||||
{
|
||||
private bool _disposed;
|
||||
public IReadOnlyCollection<ParallelCommandViewModel> ParallelCommands { get; }
|
||||
public ushort Id { get; }
|
||||
|
||||
public ParallelCommandsViewModel(ReadOnlyParallelCommands parallelCommands)
|
||||
{
|
||||
ParallelCommands = parallelCommands.Commands.Select(c => new ParallelCommandViewModel(c)).ToList().AsReadOnly();
|
||||
Id = parallelCommands.Id;
|
||||
}
|
||||
|
||||
~ParallelCommandsViewModel()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed && disposing)
|
||||
{
|
||||
foreach(var commandVm in ParallelCommands)
|
||||
{
|
||||
commandVm.Dispose();
|
||||
}
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using AsyncEvent;
|
||||
using FileTime.Core.Command;
|
||||
using FileTime.Core.Timeline;
|
||||
using MvvmGen;
|
||||
|
||||
namespace FileTime.Avalonia.ViewModels
|
||||
{
|
||||
[ViewModel]
|
||||
public partial class ParallelCommandViewModel : IDisposable
|
||||
{
|
||||
private bool _disposed;
|
||||
private readonly ReadOnlyCommandTimeState _commandTimeState;
|
||||
|
||||
[Property]
|
||||
private int _progress;
|
||||
|
||||
public CanCommandRun CanRun => _commandTimeState.CanRun;
|
||||
public bool ForceRun => _commandTimeState.ForceRun;
|
||||
|
||||
public string Name => _commandTimeState.Command.DisplayLabel;
|
||||
|
||||
public ParallelCommandViewModel(ReadOnlyCommandTimeState commandTimeState)
|
||||
{
|
||||
_commandTimeState = commandTimeState;
|
||||
_commandTimeState.Command.ProgressChanged.Add(HandleProgressChange);
|
||||
}
|
||||
|
||||
private Task HandleProgressChange(object? sender, AsyncEventArgs e)
|
||||
{
|
||||
Progress = _commandTimeState.Command.Progress;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
~ParallelCommandViewModel()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed && disposing)
|
||||
{
|
||||
_commandTimeState.Command.ProgressChanged.Remove(HandleProgressChange);
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,13 +139,18 @@
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ItemsControl Items="{Binding Commands}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Border Background="{DynamicResource ContainerBackgroundColor}" Padding="5">
|
||||
<ItemsControl Items="{Binding ParallelCommands}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Name}"/>
|
||||
<ProgressBar Margin="0,5,0,0" Maximum="100" Value="{Binding Progress}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
@@ -290,14 +295,14 @@
|
||||
<Grid
|
||||
RowDefinitions="Auto, Auto"
|
||||
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Exceptions.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
|
||||
|
||||
|
||||
<TextBlock
|
||||
Margin="0,0,0,10"
|
||||
HorizontalAlignment="Center"
|
||||
TextWrapping="Wrap"
|
||||
Text="There were some errors while opening container."
|
||||
Foreground="{DynamicResource ErrorBrush}" />
|
||||
|
||||
|
||||
<ItemsRepeater Grid.Row="1" Items="{Binding AppState.SelectedTab.ChildContainer.Exceptions}">
|
||||
<ItemsRepeater.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
Reference in New Issue
Block a user