Skip to content
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
20 changes: 14 additions & 6 deletions samples/BrowserTabTheme/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace BrowserTabTheme;

public partial class App : Application
{
private MainWindowViewModel? _mainWindowViewModel;

public override void Initialize()
{
#if DOCK_USE_GENERATED_APP_INITIALIZE_COMPONENT
Expand Down Expand Up @@ -66,15 +68,21 @@ public override void OnFrameworkInitializationCompleted()

factory.InitLayout(rootDock);

var mainWindow = new MainWindow();
mainWindow.DockControl.Factory = factory;
mainWindow.DockControl.Layout = rootDock;
mainWindow.DockControl.InitializeFactory = true;
mainWindow.DockControl.InitializeLayout = false;

_mainWindowViewModel = new MainWindowViewModel(factory, rootDock);
var mainWindow = new MainWindow
{
DataContext = _mainWindowViewModel
};
desktop.MainWindow = mainWindow;
desktop.Exit += (_, _) => DisposeMainWindowViewModel();
}

base.OnFrameworkInitializationCompleted();
}

private void DisposeMainWindowViewModel()
{
_mainWindowViewModel?.Dispose();
_mainWindowViewModel = null;
}
}
9 changes: 8 additions & 1 deletion samples/BrowserTabTheme/BrowserTabTheme.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Import Project="..\..\build\Avalonia.props" />
<Import Project="..\..\build\Avalonia.Themes.Fluent.props" />
<Import Project="..\..\build\Avalonia.Desktop.props" />
<Import Project="..\..\build\Avalonia.ReactiveUI.props" />

<ItemGroup>
<ProjectReference Include="..\..\src\Dock.Model\Dock.Model.csproj" />
Expand All @@ -25,5 +26,11 @@
<ProjectReference Include="..\..\src\Dock.Avalonia.Themes.Fluent\Dock.Avalonia.Themes.Fluent.csproj" />
</ItemGroup>

</Project>
<ItemGroup>
<PackageReference Include="ReactiveUI.SourceGenerators">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
11 changes: 9 additions & 2 deletions samples/BrowserTabTheme/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:BrowserTabTheme"
x:Class="BrowserTabTheme.MainWindow"
x:DataType="vm:MainWindowViewModel"
Title="BrowserTabTheme Sample"
Width="1300"
Height="820"
Background="{DynamicResource DockSurfaceHeaderBrush}"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaToDecorationsHint="{CompiledBinding ExtendClientAreaToDecorationsHint}"
ExtendClientAreaTitleBarHeightHint="-1"
>
<DockControl Name="DockControl" Margin="6" />
<DockControl Name="DockControl"
Margin="6"
Factory="{CompiledBinding Factory}"
Layout="{CompiledBinding Layout}"
InitializeFactory="True"
InitializeLayout="False" />

</Window>
155 changes: 155 additions & 0 deletions samples/BrowserTabTheme/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright (c) Wiesław Šoltés. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using Dock.Model.Controls;
using Dock.Model.Core;
using ReactiveUI;
using ReactiveUI.SourceGenerators;

namespace BrowserTabTheme;

/// <summary>
/// Coordinates the browser sample layout and its main-window chrome state.
/// </summary>
public sealed partial class MainWindowViewModel : ReactiveObject, IDisposable
{
private readonly HashSet<IDocumentDock> _documentDocks = new();
private readonly HashSet<INotifyCollectionChanged> _dockCollections = new();
private bool _isDisposed;

/// <summary>
/// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
/// </summary>
/// <param name="factory">The layout factory.</param>
/// <param name="layout">The main root layout.</param>
public MainWindowViewModel(IFactory factory, IRootDock layout)
{
Factory = factory ?? throw new ArgumentNullException(nameof(factory));
Layout = layout ?? throw new ArgumentNullException(nameof(layout));
ExtendClientAreaToDecorationsHint = true;
RefreshSubscriptions();
}

/// <summary>
/// Gets the layout factory used by the dock control.
/// </summary>
public IFactory Factory { get; }

/// <summary>
/// Gets the main root layout.
/// </summary>
public IRootDock Layout { get; }

/// <summary>
/// Gets whether content should extend into the main window decorations.
/// </summary>
[Reactive]
public partial bool ExtendClientAreaToDecorationsHint { get; private set; }

/// <inheritdoc/>
public void Dispose()
{
if (_isDisposed)
{
return;
}

_isDisposed = true;
ClearSubscriptions();
}

private void RefreshSubscriptions()
{
ClearSubscriptions();

var pending = new Stack<IDockable>();
var visited = new HashSet<IDockable>();
pending.Push(Layout);

while (pending.Count > 0)
{
var dockable = pending.Pop();
if (!visited.Add(dockable))
{
continue;
}

if (dockable is IDocumentDock documentDock)
{
_documentDocks.Add(documentDock);
if (documentDock is INotifyPropertyChanged notifyingDocumentDock)
{
notifyingDocumentDock.PropertyChanged += OnDocumentDockPropertyChanged;
}
}

if (dockable is not IDock { VisibleDockables: { } visibleDockables })
{
continue;
}

if (visibleDockables is INotifyCollectionChanged notifyingCollection
&& _dockCollections.Add(notifyingCollection))
{
notifyingCollection.CollectionChanged += OnDockCollectionChanged;
}

for (var index = visibleDockables.Count - 1; index >= 0; index--)
{
pending.Push(visibleDockables[index]);
}
}

UpdateChromeState();
}

private void ClearSubscriptions()
{
foreach (var documentDock in _documentDocks)
{
if (documentDock is INotifyPropertyChanged notifyingDocumentDock)
{
notifyingDocumentDock.PropertyChanged -= OnDocumentDockPropertyChanged;
}
}

foreach (var dockCollection in _dockCollections)
{
dockCollection.CollectionChanged -= OnDockCollectionChanged;
}

_documentDocks.Clear();
_dockCollections.Clear();
}

private void OnDockCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
RefreshSubscriptions();
}

private void OnDocumentDockPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (string.IsNullOrEmpty(e.PropertyName) || e.PropertyName == nameof(IDocumentDock.LayoutMode))
{
UpdateChromeState();
}
}

private void UpdateChromeState()
{
foreach (var documentDock in _documentDocks)
{
if (documentDock.LayoutMode == DocumentLayoutMode.Mdi)
{
ExtendClientAreaToDecorationsHint = false;
return;
}
}

ExtendClientAreaToDecorationsHint = true;
}
}
6 changes: 5 additions & 1 deletion samples/BrowserTabTheme/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ This sample backports a browser-tab visual style from StackWich into the origina

- Browser-like document and tool tab visuals.
- Browser-style window chrome driven by Avalonia drawn decorations and Dock theme resources.
- Dock drag/drop, float, pin, and document creation behavior preserved.
- Dock drag/drop, including dropping a tab onto a side target to create a new
horizontal or vertical document dock.
- Native main-window chrome while document layout mode is MDI, keeping maximized
MDI children clear of the operating-system caption controls.
- Float, pin, and document creation behavior preserved.
- Theme dictionaries for both Light (`Default`) and Dark variants.

## What is intentionally excluded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@
<x:Boolean x:Key="DockDocumentTabStripHideWhenEmpty">False</x:Boolean>
<x:Boolean x:Key="DockDocumentTabStripToggleWindowStateOnDoubleTap">True</x:Boolean>
<x:Boolean x:Key="DockDocumentControlTabStripVisible">True</x:Boolean>
<x:Boolean x:Key="DockDocumentControlShowDockIndicatorOnly">True</x:Boolean>
<!-- Keep the full local selector available so a tab can be dropped into a
newly created horizontal or vertical document dock. -->
<x:Boolean x:Key="DockDocumentControlShowDockIndicatorOnly">False</x:Boolean>
<x:Boolean x:Key="DockDocumentTabStripSeparatorVisible">False</x:Boolean>
<sys:Double x:Key="DockDocumentControlVerticalSpacing">6</sys:Double>
<StaticResource x:Key="DockDocumentContentBorderBrush" ResourceKey="DockBorderSubtleBrush" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Wiesław Šoltés. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

using BrowserTabTheme;
using Dock.Model.Controls;
using Dock.Model.Core;
using Dock.Model.Mvvm;
using Xunit;

namespace Dock.Avalonia.HeadlessTests;

public class BrowserTabThemeMainWindowViewModelTests
{
[Fact]
public void ChromeStateTracksAllCurrentDocumentDocks()
{
var factory = new Factory();
var root = factory.CreateRootDock();
root.VisibleDockables = factory.CreateList<IDockable>();
var proportionalDock = factory.CreateProportionalDock();
proportionalDock.VisibleDockables = factory.CreateList<IDockable>();
var firstDocumentDock = factory.CreateDocumentDock();
firstDocumentDock.VisibleDockables = factory.CreateList<IDockable>();

factory.AddDockable(proportionalDock, firstDocumentDock);
factory.AddDockable(root, proportionalDock);
factory.InitLayout(root);

using var viewModel = new MainWindowViewModel(factory, root);

Assert.True(viewModel.ExtendClientAreaToDecorationsHint);

var secondDocumentDock = factory.CreateDocumentDock();
secondDocumentDock.VisibleDockables = factory.CreateList<IDockable>();
factory.AddDockable(proportionalDock, secondDocumentDock);
secondDocumentDock.LayoutMode = DocumentLayoutMode.Mdi;

Assert.False(viewModel.ExtendClientAreaToDecorationsHint);

firstDocumentDock.LayoutMode = DocumentLayoutMode.Mdi;
factory.RemoveDockable(secondDocumentDock, false);

Assert.False(viewModel.ExtendClientAreaToDecorationsHint);

firstDocumentDock.LayoutMode = DocumentLayoutMode.Tabbed;

Assert.True(viewModel.ExtendClientAreaToDecorationsHint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Import Project="..\..\build\SignAssembly.props" />

<ItemGroup>
<ProjectReference Include="..\..\samples\BrowserTabTheme\BrowserTabTheme.csproj" />
<ProjectReference Include="..\..\src\Dock.Avalonia.Themes.Fluent\Dock.Avalonia.Themes.Fluent.csproj" />
<ProjectReference Include="..\..\src\Dock.Avalonia.Themes.Simple\Dock.Avalonia.Themes.Simple.csproj" />
<ProjectReference Include="..\..\src\Dock.Model\Dock.Model.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Avalonia.Styling;
using Dock.Avalonia.Controls;
using Dock.Avalonia.Themes.Browser;
using Dock.Avalonia.Themes.Fluent;
using Dock.Avalonia.Themes.Simple;
using Xunit;
Expand Down Expand Up @@ -36,4 +38,17 @@ public void DockSimpleTheme_Can_Instantiate()
Styles theme = new DockSimpleTheme();
Assert.NotNull(theme);
}

[AvaloniaFact]
public void BrowserTabTheme_Enables_Full_Document_Dock_Selector()
{
var theme = new BrowserTabTheme();
var resourceNode = Assert.IsAssignableFrom<IResourceNode>(theme);

Assert.True(resourceNode.TryGetResource(
"DockDocumentControlShowDockIndicatorOnly",
ThemeVariant.Default,
out var resource));
Assert.False(Assert.IsType<bool>(resource));
}
}
Loading