Timeline commands
This commit is contained in:
@@ -12,13 +12,14 @@ namespace FileTime.Core.Command
|
|||||||
public int Progress => 100;
|
public int Progress => 100;
|
||||||
|
|
||||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||||
public string DisplayLabel { get; } = "CreateContainer";
|
public string DisplayLabel { get; }
|
||||||
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
||||||
|
|
||||||
public CreateContainerCommand(AbsolutePath container, string newContainerName)
|
public CreateContainerCommand(AbsolutePath container, string newContainerName)
|
||||||
{
|
{
|
||||||
Container = container;
|
Container = container;
|
||||||
NewContainerName = newContainerName;
|
NewContainerName = newContainerName;
|
||||||
|
DisplayLabel = $"Create container {newContainerName}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Execute(TimeRunner timeRunner)
|
public async Task Execute(TimeRunner timeRunner)
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ namespace FileTime.Core.Command
|
|||||||
|
|
||||||
public int Progress => 100;
|
public int Progress => 100;
|
||||||
public AsyncEventHandler ProgressChanged { get; } = new();
|
public AsyncEventHandler ProgressChanged { get; } = new();
|
||||||
public string DisplayLabel { get; } = "CreateElement";
|
public string DisplayLabel { get; }
|
||||||
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
public IReadOnlyList<string> CanRunMessages { get; } = new List<string>().AsReadOnly();
|
||||||
|
|
||||||
public CreateElementCommand(AbsolutePath container, string newElementName)
|
public CreateElementCommand(AbsolutePath container, string newElementName)
|
||||||
{
|
{
|
||||||
Container = container;
|
Container = container;
|
||||||
NewElementName = newElementName;
|
NewElementName = newElementName;
|
||||||
|
DisplayLabel = $"Create element {newElementName}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Execute(TimeRunner timeRunner)
|
public async Task Execute(TimeRunner timeRunner)
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\AppCommon\FileTime.App.Style\FileTime.App.Style.csproj" />
|
<ProjectReference Include="..\..\AppCommon\FileTime.App.Style\FileTime.App.Style.csproj" />
|
||||||
<ProjectReference Include="..\AsyncEvent\AsyncEvent.csproj" />
|
<ProjectReference Include="..\AsyncEvent\AsyncEvent.csproj" />
|
||||||
|
|||||||
14
src/Core/FileTime.Core/Timeline/CommandRunner.cs
Normal file
14
src/Core/FileTime.Core/Timeline/CommandRunner.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace FileTime.Core.Timeline
|
||||||
|
{
|
||||||
|
public class CommandRunner
|
||||||
|
{
|
||||||
|
public Thread Thread { get; }
|
||||||
|
public CommandTimeState Command { get; }
|
||||||
|
|
||||||
|
public CommandRunner(Thread thread, CommandTimeState command)
|
||||||
|
{
|
||||||
|
Thread = thread;
|
||||||
|
Command = command;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using AsyncEvent;
|
using AsyncEvent;
|
||||||
using FileTime.Core.Command;
|
using FileTime.Core.Command;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace FileTime.Core.Timeline
|
namespace FileTime.Core.Timeline
|
||||||
{
|
{
|
||||||
@@ -9,10 +10,11 @@ namespace FileTime.Core.Timeline
|
|||||||
private readonly CommandExecutor _commandExecutor;
|
private readonly CommandExecutor _commandExecutor;
|
||||||
private readonly List<ParallelCommands> _commandsToRun = new();
|
private readonly List<ParallelCommands> _commandsToRun = new();
|
||||||
private readonly object _guard = new();
|
private readonly object _guard = new();
|
||||||
|
private readonly ILogger<TimeRunner> _logger;
|
||||||
|
|
||||||
private bool _resourceIsInUse;
|
private bool _resourceIsInUse;
|
||||||
private readonly List<Thread> _commandRunners = new();
|
private readonly List<CommandRunner> _commandRunners = new();
|
||||||
private bool _enableRunning; //= true;
|
private bool _enableRunning = true;
|
||||||
|
|
||||||
private IReadOnlyList<ReadOnlyParallelCommands> _parallelCommands = new List<ReadOnlyParallelCommands>();
|
private IReadOnlyList<ReadOnlyParallelCommands> _parallelCommands = new List<ReadOnlyParallelCommands>();
|
||||||
|
|
||||||
@@ -41,14 +43,15 @@ namespace FileTime.Core.Timeline
|
|||||||
|
|
||||||
public AsyncEventHandler<AbsolutePath> RefreshContainer { get; } = new AsyncEventHandler<AbsolutePath>();
|
public AsyncEventHandler<AbsolutePath> RefreshContainer { get; } = new AsyncEventHandler<AbsolutePath>();
|
||||||
|
|
||||||
public AsyncEventHandler CommandsChangedAsync { get; } = new();
|
public AsyncEventHandler<IReadOnlyList<ReadOnlyParallelCommands>> CommandsChangedAsync { get; } = new();
|
||||||
|
|
||||||
public TimeRunner(CommandExecutor commandExecutor)
|
public TimeRunner(CommandExecutor commandExecutor, ILogger<TimeRunner> logger)
|
||||||
{
|
{
|
||||||
_commandExecutor = commandExecutor;
|
_commandExecutor = commandExecutor;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddCommand(ICommand command, ParallelCommands? batch = null, bool toNewBatch = false)
|
public async Task AddCommand(ICommand command, int? batchId = null, bool toNewBatch = false)
|
||||||
{
|
{
|
||||||
await RunWithLockAsync(async () =>
|
await RunWithLockAsync(async () =>
|
||||||
{
|
{
|
||||||
@@ -64,9 +67,9 @@ namespace FileTime.Core.Timeline
|
|||||||
batchToAdd = new ParallelCommands(_commandsToRun.Last().Result);
|
batchToAdd = new ParallelCommands(_commandsToRun.Last().Result);
|
||||||
_commandsToRun.Add(batchToAdd);
|
_commandsToRun.Add(batchToAdd);
|
||||||
}
|
}
|
||||||
else if (batch != null && _commandsToRun.Contains(batch))
|
else if (batchId != null && _commandsToRun.Find(b => b.Id == batchId) is ParallelCommands parallelCommands)
|
||||||
{
|
{
|
||||||
batchToAdd = batch;
|
batchToAdd = parallelCommands;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -80,20 +83,14 @@ namespace FileTime.Core.Timeline
|
|||||||
{
|
{
|
||||||
StartCommandRunner();
|
StartCommandRunner();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
await UpdateReadOnlyCommands();
|
await UpdateReadOnlyCommands();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task TryStartCommandRunner()
|
public async Task TryStartCommandRunner()
|
||||||
{
|
{
|
||||||
await RunWithLockAsync(() =>
|
await RunWithLockAsync(() => StartCommandRunner());
|
||||||
{
|
|
||||||
if (_commandRunners.Count == 0 && _commandsToRun.Count > 0)
|
|
||||||
{
|
|
||||||
StartCommandRunner();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartCommandRunner()
|
private void StartCommandRunner()
|
||||||
@@ -112,9 +109,15 @@ namespace FileTime.Core.Timeline
|
|||||||
{
|
{
|
||||||
foreach (var command in _commandsToRun[0].Commands)
|
foreach (var command in _commandsToRun[0].Commands)
|
||||||
{
|
{
|
||||||
if (command.CanRun == CanCommandRun.True || (command.CanRun == CanCommandRun.Forceable && command.ForceRun))
|
if (_commandRunners.Find(r => r.Command == command) != null)
|
||||||
{
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (command.CanRun == CanCommandRun.True || (command.CanRun == CanCommandRun.Forceable && command.ForceRun))
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Starting command: {0}", command.Command.DisplayLabel);
|
||||||
var thread = new Thread(new ParameterizedThreadStart(RunCommand));
|
var thread = new Thread(new ParameterizedThreadStart(RunCommand));
|
||||||
|
_commandRunners.Add(new CommandRunner(thread, command));
|
||||||
thread.Start(command);
|
thread.Start(command);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -144,28 +147,33 @@ namespace FileTime.Core.Timeline
|
|||||||
|
|
||||||
private async Task DisposeCommandThread(Thread thread, CommandTimeState? command)
|
private async Task DisposeCommandThread(Thread thread, CommandTimeState? command)
|
||||||
{
|
{
|
||||||
await RunWithLockAsync(() =>
|
await RunWithLockAsync(async () =>
|
||||||
{
|
{
|
||||||
if (command != null)
|
if (command != null)
|
||||||
{
|
{
|
||||||
|
_logger.LogDebug("Command finished running: {0}", command.Command.DisplayLabel);
|
||||||
_commandsToRun[0].Remove(command);
|
_commandsToRun[0].Remove(command);
|
||||||
if (_commandsToRun[0].Commands.Count == 0)
|
if (_commandsToRun[0].Commands.Count == 0)
|
||||||
{
|
{
|
||||||
|
_logger.LogDebug("Removing empty command array. {0} batch left.", _commandsToRun.Count - 1);
|
||||||
_commandsToRun.RemoveAt(0);
|
_commandsToRun.RemoveAt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_commandRunners.Remove(thread);
|
var currentCommandRunner = _commandRunners.Find(r => r.Thread == thread);
|
||||||
|
if (currentCommandRunner != null) _commandRunners.Remove(currentCommandRunner);
|
||||||
|
await UpdateReadOnlyCommands();
|
||||||
|
StartCommandRunner();
|
||||||
});
|
});
|
||||||
await UpdateReadOnlyCommands();
|
|
||||||
|
|
||||||
await TryStartCommandRunner();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Refresh()
|
public async Task Refresh()
|
||||||
{
|
{
|
||||||
await RunWithLockAsync(async () => await RefreshCommands(PointInTime.CreateEmpty()));
|
await RunWithLockAsync(async () =>
|
||||||
await UpdateReadOnlyCommands();
|
{
|
||||||
|
await RefreshCommands(PointInTime.CreateEmpty());
|
||||||
|
await UpdateReadOnlyCommands();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RefreshCommands(PointInTime? fullStartTime = null)
|
private async Task RefreshCommands(PointInTime? fullStartTime = null)
|
||||||
@@ -181,11 +189,10 @@ namespace FileTime.Core.Timeline
|
|||||||
|
|
||||||
private async Task UpdateReadOnlyCommands()
|
private async Task UpdateReadOnlyCommands()
|
||||||
{
|
{
|
||||||
var wait = false;
|
var wait = _commandsToRun.Count == 1;
|
||||||
await RunWithLockAsync(() => wait = _commandsToRun.Count == 1);
|
|
||||||
if (wait) await Task.Delay(100);
|
if (wait) await Task.Delay(100);
|
||||||
await RunWithLockAsync(() => _parallelCommands = _commandsToRun.ConvertAll(c => new ReadOnlyParallelCommands(c)).AsReadOnly());
|
_parallelCommands = _commandsToRun.ConvertAll(c => new ReadOnlyParallelCommands(c)).AsReadOnly();
|
||||||
await CommandsChangedAsync.InvokeAsync(this, AsyncEventArgs.Empty);
|
await CommandsChangedAsync.InvokeAsync(this, _parallelCommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunWithLockAsync(Action action)
|
private async Task RunWithLockAsync(Action action)
|
||||||
|
|||||||
@@ -46,4 +46,9 @@
|
|||||||
<DependentUpon>MainWindow.axaml</DependentUpon>
|
<DependentUpon>MainWindow.axaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.Development.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
private TimeRunner _timeRunner;
|
private TimeRunner _timeRunner;
|
||||||
private IEnumerable<IContentProvider> _contentProviders;
|
private IEnumerable<IContentProvider> _contentProviders;
|
||||||
private IIconProvider _iconProvider;
|
private IIconProvider _iconProvider;
|
||||||
|
private bool _addCommandToNextBatch;
|
||||||
|
|
||||||
private Func<Task>? _inputHandler;
|
private Func<Task>? _inputHandler;
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
App.ServiceProvider.GetService<TopContainer>();
|
App.ServiceProvider.GetService<TopContainer>();
|
||||||
await StatePersistence.LoadStatesAsync();
|
await StatePersistence.LoadStatesAsync();
|
||||||
|
|
||||||
_timeRunner.CommandsChangedAsync.Add(UpdateParalellCommands);
|
_timeRunner.CommandsChangedAsync.Add(UpdateParallelCommands);
|
||||||
InitCommandBindings();
|
InitCommandBindings();
|
||||||
|
|
||||||
_keysToSkip.Add(new KeyWithModifiers[] { new KeyWithModifiers(Key.Up) });
|
_keysToSkip.Add(new KeyWithModifiers[] { new KeyWithModifiers(Key.Up) });
|
||||||
@@ -213,10 +214,8 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
_logger?.LogInformation($"{nameof(MainPageViewModel)} initialized.");
|
_logger?.LogInformation($"{nameof(MainPageViewModel)} initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateParalellCommands(object? sender, AsyncEventArgs e, CancellationToken token)
|
private Task UpdateParallelCommands(object? sender, IReadOnlyList<ReadOnlyParallelCommands> parallelCommands, CancellationToken token)
|
||||||
{
|
{
|
||||||
var parallelCommands = await _timeRunner.GetParallelCommandsAsync();
|
|
||||||
|
|
||||||
foreach (var parallelCommand in parallelCommands)
|
foreach (var parallelCommand in parallelCommands)
|
||||||
{
|
{
|
||||||
if (!TimelineCommands.Any(c => c.Id == parallelCommand.Id))
|
if (!TimelineCommands.Any(c => c.Id == parallelCommand.Id))
|
||||||
@@ -265,6 +264,8 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
parallelCommandsVM.ParallelCommands.Remove(commandVMsToRemove[i]);
|
parallelCommandsVM.ParallelCommands.Remove(commandVMsToRemove[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IContainer?> GetContainerForWindowsDrive(DriveInfo drive)
|
private async Task<IContainer?> GetContainerForWindowsDrive(DriveInfo drive)
|
||||||
@@ -441,7 +442,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
{
|
{
|
||||||
var container = AppState.SelectedTab.CurrentLocation.Container;
|
var container = AppState.SelectedTab.CurrentLocation.Container;
|
||||||
var createContainerCommand = new CreateContainerCommand(new Core.Models.AbsolutePath(container), Inputs[0].Value);
|
var createContainerCommand = new CreateContainerCommand(new Core.Models.AbsolutePath(container), Inputs[0].Value);
|
||||||
await _timeRunner.AddCommand(createContainerCommand);
|
await AddCommand(createContainerCommand);
|
||||||
Inputs = null;
|
Inputs = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -459,7 +460,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
{
|
{
|
||||||
var container = AppState.SelectedTab.CurrentLocation.Container;
|
var container = AppState.SelectedTab.CurrentLocation.Container;
|
||||||
var createElementCommand = new CreateElementCommand(new Core.Models.AbsolutePath(container), Inputs[0].Value);
|
var createElementCommand = new CreateElementCommand(new Core.Models.AbsolutePath(container), Inputs[0].Value);
|
||||||
await _timeRunner.AddCommand(createElementCommand);
|
await AddCommand(createElementCommand);
|
||||||
Inputs = null;
|
Inputs = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -516,12 +517,14 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
var askForDelete = false;
|
var askForDelete = false;
|
||||||
var questionText = "";
|
var questionText = "";
|
||||||
var shouldDelete = false;
|
var shouldDelete = false;
|
||||||
|
var shouldClearMarkedItems = false;
|
||||||
|
|
||||||
var currentSelectedItems = await AppState.SelectedTab.TabState.GetCurrentMarkedItems();
|
var currentSelectedItems = await AppState.SelectedTab.TabState.GetCurrentMarkedItems();
|
||||||
var currentSelectedItem = AppState.SelectedTab.SelectedItem?.Item;
|
var currentSelectedItem = AppState.SelectedTab.SelectedItem?.Item;
|
||||||
if (currentSelectedItems.Count > 0)
|
if (currentSelectedItems.Count > 0)
|
||||||
{
|
{
|
||||||
itemsToDelete = currentSelectedItems.Cast<Core.Models.AbsolutePath>().ToList();
|
itemsToDelete = new List<AbsolutePath>(currentSelectedItems);
|
||||||
|
shouldClearMarkedItems = true;
|
||||||
|
|
||||||
//FIXME: check 'is Container'
|
//FIXME: check 'is Container'
|
||||||
if (currentSelectedItems.Count == 1)
|
if (currentSelectedItems.Count == 1)
|
||||||
@@ -545,9 +548,9 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
}
|
}
|
||||||
else if (currentSelectedItem != null)
|
else if (currentSelectedItem != null)
|
||||||
{
|
{
|
||||||
itemsToDelete = new List<Core.Models.AbsolutePath>()
|
itemsToDelete = new List<AbsolutePath>()
|
||||||
{
|
{
|
||||||
new Core.Models.AbsolutePath(currentSelectedItem)
|
new AbsolutePath(currentSelectedItem)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (currentSelectedItem is IContainer container && (await container.GetItems())?.Count > 0)
|
if (currentSelectedItem is IContainer container && (await container.GetItems())?.Count > 0)
|
||||||
@@ -575,16 +578,22 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
|
|
||||||
async Task HandleDelete()
|
async Task HandleDelete()
|
||||||
{
|
{
|
||||||
var deleteCommand = new DeleteCommand();
|
var deleteCommand = new DeleteCommand
|
||||||
deleteCommand.HardDelete = hardDelete;
|
{
|
||||||
|
HardDelete = hardDelete
|
||||||
|
};
|
||||||
|
|
||||||
foreach (var itemToDelete in itemsToDelete!)
|
foreach (var itemToDelete in itemsToDelete!)
|
||||||
{
|
{
|
||||||
deleteCommand.ItemsToDelete.Add(itemToDelete);
|
deleteCommand.ItemsToDelete.Add(itemToDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
await _timeRunner.AddCommand(deleteCommand);
|
await AddCommand(deleteCommand);
|
||||||
_clipboard.Clear();
|
_clipboard.Clear();
|
||||||
|
if (shouldClearMarkedItems)
|
||||||
|
{
|
||||||
|
await AppState.SelectedTab.TabState.ClearCurrentMarkedItems();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,7 +630,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
? virtualContainer.BaseContainer
|
? virtualContainer.BaseContainer
|
||||||
: currentLocation;
|
: currentLocation;
|
||||||
|
|
||||||
await _timeRunner.AddCommand(command);
|
await AddCommand(command);
|
||||||
|
|
||||||
_clipboard.Clear();
|
_clipboard.Clear();
|
||||||
}
|
}
|
||||||
@@ -637,7 +646,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
if (Inputs != null)
|
if (Inputs != null)
|
||||||
{
|
{
|
||||||
var renameCommand = new RenameCommand(new Core.Models.AbsolutePath(selectedItem), Inputs[0].Value);
|
var renameCommand = new RenameCommand(new Core.Models.AbsolutePath(selectedItem), Inputs[0].Value);
|
||||||
await _timeRunner.AddCommand(renameCommand);
|
await AddCommand(renameCommand);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -669,6 +678,21 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
await _timeRunner.Refresh();
|
await _timeRunner.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task ChangeTimelineMode()
|
||||||
|
{
|
||||||
|
_addCommandToNextBatch = !_addCommandToNextBatch;
|
||||||
|
var text = "Timeline mode: " + (_addCommandToNextBatch ? "Continuous" : "Parallel");
|
||||||
|
_popupTexts.Add(text);
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(5000);
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() => _popupTexts.Remove(text));
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
private Task GoToContainer()
|
private Task GoToContainer()
|
||||||
{
|
{
|
||||||
var handler = async () =>
|
var handler = async () =>
|
||||||
@@ -804,6 +828,34 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
|
|
||||||
private Task SelectPreviousTimelineBlock()
|
private Task SelectPreviousTimelineBlock()
|
||||||
{
|
{
|
||||||
|
var currentSelected = GetSelectedTimelineCommandOrSelectFirst();
|
||||||
|
if (currentSelected == null) return Task.CompletedTask;
|
||||||
|
|
||||||
|
ParallelCommandsViewModel? newBlockVM = null;
|
||||||
|
ParallelCommandsViewModel? previousBlockVM = null;
|
||||||
|
|
||||||
|
foreach (var timelineBlock in TimelineCommands)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach (var command in timelineBlock.ParallelCommands)
|
||||||
|
{
|
||||||
|
if (command.IsSelected)
|
||||||
|
{
|
||||||
|
newBlockVM = previousBlockVM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
previousBlockVM = timelineBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newBlockVM == null) return Task.CompletedTask;
|
||||||
|
|
||||||
|
foreach (var val in TimelineCommands.Select(t => t.ParallelCommands.Select((c, i) => (ParalellCommandVM: t, CommandVM: c, Index: i))).SelectMany(t => t))
|
||||||
|
{
|
||||||
|
val.CommandVM.IsSelected = val.ParalellCommandVM == newBlockVM && val.Index == 0;
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -845,6 +897,35 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
|
|
||||||
private Task SelectNextTimelineBlock()
|
private Task SelectNextTimelineBlock()
|
||||||
{
|
{
|
||||||
|
var currentSelected = GetSelectedTimelineCommandOrSelectFirst();
|
||||||
|
if (currentSelected == null) return Task.CompletedTask;
|
||||||
|
|
||||||
|
ParallelCommandsViewModel? newBlockVM = null;
|
||||||
|
var select = false;
|
||||||
|
foreach (var timelineBlock in TimelineCommands)
|
||||||
|
{
|
||||||
|
if (select)
|
||||||
|
{
|
||||||
|
newBlockVM = timelineBlock;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
foreach (var command in timelineBlock.ParallelCommands)
|
||||||
|
{
|
||||||
|
if (command.IsSelected)
|
||||||
|
{
|
||||||
|
select = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newBlockVM == null) return Task.CompletedTask;
|
||||||
|
|
||||||
|
foreach (var val in TimelineCommands.Select(t => t.ParallelCommands.Select((c, i) => (ParalellCommandVM: t, CommandVM: c, Index: i))).SelectMany(t => t))
|
||||||
|
{
|
||||||
|
val.CommandVM.IsSelected = val.ParalellCommandVM == newBlockVM && val.Index == 0;
|
||||||
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -862,6 +943,35 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task AddCommand(ICommand command)
|
||||||
|
{
|
||||||
|
if (_addCommandToNextBatch)
|
||||||
|
{
|
||||||
|
await _timeRunner.AddCommand(command, toNewBatch: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ParallelCommandsViewModel? batchToAdd = null;
|
||||||
|
foreach (var val in TimelineCommands.Select(t => t.ParallelCommands.Select(c => (ParalellCommandVM: t, CommandVM: c))).SelectMany(t => t))
|
||||||
|
{
|
||||||
|
if (val.CommandVM.IsSelected)
|
||||||
|
{
|
||||||
|
batchToAdd = val.ParalellCommandVM;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (batchToAdd != null)
|
||||||
|
{
|
||||||
|
await _timeRunner.AddCommand(command, batchToAdd.Id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _timeRunner.AddCommand(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public async void ProcessInputs()
|
public async void ProcessInputs()
|
||||||
{
|
{
|
||||||
@@ -882,7 +992,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public void ProcessMessageBoxCommand()
|
public void ProcessMessageBox()
|
||||||
{
|
{
|
||||||
_inputHandler?.Invoke();
|
_inputHandler?.Invoke();
|
||||||
|
|
||||||
@@ -891,7 +1001,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public void CancelMessageBoxCommand()
|
public void CancelMessageBox()
|
||||||
{
|
{
|
||||||
MessageBoxText = null;
|
MessageBoxText = null;
|
||||||
_inputHandler = null;
|
_inputHandler = null;
|
||||||
@@ -923,10 +1033,18 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
if (key == Key.Escape)
|
if (key == Key.Escape)
|
||||||
{
|
{
|
||||||
IsAllShortcutVisible = false;
|
IsAllShortcutVisible = false;
|
||||||
|
MessageBoxText = null;
|
||||||
_previousKeys.Clear();
|
_previousKeys.Clear();
|
||||||
PossibleCommands = new();
|
PossibleCommands = new();
|
||||||
setHandled(true);
|
setHandled(true);
|
||||||
}
|
}
|
||||||
|
else if (key == Key.Enter
|
||||||
|
&& MessageBoxText != null)
|
||||||
|
{
|
||||||
|
_previousKeys.Clear();
|
||||||
|
ProcessMessageBox();
|
||||||
|
setHandled(true);
|
||||||
|
}
|
||||||
else if (selectedCommandBinding != null)
|
else if (selectedCommandBinding != null)
|
||||||
{
|
{
|
||||||
setHandled(true);
|
setHandled(true);
|
||||||
@@ -975,6 +1093,10 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
{
|
{
|
||||||
IsAllShortcutVisible = false;
|
IsAllShortcutVisible = false;
|
||||||
}
|
}
|
||||||
|
else if (MessageBoxText != null)
|
||||||
|
{
|
||||||
|
MessageBoxText = null;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await ExitRapidTravelMode();
|
await ExitRapidTravelMode();
|
||||||
@@ -1311,6 +1433,11 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
FileTime.App.Core.Command.Commands.Dummy,
|
FileTime.App.Core.Command.Commands.Dummy,
|
||||||
new KeyWithModifiers[] { new KeyWithModifiers(Key.L) },
|
new KeyWithModifiers[] { new KeyWithModifiers(Key.L) },
|
||||||
SelectNextTimelineBlock),
|
SelectNextTimelineBlock),
|
||||||
|
new CommandBinding(
|
||||||
|
"command running mode",
|
||||||
|
FileTime.App.Core.Command.Commands.Dummy,
|
||||||
|
new KeyWithModifiers[] { new KeyWithModifiers(Key.T), new KeyWithModifiers(Key.M) },
|
||||||
|
ChangeTimelineMode),
|
||||||
//TODO REMOVE
|
//TODO REMOVE
|
||||||
new CommandBinding(
|
new CommandBinding(
|
||||||
"open in default file browser",
|
"open in default file browser",
|
||||||
|
|||||||
@@ -157,19 +157,21 @@
|
|||||||
</ItemsControl.ItemsPanel>
|
</ItemsControl.ItemsPanel>
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<Border Background="{DynamicResource ContainerBackgroundColor}" Padding="5">
|
<Border MaxHeight="200" Background="{DynamicResource ContainerBackgroundColor}" CornerRadius="10" Padding="5" Margin="0,0,10,0">
|
||||||
<ItemsControl Items="{Binding ParallelCommands}">
|
<ScrollViewer>
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl Items="{Binding ParallelCommands}">
|
||||||
<DataTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<Border BorderThickness="1" Classes="TimelineCommand" Classes.SelectedTimelineCommand="{Binding IsSelected}">
|
<DataTemplate>
|
||||||
<StackPanel>
|
<Border BorderThickness="1" Classes="TimelineCommand" Classes.SelectedTimelineCommand="{Binding IsSelected}">
|
||||||
<TextBlock Text="{Binding Name}"/>
|
<StackPanel>
|
||||||
<ProgressBar Margin="0,5,0,0" Maximum="100" Value="{Binding Progress}"/>
|
<TextBlock Text="{Binding Name}"/>
|
||||||
</StackPanel>
|
<ProgressBar Margin="0,5,0,0" Maximum="100" Value="{Binding Progress}"/>
|
||||||
</Border>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</Border>
|
||||||
</ItemsControl.ItemTemplate>
|
</DataTemplate>
|
||||||
</ItemsControl>
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
</ScrollViewer>
|
||||||
</Border>
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ItemsControl.ItemTemplate>
|
</ItemsControl.ItemTemplate>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"Serilog": {
|
"Serilog": {
|
||||||
"MinimalLevel": {
|
"MinimumLevel": {
|
||||||
"Default": "Debug",
|
"Default": "Debug",
|
||||||
"Override": {
|
"Override": {
|
||||||
"Microsoft": "Information",
|
"Microsoft": "Information",
|
||||||
|
|||||||
Reference in New Issue
Block a user