Skip to content

Commit

Permalink
Merge pull request #325 from BAndysc/tooldock_pinning
Browse files Browse the repository at this point in the history
Tooldock pinning
  • Loading branch information
wieslawsoltes authored Mar 11, 2024
2 parents c51a07b + 0d9b7e9 commit ca77bde
Show file tree
Hide file tree
Showing 30 changed files with 702 additions and 90 deletions.
34 changes: 24 additions & 10 deletions samples/DockMvvmSample/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,36 @@
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="PreferSystemChrome"
ids:DockProperties.IsDragEnabled="True" ids:DockProperties.IsDropEnabled="True">
<Window.Resources>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55"
x:Key="AcrylicMaterial"/>
</Window.Resources>
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>
<Panel>
<ExperimentalAcrylicBorder IsHitTestVisible="False">
<ExperimentalAcrylicBorder.Material>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55" />
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<ExperimentalAcrylicBorder IsHitTestVisible="False" Material="{StaticResource AcrylicMaterial}" />
<Panel Margin="{Binding #MainWindowView.OffScreenMargin}">
<Panel Margin="{Binding #MainWindowView.WindowDecorationMargin}">
<views:MainView />
<views:MainView>
<views:MainView.Styles>
<Style Selector="GridSplitter">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="Transparent">
<ExperimentalAcrylicBorder Material="{StaticResource AcrylicMaterial}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</views:MainView.Styles>
</views:MainView>
</Panel>
</Panel>
</Panel>
Expand Down
34 changes: 24 additions & 10 deletions samples/DockXamlSample/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,33 @@
Title="Dock Avalonia Demo" Width="800" Height="600"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="PreferSystemChrome">
<Window.Resources>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55"
x:Key="AcrylicMaterial"/>
</Window.Resources>
<Panel>
<ExperimentalAcrylicBorder IsHitTestVisible="False">
<ExperimentalAcrylicBorder.Material>
<ExperimentalAcrylicMaterial BackgroundSource="Digger"
TintColor="{DynamicResource SystemAltHighColor}"
TintOpacity="1"
FallbackColor="{DynamicResource AcrylicFallbackColor}"
MaterialOpacity="0.55" />
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<ExperimentalAcrylicBorder IsHitTestVisible="False" Material="{StaticResource AcrylicMaterial}" />
<Panel Margin="{Binding #MainWindowView.OffScreenMargin}">
<Panel Margin="{Binding #MainWindowView.WindowDecorationMargin}">
<local:MainView />
<local:MainView>
<local:MainView.Styles>
<Style Selector="GridSplitter">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="Transparent">
<ExperimentalAcrylicBorder Material="{StaticResource AcrylicMaterial}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</local:MainView.Styles>
</local:MainView>
</Panel>
</Panel>
</Panel>
Expand Down
15 changes: 15 additions & 0 deletions src/Dock.Avalonia/Controls/DockControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public class DockControl : TemplatedControl, IDockControl
public static readonly StyledProperty<IFactory?> FactoryProperty =
AvaloniaProperty.Register<DockControl, IFactory?>(nameof(Factory));

/// <summary>
/// Defines the <see cref="IsDraggingDock"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsDraggingDockProperty =
AvaloniaProperty.Register<DockControl, bool>(nameof(IsDraggingDock));

/// <inheritdoc/>
public IDockManager DockManager => _dockManager;

Expand Down Expand Up @@ -94,6 +100,15 @@ public IFactory? Factory
set => SetValue(FactoryProperty, value);
}

/// <summary>
/// Gets or sets whether any dock is being dragged.
/// </summary>
public bool IsDraggingDock
{
get => GetValue(IsDraggingDockProperty);
set => SetValue(IsDraggingDockProperty, value);
}

/// <summary>
/// Initialize the new instance of the <see cref="DockControl"/>.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions src/Dock.Avalonia/Controls/PinnedDockControl.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dmc="clr-namespace:Dock.Model.Controls;assembly=Dock.Model">
<Design.PreviewWith>
<Border>
<PinnedDockControl />
</Border>
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type PinnedDockControl}" TargetType="PinnedDockControl">

<Setter Property="PinnedDockAlignment" Value="{CompiledBinding PinnedDock.Alignment}" x:DataType="dmc:IRootDock" />

<Setter Property="Template">
<ControlTemplate>
<Grid Name="PART_PinnedDockGrid"
IsVisible="{Binding !PinnedDock.IsEmpty, FallbackValue=False}"
x:DataType="dmc:IRootDock"
x:CompileBindings="True">
<ContentControl Content="{Binding PinnedDock}" Name="PART_PinnedDock">
<ContentControl.Styles>
<Style Selector="ToolDockControl">
<Setter Property="Background">
<MultiBinding Converter="{x:Static EitherNotNullConverter.Instance}">
<CompiledBinding Path="$parent[Window].Background" />
<CompiledBinding Path="$parent[Window].TransparencyBackgroundFallback" />
</MultiBinding>
</Setter>
</Style>
<Style Selector="ToolControl">
<Setter Property="IsHitTestVisible" Value="{CompiledBinding !$parent[DockControl].IsDraggingDock}" />
</Style>
</ContentControl.Styles>
</ContentControl>
<GridSplitter Grid.Column="1" Grid.Row="1" Background="{CompiledBinding $parent[Window].Background, TargetNullValue={x:Static Brushes.Transparent}}" />
</Grid>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
91 changes: 91 additions & 0 deletions src/Dock.Avalonia/Controls/PinnedDockControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Dock.Model.Core;

namespace Dock.Avalonia.Controls;

/// <summary>
/// Interaction logic for <see cref="PinnedDockControl"/> xaml.
/// </summary>
[TemplatePart("PART_PinnedDock", typeof(ContentControl)/*, IsRequired = true*/)]
[TemplatePart("PART_PinnedDockGrid", typeof(Grid)/*, IsRequired = true*/)]
public class PinnedDockControl : TemplatedControl
{
/// <summary>
/// Define the <see cref="PinnedDockAlignment"/> property.
/// </summary>
public static readonly StyledProperty<Alignment> PinnedDockAlignmentProperty = AvaloniaProperty.Register<PinnedDockControl, Alignment>(nameof(PinnedDockAlignment));

/// <summary>
/// Gets or sets pinned dock alignment
/// </summary>
public Alignment PinnedDockAlignment
{
get => GetValue(PinnedDockAlignmentProperty);
set => SetValue(PinnedDockAlignmentProperty, value);
}

private Grid? _pinnedDockGrid;
private ContentControl? _pinnedDock;

static PinnedDockControl()
{
PinnedDockAlignmentProperty.Changed.AddClassHandler<PinnedDockControl>((control, e) => control.UpdateGrid());
}

private void UpdateGrid()
{
if (_pinnedDockGrid == null || _pinnedDock == null)
return;

_pinnedDockGrid.RowDefinitions.Clear();
_pinnedDockGrid.ColumnDefinitions.Clear();
switch (PinnedDockAlignment)
{
case Alignment.Unset:
case Alignment.Left:
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto) { MinWidth = 50 });
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star) { MinWidth = 50 });
Grid.SetColumn(_pinnedDock, 0);
Grid.SetRow(_pinnedDock, 0);
break;
case Alignment.Bottom:
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Star) { MinHeight = 50 });
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto) { MinHeight = 50 });
Grid.SetColumn(_pinnedDock, 0);
Grid.SetRow(_pinnedDock, 2);
break;
case Alignment.Right:
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star) { MinWidth = 50 });
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto));
_pinnedDockGrid.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Auto) { MinWidth = 50 });
Grid.SetColumn(_pinnedDock, 2);
Grid.SetRow(_pinnedDock, 0);
break;
case Alignment.Top:
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto) { MinHeight = 50 });
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
_pinnedDockGrid.RowDefinitions.Add(new RowDefinition(GridLength.Star) { MinHeight = 50 });
Grid.SetColumn(_pinnedDock, 1);
Grid.SetRow(_pinnedDock, 0);
break;
default:
throw new ArgumentOutOfRangeException();
}
}

/// <inheritdoc/>
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_pinnedDockGrid = e.NameScope.Get<Grid>("PART_PinnedDockGrid");
_pinnedDock = e.NameScope.Get<ContentControl>("PART_PinnedDock");
UpdateGrid();
}
}

5 changes: 4 additions & 1 deletion src/Dock.Avalonia/Controls/RootDockControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
Orientation="Horizontal"
Items="{Binding BottomPinnedDockables}"
IsVisible="{Binding !!BottomPinnedDockables.Count}" />
<ContentControl Content="{Binding ActiveDockable}" />
<Panel>
<ContentControl Content="{Binding ActiveDockable}" Name="PART_MainContent" />
<PinnedDockControl />
</Panel>
</DockPanel>
</DockableControl>
</ControlTemplate>
Expand Down
16 changes: 16 additions & 0 deletions src/Dock.Avalonia/Controls/RootDockControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Interactivity;
using Dock.Model.Controls;

namespace Dock.Avalonia.Controls;

/// <summary>
/// Interaction logic for <see cref="RootDockControl"/> xaml.
/// </summary>
[TemplatePart("PART_MainContent", typeof(ContentControl)/*, IsRequired = true*/)]
public class RootDockControl : TemplatedControl
{
/// <inheritdoc/>
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
var mainContent = e.NameScope.Get<ContentControl>("PART_MainContent");
mainContent.AddHandler(PointerPressedEvent, (_, _) =>
{
if (DataContext is IRootDock rootDock)
rootDock.Factory?.HidePreviewingDockables(rootDock);
}, RoutingStrategies.Tunnel);
}
}
Loading

0 comments on commit ca77bde

Please sign in to comment.