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" x:DataType="vm:DialogDemoViewModel"
mc:Ignorable="d"> mc:Ignorable="d">
<Grid ColumnDefinitions="Auto, *"> <Grid ColumnDefinitions="Auto, *">
<ScrollViewer>
<TabControl Grid.Column="0" TabStripPlacement="Left"> <TabControl Grid.Column="0" TabStripPlacement="Left">
<TabItem Header="Default Window Dialog"> <TabItem Header="Default Window Dialog">
<u:Form <u:Form
@@ -56,10 +57,10 @@
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="Style Class" /> <TextBlock Text="Style Class" />
<PathIcon <PathIcon
Theme="{StaticResource InnerPathIcon}"
VerticalAlignment="Center" VerticalAlignment="Center"
TextElement.FontWeight="Normal"
Data="{DynamicResource SemiIconHelpCircle}" 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" /> 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> </StackPanel>
</u:FormItem.Label> </u:FormItem.Label>
@@ -147,10 +148,10 @@
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="Style Class" /> <TextBlock Text="Style Class" />
<PathIcon <PathIcon
Theme="{StaticResource InnerPathIcon}"
VerticalAlignment="Center" VerticalAlignment="Center"
TextElement.FontWeight="Normal"
Data="{DynamicResource SemiIconHelpCircle}" 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" /> 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> </StackPanel>
</u:FormItem.Label> </u:FormItem.Label>
@@ -195,10 +196,11 @@
</u:Form> </u:Form>
</TabItem> </TabItem>
</TabControl> </TabControl>
</ScrollViewer>
<Grid Grid.Column="1"> <Grid Grid.Column="1">
<Border <Border
BorderBrush="{DynamicResource SemiGrey1}"
Background="{DynamicResource SemiColorBackground1}" Background="{DynamicResource SemiColorBackground1}"
BorderBrush="{DynamicResource SemiGrey1}"
BorderThickness="1" BorderThickness="1"
ClipToBounds="True" ClipToBounds="True"
CornerRadius="12"> CornerRadius="12">

View File

@@ -4,28 +4,21 @@ using Avalonia.Input.TextInput;
namespace Ursa.Controls; namespace Ursa.Controls;
public class IPv4BoxInputMethodClient:TextInputMethodClient public class IPv4BoxInputMethodClient: TextInputMethodClient
{ {
private TextPresenter? _presenter; private TextPresenter? _presenter;
public override Visual TextViewVisual => _presenter; public override Visual TextViewVisual => _presenter!;
public override bool SupportsPreedit => false; public override bool SupportsPreedit => false;
public override bool SupportsSurroundingText => true; public override bool SupportsSurroundingText => true;
public override string SurroundingText public override string SurroundingText { get; } = null!;
{
get; public override Rect CursorRectangle { get; } = new();
}
public override Rect CursorRectangle { get; }
public override TextSelection Selection { get; set; } public override TextSelection Selection { get; set; }
private IPv4Box? _parent;
public void SetPresenter(TextPresenter? presenter) public void SetPresenter(TextPresenter? presenter)
{ {
_presenter = presenter;
this.RaiseTextViewVisualChanged(); this.RaiseTextViewVisualChanged();
this.RaiseCursorRectangleChanged(); 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); set => SetValue(SpeedProperty, value);
} }
private void OnPresenterSizeChanged(object sender, SizeChangedEventArgs e) private void OnPresenterSizeChanged(object? sender, SizeChangedEventArgs e)
{ {
InvalidatePresenterPosition(); InvalidatePresenterPosition();
} }
private void TimerOnTick(object sender, System.EventArgs e) private void TimerOnTick(object? sender, System.EventArgs e)
{ {
if (Presenter is null) return; if (Presenter is null) return;
var layoutValues = Dispatcher.UIThread.Invoke(GetLayoutValues); 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.Up or Direction.Down => GetHorizontalOffset(values.Bounds, values.PresenterSize, values.HorizontalAlignment),
Direction.Left or Direction.Right => values.Left, Direction.Left or Direction.Right => values.Left,
_ => throw new NotImplementedException(),
}; };
var verticalOffset = values.Direction switch var verticalOffset = values.Direction switch
{ {
Direction.Up or Direction.Down => values.Top, Direction.Up or Direction.Down => values.Top,
Direction.Left or Direction.Right => GetVerticalOffset(values.Bounds, values.PresenterSize, values.VerticalAlignment), Direction.Left or Direction.Right => GetVerticalOffset(values.Bounds, values.PresenterSize, values.VerticalAlignment),
_ => throw new NotImplementedException(),
}; };
if (horizontalOffset is double.NaN) horizontalOffset = 0.0; if (horizontalOffset is double.NaN) horizontalOffset = 0.0;
if (verticalOffset is double.NaN) verticalOffset = 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.ImagePng) => FilePickerFileTypes.ImagePng,
nameof(FilePickerFileTypes.ImageWebp) => FilePickerFileTypes.ImageWebp, nameof(FilePickerFileTypes.ImageWebp) => FilePickerFileTypes.ImageWebp,
nameof(FilePickerFileTypes.TextPlain) => FilePickerFileTypes.TextPlain, nameof(FilePickerFileTypes.TextPlain) => FilePickerFileTypes.TextPlain,
_ => parse() _ => Parse()
}; };
FilePickerFileType parse() FilePickerFileType Parse()
{ {
var list = str.Split(','); var list = str.Split(',');
return new FilePickerFileType(list.First()) return new FilePickerFileType(list.First())
@@ -248,7 +248,7 @@ public class PathPicker : TemplatedControl
FileTypeFilter = ParseFileTypes(FileFilter) FileTypeFilter = ParseFileTypes(FileFilter)
}; };
var resFiles = await storageProvider.OpenFilePickerAsync(filePickerOpenOptions); var resFiles = await storageProvider.OpenFilePickerAsync(filePickerOpenOptions);
UpdateSelectedPaths(resFiles.Select(x => x.TryGetLocalPath()).ToArray()!); UpdateSelectedPaths(resFiles.Select(x => x.TryGetLocalPath()).ToArray());
break; break;
case UsePickerTypes.SaveFile: case UsePickerTypes.SaveFile:
FilePickerSaveOptions filePickerSaveOptions = new() FilePickerSaveOptions filePickerSaveOptions = new()
@@ -263,9 +263,7 @@ public class PathPicker : TemplatedControl
var path = (await storageProvider.SaveFilePickerAsync(filePickerSaveOptions)) var path = (await storageProvider.SaveFilePickerAsync(filePickerSaveOptions))
?.TryGetLocalPath(); ?.TryGetLocalPath();
UpdateSelectedPaths(string.IsNullOrEmpty(path) UpdateSelectedPaths([path]);
? Array.Empty<string>()
: [path]);
break; break;
case UsePickerTypes.OpenFolder: case UsePickerTypes.OpenFolder:
FolderPickerOpenOptions folderPickerOpenOptions = new() FolderPickerOpenOptions folderPickerOpenOptions = new()
@@ -277,7 +275,7 @@ public class PathPicker : TemplatedControl
SuggestedFileName = SuggestedFileName SuggestedFileName = SuggestedFileName
}; };
var resFolder = await storageProvider.OpenFolderPickerAsync(folderPickerOpenOptions); var resFolder = await storageProvider.OpenFolderPickerAsync(folderPickerOpenOptions);
UpdateSelectedPaths(resFolder.Select(x => x.TryGetLocalPath()).ToArray()!); UpdateSelectedPaths(resFolder.Select(x => x.TryGetLocalPath()).ToArray());
break; break;
default: default:
throw new ArgumentOutOfRangeException(); 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) var nonNullList = newList.Where(x => x is not null).Select(x => x!).ToList();
SelectedPaths = newList; if (nonNullList.Count != 0 || IsClearSelectionOnCancel && nonNullList.Count == 0)
SelectedPaths = nonNullList;
} }
} }

View File

@@ -7,7 +7,6 @@ using Avalonia.Input;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.Threading; using Avalonia.Threading;
using Avalonia.VisualTree;
using HeadlessTest.Ursa.TestHelpers; using HeadlessTest.Ursa.TestHelpers;
using Ursa.Controls; using Ursa.Controls;
using DatePicker = Ursa.Controls.DatePicker; using DatePicker = Ursa.Controls.DatePicker;
@@ -176,7 +175,7 @@ public class DatePickerTests
window.MouseDown(new Point(10, 10), MouseButton.Left); window.MouseDown(new Point(10, 10), MouseButton.Left);
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
var popup = picker.GetTemplateChildOfType<Popup>(DatePicker.PART_Popup); 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)) calendar?.RaiseEvent(new CalendarDayButtonEventArgs(new DateTime(2025, 2, 17))
{ RoutedEvent = CalendarView.DateSelectedEvent }); { RoutedEvent = CalendarView.DateSelectedEvent });
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
@@ -203,7 +202,7 @@ public class DatePickerTests
window.MouseDown(new Point(10, 10), MouseButton.Left); window.MouseDown(new Point(10, 10), MouseButton.Left);
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
var popup = picker.GetTemplateChildOfType<Popup>(DatePicker.PART_Popup); 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)) calendar?.RaiseEvent(new CalendarDayButtonEventArgs(new DateTime(2025, 2, 17))
{ RoutedEvent = CalendarView.DateSelectedEvent }); { RoutedEvent = CalendarView.DateSelectedEvent });
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
@@ -270,13 +269,13 @@ public class DatePickerTests
HorizontalAlignment = HorizontalAlignment.Left, HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top VerticalAlignment = VerticalAlignment.Top
}; };
var focustextBox = new TextBox(); var focusTextBox = new TextBox();
window.Content = new StackPanel() window.Content = new StackPanel()
{ {
Children = Children =
{ {
picker, picker,
focustextBox, focusTextBox,
} }
}; };
window.Show(); window.Show();
@@ -289,7 +288,7 @@ public class DatePickerTests
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
Assert.Equal(new DateTime(2025, 2, 18), picker.SelectedDate); Assert.Equal(new DateTime(2025, 2, 18), picker.SelectedDate);
textBox?.SetValue(TextBox.TextProperty, "2025-02-18-"); textBox?.SetValue(TextBox.TextProperty, "2025-02-18-");
focustextBox.Focus(); focusTextBox.Focus();
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
Assert.Null(picker.SelectedDate); Assert.Null(picker.SelectedDate);
} }
@@ -356,7 +355,6 @@ public class DatePickerTests
var position = nextButton.TranslatePoint(new Point(5, 5), window); var position = nextButton.TranslatePoint(new Point(5, 5), window);
Assert.NotNull(position); Assert.NotNull(position);
window.MouseDown(new Point(10, 10), MouseButton.Left); window.MouseDown(new Point(10, 10), MouseButton.Left);
var renderRoot = popup.GetVisualRoot();
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
Assert.True(picker.IsDropdownOpen); 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.Threading;
using Avalonia.VisualTree; using Avalonia.VisualTree;
using Ursa.Controls; using Ursa.Controls;
@@ -17,11 +16,13 @@ public class DrawerCloseEventTest
}; };
testWindow.Show(); testWindow.Show();
DrawerCloseTestPopupControl level1 = new(); DrawerCloseTestPopupControl level1 = new();
OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root"); _ = OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root");
level1.OpenPopup(); level1.OpenPopup();
var level2 = level1.Popup; var level2 = level1.Popup;
Assert.NotNull(level2);
level2.OpenPopup(); level2.OpenPopup();
var level3 = level2.Popup; var level3 = level2.Popup;
Assert.NotNull(level3);
level2.ClosePopup(); level2.ClosePopup();
await Task.Delay(TimeSpan.FromSeconds(1)); await Task.Delay(TimeSpan.FromSeconds(1));
Dispatcher.UIThread.RunJobs(); Dispatcher.UIThread.RunJobs();
@@ -47,11 +48,13 @@ public class DrawerCloseEventTest
Assert.Equal(level2.LResult, level2.RResult); Assert.Equal(level2.LResult, level2.RResult);
Assert.Equal(level3.LResult, level3.RResult); Assert.Equal(level3.LResult, level3.RResult);
OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root"); _ = OverlayDialog.ShowCustomModal<object>(level1, new DrawerCloseTestPopupControlVM(), "root");
level1.OpenPopup(); level1.OpenPopup();
level2 = level1.Popup; level2 = level1.Popup;
Assert.NotNull(level2);
level2.OpenPopup(); level2.OpenPopup();
level3 = level2.Popup; level3 = level2.Popup;
Assert.NotNull(level3);
level3.OpenPopup(); level3.OpenPopup();
level1.Close(); level1.Close();
await Task.Delay(TimeSpan.FromSeconds(1)); await Task.Delay(TimeSpan.FromSeconds(1));

View File

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

View File

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

View File

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