Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ribbon.OnTitleBarChanged clearing the new title bar instead of the old one #450

Merged
merged 2 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Fluent.Ribbon.Tests/Controls/RibbonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,38 @@ private static void AssertAttElementsHaveSameValue(Dictionary<FrameworkElement,
Assert.That(element.Key.GetValue(property), Is.EqualTo(expectedValue), $"{property.Name} on {element.Value} should match.");
}
}

[Test]
public void TitleBar_properties_synchronised_with_ribbon()
{
var ribbon = new Ribbon { ContextualGroups = { new RibbonContextualTabGroup() } };
using (new TestRibbonWindow(ribbon))
{
ribbon.ApplyTemplate();
Assert.IsNotNull(ribbon.QuickAccessToolBar);

var oldTitleBar = ribbon.TitleBar = new RibbonTitleBar();
Assert.AreEqual(1, oldTitleBar.Items.Count);
Assert.AreSame(ribbon.QuickAccessToolBar, oldTitleBar.QuickAccessToolBar);

var newTitleBar = new RibbonTitleBar();
Assert.AreEqual(0, newTitleBar.Items.Count);
Assert.IsNull(newTitleBar.QuickAccessToolBar);

// assign a new title bar, the contextual groups and quick access are transferred across
ribbon.TitleBar = newTitleBar;
Assert.AreEqual(0, oldTitleBar.Items.Count);
Assert.IsNull(oldTitleBar.QuickAccessToolBar);
Assert.AreEqual(1, newTitleBar.Items.Count);
Assert.AreSame(ribbon.QuickAccessToolBar, newTitleBar.QuickAccessToolBar);

// remove the title bar
ribbon.TitleBar = null;
Assert.AreEqual(0, oldTitleBar.Items.Count);
Assert.IsNull(oldTitleBar.QuickAccessToolBar);
Assert.AreEqual(0, newTitleBar.Items.Count);
Assert.IsNull(newTitleBar.QuickAccessToolBar);
}
}
}
}
28 changes: 14 additions & 14 deletions Fluent.Ribbon/Controls/Ribbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,25 +655,25 @@ private static void OnTitleBarChanged(DependencyObject d, DependencyPropertyChan
{
foreach (var ribbonContextualTabGroup in ribbon.ContextualGroups)
{
ribbon.TitleBar.Items.Remove(ribbonContextualTabGroup);
oldValue.Items.Remove(ribbonContextualTabGroup);
}

// Make sure everything is cleared
ribbon.TitleBar.Items.Clear();
oldValue.Items.Clear();

ribbon.RemoveQuickAccessToolBarFromTitleBar();
ribbon.RemoveQuickAccessToolBarFromTitleBar(oldValue);
}

if (newValue != null)
{
foreach (var contextualTabGroup in ribbon.ContextualGroups)
{
ribbon.TitleBar.Items.Add(contextualTabGroup);
newValue.Items.Add(contextualTabGroup);
}

if (ribbon.ShowQuickAccessToolBarAboveRibbon)
{
ribbon.MoveQuickAccessToolBarToTitleBar();
ribbon.MoveQuickAccessToolBarToTitleBar(newValue);
}
}
}
Expand Down Expand Up @@ -708,11 +708,11 @@ private static void OnShowQuickAccesToolBarAboveRibbonChanged(DependencyObject d
{
if ((bool)e.NewValue)
{
ribbon.MoveQuickAccessToolBarToTitleBar();
ribbon.MoveQuickAccessToolBarToTitleBar(ribbon.TitleBar);
}
else
{
ribbon.RemoveQuickAccessToolBarFromTitleBar();
ribbon.RemoveQuickAccessToolBarFromTitleBar(ribbon.TitleBar);
}

ribbon.TitleBar.InvalidateMeasure();
Expand Down Expand Up @@ -1614,15 +1614,15 @@ public override void OnApplyTemplate()

if (this.ShowQuickAccessToolBarAboveRibbon)
{
this.MoveQuickAccessToolBarToTitleBar();
this.MoveQuickAccessToolBarToTitleBar(this.TitleBar);
}
}

private void MoveQuickAccessToolBarToTitleBar()
private void MoveQuickAccessToolBarToTitleBar(RibbonTitleBar titleBar)
{
if (this.TitleBar != null)
if (titleBar != null)
{
this.TitleBar.QuickAccessToolBar = this.QuickAccessToolBar;
titleBar.QuickAccessToolBar = this.QuickAccessToolBar;
}

if (this.QuickAccessToolBar != null)
Expand All @@ -1636,11 +1636,11 @@ private void MoveQuickAccessToolBarToTitleBar()
}
}

private void RemoveQuickAccessToolBarFromTitleBar()
private void RemoveQuickAccessToolBarFromTitleBar(RibbonTitleBar titleBar)
{
if (this.TitleBar != null)
if (titleBar != null)
{
this.TitleBar.QuickAccessToolBar = null;
titleBar.QuickAccessToolBar = null;
}

if (this.QuickAccessToolBar != null)
Expand Down