Skip to content

Commit

Permalink
Merge pull request #591 from irihitech/clean
Browse files Browse the repository at this point in the history
Clean up warning and non-library issues
  • Loading branch information
rabbitism authored Feb 27, 2025
2 parents bb6d457 + 2b34418 commit 3cf4fa0
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 233 deletions.
370 changes: 186 additions & 184 deletions demo/Ursa.Demo/Pages/DialogDemo.axaml

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions src/Ursa/Controls/IPv4Box/IPv4BoxInputMethodClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,21 @@

namespace Ursa.Controls;

public class IPv4BoxInputMethodClient:TextInputMethodClient
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();
}
}
6 changes: 4 additions & 2 deletions src/Ursa/Controls/Marquee/Marquee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ public double Speed
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);
Expand Down Expand Up @@ -177,11 +177,13 @@ protected override Size MeasureOverride(Size availableSize)
{
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;
Expand Down
19 changes: 9 additions & 10 deletions src/Ursa/Controls/PathPicker/PathPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ private static FilePickerFileType ParseFilePickerType(string str)
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())
Expand Down Expand Up @@ -248,7 +248,7 @@ await storageProvider.TryGetFolderFromPathAsync(SuggestedStartPath),
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()
Expand All @@ -263,9 +263,7 @@ await storageProvider.TryGetFolderFromPathAsync(SuggestedStartPath),

var path = (await storageProvider.SaveFilePickerAsync(filePickerSaveOptions))
?.TryGetLocalPath();
UpdateSelectedPaths(string.IsNullOrEmpty(path)
? Array.Empty<string>()
: [path]);
UpdateSelectedPaths([path]);
break;
case UsePickerTypes.OpenFolder:
FolderPickerOpenOptions folderPickerOpenOptions = new()
Expand All @@ -277,7 +275,7 @@ await storageProvider.TryGetFolderFromPathAsync(SuggestedStartPath),
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();
Expand All @@ -298,9 +296,10 @@ await storageProvider.TryGetFolderFromPathAsync(SuggestedStartPath),
}
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Avalonia.Layout;
using Avalonia.LogicalTree;
using Avalonia.Threading;
using Avalonia.VisualTree;
using HeadlessTest.Ursa.TestHelpers;
using Ursa.Controls;
using DatePicker = Ursa.Controls.DatePicker;
Expand Down Expand Up @@ -176,7 +175,7 @@ public void SelectedDate_Set_TextBox_Text()
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();
Expand All @@ -203,7 +202,7 @@ public void Set_SelectedDate_To_Null_Clears_TextBox()
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();
Expand Down Expand Up @@ -270,13 +269,13 @@ public void Set_Invalid_TextBox_Text_Clears_SelectedDate()
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top
};
var focustextBox = new TextBox();
var focusTextBox = new TextBox();
window.Content = new StackPanel()
{
Children =
{
picker,
focustextBox,
focusTextBox,
}
};
window.Show();
Expand All @@ -289,7 +288,7 @@ public void Set_Invalid_TextBox_Text_Clears_SelectedDate()
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);
}
Expand Down Expand Up @@ -356,7 +355,6 @@ public void Click_On_Popup_Will_Not_Close_Popup()
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Avalonia.Headless.XUnit;
using Avalonia.Threading;
using Avalonia.VisualTree;
using Ursa.Controls;
Expand All @@ -17,11 +16,13 @@ public async void Test()
};
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();
Expand All @@ -47,11 +48,13 @@ public async void Test()
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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,7 +12,7 @@ public DrawerCloseTestPopupControl()
}

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; }

Expand All @@ -32,7 +25,7 @@ public async void OpenPopup()

public void ClosePopup()
{
(Popup.DataContext as DrawerCloseTestPopupControlVM)?.Close();
(Popup?.DataContext as DrawerCloseTestPopupControlVM)?.Close();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async void Default_Drawer_Is_Constrained_When_Content_Is_Large(Position p
};
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();
Expand Down Expand Up @@ -57,7 +57,6 @@ public async void Custom_Drawer_Is_Constrained_When_Content_Is_Large(Position po
};
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ public void Button_Panel_Button_Triggers_Command()
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);
Expand Down

0 comments on commit 3cf4fa0

Please sign in to comment.