TimeTravel
This commit is contained in:
@@ -6,11 +6,11 @@ using FileTime.Avalonia.Services;
|
||||
using FileTime.Avalonia.ViewModels;
|
||||
using MvvmGen;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FileTime.App.Core.Tab;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FileTime.Avalonia.Application
|
||||
{
|
||||
@@ -18,8 +18,11 @@ namespace FileTime.Avalonia.Application
|
||||
[Inject(typeof(ItemNameConverterService))]
|
||||
[Inject(typeof(LocalContentProvider))]
|
||||
[Inject(typeof(Tab))]
|
||||
public partial class TabContainer
|
||||
public partial class TabContainer : INewItemProcessor
|
||||
{
|
||||
[Property]
|
||||
private TabState _tabState;
|
||||
|
||||
[Property]
|
||||
private ContainerViewModel _parent;
|
||||
|
||||
@@ -45,25 +48,33 @@ namespace FileTime.Avalonia.Application
|
||||
if (_selectedItem != value)// && value != null
|
||||
{
|
||||
_selectedItem = value;
|
||||
|
||||
OnPropertyChanged("SelectedItem");
|
||||
SelectedItemChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnInitialize()
|
||||
{
|
||||
_tabState = new TabState(Tab);
|
||||
}
|
||||
|
||||
public async Task Init(int tabNumber)
|
||||
{
|
||||
TabNumber = tabNumber;
|
||||
Tab.CurrentLocationChanged.Add(Tab_CurrentLocationChanged);
|
||||
Tab.CurrentSelectedItemChanged.Add(Tab_CurrentSelectedItemChanged);
|
||||
|
||||
CurrentLocation = new ContainerViewModel(await Tab.GetCurrentLocation(), ItemNameConverterService);
|
||||
var currentLocation = await Tab.GetCurrentLocation();
|
||||
var parent = GenerateParent(currentLocation);
|
||||
CurrentLocation = new ContainerViewModel(this, parent, currentLocation, ItemNameConverterService);
|
||||
await CurrentLocation.Init();
|
||||
|
||||
var parent = (await Tab.GetCurrentLocation()).GetParent();
|
||||
if (parent != null)
|
||||
{
|
||||
Parent = new ContainerViewModel(parent, ItemNameConverterService);
|
||||
parent.ChildrenToAdopt.Add(CurrentLocation);
|
||||
Parent = parent;
|
||||
await Parent.Init();
|
||||
}
|
||||
else
|
||||
@@ -74,16 +85,28 @@ namespace FileTime.Avalonia.Application
|
||||
await UpdateCurrentSelectedItem();
|
||||
}
|
||||
|
||||
private ContainerViewModel? GenerateParent(IContainer? container, bool recursive = false)
|
||||
{
|
||||
var parentContainer = container?.GetParent();
|
||||
if (parentContainer == null) return null;
|
||||
var parentParent = recursive ? GenerateParent(parentContainer.GetParent(), recursive) : null;
|
||||
|
||||
var parent = new ContainerViewModel(this, parentParent, parentContainer, ItemNameConverterService);
|
||||
parentParent?.ChildrenToAdopt.Add(parent);
|
||||
return parent;
|
||||
}
|
||||
|
||||
private async Task Tab_CurrentLocationChanged(object? sender, AsyncEventArgs e)
|
||||
{
|
||||
var currentLocation = await Tab.GetCurrentLocation();
|
||||
CurrentLocation = new ContainerViewModel(currentLocation, ItemNameConverterService);
|
||||
var parent = GenerateParent(currentLocation);
|
||||
CurrentLocation = new ContainerViewModel(this, parent, currentLocation, ItemNameConverterService);
|
||||
await CurrentLocation.Init();
|
||||
|
||||
var parent = currentLocation.GetParent();
|
||||
if (parent != null)
|
||||
{
|
||||
Parent = new ContainerViewModel(parent, ItemNameConverterService);
|
||||
parent.ChildrenToAdopt.Add(CurrentLocation);
|
||||
Parent = parent;
|
||||
await Parent.Init();
|
||||
}
|
||||
else
|
||||
@@ -97,39 +120,89 @@ namespace FileTime.Avalonia.Application
|
||||
await UpdateCurrentSelectedItem();
|
||||
}
|
||||
|
||||
private async Task UpdateCurrentSelectedItem()
|
||||
public async Task UpdateCurrentSelectedItem()
|
||||
{
|
||||
var tabCurrentSelectenItem = await Tab.GetCurrentSelectedItem();
|
||||
IItemViewModel? currentSelectenItem = null;
|
||||
if (tabCurrentSelectenItem == null)
|
||||
try
|
||||
{
|
||||
SelectedItem = null;
|
||||
ChildContainer = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSelectenItem = (await _currentLocation.GetItems()).FirstOrDefault(i => i.Item.Name == tabCurrentSelectenItem.Name);
|
||||
if (currentSelectenItem is ContainerViewModel currentSelectedContainer)
|
||||
{
|
||||
SelectedItem = currentSelectedContainer;
|
||||
ChildContainer = currentSelectedContainer;
|
||||
}
|
||||
else if (currentSelectenItem is ElementViewModel element)
|
||||
{
|
||||
SelectedItem = element;
|
||||
ChildContainer = null;
|
||||
}
|
||||
else
|
||||
var tabCurrentSelectenItem = await Tab.GetCurrentSelectedItem();
|
||||
IItemViewModel? currentSelectenItem = null;
|
||||
if (tabCurrentSelectenItem == null)
|
||||
{
|
||||
SelectedItem = null;
|
||||
ChildContainer = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSelectenItem = (await _currentLocation.GetItems()).FirstOrDefault(i => i.Item.Name == tabCurrentSelectenItem.Name);
|
||||
if (currentSelectenItem is ContainerViewModel currentSelectedContainer)
|
||||
{
|
||||
SelectedItem = currentSelectedContainer;
|
||||
ChildContainer = currentSelectedContainer;
|
||||
}
|
||||
else if (currentSelectenItem is ElementViewModel element)
|
||||
{
|
||||
SelectedItem = element;
|
||||
ChildContainer = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedItem = null;
|
||||
ChildContainer = null;
|
||||
}
|
||||
}
|
||||
|
||||
var items = await _currentLocation.GetItems();
|
||||
foreach (var item in items)
|
||||
var items = await _currentLocation.GetItems();
|
||||
if (items != null && items.Count > 0)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
var isSelected = item == currentSelectenItem;
|
||||
item.IsSelected = isSelected;
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
var parent = item.Parent;
|
||||
while (parent != null)
|
||||
{
|
||||
parent.IsSelected = true;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var child = item;
|
||||
while (child is ContainerViewModel containerViewModel && containerViewModel.Container.IsLoaded)
|
||||
{
|
||||
var activeChildItem = await Tab.GetItemByLastPath(containerViewModel.Container);
|
||||
child = (await containerViewModel.GetItems()).FirstOrDefault(i => i.Item == activeChildItem);
|
||||
if (child != null)
|
||||
{
|
||||
child.IsSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//INFO collection modified exception on: child = (await containerViewModel.GetItems()).FirstOrDefault(i => i.Item == activeChildItem);
|
||||
//TODO: handle or error message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var parent = _currentLocation;
|
||||
while (parent != null)
|
||||
{
|
||||
parent.IsSelected = true;
|
||||
parent = parent.Parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
item.IsSelected = item == currentSelectenItem;
|
||||
//INFO collection modified exception on: currentSelectenItem = (await _currentLocation.GetItems()).FirstOrDefault(i => i.Item.Name == tabCurrentSelectenItem.Name);
|
||||
//TODO: handle or error message
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,9 +285,32 @@ namespace FileTime.Avalonia.Application
|
||||
(await Tab.GetCurrentLocation())?.CreateContainer(name);
|
||||
}
|
||||
|
||||
public async Task CreateElement(string name)
|
||||
{
|
||||
(await Tab.GetCurrentLocation())?.CreateElement(name);
|
||||
}
|
||||
|
||||
public async Task OpenContainer(IContainer container)
|
||||
{
|
||||
await Tab.OpenContainer(container);
|
||||
}
|
||||
|
||||
public async Task MarkCurrentItem()
|
||||
{
|
||||
await _tabState.MakrCurrentItem();
|
||||
}
|
||||
|
||||
public async Task UpdateMarkedItems(ContainerViewModel containerViewModel)
|
||||
{
|
||||
if (containerViewModel == CurrentLocation && containerViewModel.Container.IsLoaded)
|
||||
{
|
||||
var selectedItems = TabState.GetCurrentMarkedItems(containerViewModel.Container);
|
||||
|
||||
foreach (var item in await containerViewModel.GetItems())
|
||||
{
|
||||
item.IsMarked = selectedItems.Any(c => c.Path == item.Item.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user