WIP CommandScheduler UI
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using DynamicData;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
|
||||
namespace FileTime.App.Core.Models;
|
||||
|
||||
public partial class BindedCollection<T> : IDisposable, INotifyPropertyChanged
|
||||
{
|
||||
private readonly IDisposable? _disposable;
|
||||
private IDisposable? _innerDisposable;
|
||||
|
||||
[Notify] private ReadOnlyObservableCollection<T>? _collection;
|
||||
|
||||
public BindedCollection()
|
||||
{
|
||||
}
|
||||
|
||||
public BindedCollection(IObservable<IChangeSet<T>> dynamicList)
|
||||
{
|
||||
_disposable = dynamicList
|
||||
.Bind(out var collection)
|
||||
.DisposeMany()
|
||||
.Subscribe();
|
||||
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
public BindedCollection(IObservable<IObservable<IChangeSet<T>>?> dynamicListSource)
|
||||
{
|
||||
_disposable = dynamicListSource.Subscribe(dynamicList =>
|
||||
{
|
||||
_innerDisposable?.Dispose();
|
||||
if (dynamicList is not null)
|
||||
{
|
||||
_innerDisposable = dynamicList
|
||||
.Bind(out var collection)
|
||||
.DisposeMany()
|
||||
.Subscribe();
|
||||
|
||||
Collection = collection;
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_disposable?.Dispose();
|
||||
_innerDisposable?.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public partial class BindedCollection<T, TKey> : IDisposable, INotifyPropertyChanged where TKey : notnull
|
||||
{
|
||||
private readonly IDisposable? _disposable;
|
||||
private IDisposable? _innerDisposable;
|
||||
|
||||
[Notify] private ReadOnlyObservableCollection<T>? _collection;
|
||||
|
||||
public BindedCollection()
|
||||
{
|
||||
}
|
||||
|
||||
public BindedCollection(IObservable<IChangeSet<T, TKey>> dynamicList)
|
||||
{
|
||||
_disposable = dynamicList
|
||||
.Bind(out var collection)
|
||||
.DisposeMany()
|
||||
.Subscribe();
|
||||
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
public BindedCollection(IObservable<IObservable<IChangeSet<T, TKey>>?> dynamicListSource)
|
||||
{
|
||||
_disposable = dynamicListSource.Subscribe(dynamicList =>
|
||||
{
|
||||
_innerDisposable?.Dispose();
|
||||
if (dynamicList is not null)
|
||||
{
|
||||
_innerDisposable = dynamicList
|
||||
.Bind(out var collection)
|
||||
.DisposeMany()
|
||||
.Subscribe();
|
||||
|
||||
Collection = collection;
|
||||
}
|
||||
else
|
||||
{
|
||||
Collection = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_disposable?.Dispose();
|
||||
_innerDisposable?.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace FileTime.App.Core.UserCommand;
|
||||
|
||||
public class PauseCommandSchedulerCommand : IIdentifiableUserCommand
|
||||
{
|
||||
public const string CommandName = "pause_command_scheduler";
|
||||
public static PauseCommandSchedulerCommand Instance { get; } = new();
|
||||
|
||||
private PauseCommandSchedulerCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public string UserCommandID => CommandName;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace FileTime.App.Core.UserCommand;
|
||||
|
||||
public sealed class StartCommandSchedulerCommand : IIdentifiableUserCommand
|
||||
{
|
||||
public const string CommandName = "start_command_scheduler";
|
||||
public static StartCommandSchedulerCommand Instance { get; } = new();
|
||||
|
||||
private StartCommandSchedulerCommand()
|
||||
{
|
||||
}
|
||||
|
||||
public string UserCommandID => CommandName;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.Core.Timeline;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
@@ -13,6 +12,7 @@ public interface IAppState
|
||||
IObservable<ViewMode> ViewMode { get; }
|
||||
string RapidTravelText { get; set; }
|
||||
ITabViewModel? CurrentSelectedTab { get; }
|
||||
ITimelineViewModel TimelineViewModel { get; }
|
||||
|
||||
void AddTab(ITabViewModel tabViewModel);
|
||||
void RemoveTab(ITabViewModel tabViewModel);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FileTime.App.Core.ViewModels.Timeline;
|
||||
|
||||
public interface ICommandTimeStateViewModel
|
||||
{
|
||||
IObservable<int> TotalProgress { get; }
|
||||
IObservable<string> DisplayLabel { get; }
|
||||
IObservable<bool> IsSelected { get; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels.Timeline;
|
||||
|
||||
public interface IParallelCommandsViewModel
|
||||
{
|
||||
BindedCollection<ICommandTimeStateViewModel> Commands { get; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels.Timeline;
|
||||
|
||||
public interface ITimelineViewModel
|
||||
{
|
||||
BindedCollection<IParallelCommandsViewModel> ParallelCommandsGroups { get; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using FileTime.App.Core.UserCommand;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||
|
||||
public class CommandSchedulerUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
{
|
||||
private readonly ICommandScheduler _commandScheduler;
|
||||
|
||||
public CommandSchedulerUserCommandHandlerService(ICommandScheduler commandScheduler)
|
||||
{
|
||||
_commandScheduler = commandScheduler;
|
||||
AddCommandHandlers(new IUserCommandHandler[]
|
||||
{
|
||||
new TypeUserCommandHandler<PauseCommandSchedulerCommand>(PauseCommandScheduler),
|
||||
new TypeUserCommandHandler<StartCommandSchedulerCommand>(StartCommandScheduler),
|
||||
});
|
||||
}
|
||||
|
||||
private async Task PauseCommandScheduler()
|
||||
=> await _commandScheduler.SetRunningEnabledAsync(false);
|
||||
|
||||
private async Task StartCommandScheduler()
|
||||
=> await _commandScheduler.SetRunningEnabledAsync(true);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
SaveCurrentLocation(l => _currentLocation = l);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
|
||||
_markedItems = new BindedCollection<FullName>(appState.SelectedTab.Select(t => t?.MarkedItems));
|
||||
_markedItems = appState.SelectedTab.Select(t => t?.MarkedItems).ToBindedCollection();
|
||||
|
||||
AddCommandHandlers(new IUserCommandHandler[]
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using FileTime.App.Core.Services.UserCommandHandler;
|
||||
using FileTime.App.Core.StartupServices;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.App.Core.ViewModels.ItemPreview;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
@@ -23,6 +24,7 @@ public static class Startup
|
||||
serviceCollection.TryAddSingleton<IClipboardService, ClipboardService>();
|
||||
serviceCollection.TryAddSingleton<IIdentifiableUserCommandService, IdentifiableUserCommandService>();
|
||||
serviceCollection.TryAddSingleton<IItemPreviewService, ItemPreviewService>();
|
||||
serviceCollection.TryAddSingleton<ITimelineViewModel, TimelineViewModel>();
|
||||
|
||||
return serviceCollection
|
||||
.AddCommandHandlers()
|
||||
@@ -35,6 +37,7 @@ public static class Startup
|
||||
return serviceCollection
|
||||
.AddSingleton<IUserCommandHandler, NavigationUserCommandHandlerService>()
|
||||
.AddSingleton<IUserCommandHandler, ItemManipulationUserCommandHandlerService>()
|
||||
.AddSingleton<IUserCommandHandler, ToolUserCommandHandlerService>();
|
||||
.AddSingleton<IUserCommandHandler, ToolUserCommandHandlerService>()
|
||||
.AddSingleton<IUserCommandHandler, CommandSchedulerUserCommandHandlerService>();
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,9 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
|
||||
AddUserCommand(PasteCommand.Merge);
|
||||
AddUserCommand(PasteCommand.Overwrite);
|
||||
AddUserCommand(PasteCommand.Skip);
|
||||
AddUserCommand(PauseCommandSchedulerCommand.Instance);
|
||||
AddUserCommand(RefreshCommand.Instance);
|
||||
AddUserCommand(StartCommandSchedulerCommand.Instance);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToLastTab);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToTab1);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToTab2);
|
||||
|
||||
@@ -3,12 +3,14 @@ using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using MvvmGen;
|
||||
using MoreLinq;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
[ViewModel]
|
||||
[Inject(typeof(ITimelineViewModel), "TimelineViewModel", PropertyAccessModifier = AccessModifier.Public)]
|
||||
public abstract partial class AppStateBase : IAppState
|
||||
{
|
||||
private readonly BehaviorSubject<string?> _searchText = new(null);
|
||||
@@ -76,7 +78,10 @@ public abstract partial class AppStateBase : IAppState
|
||||
|
||||
private ITabViewModel? GetSelectedTab(IEnumerable<ITabViewModel> tabs, ITabViewModel? expectedSelectedTab)
|
||||
{
|
||||
var (preferred, others) = tabs.OrderBy(t => t.TabNumber).Partition(t => t.TabNumber >= (expectedSelectedTab?.TabNumber ?? 0));
|
||||
var (preferred, others) =
|
||||
tabs
|
||||
.OrderBy(t => t.TabNumber)
|
||||
.Partition(t => t.TabNumber >= (expectedSelectedTab?.TabNumber ?? 0));
|
||||
return preferred.Concat(others.Reverse()).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels.Timeline;
|
||||
|
||||
public class CommandTimeStateViewModel : ICommandTimeStateViewModel
|
||||
{
|
||||
public IObservable<int> TotalProgress { get; }
|
||||
|
||||
public IObservable<string> DisplayLabel { get; }
|
||||
|
||||
public IObservable<bool> IsSelected { get; }
|
||||
|
||||
public CommandTimeStateViewModel(CommandTimeState commandTimeState)
|
||||
{
|
||||
DisplayLabel = commandTimeState.Command.DisplayLabel;
|
||||
TotalProgress = commandTimeState.Command.TotalProgress;
|
||||
//TODO
|
||||
IsSelected = new BehaviorSubject<bool>(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using DynamicData.Alias;
|
||||
using FileTime.Core.Extensions;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels.Timeline;
|
||||
|
||||
public class ParallelCommandsViewModel : IParallelCommandsViewModel
|
||||
{
|
||||
public BindedCollection<ICommandTimeStateViewModel> Commands { get; }
|
||||
|
||||
public ParallelCommandsViewModel(ParallelCommands parallelCommands)
|
||||
{
|
||||
Commands = parallelCommands
|
||||
.Commands
|
||||
.Select(c => new CommandTimeStateViewModel(c) as ICommandTimeStateViewModel)
|
||||
.ToBindedCollection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using DynamicData.Alias;
|
||||
using FileTime.Core.Extensions;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels.Timeline;
|
||||
|
||||
public class TimelineViewModel : ITimelineViewModel
|
||||
{
|
||||
public BindedCollection<IParallelCommandsViewModel> ParallelCommandsGroups { get; }
|
||||
|
||||
public TimelineViewModel(ICommandScheduler commandScheduler)
|
||||
{
|
||||
ParallelCommandsGroups =
|
||||
commandScheduler
|
||||
.CommandsToRun
|
||||
.Select(p => new ParallelCommandsViewModel(p) as IParallelCommandsViewModel)
|
||||
.ToBindedCollection();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user