Skip to content

Commit

Permalink
V2 fix warnings (gui-cs#3671)
Browse files Browse the repository at this point in the history
* Fixed NumericUpDown warning

* Fixed Aot Warning

* Fixed warnings in Application.cs

* Fixed more NumericUpDown warning

* Fixed CommandImpl warning

* Fixed Thickness warnings

* Fixed Label warning

* Fixed warning

* Fixed menubar test warning

* Fixed warnings

* Fixed warnings

* Removed dead code

* Fixed warnings
  • Loading branch information
tig authored Aug 19, 2024
1 parent a0c03b1 commit b267e16
Show file tree
Hide file tree
Showing 17 changed files with 5,783 additions and 5,809 deletions.
4 changes: 2 additions & 2 deletions NativeAot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ private static void Main (string [] args)

#region The code in this region is not intended for use in a native Aot self-contained. It's just here to make sure there is no functionality break with localization in Terminal.Gui using self-contained

if (Equals(Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture) && Application.SupportedCultures.Count == 0)
if (Equals(Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture) && Application.SupportedCultures!.Count == 0)
{
// Only happens if the project has <InvariantGlobalization>true</InvariantGlobalization>
Debug.Assert (Application.SupportedCultures.Count == 0);
}
else
{
Debug.Assert (Application.SupportedCultures.Count > 0);
Debug.Assert (Application.SupportedCultures!.Count > 0);
Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture));
}

Expand Down
33 changes: 3 additions & 30 deletions Terminal.Gui/Application/Application.Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static bool OnKeyDown (Key keyEvent)

foreach (Command command in appBinding.Commands)
{
if (!CommandImplementations.ContainsKey (command))
if (!CommandImplementations!.ContainsKey (command))
{
throw new NotSupportedException (
@$"A KeyBinding was set up for the command {command} ({keyEvent}) but that command is not supported by Application."
Expand Down Expand Up @@ -274,7 +274,7 @@ public static bool OnKeyUp (Key a)
/// <summary>
/// Commands for Application.
/// </summary>
private static Dictionary<Command, Func<CommandContext, bool?>> CommandImplementations { get; set; }
private static Dictionary<Command, Func<CommandContext, bool?>>? CommandImplementations { get; set; }

/// <summary>
/// <para>
Expand All @@ -292,7 +292,7 @@ public static bool OnKeyUp (Key a)
/// </remarks>
/// <param name="command">The command.</param>
/// <param name="f">The function.</param>
private static void AddCommand (Command command, Func<bool?> f) { CommandImplementations [command] = ctx => f (); }
private static void AddCommand (Command command, Func<bool?> f) { CommandImplementations! [command] = ctx => f (); }

static Application () { AddApplicationKeyBindings (); }

Expand Down Expand Up @@ -432,31 +432,4 @@ internal static List<KeyBinding> GetViewKeyBindings ()
.Distinct ()
.ToList ();
}

///// <summary>
///// Gets the list of Views that have <see cref="KeyBindingScope.Application"/> key bindings for the specified key.
///// </summary>
///// <remarks>
///// This is an internal method used by the <see cref="View"/> class to add Application key bindings.
///// </remarks>
///// <param name="key">The key to check.</param>
///// <param name="views">Outputs the list of views bound to <paramref name="key"/></param>
///// <returns><see langword="True"/> if successful.</returns>
//internal static bool TryGetKeyBindings (Key key, out List<View> views) { return _keyBindings.TryGetValue (key, out views); }

/// <summary>
/// Removes all <see cref="KeyBindingScope.Application"/> scoped key bindings for the specified view.
/// </summary>
/// <remarks>
/// This is an internal method used by the <see cref="View"/> class to remove Application key bindings.
/// </remarks>
/// <param name="view">The view that is bound to the key.</param>
internal static void RemoveKeyBindings (View view)
{
List<KeyBinding> list = KeyBindings.Bindings
.Where (kv => kv.Value.Scope != KeyBindingScope.Application)
.Select (kv => kv.Value)
.Distinct ()
.ToList ();
}
}
12 changes: 8 additions & 4 deletions Terminal.Gui/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static partial class Application
/// <returns>A string representation of the Application </returns>
public new static string ToString ()
{
ConsoleDriver driver = Driver;
ConsoleDriver? driver = Driver;

if (driver is null)
{
Expand All @@ -47,13 +47,17 @@ public static partial class Application
/// </summary>
/// <param name="driver">The driver to use to render the contents.</param>
/// <returns>A string representation of the Application </returns>
public static string ToString (ConsoleDriver driver)
public static string ToString (ConsoleDriver? driver)
{
if (driver is null)
{
return string.Empty;
}
var sb = new StringBuilder ();

Cell [,] contents = driver.Contents;
Cell [,] contents = driver?.Contents!;

for (var r = 0; r < driver.Rows; r++)
for (var r = 0; r < driver!.Rows; r++)
{
for (var c = 0; c < driver.Cols; c++)
{
Expand Down
8 changes: 4 additions & 4 deletions Terminal.Gui/Drawing/Thickness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Thickness (int left, int top, int right, int bottom)
[JsonInclude]
public int Bottom
{
get => (int)_sides.W;
readonly get => (int)_sides.W;
set => _sides.W = value;
}

Expand Down Expand Up @@ -249,7 +249,7 @@ public int Horizontal
[JsonInclude]
public int Left
{
get => (int)_sides.X;
readonly get => (int)_sides.X;
set => _sides.X = value;
}

Expand All @@ -265,15 +265,15 @@ public int Left
[JsonInclude]
public int Right
{
get => (int)_sides.Z;
readonly get => (int)_sides.Z;
set => _sides.Z = value;
}

/// <summary>Gets or sets the width of the upper side of the rectangle.</summary>
[JsonInclude]
public int Top
{
get => (int)_sides.Y;
readonly get => (int)_sides.Y;
set => _sides.Y = value;
}

Expand Down
1 change: 0 additions & 1 deletion Terminal.Gui/View/View.Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private void SetupKeyboard ()
private void DisposeKeyboard ()
{
TitleTextFormatter.HotKeyChanged -= TitleTextFormatter_HotKeyChanged;
Application.RemoveKeyBindings (this);
}

#region HotKey Support
Expand Down
4 changes: 2 additions & 2 deletions Terminal.Gui/Views/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public override Rune HotKeySpecifier
set => TextFormatter.HotKeySpecifier = base.HotKeySpecifier = value;
}

private new bool? FocusNext ()
private bool? FocusNext ()
{
var me = SuperView?.Subviews.IndexOf (this) ?? -1;
int me = SuperView?.Subviews.IndexOf (this) ?? -1;
if (me != -1 && me < SuperView?.Subviews.Count - 1)
{
SuperView?.Subviews [me + 1].SetFocus ();
Expand Down
13 changes: 7 additions & 6 deletions Terminal.Gui/Views/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public NumericUpDown ()
return false;
}

if (Value is { })
if (Value is { } && Increment is { })
{
Value = (dynamic)Value + (dynamic)Increment;
}
Expand All @@ -117,11 +117,12 @@ public NumericUpDown ()
return false;
}

if (Value is { })
if (Value is { } && Increment is { })
{
Value = (dynamic)Value - (dynamic)Increment;
}


return true;
});

Expand Down Expand Up @@ -218,23 +219,23 @@ private void SetText ()
Text = _number.Text;
}

private T _increment;
private T? _increment;

/// <summary>
/// </summary>
public T Increment
public T? Increment
{
get => _increment;
set
{
if ((dynamic)_increment == (dynamic)value)
if (_increment is { } && value is { } && (dynamic)_increment == (dynamic)value)
{
return;
}

_increment = value;

IncrementChanged?.Invoke (this, new (value));
IncrementChanged?.Invoke (this, new (value!));
}
}

Expand Down
4 changes: 3 additions & 1 deletion UICatalog/Scenarios/ListViewWithSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ public bool IsMarked (int item)

return false;
}

#pragma warning disable CS0067
/// <inheritdoc />
public event NotifyCollectionChangedEventHandler CollectionChanged;
#pragma warning restore CS0067

public int Count => Scenarios?.Count ?? 0;
public int Length { get; private set; }
public bool SuspendCollectionChangedEvent { get => throw new System.NotImplementedException (); set => throw new System.NotImplementedException (); }
Expand Down
2 changes: 1 addition & 1 deletion UICatalog/UICatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public UICatalogTopLevel ()
Add (CategoryList);
Add (ScenarioList);

Add (MenuBar);
Add (MenuBar!);

if (StatusBar is { })
{
Expand Down
2 changes: 2 additions & 0 deletions UnitTests/Configuration/ConfigurationMangerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public void TestConfigProperties ()
)
);

#pragma warning disable xUnit2029
Assert.Empty (
Settings.Where (
cp => cp.Value.PropertyInfo!.GetCustomAttribute (
Expand All @@ -397,6 +398,7 @@ public void TestConfigProperties ()
== null
)
);
#pragma warning restore xUnit2029

// Application is a static class
PropertyInfo pi = typeof (Application).GetProperty ("QuitKey");
Expand Down
Loading

0 comments on commit b267e16

Please sign in to comment.