Cleaning up warning

This commit is contained in:
2023-09-05 21:22:30 +02:00
parent ecfd0d1b93
commit e6fd8d4ab5
34 changed files with 119 additions and 183 deletions

View File

@@ -23,7 +23,7 @@ public class ContainerSizeSizeScanProvider : ContentProviderBase, IContainerSize
_serviceProvider = serviceProvider;
}
public override async Task<IItem> GetItemByFullNameAsync(
public override Task<IItem> GetItemByFullNameAsync(
FullName fullName,
PointInTime pointInTime,
bool forceResolve = false,
@@ -32,14 +32,14 @@ public class ContainerSizeSizeScanProvider : ContentProviderBase, IContainerSize
)
{
if (fullName.Path == ContentProviderName)
return this;
return Task.FromResult((IItem)this);
var pathParts = fullName.Path.Split(Constants.SeparatorChar);
var item = _sizeScanTasks.FirstOrDefault(t => t.SizeSizeScanContainer.Name == pathParts[1])?.SizeSizeScanContainer;
if (pathParts.Length == 2)
return item ?? throw new ItemNotFoundException(fullName);
return Task.FromResult((IItem)item!) ?? throw new ItemNotFoundException(fullName);
for (var i = 2; i < pathParts.Length - 1 && item != null; i++)
{
@@ -47,22 +47,8 @@ public class ContainerSizeSizeScanProvider : ContentProviderBase, IContainerSize
item = item.ChildContainers.FirstOrDefault(c => c.Name == childName);
}
if (item is not null)
{
var childItem = item.SizeItems.FirstOrDefault(c => c.Name == pathParts[^1]);
if (childItem is not null) return childItem;
/*var childName = item.RealContainer.FullName?.GetChild(pathParts[^1]);
if (childName is null) throw new ItemNotFoundException(fullName);
return await _timelessContentProvider.GetItemByFullNameAsync(
childName,
pointInTime,
forceResolve,
forceResolvePathType,
itemInitializationSettings
);*/
}
var childItem = item?.SizeItems.FirstOrDefault(c => c.Name == pathParts[^1]);
if (childItem != null) return Task.FromResult((IItem)childItem);
throw new ItemNotFoundException(fullName);
}

View File

@@ -17,8 +17,8 @@ public interface ITabViewModel : IInitable<ITab, int>, IDisposable
IDeclarativeProperty<IContainerViewModel?> CurrentSelectedItemAsContainer { get; }
IDeclarativeProperty<ObservableCollection<IItemViewModel>?> CurrentItems { get; }
IDeclarativeProperty<ObservableCollection<FullName>> MarkedItems { get; }
IDeclarativeProperty<ObservableCollection<IItemViewModel>> SelectedsChildren { get; }
IDeclarativeProperty<ObservableCollection<IItemViewModel>> ParentsChildren { get; }
IDeclarativeProperty<ObservableCollection<IItemViewModel>?> SelectedsChildren { get; }
IDeclarativeProperty<ObservableCollection<IItemViewModel>?> ParentsChildren { get; }
IDeclarativeProperty<int?> CurrentSelectedItemIndex { get; set; }
void ClearMarkedItems();

View File

@@ -8,8 +8,8 @@ namespace FileTime.App.Core.Services;
public abstract class DialogServiceBase : IDialogServiceBase
{
private readonly IModalService _modalService;
private OcConsumer _readInputConsumer = new();
private OcConsumer _lastMessageBoxConsumer = new();
private readonly OcConsumer _readInputConsumer = new();
private readonly OcConsumer _lastMessageBoxConsumer = new();
public ScalarComputing<ReadInputsViewModel?> ReadInput { get; }
public ScalarComputing<MessageBoxViewModel?> LastMessageBox { get; }
@@ -20,14 +20,14 @@ public abstract class DialogServiceBase : IDialogServiceBase
.OpenModals
.OfTypeComputing<ReadInputsViewModel>()
.FirstComputing()
.For(_readInputConsumer);
.For(_readInputConsumer)!;
LastMessageBox =
modalService
.OpenModals
.OfTypeComputing<MessageBoxViewModel>()
.LastComputing()
.For(_lastMessageBoxConsumer);
.For(_lastMessageBoxConsumer)!;
}
private void ReadInputs(

View File

@@ -166,7 +166,7 @@ public class TabPersistenceService : ITabPersistenceService
}
var tab = await _serviceProvider
.GetAsyncInitableResolver<IContainer>(currentDirectory ?? _localContentProvider)
.GetAsyncInitableResolver(currentDirectory ?? _localContentProvider)
.GetRequiredServiceAsync<ITab>();
var tabViewModel = _serviceProvider.GetInitableResolver(tab, 1).GetRequiredService<ITabViewModel>();
@@ -191,8 +191,8 @@ public class TabPersistenceService : ITabPersistenceService
if (tab.Path == null) continue;
if (_contentProvidersNotToRestore.Any(p => tab.Path.StartsWith(p))) continue;
IContainer? container = null;
var path = FullName.CreateSafe(tab.Path);
IContainer? container;
var path = FullName.CreateSafe(tab.Path)!;
while (true)
{
try
@@ -213,7 +213,7 @@ public class TabPersistenceService : ITabPersistenceService
}
catch
{
path = path?.GetParent();
path = path.GetParent();
if (path == null)
{
throw new Exception($"Could not find an initializable path along {tab.Path}");

View File

@@ -91,7 +91,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
if (selectedCommandBinding != null)
{
args.Handled = true;
await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command));
await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command)!);
}
}
}

View File

@@ -47,10 +47,10 @@ public abstract partial class AppStateBase : IAppState
SearchText = _searchText.AsObservable();
SelectedTab = DeclarativePropertyHelpers.CombineLatest<ObservableCollection<ITabViewModel>, ITabViewModel, ITabViewModel>(
_tabs.Watch(),
_selectedTab,
(tabs, selectedTab) => Task.FromResult(GetSelectedTab(tabs, selectedTab))
);
_tabs.Watch()!,
_selectedTab!,
(tabs, selectedTab) => Task.FromResult(GetSelectedTab(tabs, selectedTab)!)
)!;
Tabs = new ReadOnlyObservableCollection<ITabViewModel>(_tabs);
@@ -58,7 +58,7 @@ public abstract partial class AppStateBase : IAppState
.Map(t => t?.CurrentLocation)
.Switch()
.Map(c => c?.GetExtension<StatusProviderContainerExtension>()?.GetStatusProperty())
.Switch();
.Switch()!;
}
public void AddTab(ITabViewModel tabViewModel)

View File

@@ -45,7 +45,7 @@ public abstract partial class ItemViewModel : IItemViewModel
var sourceCollection = itemViewModelType switch
{
ItemViewModelType.Main => parentTab.CurrentItems,
ItemViewModelType.Main => parentTab.CurrentItems!,
ItemViewModelType.Parent => parentTab.ParentsChildren,
ItemViewModelType.SelectedChild => parentTab.SelectedsChildren,
_ => throw new InvalidEnumArgumentException()
@@ -59,15 +59,15 @@ public abstract partial class ItemViewModel : IItemViewModel
? (IReadOnlyList<ItemNamePart>) await nameConverterProvider.GetItemNamePartsAsync(item)
: _itemNameConverterService.GetDisplayName(item.DisplayName, s)
),
_ => new DeclarativeProperty<IReadOnlyList<ItemNamePart>>(new List<ItemNamePart> {new(item.DisplayName)}),
_ => new DeclarativeProperty<IReadOnlyList<ItemNamePart>>(new List<ItemNamePart> {new(item.DisplayName)})!,
};
BaseItem = item;
DisplayName = displayName;
DisplayName = displayName!;
DisplayNameText = item.DisplayName;
IsMarked = itemViewModelType is ItemViewModelType.Main
? parentTab.MarkedItems.Map(m => m.Any(i => i.Path == item.FullName?.Path))
? parentTab.MarkedItems!.Map(m => m!.Any(i => i.Path == item.FullName?.Path))
: new DeclarativeProperty<bool>(false);
IsSelected = itemViewModelType is ItemViewModelType.Main
@@ -78,7 +78,7 @@ public abstract partial class ItemViewModel : IItemViewModel
: new DeclarativeProperty<bool>(IsInDeepestPath());
IsAlternative = sourceCollection
.Debounce(TimeSpan.FromMilliseconds(100))
.Debounce(TimeSpan.FromMilliseconds(100))!
.Map(c =>
c?.Index().FirstOrDefault(i => EqualsTo(i.Value)).Key % 2 == 1
);

View File

@@ -21,7 +21,6 @@ namespace FileTime.App.Core.ViewModels;
public partial class TabViewModel : ITabViewModel
{
private readonly IServiceProvider _serviceProvider;
private readonly IAppState _appState;
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly IRefreshSmoothnessCalculator _refreshSmoothnessCalculator;
private readonly ObservableCollection<FullName> _markedItems = new();
@@ -34,16 +33,16 @@ public partial class TabViewModel : ITabViewModel
public ITab? Tab { get; private set; }
public int TabNumber { get; private set; }
public IDeclarativeProperty<bool> IsSelected { get; }
public IDeclarativeProperty<bool> IsSelected { get; } = null!;
public IDeclarativeProperty<IContainer?> CurrentLocation { get; private set; }
public IDeclarativeProperty<IItemViewModel?> CurrentSelectedItem { get; private set; }
public IDeclarativeProperty<int?> CurrentSelectedItemIndex { get; set; }
public IDeclarativeProperty<IContainerViewModel?> CurrentSelectedItemAsContainer { get; private set; }
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> CurrentItems { get; private set; }
public IDeclarativeProperty<ObservableCollection<FullName>> MarkedItems { get; }
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> SelectedsChildren { get; private set; }
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> ParentsChildren { get; private set; }
public IDeclarativeProperty<IContainer?> CurrentLocation { get; private set; } = null!;
public IDeclarativeProperty<IItemViewModel?> CurrentSelectedItem { get; private set; } = null!;
public IDeclarativeProperty<int?> CurrentSelectedItemIndex { get; set; } = null!;
public IDeclarativeProperty<IContainerViewModel?> CurrentSelectedItemAsContainer { get; private set; } = null!;
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> CurrentItems { get; private set; } = null!;
public IDeclarativeProperty<ObservableCollection<FullName>> MarkedItems { get; } = null!;
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> SelectedsChildren { get; private set; } = null!;
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> ParentsChildren { get; private set; } = null!;
public TabViewModel(
@@ -53,10 +52,9 @@ public partial class TabViewModel : ITabViewModel
IRefreshSmoothnessCalculator refreshSmoothnessCalculator)
{
_serviceProvider = serviceProvider;
_appState = appState;
MarkedItems = _markedItems.Watch();
IsSelected = _appState.SelectedTab.Map(s => s == this);
MarkedItems = _markedItems.Watch()!;
IsSelected = appState.SelectedTab.Map(s => s == this);
_timelessContentProvider = timelessContentProvider;
_refreshSmoothnessCalculator = refreshSmoothnessCalculator;
}
@@ -117,7 +115,7 @@ public partial class TabViewModel : ITabViewModel
return Task.FromResult<int?>(-1);
});
CurrentSelectedItem.Subscribe((v) =>
CurrentSelectedItem.Subscribe(_ =>
{
_refreshSmoothnessCalculator.RegisterChange();
_refreshSmoothnessCalculator.RecalculateSmoothness();
@@ -176,12 +174,6 @@ public partial class TabViewModel : ITabViewModel
computing.For(consumer);
}
private static SortExpressionComparer<IItemViewModel> SortItems()
//TODO: Order
=> SortExpressionComparer<IItemViewModel>
.Ascending(i => i.BaseItem?.Type ?? AbsolutePathType.Unknown)
.ThenByAscending(i => i.DisplayNameText?.ToLower() ?? "");
private static IItem MapItem(AbsolutePath item)
{
var t = Task.Run(async () =>

View File

@@ -37,7 +37,7 @@ public class FrequencyNavigationViewModel : FuzzyPanelViewModel<string>, IFreque
if (keyEventArgs.Key == Keys.Enter)
{
keyEventArgs.Handled = true;
var targetContainer = await _timelessContentProvider.GetItemByFullNameAsync(new FullName(SelectedItem), PointInTime.Present);
var targetContainer = await _timelessContentProvider.GetItemByFullNameAsync(new FullName(SelectedItem!), PointInTime.Present);
var openContainerCommand = new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, targetContainer));
await _userCommandHandlerService.HandleCommandAsync(openContainerCommand);
Close();

View File

@@ -71,7 +71,9 @@ public class SearchTask : ISearchTask
_isSearching = true;
_searchingLock.Release();
#pragma warning disable CS4014
Task.Run(BootstrapSearch);
#pragma warning restore CS4014
async Task BootstrapSearch()
{

View File

@@ -6,7 +6,6 @@ namespace FileTime.ConsoleUI.App;
public interface IConsoleAppState : IAppState
{
string ErrorText { get; set; }
ObservableCollection<string> PopupTexts { get; }
ItemPreviewType? PreviewType { get; set; }
}

View File

@@ -7,7 +7,6 @@ namespace FileTime.ConsoleUI.App;
public partial class ConsoleAppState : AppStateBase, IConsoleAppState
{
[Notify] private string? _errorText;
//TODO: make it thread safe
public ObservableCollection<string> PopupTexts { get; } = new();

View File

@@ -140,6 +140,6 @@ static bool HandleInfoProviders(string[] args, IServiceProvider serviceProvider)
public partial class Program
{
public static string AppDataRoot { get; private set; }
public static string EnvironmentName { get; private set; }
public static string AppDataRoot { get; private set; } = null!;
public static string EnvironmentName { get; private set; } = null!;
}

View File

@@ -2,6 +2,6 @@ namespace FileTime.Core.Interactions;
public interface IOptionsInputElement : IInputElement
{
object Value { get; set; }
object? Value { get; set; }
IReadOnlyCollection<IOptionElement> Options { get; }
}

View File

@@ -153,7 +153,7 @@ public class CopyCommand : CommandBase, ITransportationCommand
var statusList = statuses.ToList();
var done = statusList.Count(s => s) + 1;
if (done > statusList.Count) done = statusList.Count;
return Task.FromResult($"Copy - {done} / {statusList.Count}");
})
.Subscribe(async (v, _) => await SetDisplayLabelAsync(v));

View File

@@ -325,32 +325,20 @@ public class CircularBuffer<T> : ICircularBuffer<T>
}
/// <inheritdoc/>
public int Capacity
{
get { return _buffer.Length; }
}
public int Capacity => _buffer.Length;
/// <inheritdoc/>
public bool IsFull
{
get { return Count == Capacity; }
}
public bool IsFull => Count == Capacity;
/// <inheritdoc/>
public bool IsEmpty
{
get { return Count == 0; }
}
public bool IsEmpty => Count == 0;
/// <inheritdoc/>
[Obsolete("Use Count property instead")]
public int Size => Count;
/// <inheritdoc/>
public int Count
{
get { return _size; }
}
public int Count => _size;
/// <inheritdoc/>
[Obsolete("Use First() method instead")]
@@ -381,30 +369,30 @@ public class CircularBuffer<T> : ICircularBuffer<T>
{
if (IsEmpty)
{
throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer is empty", index));
throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer is empty");
}
if (index >= _size)
{
throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer size is {1}", index, _size));
throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer size is {_size}");
}
int actualIndex = InternalIndex(index);
var actualIndex = InternalIndex(index);
return _buffer[actualIndex];
}
set
{
if (IsEmpty)
{
throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer is empty", index));
throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer is empty");
}
if (index >= _size)
{
throw new IndexOutOfRangeException(string.Format("Cannot access index {0}. Buffer size is {1}", index, _size));
throw new IndexOutOfRangeException($"Cannot access index {index}. Buffer size is {_size}");
}
int actualIndex = InternalIndex(index);
var actualIndex = InternalIndex(index);
_buffer[actualIndex] = value;
}
}
@@ -449,7 +437,7 @@ public class CircularBuffer<T> : ICircularBuffer<T>
ThrowIfEmpty("Cannot take elements from an empty buffer.");
Decrement(ref _end);
var value = _buffer[_start];
_buffer[_end] = default(T);
_buffer[_end] = default!;
--_size;
return value;
}
@@ -459,7 +447,7 @@ public class CircularBuffer<T> : ICircularBuffer<T>
{
ThrowIfEmpty("Cannot take elements from an empty buffer.");
var value = _buffer[_start];
_buffer[_start] = default(T);
_buffer[_start] = default!;
Increment(ref _start);
--_size;
return value;
@@ -478,7 +466,7 @@ public class CircularBuffer<T> : ICircularBuffer<T>
/// <inheritdoc/>
public T[] ToArray()
{
T[] newArray = new T[Count];
var newArray = new T[Count];
CopyToInternal(newArray, 0);
return newArray;
}
@@ -553,24 +541,15 @@ public class CircularBuffer<T> : ICircularBuffer<T>
#endif
/// <inheritdoc/>
public IList<ArraySegment<T>> ToArraySegments()
{
return new[] {ArrayOne(), ArrayTwo()};
}
public IList<ArraySegment<T>> ToArraySegments() => new[] {ArrayOne(), ArrayTwo()};
#if (NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER)
/// <inheritdoc/>
public SpanTuple<T> ToSpan()
{
return new SpanTuple<T>(SpanOne(), SpanTwo());
}
public SpanTuple<T> ToSpan() => new(SpanOne(), SpanTwo());
/// <inheritdoc/>
public (ReadOnlyMemory<T> A, ReadOnlyMemory<T> B) ToMemory()
{
return (MemoryOne(), MemoryTwo());
}
public (ReadOnlyMemory<T> A, ReadOnlyMemory<T> B) ToMemory() => (MemoryOne(), MemoryTwo());
#endif
@@ -583,11 +562,11 @@ public class CircularBuffer<T> : ICircularBuffer<T>
public IEnumerator<T> GetEnumerator()
{
var segments = ToArraySegments();
foreach (ArraySegment<T> segment in segments)
foreach (var segment in segments)
{
for (int i = 0; i < segment.Count; i++)
for (var i = 0; i < segment.Count; i++)
{
yield return segment.Array[segment.Offset + i];
yield return segment.Array![segment.Offset + i];
}
}
}
@@ -596,24 +575,15 @@ public class CircularBuffer<T> : ICircularBuffer<T>
#region IEnumerable implementation
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator) GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
#endregion
#if (NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER)
private void CopyToInternal(T[] array, int index)
{
CopyToInternal(array.AsSpan(index));
}
private void CopyToInternal(T[] array, int index) => CopyToInternal(array.AsSpan(index));
private void CopyToInternal(Memory<T> memory)
{
CopyToInternal(memory.Span);
}
private void CopyToInternal(Memory<T> memory) => CopyToInternal(memory.Span);
private void CopyToInternal(Span<T> span)
{
@@ -639,10 +609,10 @@ public class CircularBuffer<T> : ICircularBuffer<T>
{
var segments = ToArraySegments();
var segment = segments[0];
Array.Copy(segment.Array, segment.Offset, array, index, segment.Count);
Array.Copy(segment.Array!, segment.Offset, array, index, segment.Count);
index += segment.Count;
segment = segments[1];
Array.Copy(segment.Array, segment.Offset, array, index, segment.Count);
Array.Copy(segment.Array!, segment.Offset, array, index, segment.Count);
}
private void ThrowIfEmpty(string message = "Cannot access an empty buffer.")
@@ -690,10 +660,7 @@ public class CircularBuffer<T> : ICircularBuffer<T>
/// <param name='index'>
/// External index.
/// </param>
private int InternalIndex(int index)
{
return _start + (index < (Capacity - _start) ? index : index - Capacity);
}
private int InternalIndex(int index) => _start + (index < (Capacity - _start) ? index : index - Capacity);
// doing ArrayOne and ArrayTwo methods returning ArraySegment<T> as seen here:
// http://www.boost.org/doc/libs/1_37_0/libs/circular_buffer/doc/circular_buffer.html#classboost_1_1circular__buffer_1957cccdcb0c4ef7d80a34a990065818d

View File

@@ -14,7 +14,7 @@ public class CombineAllProperty<T, TResult> : DeclarativePropertyBase<TResult>
_sources = sourcesList;
_combiner = combiner;
var initialValueTask = _combiner(sourcesList.Select(p => p.Value));
var initialValueTask = _combiner(sourcesList.Select(p => p.Value)!);
initialValueTask.Wait();
SetNewValueSync(initialValueTask.Result);
@@ -29,7 +29,7 @@ public class CombineAllProperty<T, TResult> : DeclarativePropertyBase<TResult>
private async Task Update()
{
var values = _sources.Select(p => p.Value);
var result = await _combiner(values);
var result = await _combiner(values!);
await SetNewValueAsync(result);
}

View File

@@ -7,7 +7,7 @@ public static class DeclarativePropertyHelpers
IDeclarativeProperty<T2> prop2,
Func<T1, T2, Task<TResult>> func,
Action<TResult?>? setValueHook = null)
=> new(prop1, prop2, func, setValueHook);
=> new(prop1, prop2, func!, setValueHook);
public static CombineLatestProperty<T1, T2, T3, TResult> CombineLatest<T1, T2, T3, TResult>(
IDeclarativeProperty<T1> prop1,
@@ -15,7 +15,7 @@ public static class DeclarativePropertyHelpers
IDeclarativeProperty<T3> prop3,
Func<T1, T2, T3, Task<TResult>> func,
Action<TResult?>? setValueHook = null)
=> new(prop1, prop2, prop3, func, setValueHook);
=> new(prop1, prop2, prop3, func!, setValueHook);
public static MergeProperty<T> Merge<T>(params IDeclarativeProperty<T>[] props)
=> new(props);
@@ -46,6 +46,7 @@ public sealed class DeclarativeProperty<T> : DeclarativePropertyBase<T>
}
catch
{
// ignored
}
});
}

View File

@@ -70,7 +70,7 @@ public abstract class DeclarativePropertyBase<T> : IDeclarativeProperty<T>
{
lock (_subscriberLock)
{
_subscribers.Remove(onChange);
_subscribers.Remove(onChange!);
}
}
@@ -95,7 +95,7 @@ public abstract class DeclarativePropertyBase<T> : IDeclarativeProperty<T>
IDisposable IObservable<T>.Subscribe(IObserver<T> observer)
=> Subscribe((v, _) =>
{
observer.OnNext(v);
observer.OnNext(v!);
return Task.CompletedTask;
});

View File

@@ -21,14 +21,14 @@ public static class DeclarativePropertyExtensions
public static IDeclarativeProperty<T> DistinctUntilChanged<T>(this IDeclarativeProperty<T> from)
=> new DistinctUntilChangedProperty<T>(from);
public static IDeclarativeProperty<TTo?> Map<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> new MapProperty<TFrom?, TTo?>(mapper, from);
public static IDeclarativeProperty<TTo> Map<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> new MapProperty<TFrom?, TTo>(mapper, from);
public static IDeclarativeProperty<TTo?> Map<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, TTo?> mapper)
=> new MapProperty<TFrom?, TTo?>((next, _) => Task.FromResult(mapper(next)), from);
public static async Task<IDeclarativeProperty<TTo?>> MapAsync<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> await MapProperty<TFrom?, TTo?>.CreateAsync(mapper, from);
public static async Task<IDeclarativeProperty<TTo>> MapAsync<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, CancellationToken, Task<TTo?>> mapper)
=> await MapProperty<TFrom, TTo>.CreateAsync(mapper, from);
public static async Task<IDeclarativeProperty<TTo?>> MapAsync<TFrom, TTo>(this IDeclarativeProperty<TFrom?> from, Func<TFrom?, TTo?> mapper)
=> await MapProperty<TFrom?, TTo?>.CreateAsync((next, _) => Task.FromResult(mapper(next)), from);
@@ -65,38 +65,38 @@ public static class DeclarativePropertyExtensions
)
=> new ExtractorProperty<T>(from, extractor);
public static IDeclarativeProperty<TCollection?> Watch<TCollection, TItem>(
public static IDeclarativeProperty<TCollection> Watch<TCollection, TItem>(
this IDeclarativeProperty<TCollection?> collection)
where TCollection : IList<TItem>, INotifyCollectionChanged
=> new CollectionRepeaterProperty<TCollection?, TItem>(collection);
=> new CollectionRepeaterProperty<TCollection, TItem>(collection);
public static IDeclarativeProperty<TCollection?> Watch<TCollection, TItem>(
public static IDeclarativeProperty<TCollection> Watch<TCollection, TItem>(
this TCollection collection)
where TCollection : IList<TItem>, INotifyCollectionChanged
=> new CollectionRepeaterProperty<TCollection?, TItem>(collection);
=> new CollectionRepeaterProperty<TCollection, TItem>(collection);
public static IDeclarativeProperty<ObservableCollection<TItem>?> Watch<TItem>(
public static IDeclarativeProperty<ObservableCollection<TItem>> Watch<TItem>(
this ObservableCollection<TItem> collection)
=> new CollectionRepeaterProperty<ObservableCollection<TItem>?, TItem>(collection);
=> new CollectionRepeaterProperty<ObservableCollection<TItem>, TItem>(collection);
public static IDeclarativeProperty<ReadOnlyObservableCollection<TItem>?> Watch<TItem>(
public static IDeclarativeProperty<ReadOnlyObservableCollection<TItem>> Watch<TItem>(
this ReadOnlyObservableCollection<TItem> collection)
=> new CollectionRepeaterProperty<ReadOnlyObservableCollection<TItem>?, TItem>(collection);
=> new CollectionRepeaterProperty<ReadOnlyObservableCollection<TItem>, TItem>(collection);
public static IDeclarativeProperty<TResult?> CombineLatest<T1, T2, TResult>(
public static IDeclarativeProperty<TResult> CombineLatest<T1, T2, TResult>(
this IDeclarativeProperty<T1> prop1,
IDeclarativeProperty<T2> prop2,
Func<T1, T2, Task<TResult?>> func,
Action<TResult?>? setValueHook = null)
=> new CombineLatestProperty<T1,T2,TResult?>(prop1, prop2, func, setValueHook);
=> new CombineLatestProperty<T1,T2,TResult>(prop1, prop2, func!, setValueHook);
public static IDeclarativeProperty<T> Switch<T>(this IDeclarativeProperty<IDeclarativeProperty<T>?> from)
=> new SwitchProperty<T>(from);
public static IDeclarativeProperty<T?> Switch<T>(this IDeclarativeProperty<IDeclarativeProperty<T?>?> from)
=> new SwitchProperty<T?>(from);
public static IDeclarativeProperty<TResult?> CombineAll<T, TResult>(
public static IDeclarativeProperty<TResult> CombineAll<T, TResult>(
this IEnumerable<IDeclarativeProperty<T>> sources,
Func<IEnumerable<T>, Task<TResult?>> combiner,
Action<TResult?>? setValueHook = null)
=> new CombineAllProperty<T,TResult?>(sources, combiner, setValueHook);
=> new CombineAllProperty<T,TResult>(sources, combiner, setValueHook);
}

View File

@@ -2,10 +2,10 @@
public sealed class MapProperty<TFrom, TTo> : DeclarativePropertyBase<TTo>
{
private readonly Func<TFrom?, CancellationToken, Task<TTo?>> _mapper;
private readonly Func<TFrom, CancellationToken, Task<TTo>> _mapper;
public MapProperty(
Func<TFrom?, CancellationToken, Task<TTo?>> mapper,
Func<TFrom, CancellationToken, Task<TTo>> mapper,
IDeclarativeProperty<TFrom?> from,
Action<TTo?>? setValueHook = null) : base(setValueHook)
{
@@ -15,16 +15,16 @@ public sealed class MapProperty<TFrom, TTo> : DeclarativePropertyBase<TTo>
private async Task SetValue(TFrom? next, CancellationToken cancellationToken = default)
{
var newValue = await _mapper(next, cancellationToken);
var newValue = await _mapper(next!, cancellationToken);
await SetNewValueAsync(newValue, cancellationToken);
}
public static async Task<MapProperty<TFrom?, TTo?>> CreateAsync(
Func<TFrom?, CancellationToken, Task<TTo?>> mapper,
public static async Task<MapProperty<TFrom, TTo>> CreateAsync(
Func<TFrom, CancellationToken, Task<TTo>> mapper,
IDeclarativeProperty<TFrom?> from,
Action<TTo?>? setValueHook = null)
{
var prop = new MapProperty<TFrom?, TTo?>(mapper, from, setValueHook);
var prop = new MapProperty<TFrom, TTo>(mapper, from, setValueHook);
await prop.SetValue(from.Value);
return prop;

View File

@@ -72,7 +72,7 @@ public sealed class Binding<TDataContext, TExpressionResult, TResult> : Property
{
if (couldCompute)
{
value = _converter(_dataContextMapper(_dataSourceView.DataContext));
value = _converter(_dataContextMapper(_dataSourceView.DataContext!));
}
else
{

View File

@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
using TerminalUI.Extensions;
using TerminalUI.Models;
@@ -339,17 +340,6 @@ public sealed class Grid<T> : ChildCollectionView<Grid<T>, T>, IVisibilityChange
return (x, y);
}
private void WithCalculatedSize(in RenderContext renderContext, Option<Size> size, WithSizes actionWithSizes)
{
WithCalculatedSize(renderContext, size, Helper);
object? Helper(in RenderContext renderContext1, ReadOnlySpan<int> widths, ReadOnlySpan<int> heights)
{
actionWithSizes(renderContext1, widths, heights);
return null;
}
}
private TResult WithCalculatedSize<TResult>(in RenderContext renderContext, Option<Size> size, WithSizes<TResult> actionWithSizes)
{
//TODO: Optimize it, dont calculate all of these, only if there is Auto value(s)

View File

@@ -60,7 +60,7 @@ public sealed partial class TextBox<T> : View<TextBox<T>, T>, IFocusable, IDispl
((INotifyPropertyChanged) this).PropertyChanged += OnPropertyChangedEventHandler;
}
private void OnPropertyChangedEventHandler(object sender, PropertyChangedEventArgs args)
private void OnPropertyChangedEventHandler(object? sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == nameof(Text))
{

View File

@@ -2,6 +2,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using GeneralInputKey;
using PropertyChanged.SourceGenerator;
@@ -14,6 +15,7 @@ namespace TerminalUI.Controls;
public delegate string TextTransformer(string text, Position position, Size size);
[SuppressMessage("Performance", "EPS02:Non-readonly struct used as in-parameter")]
public abstract partial class View<TConcrete, T> : IView<T> where TConcrete : View<TConcrete, T>
{
private readonly List<IDisposable> _disposables = new();
@@ -511,7 +513,6 @@ public abstract partial class View<TConcrete, T> : IView<T> where TConcrete : Vi
ProcessParentKeyHandlers(keyEventArgs);
}
protected void ProcessKeyHandlers(GeneralKeyEventArgs keyEventArgs)
{
foreach (var keyHandler in KeyHandlers)

View File

@@ -38,7 +38,7 @@ public class ConditionalTracker : ExpressionTrackerBase
{
true => _ifTrueExpressionTracker.GetValue(),
false => _ifFalseExpressionTracker.GetValue(),
_ => throw new NotSupportedException($"Conditional expression must evaluate to a boolean value, but {testValue} ({testValue.GetType().Name}) is not that.")
_ => throw new NotSupportedException($"Conditional expression must evaluate to a boolean value, but {testValue} ({testValue?.GetType().Name}) is not that.")
};
}
}

View File

@@ -68,7 +68,7 @@ public abstract class ExpressionTrackerBase : IExpressionTracker
useNull = true;
}
}
catch (Exception e)
catch (Exception)
{
useNull = true;
}

View File

@@ -35,11 +35,11 @@ public static class ViewExtensions
Expression<Func<TItem, TExpressionResult>> dataSourceExpression,
Action<bool, TExpressionResult> handler)
{
new PropertyChangedHandler<TItem, TExpressionResult>
_ = new PropertyChangedHandler<TItem, TExpressionResult>
(
dataSource,
dataSourceExpression,
handler
handler!
);
return dataSource;

View File

@@ -19,7 +19,6 @@ public class RenderEngine : IRenderEngine
private bool[,]? _updatedCells;
private bool[,]? _filledCells;
private bool[,]? _lastFilledCells;
private DateTime _renderRequestDetected;
private ITheme? _lastTheme;
public RenderEngine(IApplicationContext applicationContext, IEventLoop eventLoop)

View File

@@ -1,5 +1,4 @@
using GeneralInputKey;
using TerminalUI.ConsoleDrivers;
using TerminalUI.ConsoleDrivers;
using TerminalUI.Controls;
namespace TerminalUI.Traits;
@@ -9,5 +8,4 @@ public interface IFocusable : IView
void Focus();
void UnFocus();
void SetCursorPosition(IConsoleDriver consoleDriver);
void HandleKeyInput(GeneralKeyEventArgs keyEventArgs);
}

View File

@@ -15,13 +15,13 @@ public partial class RootDriveInfo
[Notify] private string? _label;
[Notify] private long _size = 0;
[Notify] private long _size;
[Notify] private long _free = 0;
[Notify] private long _free;
[Notify] private long _used = 0;
[Notify] private long _used;
[Notify] public long UsedPercentage => Size == 0 ? 0 : Used * 100 / Size;
public long UsedPercentage => Size == 0 ? 0 : Used * 100 / Size;
public FullName Path { get; }

View File

@@ -298,7 +298,9 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
var lockObj = new object();
var loadingIndicatorCancellation = new CancellationTokenSource();
#pragma warning disable CS4014
Task.Run(async () => await DelayedLoadingIndicator());
#pragma warning restore CS4014
await LoadChildrenInternal();
lock (lockObj)

View File

@@ -4,7 +4,7 @@ public class AdminElevationConfiguration
{
public const string SectionName = "AdminElevation";
public string? ServerExecutablePath { get; set; }
public string LinuxElevationTool { get; set; }
public string LinuxElevationTool { get; set; } = null!;
public int? ServerPort { get; set; }
public bool? StartProcess { get; set; }
}

View File

@@ -20,7 +20,7 @@ public class CompressionUserCommandHandler : AggregatedUserCommandHandler
IClipboardService clipboardService)
{
_clipboardService = clipboardService;
_markedItems = appState.SelectedTab.Map(t => t?.MarkedItems).Switch();
_markedItems = appState.SelectedTab.Map(t => t?.MarkedItems)!.Switch();
_selectedItem = appState.SelectedTab.Map(t => t?.CurrentSelectedItem).Switch();
AddCommandHandler(new IUserCommandHandler[]