Skip to content

Commit

Permalink
Merge pull request #852 from fluentribbon/issues/logicaltree
Browse files Browse the repository at this point in the history
Fixes #851 by fixing some more logical tree issues
  • Loading branch information
batzen authored Oct 3, 2020
2 parents 4b8bf15 + 2c51f31 commit 0efb915
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 86 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [#840](../../issues/840) - Ribbon does not scroll anymore
- [#848](../../issues/848) - Colorful-Theme and Fullscreen Issue
- [#849](../../issues/849) - QuickAccessToolBar not editable anymore (thanks @chrfin)
- [#851](../../issues/851) - Tab KeyTips Are Shown Together With Tab-Item KeyTips (different to 7.0.0)

## 8.0.0

Expand Down
70 changes: 52 additions & 18 deletions Fluent.Ribbon.Tests/Misc/LogicalTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,26 @@ public void CheckLogicalChildSupport(KeyValuePair<Type, DependencyProperty> item

Assert.That(control, Is.Not.Null);

var metadata = dependencyProperty.GetMetadata(control);
if (excludedTypesForLogicalChildSupportTest.Contains(controlType))
{
Assert.That(control is ILogicalChildSupport, Is.False, "Type must NOT implement ILogicalChildSupport");
return;
}
else
{
Assert.That(control is ILogicalChildSupport, Is.True, "Type must implement ILogicalChildSupport");
}

Assert.That(metadata.PropertyChangedCallback == LogicalChildSupportHelper.OnLogicalChildPropertyChanged);
var metadata = dependencyProperty.GetMetadata(control);

Assert.That(controlType.GetInterfaces(), Does.Contain(typeof(ILogicalChildSupport)));
if (excludedPropertiesForLogicalChildSupportTest.Contains(dependencyProperty))
{
Assert.That(metadata.PropertyChangedCallback != LogicalChildSupportHelper.OnLogicalChildPropertyChanged, "PropertyChangedCallback must not be LogicalChildSupportHelper.OnLogicalChildPropertyChanged");
}
else
{
Assert.That(metadata.PropertyChangedCallback == LogicalChildSupportHelper.OnLogicalChildPropertyChanged, "PropertyChangedCallback must be LogicalChildSupportHelper.OnLogicalChildPropertyChanged");
}

if (dependencyProperty.ReadOnly)
{
Expand All @@ -100,7 +115,8 @@ private static IEnumerable<Type> GetTypesWithImplementedInterface(Type type)

private static readonly Type[] excludedTypesForLogicalChildSupportTest =
{
typeof(LargeIconProviderProperties)
typeof(LargeIconProviderProperties),
typeof(GalleryItem)
};

private static readonly DependencyProperty[] excludedPropertiesForLogicalChildSupportTest =
Expand All @@ -116,16 +132,6 @@ private static IEnumerable<KeyValuePair<Type, DependencyProperty>> GetTypesThatM
{
foreach (var keyValuePair in GetDependencyPropertiesWithPropertyTypeObject())
{
if (excludedTypesForLogicalChildSupportTest.Contains(keyValuePair.Key))
{
continue;
}

if (excludedPropertiesForLogicalChildSupportTest.Contains(keyValuePair.Value))
{
continue;
}

yield return keyValuePair;
}
}
Expand Down Expand Up @@ -164,7 +170,14 @@ private static void TestLogicalTree(Type controlType, DependencyProperty propert
{
var children = LogicalTreeHelper.GetChildren(control);

Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
else
{
Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
}
}

SetValue(null);
Expand All @@ -183,7 +196,14 @@ private static void TestLogicalTree(Type controlType, DependencyProperty propert
{
var children = LogicalTreeHelper.GetChildren(control);

Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
else
{
Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
}
}

{
Expand All @@ -207,12 +227,26 @@ private static void TestLogicalTree(Type controlType, DependencyProperty propert
{
var children = LogicalTreeHelper.GetChildren(control);

Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(children, Does.Not.Contain(value), "Logical children must NOT contain the value.");
}
else
{
Assert.That(children, Does.Contain(value), "Logical children must contain the value.");
}
}

{
var parent = LogicalTreeHelper.GetParent(value);
Assert.That(parent, Is.EqualTo(control), "Parent should match.");
if (excludedPropertiesForLogicalChildSupportTest.Contains(property))
{
Assert.That(parent, Is.Not.EqualTo(control), "Parent should match.");
}
else
{
Assert.That(parent, Is.EqualTo(control), "Parent should match.");
}
}

SetValue(null);
Expand Down
33 changes: 19 additions & 14 deletions Fluent.Ribbon/Adorners/KeyTipAdorner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ReSharper disable once CheckNamespace
// ReSharper disable once CheckNamespace
namespace Fluent
{
using System;
Expand Down Expand Up @@ -134,17 +134,15 @@ private void FindKeyTips(FrameworkElement container, bool hide)

if (keys != null || child is IKeyTipInformationProvider)
{
if (groupBox != null)
{
this.GenerateAndAddGroupBoxKeyTipInformation(hide, keys, child, groupBox);
}
else
if (groupBox is null)
{
this.GenerateAndAddRegularKeyTipInformations(keys, child, hide);

// Do not search deeper in the tree
continue;
}

this.GenerateAndAddGroupBoxKeyTipInformation(hide, keys, child, groupBox);
}

var innerHide = hide || groupBox?.State == RibbonGroupBoxState.Collapsed;
Expand Down Expand Up @@ -214,6 +212,13 @@ private static IList<FrameworkElement> GetVisibleChildren(FrameworkElement eleme
children = children.Concat(UIHelper.GetAllItemContainers<FrameworkElement>(itemsControl));
}

// Don't show key tips for the selected content too early
if (element is RibbonTabControl ribbonTabControl
&& ribbonTabControl.SelectedContent is FrameworkElement selectedContent)
{
children = children.Except(new[] { selectedContent });
}

return children
.Where(x => x.Visibility == Visibility.Visible)
.Distinct()
Expand Down Expand Up @@ -250,7 +255,7 @@ public void Attach()

this.adornerLayer = GetAdornerLayer(this.oneOfAssociatedElements);

if (this.adornerLayer == null)
if (this.adornerLayer is null)
{
this.LogDebug("No adorner layer found");
this.isAttaching = false;
Expand Down Expand Up @@ -337,7 +342,7 @@ private static AdornerLayer GetAdornerLayer(UIElement element)

while (true)
{
if (current == null)
if (current is null)
{
return null;
}
Expand All @@ -360,7 +365,7 @@ private static UIElement GetTopLevelElement(UIElement element)
{
var current = VisualTreeHelper.GetParent(element) as UIElement;

if (current == null)
if (current is null)
{
return element;
}
Expand Down Expand Up @@ -406,7 +411,7 @@ public bool Forward(string keys, bool click)
this.LogTrace("Trying to forward keys \"{0}\"...", keys);

var keyTipInformation = this.TryGetKeyTipInformation(keys);
if (keyTipInformation == null)
if (keyTipInformation is null)
{
this.LogTrace("Found no element for keys \"{0}\".", keys);
return false;
Expand Down Expand Up @@ -639,7 +644,7 @@ private void UpdateKeyTipPositions()
// Dialog Launcher Button Exclusive Placement
var keyTipSize = keyTipInformation.KeyTip.DesiredSize;
var elementSize = keyTipInformation.VisualTarget.RenderSize;
if (rows == null)
if (rows is null)
{
continue;
}
Expand Down Expand Up @@ -691,7 +696,7 @@ private void UpdateKeyTipPositions()
// InRibbonGallery Exclusive Placement
var keyTipSize = keyTipInformation.KeyTip.DesiredSize;
var elementSize = keyTipInformation.VisualTarget.RenderSize;
if (rows == null)
if (rows is null)
{
continue;
}
Expand Down Expand Up @@ -773,7 +778,7 @@ private static bool IsWithinRibbonToolbarInTwoLine(DependencyObject element)
var ribbonToolBar = UIHelper.GetParent<RibbonToolBar>(element);

var definition = ribbonToolBar?.GetCurrentLayoutDefinition();
if (definition == null)
if (definition is null)
{
return false;
}
Expand All @@ -795,7 +800,7 @@ private static bool IsWithinQuickAccessToolbar(DependencyObject element)

private static void SnapToRowsIfPresent(double[] rows, KeyTipInformation keyTipInformation, Point translatedPoint)
{
if (rows == null)
if (rows is null)
{
return;
}
Expand Down
5 changes: 3 additions & 2 deletions Fluent.Ribbon/Collections/CollectionSyncHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Fluent.Collections
{
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

Expand All @@ -12,7 +13,7 @@ public class CollectionSyncHelper<TItem>
/// <summary>
/// Creates a new instance with <paramref name="source"/> as <see cref="Source"/> and <paramref name="target"/> as <see cref="Target"/>.
/// </summary>
public CollectionSyncHelper(ObservableCollection<TItem> source, ObservableCollection<TItem> target)
public CollectionSyncHelper(ObservableCollection<TItem> source, IList target)
{
this.Source = source ?? throw new ArgumentNullException(nameof(source));
this.Target = target ?? throw new ArgumentNullException(nameof(target));
Expand All @@ -30,7 +31,7 @@ public CollectionSyncHelper(ObservableCollection<TItem> source, ObservableCollec
/// <summary>
/// The target collection.
/// </summary>
public ObservableCollection<TItem> Target { get; }
public IList Target { get; }

/// <summary>
/// Clears <see cref="Target"/> and then copies all items from <see cref="Source"/> to <see cref="Target"/>.
Expand Down
Loading

0 comments on commit 0efb915

Please sign in to comment.