Skip to content

Commit

Permalink
Enabling nullable in KeyTip and KeyTipAdorner
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Nov 29, 2020
1 parent 9a35748 commit 8fc83c9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Directory.packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageVersion Include="JetBrains.Annotations" version="2020.3.0" />

<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" version="3.8.0" />
<PackageVersion Include="StyleCop.Analyzers" version="1.1.118" />
<PackageVersion Include="StyleCop.Analyzers" version="1.2.0-beta.261" />
<PackageVersion Include="WpfAnalyzers" version="3.2.0" />
</ItemGroup>
</Project>
52 changes: 29 additions & 23 deletions Fluent.Ribbon/Adorners/KeyTipAdorner.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
// ReSharper disable once CheckNamespace
namespace Fluent
{
Expand Down Expand Up @@ -25,7 +26,7 @@ public class KeyTipAdorner : Adorner
/// This event is occured when adorner is
/// detached and is not able to be attached again
/// </summary>
public event EventHandler<KeyTipPressedResult> Terminated;
public event EventHandler<KeyTipPressedResult>? Terminated;

#endregion

Expand All @@ -38,8 +39,8 @@ public class KeyTipAdorner : Adorner
private readonly FrameworkElement oneOfAssociatedElements;

// Parent adorner
private readonly KeyTipAdorner parentAdorner;
private KeyTipAdorner childAdorner;
private readonly KeyTipAdorner? parentAdorner;
private KeyTipAdorner? childAdorner;

private readonly FrameworkElement keyTipElementContainer;

Expand All @@ -50,7 +51,7 @@ public class KeyTipAdorner : Adorner
// Designate that this adorner is terminated
private bool terminated;

private AdornerLayer adornerLayer;
private AdornerLayer? adornerLayer;

#endregion

Expand All @@ -61,15 +62,15 @@ public class KeyTipAdorner : Adorner
/// </summary>
public bool IsAdornerChainAlive
{
get { return this.isAttaching || this.attached || (this.childAdorner != null && this.childAdorner.IsAdornerChainAlive); }
get { return this.isAttaching || this.attached || this.childAdorner?.IsAdornerChainAlive == true; }
}

/// <summary>
/// Returns whether any key tips are visibile.
/// </summary>
public bool AreAnyKeyTipsVisible
{
get { return this.keyTipInformations.Any(x => x.IsVisible) || (this.childAdorner != null && this.childAdorner.AreAnyKeyTipsVisible); }
get { return this.keyTipInformations.Any(x => x.IsVisible) || this.childAdorner?.AreAnyKeyTipsVisible == true; }
}

/// <summary>
Expand All @@ -79,9 +80,9 @@ public KeyTipAdorner ActiveKeyTipAdorner
{
get
{
return this.childAdorner != null && this.childAdorner.IsAdornerChainAlive
? this.childAdorner.ActiveKeyTipAdorner
: this;
return this.childAdorner?.IsAdornerChainAlive == true
? this.childAdorner.ActiveKeyTipAdorner
: this;
}
}

Expand Down Expand Up @@ -132,7 +133,8 @@ private void FindKeyTips(FrameworkElement container, bool hide)

var keys = KeyTip.GetKeys(child);

if (keys != null || child is IKeyTipInformationProvider)
if (keys is null == false
|| child is IKeyTipInformationProvider)
{
if (groupBox is null)
{
Expand All @@ -142,7 +144,10 @@ private void FindKeyTips(FrameworkElement container, bool hide)
continue;
}

this.GenerateAndAddGroupBoxKeyTipInformation(hide, keys, child, groupBox);
if (keys is null == false)
{
this.GenerateAndAddGroupBoxKeyTipInformation(hide, keys, child, groupBox);
}
}

var innerHide = hide || groupBox?.State == RibbonGroupBoxState.Collapsed;
Expand All @@ -160,20 +165,20 @@ private void GenerateAndAddGroupBoxKeyTipInformation(bool hide, string keys, Fra
this.LogDebug("Found KeyTipped RibbonGroupBox \"{0}\" with keys \"{1}\".", keyTipInformation.AssociatedElement, keyTipInformation.Keys);
}

private void GenerateAndAddRegularKeyTipInformations(string keys, FrameworkElement child, bool hide)
private void GenerateAndAddRegularKeyTipInformations(string? keys, FrameworkElement child, bool hide)
{
IEnumerable<KeyTipInformation> informations;
IEnumerable<KeyTipInformation>? informations = null;

if (child is IKeyTipInformationProvider keyTipInformationProvider)
{
informations = keyTipInformationProvider.GetKeyTipInformations(hide);
}
else
else if (keys is null == false)
{
informations = new[] { new KeyTipInformation(keys, child, hide) };
}

if (informations != null)
if (informations is null == false)
{
foreach (var keyTipInformation in informations)
{
Expand Down Expand Up @@ -298,7 +303,7 @@ public void Detach()
this.oneOfAssociatedElements.Loaded -= this.OnDelayAttach;

// Show this adorner
this.adornerLayer.Remove(this);
this.adornerLayer?.Remove(this);

this.attached = false;

Expand Down Expand Up @@ -336,7 +341,7 @@ public void Terminate(KeyTipPressedResult keyTipPressedResult)

#region Static Methods

private static AdornerLayer GetAdornerLayer(UIElement element)
private static AdornerLayer? GetAdornerLayer(UIElement element)
{
var current = element;

Expand Down Expand Up @@ -388,7 +393,7 @@ public void Back()
var control = this.keyTipElementContainer as IKeyTipedControl;
control?.OnKeyTipBack();

if (this.parentAdorner != null)
if (this.parentAdorner is null == false)
{
this.LogDebug("Back");
this.Detach();
Expand Down Expand Up @@ -588,11 +593,12 @@ private void UpdateKeyTipPositions()
return;
}

double[] rows = null;
double[]? rows = null;
var groupBox = this.oneOfAssociatedElements as RibbonGroupBox ?? UIHelper.GetParent<RibbonGroupBox>(this.oneOfAssociatedElements);
var panel = groupBox?.GetPanel();

if (panel != null)
if (panel is null == false
&& groupBox is null == false)
{
var height = groupBox.GetLayoutRoot().DesiredSize.Height;
rows = new[]
Expand All @@ -614,7 +620,7 @@ private void UpdateKeyTipPositions()

// Update KeyTip Visibility
var visualTargetIsVisible = keyTipInformation.VisualTarget.IsVisible;
var visualTargetInVisualTree = VisualTreeHelper.GetParent(keyTipInformation.VisualTarget) != null;
var visualTargetInVisualTree = VisualTreeHelper.GetParent(keyTipInformation.VisualTarget) is null == false;
keyTipInformation.Visibility = visualTargetIsVisible && visualTargetInVisualTree ? Visibility.Visible : Visibility.Collapsed;

keyTipInformation.KeyTip.Margin = KeyTip.GetMargin(keyTipInformation.AssociatedElement);
Expand Down Expand Up @@ -795,10 +801,10 @@ private static bool IsWithinRibbonToolbarInTwoLine(DependencyObject element)
// Determines whether the element is children to quick access toolbar
private static bool IsWithinQuickAccessToolbar(DependencyObject element)
{
return UIHelper.GetParent<QuickAccessToolBar>(element) != null;
return UIHelper.GetParent<QuickAccessToolBar>(element) is null == false;
}

private static void SnapToRowsIfPresent(double[] rows, KeyTipInformation keyTipInformation, Point translatedPoint)
private static void SnapToRowsIfPresent(double[]? rows, KeyTipInformation keyTipInformation, Point translatedPoint)
{
if (rows is null)
{
Expand Down
7 changes: 4 additions & 3 deletions Fluent.Ribbon/Controls/KeyTip.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
// ReSharper disable once CheckNamespace
namespace Fluent
{
Expand Down Expand Up @@ -28,7 +29,7 @@ private static void OnKeysChanged(DependencyObject d, DependencyPropertyChangedE
/// </summary>
/// <param name="element">The given element</param>
/// <param name="value">Value</param>
public static void SetKeys(DependencyObject element, string value)
public static void SetKeys(DependencyObject element, string? value)
{
element.SetValue(KeysProperty, value);
}
Expand All @@ -41,9 +42,9 @@ public static void SetKeys(DependencyObject element, string value)
[AttachedPropertyBrowsableForChildren(IncludeDescendants = true)]
[System.ComponentModel.Category("KeyTips")]
[System.ComponentModel.Description("Key sequence for the given element")]
public static string GetKeys(DependencyObject element)
public static string? GetKeys(DependencyObject element)
{
return (string)element.GetValue(KeysProperty);
return (string?)element.GetValue(KeysProperty);
}

#endregion
Expand Down

0 comments on commit 8fc83c9

Please sign in to comment.