Move common things to AppCore from GuiApp 2

This commit is contained in:
2023-08-07 13:09:58 +02:00
parent 936c3896b9
commit 8f5caf5c57
20 changed files with 97 additions and 73 deletions

View File

@@ -55,4 +55,14 @@ public enum Keys
Tab,
LWin,
RWin,
Num0,
Num1,
Num2,
Num3,
Num4,
Num5,
Num6,
Num7,
Num8,
Num9,
}

View File

@@ -1,3 +1,3 @@
namespace FileTime.GuiApp.App.Models;
namespace FileTime.App.Core.Models;
public record SpecialKeysStatus(bool IsAltPressed, bool IsShiftPressed, bool IsCtrlPressed);

View File

@@ -1,3 +1,3 @@
namespace FileTime.GuiApp.App.Services;
namespace FileTime.App.Core.Services;
public interface IDefaultModeKeyInputHandler : IKeyInputHandler { }

View File

@@ -0,0 +1,8 @@
using FileTime.App.Core.Models;
namespace FileTime.App.Core.Services;
public interface IKeyInputHandler
{
Task HandleInputKey(Keys key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled);
}

View File

@@ -1,3 +1,3 @@
namespace FileTime.GuiApp.App.Services;
namespace FileTime.App.Core.Services;
public interface IRapidTravelModeKeyInputHandler : IKeyInputHandler { }

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using DeclarativeProperty;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.ViewModels.Timeline;
@@ -13,8 +14,10 @@ public interface IAppState
IDeclarativeProperty<ViewMode> ViewMode { get; }
DeclarativeProperty<string?> RapidTravelText { get; }
IDeclarativeProperty<string?> RapidTravelTextDebounced { get; }
ITimelineViewModel TimelineViewModel { get; }
IDeclarativeProperty<string?> ContainerStatus { get; }
List<KeyConfig> PreviousKeys { get; }
List<CommandBindingConfiguration> PossibleCommands { get; set; }
bool NoCommandFound { get; set; }
void AddTab(ITabViewModel tabViewModel);
void RemoveTab(ITabViewModel tabViewModel);

View File

@@ -16,6 +16,10 @@
<PackageReference Include="morelinq" Version="3.4.2" />
<PackageReference Include="MvvmGen" Version="1.2.1" />
<PackageReference Include="ObservableComputations" Version="2.3.0" />
<PackageReference Include="PropertyChanged.SourceGenerator" Version="1.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
</ItemGroup>

View File

@@ -1,23 +1,19 @@
using Avalonia.Input;
using FileTime.App.Core.Services;
using DeclarativeProperty;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.Extensions;
using FileTime.App.Core.Models;
using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Extensions;
using FileTime.Core.Models;
using FileTime.Core.Models.Extensions;
using FileTime.GuiApp.App.Models;
using FileTime.GuiApp.App.ViewModels;
using Microsoft.Extensions.Logging;
using DeclarativeProperty;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.Extensions;
using FileTime.App.Core.Models;
namespace FileTime.GuiApp.App.Services;
namespace FileTime.App.Core.Services;
public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
{
private readonly IGuiAppState _appState;
private readonly IAppState _appState;
private readonly IModalService _modalService;
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
private readonly List<KeyConfig[]> _keysToSkip = new();
@@ -25,21 +21,18 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
private readonly ILogger<DefaultModeKeyInputHandler> _logger;
private readonly IUserCommandHandlerService _userCommandHandlerService;
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
private readonly IAppKeyService<Key> _appKeyService;
private readonly BindedCollection<IModalViewModel> _openModals;
public DefaultModeKeyInputHandler(
IGuiAppState appState,
IAppState appState,
IModalService modalService,
IKeyboardConfigurationService keyboardConfigurationService,
ILogger<DefaultModeKeyInputHandler> logger,
IUserCommandHandlerService userCommandHandlerService,
IIdentifiableUserCommandService identifiableUserCommandService,
IAppKeyService<Key> appKeyService)
IIdentifiableUserCommandService identifiableUserCommandService)
{
_appState = appState;
_identifiableUserCommandService = identifiableUserCommandService;
_appKeyService = appKeyService;
_keyboardConfigurationService = keyboardConfigurationService;
_logger = logger;
_modalService = modalService;
@@ -61,9 +54,8 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
_keysToSkip.Add(new[] {new KeyConfig(Keys.RWin)});
}
public async Task HandleInputKey(Key key2, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
public async Task HandleInputKey(Keys key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
{
if (_appKeyService.MapKey(key2) is not { } key) return;
var keyWithModifiers = new KeyConfig(key, shift: specialKeysStatus.IsShiftPressed, alt: specialKeysStatus.IsAltPressed, ctrl: specialKeysStatus.IsCtrlPressed);
_appState.PreviousKeys.Add(keyWithModifiers);
@@ -72,7 +64,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
if (key == Keys.Escape)
{
var doGeneralReset = _appState.PreviousKeys.Count > 1 || _appState.IsAllShortcutVisible;
var doGeneralReset = _appState.PreviousKeys.Count > 1;
if ((_openModals.Collection?.Count ?? 0) > 0)
{
@@ -106,7 +98,6 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
if (doGeneralReset)
{
setHandled(true);
_appState.IsAllShortcutVisible = false;
_appState.PreviousKeys.Clear();
_appState.PossibleCommands = new();
}

View File

@@ -1,16 +1,13 @@
using Avalonia.Input;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.Extensions;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
using FileTime.Core.Extensions;
using FileTime.Core.Models;
using FileTime.GuiApp.App.Models;
using Microsoft.Extensions.Logging;
namespace FileTime.GuiApp.App.Services;
namespace FileTime.App.Core.Services;
public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
{
@@ -22,7 +19,6 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
private readonly IUserCommandHandlerService _userCommandHandlerService;
private readonly ILogger<RapidTravelModeKeyInputHandler> _logger;
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
private readonly IAppKeyService<Key> _appKeyService;
private readonly BindedCollection<IModalViewModel> _openModals;
private ITabViewModel? _selectedTab;
@@ -32,8 +28,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
IKeyboardConfigurationService keyboardConfigurationService,
IUserCommandHandlerService userCommandHandlerService,
ILogger<RapidTravelModeKeyInputHandler> logger,
IIdentifiableUserCommandService identifiableUserCommandService,
IAppKeyService<Key> appKeyService)
IIdentifiableUserCommandService identifiableUserCommandService)
{
_appState = appState;
_modalService = modalService;
@@ -41,7 +36,6 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
_userCommandHandlerService = userCommandHandlerService;
_logger = logger;
_identifiableUserCommandService = identifiableUserCommandService;
_appKeyService = appKeyService;
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
@@ -59,9 +53,8 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
});
}
public async Task HandleInputKey(Key key2, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
public async Task HandleInputKey(Keys key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
{
if (_appKeyService.MapKey(key2) is not { } key) return;
var keyString = key.ToString();
if (key == Keys.Escape)

View File

@@ -2,16 +2,16 @@ using System.Collections.ObjectModel;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using DeclarativeProperty;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.ViewModels.Timeline;
using FileTime.Core.Models.Extensions;
using MvvmGen;
using MoreLinq;
using PropertyChanged.SourceGenerator;
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);
@@ -29,8 +29,11 @@ public abstract partial class AppStateBase : IAppState
public IDeclarativeProperty<string?> RapidTravelTextDebounced { get; private set; }
public IDeclarativeProperty<string?> ContainerStatus { get; private set; }
[Notify] public List<KeyConfig> PreviousKeys { get; } = new();
[Notify] public List<CommandBindingConfiguration> PossibleCommands { get; set; } = new();
[Notify] public bool NoCommandFound { get; set; }
partial void OnInitialize()
protected AppStateBase()
{
RapidTravelText = new("");
RapidTravelTextDebounced = RapidTravelText

View File

@@ -1,9 +0,0 @@
using Avalonia.Input;
using FileTime.GuiApp.App.Models;
namespace FileTime.GuiApp.App.Services;
public interface IKeyInputHandler
{
Task HandleInputKey(Key key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled);
}

View File

@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.ViewModels;
using FileTime.GuiApp.App.Models;
@@ -7,10 +6,6 @@ namespace FileTime.GuiApp.App.ViewModels;
public interface IGuiAppState : IAppState
{
List<KeyConfig> PreviousKeys { get; }
bool IsAllShortcutVisible { get; set; }
bool NoCommandFound { get; set; }
List<CommandBindingConfiguration> PossibleCommands { get; set; }
ObservableCollection<RootDriveInfo> RootDriveInfos { get; set; }
IReadOnlyList<PlaceInfo> Places { get; set; }
ObservableCollection<string> PopupTexts { get; }

View File

@@ -2,7 +2,6 @@
using Avalonia.Input;
using FileTime.App.Core.Models;
using FileTime.App.Core.Services;
using FileTime.GuiApp.App.Models;
namespace FileTime.GuiApp.App.Services;
@@ -55,6 +54,16 @@ public class GuiAppKeyService : IAppKeyService<Key>
{Key.F10, Keys.F10},
{Key.F11, Keys.F11},
{Key.F12, Keys.F12},
{Key.D0, Keys.Num0},
{Key.D1, Keys.Num1},
{Key.D2, Keys.Num2},
{Key.D3, Keys.Num3},
{Key.D4, Keys.Num4},
{Key.D5, Keys.Num5},
{Key.D6, Keys.Num6},
{Key.D7, Keys.Num7},
{Key.D8, Keys.Num8},
{Key.D9, Keys.Num9},
{Key.Up, Keys.Up},
{Key.Down, Keys.Down},
{Key.Left, Keys.Left},

View File

@@ -1,5 +1,7 @@
using Avalonia.Input;
using FileTime.App.Core.Models;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.GuiApp.App.Models;
using FileTime.GuiApp.App.ViewModels;
@@ -10,8 +12,10 @@ public class KeyInputHandlerService : IKeyInputHandlerService
private readonly IGuiAppState _appState;
private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler;
private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler;
private readonly IAppKeyService<Key> _appKeyService;
private ViewMode _viewMode;
private GuiPanel _activePanel;
private readonly Dictionary<(GuiPanel, Key), GuiPanel> _panelMovements = new()
{
[(GuiPanel.FileBrowser, Key.Up)] = GuiPanel.Timeline,
@@ -21,12 +25,13 @@ public class KeyInputHandlerService : IKeyInputHandlerService
public KeyInputHandlerService(
IGuiAppState appState,
IDefaultModeKeyInputHandler defaultModeKeyInputHandler,
IRapidTravelModeKeyInputHandler rapidTravelModeKeyInputHandler
)
IRapidTravelModeKeyInputHandler rapidTravelModeKeyInputHandler,
IAppKeyService<Key> appKeyService)
{
_appState = appState;
_defaultModeKeyInputHandler = defaultModeKeyInputHandler;
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
_appKeyService = appKeyService;
appState.ViewMode.Subscribe(v => _viewMode = v);
appState.ActivePanel.Subscribe(p => _activePanel = p);
@@ -65,11 +70,17 @@ public class KeyInputHandlerService : IKeyInputHandlerService
{
if (_viewMode == ViewMode.Default)
{
await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled);
if (_appKeyService.MapKey(key) is { } mappedKey)
{
await _defaultModeKeyInputHandler.HandleInputKey(mappedKey, specialKeyStatus, setHandled);
}
}
else
{
await _rapidTravelModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled);
if (_appKeyService.MapKey(key) is { } mappedKey)
{
await _rapidTravelModeKeyInputHandler.HandleInputKey(mappedKey, specialKeyStatus, setHandled);
}
}
}
else if (_activePanel == GuiPanel.Timeline)

View File

@@ -1,6 +1,7 @@
using FileTime.App.CommandPalette.Services;
using FileTime.App.Core.Services;
using FileTime.App.Core.ViewModels;
using FileTime.App.Core.ViewModels.Timeline;
using FileTime.App.FrequencyNavigation.Services;
using FileTime.GuiApp.App.Services;
using FileTime.Providers.LocalAdmin;
@@ -17,5 +18,6 @@ public interface IMainWindowViewModel : IMainWindowViewModelBase
IRefreshSmoothnessCalculator RefreshSmoothnessCalculator { get; }
IAdminElevationManager AdminElevationManager { get; }
IClipboardService ClipboardService { get; }
ITimelineViewModel TimelineViewModel { get; }
Task RunOrOpenItem(IItemViewModel itemViewModel);
}

View File

@@ -6,6 +6,7 @@ using FileTime.App.CommandPalette.Services;
using FileTime.App.Core.Services;
using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
using FileTime.App.Core.ViewModels.Timeline;
using FileTime.App.FrequencyNavigation.Services;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
@@ -35,6 +36,7 @@ namespace FileTime.GuiApp.App.ViewModels;
[Inject(typeof(IAdminElevationManager), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(IClipboardService), PropertyAccessModifier = AccessModifier.Public)]
[Inject(typeof(IModalService), PropertyName = "_modalService")]
[Inject(typeof(ITimelineViewModel), PropertyAccessModifier = AccessModifier.Public)]
public partial class MainWindowViewModel : IMainWindowViewModel
{
public bool Loading => false;

View File

@@ -323,7 +323,7 @@
</ia:DataTriggerBehavior>
</i:Interaction.Behaviors>
<ItemsControl
ItemsSource="{Binding AppState.TimelineViewModel.ParallelCommandsGroups.Collection}"
ItemsSource="{Binding TimelineViewModel.ParallelCommandsGroups.Collection}"
VerticalAlignment="Stretch"
x:Name="CommandGroups">
<ItemsControl.ItemsPanel>

View File

@@ -15,4 +15,11 @@
<ProjectReference Include="..\FileTime.GuiApp.App.Abstractions\FileTime.GuiApp.App.Abstractions.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="PropertyChanged.SourceGenerator" Version="1.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@@ -8,30 +8,26 @@ using FileTime.App.Core.ViewModels.Timeline;
using FileTime.GuiApp.App.Models;
using FileTime.GuiApp.App.ViewModels;
using MvvmGen;
using PropertyChanged.SourceGenerator;
namespace FileTime.GuiApp.CustomImpl.ViewModels;
[ViewModel(GenerateConstructor = false)]
public partial class GuiAppState : AppStateBase, IGuiAppState, IDisposable
{
private readonly BehaviorSubject<GuiPanel> _activePanel = new(GuiPanel.FileBrowser);
public GuiAppState(ITimelineViewModel timelineViewModel) : base(timelineViewModel)
public GuiAppState()
{
ActivePanel = _activePanel.AsObservable();
}
[Property] private bool _isAllShortcutVisible;
[Notify] private bool _noCommandFound;
[Property] private bool _noCommandFound;
[Notify] private List<CommandBindingConfiguration> _possibleCommands = new();
[Property] private List<CommandBindingConfiguration> _possibleCommands = new();
[Notify] private ObservableCollection<RootDriveInfo> _rootDriveInfos = new();
[Property] private ObservableCollection<RootDriveInfo> _rootDriveInfos = new();
[Property] private IReadOnlyList<PlaceInfo> _places = new List<PlaceInfo>();
public List<KeyConfig> PreviousKeys { get; } = new();
[Notify] private IReadOnlyList<PlaceInfo> _places = new List<PlaceInfo>();
public ObservableCollection<string> PopupTexts { get; } = new();
public IObservable<GuiPanel> ActivePanel { get; }

View File

@@ -38,7 +38,6 @@
public void AddTab(ITabViewModel tabViewModel) => throw new NotImplementedException();
public List<KeyConfig> PreviousKeys { get; }
public bool IsAllShortcutVisible { get; set; }
public bool NoCommandFound { get; set; }
public List<CommandBindingConfiguration> PossibleCommands { get; set; }
public BindedCollection<RootDriveInfo, string> RootDriveInfos { get; set; }