Skip to content

Commit

Permalink
Merge pull request #400 from AvaloniaCommunity/warningsCleanup
Browse files Browse the repository at this point in the history
Add nullability to many places in Material.Avalonia.Dialogs, resolves warnings
  • Loading branch information
SKProCH authored Sep 7, 2024
2 parents 2f1deda + c64e7e2 commit 0e584d0
Show file tree
Hide file tree
Showing 41 changed files with 113 additions and 133 deletions.
7 changes: 4 additions & 3 deletions Material.Avalonia.Demo.Browser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Browser;
using Material.Avalonia.Demo;
using ShowMeTheXaml;

[assembly: SupportedOSPlatform("browser")]

internal sealed partial class Program
namespace Material.Avalonia.Demo.Browser;

internal static class Program
{
private static Task Main(string[] args) => BuildAvaloniaApp()
private static Task Main() => BuildAvaloniaApp()
.StartBrowserAppAsync("out");

public static AppBuilder BuildAvaloniaApp()
Expand Down
3 changes: 1 addition & 2 deletions Material.Avalonia.Demo.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using Avalonia;
using Material.Avalonia.Demo;
using ShowMeTheXaml;

namespace Material.Demo {
namespace Material.Avalonia.Demo.Desktop {
internal class Program {
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
Expand Down
2 changes: 0 additions & 2 deletions Material.Avalonia.Demo/App.axaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:themes="clr-namespace:Material.Styles.Themes;assembly=Material.Styles"
xmlns:showMeTheXaml="clr-namespace:ShowMeTheXaml;assembly=ShowMeTheXaml.Avalonia"
xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:grammars="clr-namespace:TextMateSharp.Grammars;assembly=TextMateSharp.Grammars"
xmlns:avaloniaEdit="clr-namespace:ShowMeTheXaml.Avalonia.AvaloniaEdit;assembly=ShowMeTheXaml.Avalonia.AvaloniaEdit"
x:Class="Material.Avalonia.Demo.App">
<Application.Resources>
<FontFamily x:Key="ContentControlThemeFontFamily">fonts:Inter#Inter, $Default</FontFamily>
Expand Down
3 changes: 1 addition & 2 deletions Material.Avalonia.Demo/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
xmlns:models="clr-namespace:Material.Avalonia.Demo.Models"
xmlns:pages="clr-namespace:Material.Avalonia.Demo.Pages"
xmlns:pages1="clr-namespace:Material.Demo.Pages"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Material.Avalonia.Demo.MainView">
<UserControl.Styles>
Expand Down Expand Up @@ -191,7 +190,7 @@
<pages:DialogDemo />

<!-- Snackbar -->
<pages1:SnackbarDemo />
<pages:SnackbarDemo />

<!-- ScrollViewer -->
<pages:ScrollViewerDemo />
Expand Down
3 changes: 0 additions & 3 deletions Material.Avalonia.Demo/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using Material.Styles.Controls;
using Material.Styles.Models;
Expand All @@ -15,8 +14,6 @@
namespace Material.Avalonia.Demo;

public partial class MainView : UserControl {
private readonly List<SnackbarModel> helloSnackBars = new();

public MainView() {
InitializeComponent();
DrawerList.PointerReleased += DrawerSelectionChanged;
Expand Down
8 changes: 0 additions & 8 deletions Material.Avalonia.Demo/Pages/SideSheetDemo.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ public SideSheetDemo() {
InitializeComponent();
}

private void CloseSideInfoButton_OnClick(object? sender, RoutedEventArgs e) {
var vm = DataContext as SideSheetDemoViewModel;
if (vm == null)
return;

vm.SideInfoOpened = false;
}

private void OpenSideInfoButton_OnClick(object? sender, RoutedEventArgs e) {
var vm = DataContext as SideSheetDemoViewModel;
if (vm == null)
Expand Down
2 changes: 1 addition & 1 deletion Material.Avalonia.Demo/Pages/SnackbarDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles"
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
xmlns:showMeTheXaml="clr-namespace:ShowMeTheXaml;assembly=ShowMeTheXaml.Avalonia"
x:Class="Material.Demo.Pages.SnackbarDemo">
x:Class="Material.Avalonia.Demo.Pages.SnackbarDemo">
<StackPanel VerticalAlignment="Top">
<showMeTheXaml:XamlDisplay UniqueId="Snackbar1">
<controls:Card Height="200">
Expand Down
2 changes: 1 addition & 1 deletion Material.Avalonia.Demo/Pages/SnackbarDemo.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Material.Styles.Controls;
using Material.Styles.Models;

namespace Material.Demo.Pages;
namespace Material.Avalonia.Demo.Pages;

public partial class SnackbarDemo : UserControl {
private int _actionCount;
Expand Down
2 changes: 1 addition & 1 deletion Material.Avalonia.Demo/Pages/TogglesDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
<ToggleButton Theme="{StaticResource MaterialFlatButton}">
<TextBlock>
<Run>Button's ControlThemes if you don't want pressed state: </Run>
<Run Text="{Binding $parent[ToggleButton].IsChecked}"></Run>
<Run Text="{Binding $parent[ToggleButton].IsChecked}" />
</TextBlock>
</ToggleButton>
</showMeTheXaml:XamlDisplay>
Expand Down
2 changes: 1 addition & 1 deletion Material.Avalonia.Demo/ViewModels/RelayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void RaiseCanExecute() {

if (handler != null) {
// Call CanExecute via Dispatcher.UIThread.Post to prevent CanExecute can't be called from other thread.
Dispatcher.UIThread.Post(delegate { handler?.Invoke(this, new EventArgs()); });
Dispatcher.UIThread.Post(delegate { handler.Invoke(this, EventArgs.Empty); });
}
}
}
4 changes: 2 additions & 2 deletions Material.Avalonia.Dialogs/Bases/DialogWindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DialogWindowBase(TWindow window)
/// Get window content. It most used for show dialog from other places.
/// </summary>
/// <returns>The content of dialog window.</returns>
public object GetContent() => _window.Content;
public object GetContent() => _window.Content!;

/// <summary>
/// Get window itself.
Expand Down Expand Up @@ -52,7 +52,7 @@ private Task<TResult> Procedure(Action action)
{
var tcs = new TaskCompletionSource<TResult>();

void OnceHandler(object sender, EventArgs args)
void OnceHandler(object? sender, EventArgs args)
{
tcs.TrySetResult(_window.GetResult());
_window.Closed -= OnceHandler;
Expand Down
10 changes: 5 additions & 5 deletions Material.Avalonia.Dialogs/Bases/DialogWindowBuilderParamsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class DialogWindowBuilderParamsBase
public string WindowTitle = "Warning";
public double? MaxWidth = null;
public double? Width = null;
public string ContentHeader = null;
public string SupportingText = null;
public string? ContentHeader = null;
public string? SupportingText = null;
public bool Borderless = false;
public WindowStartupLocation StartupLocation = WindowStartupLocation.CenterScreen;

Expand All @@ -24,19 +24,19 @@ public class DialogWindowBuilderParamsBase
/// <summary>
/// Specify <see cref="Avalonia.Media.Imaging.Bitmap"/>, <see cref="Avalonia.Controls.Control"/> or <see cref="DialogIconKind"/> for dialog header icon.
/// </summary>
public object DialogIcon = null;
public object? DialogIcon = null;

/// <summary>
/// Build dialog buttons stack (left side).
/// <br/>You can use <seealso cref="DialogHelper.CreateSimpleDialogButtons(Enums.DialogButtonsEnum)"/> for create buttons stack in easy way.
/// </summary>
public DialogButton[] NeutralDialogButtons;
public DialogButton[]? NeutralDialogButtons;

/// <summary>
/// Build dialog buttons stack.
/// <br/>You can use <seealso cref="DialogHelper.CreateSimpleDialogButtons(Enums.DialogButtonsEnum)"/> for create buttons stack in easy way.
/// </summary>
public DialogButton[] DialogButtons;
public DialogButton[]? DialogButtons;

/// <summary>
/// Define result after close the dialog not from buttons
Expand Down
17 changes: 8 additions & 9 deletions Material.Avalonia.Dialogs/Commands/MaterialDialogRelayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ namespace Material.Dialog.Commands {
/// If you want to use this one, you should copy all whole code and paste them to your new RelayCommand.cs source file.
/// </summary>
public class MaterialDialogRelayCommand : ICommand {
private readonly Func<object, bool> canExecute;
private readonly Action<object> execute;
private readonly Func<object?, bool>? canExecute;
private readonly Action<object?> execute;

public MaterialDialogRelayCommand(Action<object> execute, Func<object, bool> canExecute = null) {
public MaterialDialogRelayCommand(Action<object?> execute, Func<object?, bool>? canExecute = null) {
this.execute = execute;
this.canExecute = canExecute;
}
public event EventHandler CanExecuteChanged;
public event EventHandler? CanExecuteChanged;

public bool CanExecute(object parameter) {
var result = canExecute == null || canExecute(parameter);
return result;
public bool CanExecute(object? parameter) {
return canExecute == null || canExecute(parameter);
}

public void Execute(object parameter) {
public void Execute(object? parameter) {
execute(parameter);
}

Expand All @@ -32,7 +31,7 @@ public void RaiseCanExecute() {

if (handler != null) {
// Call CanExecute via Dispatcher.UIThread.Post to prevent CanExecute can't be called from other thread.
Dispatcher.UIThread.Post(delegate { handler?.Invoke(this, new EventArgs()); });
Dispatcher.UIThread.Post(delegate { handler?.Invoke(this, EventArgs.Empty); });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
namespace Material.Dialog.Converters {
public class StringToTransformConverter : IValueConverter {
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) {
if (value == null)
var stringValue = value?.ToString();
if (stringValue == null)
return TransformOperation.Identity;
var r = TransformOperations.Parse(value.ToString());
return r;
return TransformOperations.Parse(stringValue);
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) {
throw new NotImplementedException();
throw new NotSupportedException();
}
}
}
4 changes: 2 additions & 2 deletions Material.Avalonia.Dialogs/CustomDialogBuilderParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Material.Dialog
{
public class CustomDialogBuilderParams : DialogWindowBuilderParamsBase
{
public object Content = null;
public IDataTemplate ContentTemplate = null;
public object? Content = null;
public IDataTemplate? ContentTemplate = null;
}
}
8 changes: 4 additions & 4 deletions Material.Avalonia.Dialogs/DateTimePickerDialogResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ public class DateTimePickerDialogResult : IDialogResult {
// ReSharper disable once InconsistentNaming
internal TimeSpan _timeSpan;

internal string Result;
internal string? _result;
public DateTimePickerDialogResult() { }

public DateTimePickerDialogResult(string result, TimeSpan time) {
Result = result;
_result = result;
_timeSpan = time;
}

public DateTimePickerDialogResult(string result, DateTime date) {
Result = result;
_result = result;
_dateTime = date;
}
public string GetResult => Result;
public string? GetResult => _result;

/// <summary>
/// Get results of TimePicker.
Expand Down
4 changes: 2 additions & 2 deletions Material.Avalonia.Dialogs/DialogResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Material.Dialog {
public class DialogResult : IDialogResult {
private string result;
private string? result;


public DialogResult() { }
Expand All @@ -16,6 +16,6 @@ public DialogResult(string result) {
/// </summary>
public static DialogResult NoResult { get; private set; } = new() { result = "none" };

public virtual string GetResult => result;
public virtual string? GetResult => result;
}
}
13 changes: 5 additions & 8 deletions Material.Avalonia.Dialogs/Icons/DialogIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) {
}

private void UpdateData() {
string data = null;
DialogIconsDataFactory.DataIndex.Value?.TryGetValue(Kind, out data);
var g = StreamGeometry.Parse(data);
if (DialogIconsDataFactory.DataIndex.Value?.TryGetValue(Kind, out var data) != true) return;
var g = StreamGeometry.Parse(data!);
Data = g;
}

private void UpdateColor() {
if (UseRecommendColor) {
string color = null;
DialogIconsDataFactory.RecommendColorIndex.Value?.TryGetValue(Kind, out color);
Foreground = SolidColorBrush.Parse(color);
}
if (!UseRecommendColor) return;
if (DialogIconsDataFactory.RecommendColorIndex.Value?.TryGetValue(Kind, out var color) != true) return;
Foreground = SolidColorBrush.Parse(color!);
}
}
}
2 changes: 1 addition & 1 deletion Material.Avalonia.Dialogs/Interfaces/IDialogResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface IDialogResult
{
string GetResult { get; }
string? GetResult { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Material.Dialog.Resources
public class TemplateResources : ResourceDictionary
{
// ReSharper disable UnusedMember.Local
private void DialogButtonTemplate_OnSelectTemplateKey(object sender, SelectTemplateEventArgs e)
private void DialogButtonTemplate_OnSelectTemplateKey(object _, SelectTemplateEventArgs e)
{
e.TemplateKey = e.DataContext switch
{
Expand Down
10 changes: 5 additions & 5 deletions Material.Avalonia.Dialogs/TextFieldBuilderParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TextFieldBuilderParams {
};

//[Obsolete("Currently AvaloniaUI are not supported to binding classes, do not use this before they fixed this.")]
public string Classes;
public string? Classes;
public string DefaultText = "";

/// <summary>
Expand All @@ -26,17 +26,17 @@ public class TextFieldBuilderParams {
/// <p>Helper text conveys additional guidance about the input field, such as how it will be used. It should only take up a single line, being persistently visible or visible only on focus.</p>
/// Read <a href="https://material.io/components/text-fields#anatomy">Material Design documentations. Text fields anatomy. Assistive elements</a> for more information.
/// </summary>
public string HelperText = null;
public string? HelperText = null;

/// <summary>
/// Floating label text
/// </summary>
public string Label;
public string? Label;

public char MaskChar = '*';
public int MaxCountChars;

public string PlaceholderText = null;
public string? PlaceholderText = null;

/// <summary>
/// Define an data validate function, result using <see cref="Tuple{Boolean,String}"/>
Expand All @@ -45,6 +45,6 @@ public class TextFieldBuilderParams {
/// <br/><seealso cref="Tuple{Boolean,String}.Item2"/> is information about invalid field, should be string.
/// </list>
/// </summary>
public Func<string, Tuple<bool, string>> Validater;
public Func<string, Tuple<bool, string>>? Validater;
}
}
Loading

0 comments on commit 0e584d0

Please sign in to comment.