Fixes, UI improvements

child container, preview, etc
This commit is contained in:
2022-02-13 21:08:57 +01:00
parent 7019918496
commit 9661155cdd
5 changed files with 78 additions and 123 deletions

View File

@@ -33,7 +33,7 @@ namespace FileTime.Avalonia.Application
private ContainerViewModel _currentLocation; private ContainerViewModel _currentLocation;
[Property] [Property]
private ContainerViewModel _childContainer; private ContainerViewModel? _childContainer;
[Property] [Property]
private int _tabNumber; private int _tabNumber;
@@ -51,16 +51,16 @@ namespace FileTime.Avalonia.Application
{ {
if (!_updateFromCode && value != null) if (!_updateFromCode && value != null)
{ {
try /*try
{ {*/
/*var task = SetSelectedItemAsync(value, true); /*var task = SetSelectedItemAsync(value, true);
Task.WaitAll(new Task[] { task }, 100);*/ Task.WaitAll(new Task[] { task }, 100);*/
SetSelectedItemAsync(value, true); SetSelectedItemAsync(value, true);
} /*}
catch catch
{ {
//TODO: Debug, linux start after restore 3 tabs //TODO: Debug, linux start after restore 3 tabs
} }*/
} }
} }
} }
@@ -74,23 +74,10 @@ namespace FileTime.Avalonia.Application
{ {
_selectedItem = value; _selectedItem = value;
if (value is ElementViewModel elementViewModel) await Tab.SetCurrentSelectedItem(SelectedItem?.Item, fromDataBinding);
{
var elementPreview = new ElementPreviewViewModel();
await elementPreview.Init(elementViewModel.Element);
ElementPreview = elementPreview;
}
else
{
ElementPreview = null;
}
if (await Tab.SetCurrentSelectedItem(SelectedItem?.Item, fromDataBinding))
{
OnPropertyChanged(nameof(SelectedItem)); OnPropertyChanged(nameof(SelectedItem));
} }
} }
}
partial void OnInitialize() partial void OnInitialize()
{ {
@@ -161,17 +148,18 @@ namespace FileTime.Avalonia.Application
public async Task UpdateCurrentSelectedItem(CancellationToken token = default) public async Task UpdateCurrentSelectedItem(CancellationToken token = default)
{ {
try /*try
{ {*/
var tabCurrentSelectenItem = await Tab.GetCurrentSelectedItem();
if (token.IsCancellationRequested) return; if (token.IsCancellationRequested) return;
var tabCurrentSelectenItem = await Tab.GetCurrentSelectedItem();
ContainerViewModel? newChildContainer = null;
IItemViewModel? currentSelectenItem = null; IItemViewModel? currentSelectenItem = null;
if (tabCurrentSelectenItem == null) if (tabCurrentSelectenItem == null)
{ {
await SetSelectedItemAsync(null); await SetSelectedItemAsync(null);
ChildContainer = null;
} }
else else
{ {
@@ -179,22 +167,49 @@ namespace FileTime.Avalonia.Application
if (currentSelectenItem is ContainerViewModel currentSelectedContainer) if (currentSelectenItem is ContainerViewModel currentSelectedContainer)
{ {
await SetSelectedItemAsync(currentSelectedContainer); await SetSelectedItemAsync(currentSelectedContainer);
ChildContainer = currentSelectedContainer; newChildContainer = currentSelectedContainer;
} }
else if (currentSelectenItem is ElementViewModel element) else if (currentSelectenItem is ElementViewModel element)
{ {
await SetSelectedItemAsync(element); await SetSelectedItemAsync(element);
ChildContainer = null;
} }
else else
{ {
await SetSelectedItemAsync(null); await SetSelectedItemAsync(null);
ChildContainer = null;
} }
} }
await UpdateParents(token);
var start = DateTime.Now;
while (true)
{
await Task.Delay(1);
if (token.IsCancellationRequested) return; if (token.IsCancellationRequested) return;
if ((DateTime.Now - start).Milliseconds > 500) break;
}
ChildContainer = newChildContainer;
if (currentSelectenItem is ElementViewModel elementViewModel)
{
var elementPreview = new ElementPreviewViewModel();
await elementPreview.Init(elementViewModel.Element);
ElementPreview = elementPreview;
}
else
{
ElementPreview = null;
}
/*}
catch
{
//INFO collection modified exception on: currentSelectenItem = (await _currentLocation.GetItems()).FirstOrDefault(i => i.Item.Name == tabCurrentSelectenItem.Name);
//TODO: handle or error message
}*/
async Task UpdateParents(CancellationToken token = default)
{
var items = await _currentLocation.GetItems(token); var items = await _currentLocation.GetItems(token);
if (items?.Count > 0) if (items?.Count > 0)
{ {
@@ -244,11 +259,6 @@ namespace FileTime.Avalonia.Application
} }
} }
} }
catch
{
//INFO collection modified exception on: currentSelectenItem = (await _currentLocation.GetItems()).FirstOrDefault(i => i.Item.Name == tabCurrentSelectenItem.Name);
//TODO: handle or error message
}
} }
public async Task SetCurrentSelectedItem(IItem newItem) public async Task SetCurrentSelectedItem(IItem newItem)
@@ -269,9 +279,12 @@ namespace FileTime.Avalonia.Application
} }
catch catch
{ {
_updateFromCode = false;
throw; throw;
} }
finally
{
_updateFromCode = false;
}
} }
private CancellationToken CancelAndGenerateNextMovementToken() private CancellationToken CancelAndGenerateNextMovementToken()

View File

@@ -80,9 +80,9 @@ namespace FileTime.Avalonia.Services
else if (selectedCommandBinding != null) else if (selectedCommandBinding != null)
{ {
setHandled(true); setHandled(true);
await _commandHandlerService.HandleCommandAsync(selectedCommandBinding.Command);
_appState.PreviousKeys.Clear(); _appState.PreviousKeys.Clear();
_appState.PossibleCommands = new(); _appState.PossibleCommands = new();
await _commandHandlerService.HandleCommandAsync(selectedCommandBinding.Command);
} }
else if (_keysToSkip.Any(k => AreKeysEqual(k, _appState.PreviousKeys))) else if (_keysToSkip.Any(k => AreKeysEqual(k, _appState.PreviousKeys)))
{ {
@@ -99,6 +99,7 @@ namespace FileTime.Avalonia.Services
} }
else else
{ {
setHandled(true);
var possibleCommands = _keyboardConfigurationService.AllShortcut.Where(c => AreKeysEqual(c.Keys[0], keyWithModifiers)).ToList(); var possibleCommands = _keyboardConfigurationService.AllShortcut.Where(c => AreKeysEqual(c.Keys[0], keyWithModifiers)).ToList();
if (possibleCommands.Count == 0) if (possibleCommands.Count == 0)
@@ -110,7 +111,6 @@ namespace FileTime.Avalonia.Services
{ {
_appState.PossibleCommands = possibleCommands; _appState.PossibleCommands = possibleCommands;
} }
setHandled(true);
} }
} }
else else

View File

@@ -67,71 +67,6 @@ namespace FileTime.Avalonia.ViewModels
public List<ItemNamePart> DisplayName => ItemNameConverterService.GetDisplayName(this); public List<ItemNamePart> DisplayName => ItemNameConverterService.GetDisplayName(this);
/*[Obsolete($"This property is for databinding only, use {nameof(GetContainers)} method instead.")]
public ObservableCollection<ContainerViewModel> Containers
{
get
{
try
{
if (!_isInitialized) Task.Run(Refresh).Wait();
}
catch(Exception e) { }
return _containers;
}
set
{
if (value != _containers)
{
_containers = value;
OnPropertyChanged(nameof(Containers));
}
}
}
[Obsolete($"This property is for databinding only, use {nameof(GetElements)} method instead.")]
public ObservableCollection<ElementViewModel> Elements
{
get
{
try
{
if (!_isInitialized) Task.Run(Refresh).Wait();
}
catch(Exception e) { }
return _elements;
}
set
{
if (value != _elements)
{
_elements = value;
OnPropertyChanged(nameof(Elements));
}
}
}
[Obsolete($"This property is for databinding only, use {nameof(GetItems)} method instead.")]
public ObservableCollection<IItemViewModel> Items
{
get
{
try
{
if (!_isInitialized) Task.Run(Refresh).Wait();
}
catch(Exception e) { }
return _items;
}
set
{
if (value != _items)
{
_items = value;
OnPropertyChanged(nameof(Items));
}
}
}*/
public Task Containers => GetContainers(); public Task Containers => GetContainers();
public Task Elements => GetElements(); public Task Elements => GetElements();
public Task Items => GetItems(); public Task Items => GetItems();

View File

@@ -248,9 +248,10 @@
AutoScrollToSelectedItem="True" AutoScrollToSelectedItem="True"
IsTabStop="True" IsTabStop="True"
Items="{Binding AppState.SelectedTab.CurrentLocation.Items^}" Items="{Binding AppState.SelectedTab.CurrentLocation.Items^}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedItem="{Binding AppState.SelectedTab.SelectedItem, Mode=TwoWay}" SelectedItem="{Binding AppState.SelectedTab.SelectedItem, Mode=TwoWay}"
SelectionChanged="OnCurrentItemsSelectionChanged"
Classes="ContentListView"> Classes="ContentListView">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>

View File

@@ -154,5 +154,11 @@ namespace FileTime.Avalonia.Views
BeginMoveDrag(e); BeginMoveDrag(e);
} }
} }
private void OnCurrentItemsSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var listBox = this.FindControl<ListBox>("CurrentItems");
listBox.ScrollIntoView(listBox.SelectedIndex);
}
} }
} }