Command refactor, fixes, improvements
This commit is contained in:
@@ -24,8 +24,8 @@ namespace FileTime.Avalonia
|
||||
.BuildServiceProvider()
|
||||
.InitSerilog();
|
||||
|
||||
var _logger = ServiceProvider.GetService<ILogger<App>>();
|
||||
_logger?.LogInformation("App initialization completed.");
|
||||
var logger = ServiceProvider.GetService<ILogger<App>>();
|
||||
logger?.LogInformation("App initialization completed.");
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FileTime.App.Core.Tab;
|
||||
using System.Threading;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Avalonia.Application
|
||||
{
|
||||
@@ -18,6 +19,7 @@ namespace FileTime.Avalonia.Application
|
||||
[Inject(typeof(ItemNameConverterService))]
|
||||
[Inject(typeof(LocalContentProvider))]
|
||||
[Inject(typeof(Tab))]
|
||||
[Inject(typeof(TimeRunner), propertyName: "_timeRunner")]
|
||||
public partial class TabContainer : INewItemProcessor
|
||||
{
|
||||
private bool _updateFromCode;
|
||||
@@ -77,6 +79,21 @@ namespace FileTime.Avalonia.Application
|
||||
partial void OnInitialize()
|
||||
{
|
||||
_tabState = new TabState(Tab);
|
||||
_timeRunner.RefreshContainer.Add(TimeRunnerContainerRefreshed);
|
||||
|
||||
}
|
||||
|
||||
private async Task TimeRunnerContainerRefreshed(object? sender, AbsolutePath container, CancellationToken token = default)
|
||||
{
|
||||
var currentLocation = await Tab.GetCurrentLocation();
|
||||
if (currentLocation != null)
|
||||
{
|
||||
var currentLocationPath = new AbsolutePath(currentLocation);
|
||||
if (currentLocationPath == container)
|
||||
{
|
||||
await currentLocation.RefreshAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Init(int tabNumber)
|
||||
|
||||
@@ -12,6 +12,12 @@ using FileTime.Avalonia.Misc;
|
||||
using FileTime.Avalonia.Models;
|
||||
using FileTime.Avalonia.ViewModels;
|
||||
using FileTime.Core.Command;
|
||||
using FileTime.Core.Command.Copy;
|
||||
using FileTime.Core.Command.CreateContainer;
|
||||
using FileTime.Core.Command.CreateElement;
|
||||
using FileTime.Core.Command.Delete;
|
||||
using FileTime.Core.Command.Move;
|
||||
using FileTime.Core.Command.Rename;
|
||||
using FileTime.Core.Components;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
@@ -229,7 +235,7 @@ namespace FileTime.Avalonia.Services
|
||||
var newTab = new Tab();
|
||||
await newTab.Init(newContainer);
|
||||
|
||||
tabContainer = new TabContainer(newTab, _localContentProvider, _itemNameConverterService);
|
||||
tabContainer = new TabContainer(_timeRunner, newTab, _localContentProvider, _itemNameConverterService);
|
||||
await tabContainer.Init(number);
|
||||
|
||||
var i = 0;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
@@ -13,6 +11,7 @@ using FileTime.Core.Providers;
|
||||
using FileTime.Providers.Local;
|
||||
using FileTime.Core.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Avalonia.Services
|
||||
{
|
||||
@@ -25,13 +24,15 @@ namespace FileTime.Avalonia.Services
|
||||
private readonly IEnumerable<IContentProvider> _contentProviders;
|
||||
private readonly LocalContentProvider _localContentProvider;
|
||||
private readonly ILogger<StatePersistenceService> _logger;
|
||||
private readonly TimeRunner _timeRunner;
|
||||
|
||||
public StatePersistenceService(
|
||||
AppState appState,
|
||||
ItemNameConverterService itemNameConverterService,
|
||||
IEnumerable<IContentProvider> contentProviders,
|
||||
LocalContentProvider localContentProvider,
|
||||
ILogger<StatePersistenceService> logger)
|
||||
ILogger<StatePersistenceService> logger,
|
||||
TimeRunner timeRunner)
|
||||
{
|
||||
_appState = appState;
|
||||
_itemNameConverterService = itemNameConverterService;
|
||||
@@ -45,6 +46,7 @@ namespace FileTime.Avalonia.Services
|
||||
PropertyNameCaseInsensitive = true,
|
||||
WriteIndented = true
|
||||
};
|
||||
this._timeRunner = timeRunner;
|
||||
}
|
||||
|
||||
public async Task LoadStatesAsync()
|
||||
@@ -151,7 +153,7 @@ namespace FileTime.Avalonia.Services
|
||||
}
|
||||
}
|
||||
|
||||
var newTabContainer = new TabContainer(newTab, _localContentProvider, _itemNameConverterService);
|
||||
var newTabContainer = new TabContainer(_timeRunner, newTab, _localContentProvider, _itemNameConverterService);
|
||||
await newTabContainer.Init(tab.Number);
|
||||
_appState.Tabs.Add(newTabContainer);
|
||||
}
|
||||
|
||||
@@ -154,10 +154,10 @@ namespace FileTime.Avalonia.ViewModels
|
||||
{
|
||||
_isRefreshing = true;
|
||||
|
||||
List<ContainerViewModel> newContainers = new List<ContainerViewModel>();
|
||||
List<ElementViewModel> newElements = new List<ElementViewModel>();
|
||||
List<ContainerViewModel> newContainers = new();
|
||||
List<ElementViewModel> newElements = new();
|
||||
|
||||
if (await _container.GetContainers() is IReadOnlyList<IContainer> containers)
|
||||
if (await _container.GetContainers(token) is IReadOnlyList<IContainer> containers)
|
||||
{
|
||||
foreach (var container in containers)
|
||||
{
|
||||
@@ -165,7 +165,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
if (await _container.GetElements() is IReadOnlyList<IElement> elements)
|
||||
if (await _container.GetElements(token) is IReadOnlyList<IElement> elements)
|
||||
{
|
||||
foreach (var element in elements)
|
||||
{
|
||||
@@ -216,7 +216,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
_exceptions.Add(e);
|
||||
}
|
||||
|
||||
await _newItemProcessor.UpdateMarkedItems(this);
|
||||
await _newItemProcessor.UpdateMarkedItems(this, CancellationToken.None);
|
||||
|
||||
_isRefreshing = false;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace FileTime.Avalonia.ViewModels
|
||||
var tab = new Tab();
|
||||
await tab.Init(LocalContentProvider);
|
||||
|
||||
var tabContainer = new TabContainer(tab, LocalContentProvider, ItemNameConverterService);
|
||||
var tabContainer = new TabContainer(_timeRunner, tab, LocalContentProvider, ItemNameConverterService);
|
||||
await tabContainer.Init(1);
|
||||
tabContainer.IsSelected = true;
|
||||
AppState.Tabs.Add(tabContainer);
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace FileTime.Avalonia.Views
|
||||
|
||||
private void InputText_AttachedToVisualTree(object? sender, VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
if (sender is TextBox inputText && inputText.DataContext is InputElementWrapper inputElementWrapper && inputElementWrapper == ViewModel!.AppState.Inputs.First())
|
||||
if (sender is TextBox inputText && inputText.IsVisible && inputText.DataContext is InputElementWrapper inputElementWrapper && inputElementWrapper == ViewModel!.AppState.Inputs[0])
|
||||
{
|
||||
inputText.Focus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user