Merge pull request #591 from irihitech/clean

Clean up warning and non-library issues
This commit is contained in:
Dong Bin
2025-02-27 17:24:14 +08:00
committed by GitHub
9 changed files with 223 additions and 233 deletions

View File

@@ -12,6 +12,7 @@
x:DataType="vm:DialogDemoViewModel"
mc:Ignorable="d">
<Grid ColumnDefinitions="Auto, *">
<ScrollViewer>
<TabControl Grid.Column="0" TabStripPlacement="Left">
<TabItem Header="Default Window Dialog">
<u:Form
@@ -56,10 +57,10 @@
<StackPanel Orientation="Horizontal">
<TextBlock Text="Style Class" />
<PathIcon
Theme="{StaticResource InnerPathIcon}"
VerticalAlignment="Center"
TextElement.FontWeight="Normal"
Data="{DynamicResource SemiIconHelpCircle}"
TextElement.FontWeight="Normal"
Theme="{StaticResource InnerPathIcon}"
ToolTip.Tip="Pass a Style Class to the created Dialog. In this example, if you set StyleClass as 'Custom', You will get Special Style for OK Button. These styles usually are defined in the root of your App/Window" />
</StackPanel>
</u:FormItem.Label>
@@ -147,10 +148,10 @@
<StackPanel Orientation="Horizontal">
<TextBlock Text="Style Class" />
<PathIcon
Theme="{StaticResource InnerPathIcon}"
VerticalAlignment="Center"
TextElement.FontWeight="Normal"
Data="{DynamicResource SemiIconHelpCircle}"
TextElement.FontWeight="Normal"
Theme="{StaticResource InnerPathIcon}"
ToolTip.Tip="Pass a Style Class to the created Dialog. In this example, if you set StyleClass as 'Custom', You will get Special Style for OK Button. These styles usually are defined in the root of your App/Window" />
</StackPanel>
</u:FormItem.Label>
@@ -195,10 +196,11 @@
</u:Form>
</TabItem>
</TabControl>
</ScrollViewer>
<Grid Grid.Column="1">
<Border
BorderBrush="{DynamicResource SemiGrey1}"
Background="{DynamicResource SemiColorBackground1}"
BorderBrush="{DynamicResource SemiGrey1}"
BorderThickness="1"
ClipToBounds="True"
CornerRadius="12">

View File

@@ -7,25 +7,18 @@ namespace Ursa.Controls;
public class IPv4BoxInputMethodClient: TextInputMethodClient
{
private TextPresenter? _presenter;
public override Visual TextViewVisual => _presenter;
public override Visual TextViewVisual => _presenter!;
public override bool SupportsPreedit => false;
public override bool SupportsSurroundingText => true;
public override string SurroundingText
{
get;
}
public override Rect CursorRectangle { get; }
public override string SurroundingText { get; } = null!;
public override Rect CursorRectangle { get; } = new();
public override TextSelection Selection { get; set; }
private IPv4Box? _parent;
public void SetPresenter(TextPresenter? presenter)
{
_presenter = presenter;
this.RaiseTextViewVisualChanged();
this.RaiseCursorRectangleChanged();
}
private void OnParentPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
this.RaiseSelectionChanged();
}
}

View File

@@ -124,14 +124,14 @@ public class Marquee : ContentControl
set => SetValue(SpeedProperty, value);
}
private void OnPresenterSizeChanged(object sender, SizeChangedEventArgs e)
private void OnPresenterSizeChanged(object? sender, SizeChangedEventArgs e)
{
InvalidatePresenterPosition();
}
private void TimerOnTick(object sender, System.EventArgs e)
private void TimerOnTick(object? sender, System.EventArgs e)
{
if (Presenter is null) return;
var layoutValues = Dispatcher.UIThread.Invoke(GetLayoutValues);
@@ -177,11 +177,13 @@ public class Marquee : ContentControl
{
Direction.Up or Direction.Down => GetHorizontalOffset(values.Bounds, values.PresenterSize, values.HorizontalAlignment),
Direction.Left or Direction.Right => values.Left,
_ => throw new NotImplementedException(),
};
var verticalOffset = values.Direction switch
{
Direction.Up or Direction.Down => values.Top,
Direction.Left or Direction.Right => GetVerticalOffset(values.Bounds, values.PresenterSize, values.VerticalAlignment),
_ => throw new NotImplementedException(),
};
if (horizontalOffset is double.NaN) horizontalOffset = 0.0;
if (verticalOffset is double.NaN) verticalOffset = 0.0;

View File

@@ -204,10 +204,10 @@ public class PathPicker : TemplatedControl
nameof(FilePickerFileTypes.ImagePng) => FilePickerFileTypes.ImagePng,
nameof(FilePickerFileTypes.ImageWebp) => FilePickerFileTypes.ImageWebp,
nameof(FilePickerFileTypes.TextPlain) => FilePickerFileTypes.TextPlain,
_ => parse()
_ => Parse()
};
FilePickerFileType parse()
FilePickerFileType Parse()
{
var list = str.Split(',');
return new FilePickerFileType(list.First())
@@ -248,7 +248,7 @@ public class PathPicker : TemplatedControl
FileTypeFilter = ParseFileTypes(FileFilter)
};
var resFiles = await storageProvider.OpenFilePickerAsync(filePickerOpenOptions);
UpdateSelectedPaths(resFiles.Select(x => x.TryGetLocalPath()).ToArray()!);
UpdateSelectedPaths(resFiles.Select(x => x.TryGetLocalPath()).ToArray());
break;
case UsePickerTypes.SaveFile:
FilePickerSaveOptions filePickerSaveOptions = new()
@@ -263,9 +263,7 @@ public class PathPicker : TemplatedControl
var path = (await storageProvider.SaveFilePickerAsync(filePickerSaveOptions))
?.TryGetLocalPath();
UpdateSelectedPaths(string.IsNullOrEmpty(path)
? Array.Empty<string>()
: [path]);
UpdateSelectedPaths([path]);
break;
case UsePickerTypes.OpenFolder:
FolderPickerOpenOptions folderPickerOpenOptions = new()
@@ -277,7 +275,7 @@ public class PathPicker : TemplatedControl
SuggestedFileName = SuggestedFileName
};
var resFolder = await storageProvider.OpenFolderPickerAsync(folderPickerOpenOptions);
UpdateSelectedPaths(resFolder.Select(x => x.TryGetLocalPath()).ToArray()!);
UpdateSelectedPaths(resFolder.Select(x => x.TryGetLocalPath()).ToArray());
break;
default:
throw new ArgumentOutOfRangeException();
@@ -298,9 +296,10 @@ public class PathPicker : TemplatedControl
}
}
private void UpdateSelectedPaths(IReadOnlyList<string> newList)
private void UpdateSelectedPaths(IReadOnlyList<string?> newList)
{
if (newList.Count != 0 || IsClearSelectionOnCancel && newList.Count == 0)
SelectedPaths = newList;
var nonNullList = newList.Where(x => x is not null).Select(x => x!).ToList();
if (nonNullList.Count != 0 || IsClearSelectionOnCancel && nonNullList.Count == 0)
SelectedPaths = nonNullList;
}
}

View File

@@ -7,7 +7,6 @@ using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.LogicalTree;
using Avalonia.Threading;
using Avalonia.VisualTree;
using HeadlessTest.Ursa.TestHelpers;
using Ursa.Controls;
using DatePicker = Ursa.Controls.DatePicker;
@@ -176,7 +175,7 @@ public class DatePickerTests
window.MouseDown(new Point(10, 10), MouseButton.Left);
Dispatcher.UIThread.RunJobs();
var popup = picker.GetTemplateChildOfType<Popup>(DatePicker.PART_Popup);
var calendar = popup.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
var calendar = popup?.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
calendar?.RaiseEvent(new CalendarDayButtonEventArgs(new DateTime(2025, 2, 17))
{ RoutedEvent = CalendarView.DateSelectedEvent });
Dispatcher.UIThread.RunJobs();
@@ -203,7 +202,7 @@ public class DatePickerTests
window.MouseDown(new Point(10, 10), MouseButton.Left);
Dispatcher.UIThread.RunJobs();
var popup = picker.GetTemplateChildOfType<Popup>(DatePicker.PART_Popup);
var calendar = popup.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
var calendar = popup?.GetLogicalDescendants().OfType<CalendarView>().FirstOrDefault();
calendar?.RaiseEvent(new CalendarDayButtonEventArgs(new DateTime(2025, 2, 17))
{ RoutedEvent = CalendarView.DateSelectedEvent });
Dispatcher.UIThread.RunJobs();
@@ -270,13 +269,13 @@ public class DatePickerTests
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top
};
var focustextBox = new TextBox();
var focusTextBox = new TextBox();
window.Content = new StackPanel()
{
Children =
{
picker,
focustextBox,
focusTextBox,
}
};
window.Show();
@@ -289,7 +288,7 @@ public class DatePickerTests
Dispatcher.UIThread.RunJobs();
Assert.Equal(new DateTime(2025, 2, 18), picker.SelectedDate);
textBox?.SetValue(TextBox.TextProperty, "2025-02-18-");
focustextBox.Focus();
focusTextBox.Focus();
Dispatcher.UIThread.RunJobs();
Assert.Null(picker.SelectedDate);
}
@@ -356,7 +355,6 @@ public class DatePickerTests
var position = nextButton.TranslatePoint(new Point(5, 5), window);
Assert.NotNull(position);
window.MouseDown(new Point(10, 10), MouseButton.Left);
var renderRoot = popup.GetVisualRoot();
Dispatcher.UIThread.RunJobs();
Assert.True(picker.IsDropdownOpen);

View File

@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Avalonia.Headless.XUnit;
using Avalonia.Threading;
using Avalonia.VisualTree;
using Ursa.Controls;
@@ -17,11 +16,13 @@ public class DrawerCloseEventTest
};
testWindow.Show();
DrawerCloseTestPopupControl level1 = new();
OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root");
_ = OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root");
level1.OpenPopup();
var level2 = level1.Popup;
Assert.NotNull(level2);
level2.OpenPopup();
var level3 = level2.Popup;
Assert.NotNull(level3);
level2.ClosePopup();
await Task.Delay(TimeSpan.FromSeconds(1));
Dispatcher.UIThread.RunJobs();
@@ -47,11 +48,13 @@ public class DrawerCloseEventTest
Assert.Equal(level2.LResult, level2.RResult);
Assert.Equal(level3.LResult, level3.RResult);
OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root");
_ = OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root");
level1.OpenPopup();
level2 = level1.Popup;
Assert.NotNull(level2);
level2.OpenPopup();
level3 = level2.Popup;
Assert.NotNull(level3);
level3.OpenPopup();
level1.Close();
await Task.Delay(TimeSpan.FromSeconds(1));

View File

@@ -1,11 +1,4 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Controls;
using Ursa.Controls;
namespace HeadlessTest.Ursa.Controls;
@@ -19,7 +12,7 @@ public partial class DrawerCloseTestPopupControl : UserControl
}
private readonly string _hostid = Path.GetRandomFileName();
public DrawerCloseTestPopupControl Popup { get; set; }
public DrawerCloseTestPopupControl? Popup { get; set; }
public int LResult { get; set; }
public int RResult { get; set; }
@@ -32,7 +25,7 @@ public partial class DrawerCloseTestPopupControl : UserControl
public void ClosePopup()
{
(Popup.DataContext as DrawerCloseTestPopupControlVM)?.Close();
(Popup?.DataContext as DrawerCloseTestPopupControlVM)?.Close();
}

View File

@@ -29,7 +29,7 @@ public class DrawerMeasureTest
};
window.Show();
Dispatcher.UIThread.RunJobs();
Drawer.ShowModal(textBlock, "hello world", null,
_ = Drawer.ShowModal(textBlock, "hello world", null,
new DrawerOptions { Position = position, TopLevelHashCode = window.GetHashCode() });
await Task.Delay(TimeSpan.FromSeconds(0.1));
var dialogControl = window.GetVisualDescendants().OfType<DefaultDrawerControl>().SingleOrDefault();
@@ -57,7 +57,6 @@ public class DrawerMeasureTest
};
window.Show();
Dispatcher.UIThread.RunJobs();
var d = window.GetVisualDescendants().ToList();
Drawer.ShowCustom(textBlock, "hello world", null,
new DrawerOptions { Position = position, TopLevelHashCode = window.GetHashCode() });
await Task.Delay(TimeSpan.FromSeconds(0.1));

View File

@@ -403,7 +403,8 @@ public class PaginationTests
window.Show();
Dispatcher.UIThread.RunJobs();
var buttonsPanel = pagination.GetTemplateChildOfType<Panel>(Pagination.PART_ButtonPanel);
var buttons = buttonsPanel.Children.OfType<PaginationButton>().ToList();
var buttons = buttonsPanel?.Children.OfType<PaginationButton>().ToList();
Assert.NotNull(buttons);
buttons[0].RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
Dispatcher.UIThread.RunJobs();
Assert.Equal(1, count);