Skip to content

Commit

Permalink
Fix: Consolidate branch, but don't close window (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
BornToBeRoot authored Apr 6, 2024
1 parent 3075a3c commit 7ac6fe4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dragablz/Dragablz.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageProjectUrl>http://dragablz.net</PackageProjectUrl>
<RepositoryUrl>https://github.com/ButchersBoy/Dragablz</RepositoryUrl>
<PackageTags>WPF TabControl Tab Tearable</PackageTags>
<PackageReleaseNotes>Support for .NET 6</PackageReleaseNotes>
<PackageReleaseNotes>Support for .NET 8</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

Expand Down
8 changes: 7 additions & 1 deletion Dragablz/TabEmptiedResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ namespace Dragablz
public enum TabEmptiedResponse
{
/// <summary>
/// Allow the Window to be closed automatically.
/// Allow the Window and Layout branch to be closed automatically.
/// </summary>
CloseWindowOrLayoutBranch,

/// <summary>
/// Allow the Layout branch to be closed automatically, but not the window.
/// </summary>
CloseLayoutBranch,

/// <summary>
/// The window will not be closed by the <see cref="TabablzControl"/>, probably meaning the implementor will close the window manually
/// </summary>
Expand Down
45 changes: 33 additions & 12 deletions Dragablz/TabablzControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,23 +1099,48 @@ internal object RemoveItem(DragablzItem dragablzItem)
var minSize = EmptyHeaderSizingHint == EmptyHeaderSizingHint.PreviousTab
? new Size(_dragablzItemsControl.ActualWidth, _dragablzItemsControl.ActualHeight)
: new Size();

_dragablzItemsControl.MinHeight = 0;
_dragablzItemsControl.MinWidth = 0;

var contentPresenter = FindChildContentPresenter(item);
RemoveFromSource(item);
_itemsHolder.Children.Remove(contentPresenter);

if (Items.Count != 0) return item;
if (Items.Count != 0)
return item;

// Find window
var window = Window.GetWindow(this);
if (window != null
&& InterTabController != null
&& InterTabController.InterTabClient.TabEmptiedHandler(this, window) == TabEmptiedResponse.CloseWindowOrLayoutBranch)

if (window == null || InterTabController == null)
{
_dragablzItemsControl.MinHeight = minSize.Height;
_dragablzItemsControl.MinWidth = minSize.Width;

return item;
}

// Get tab emptied response
var tabEmptiedResponse = InterTabController.InterTabClient.TabEmptiedHandler(this, window);

// This is e.g. to DoNothing
if (tabEmptiedResponse is not (TabEmptiedResponse.CloseLayoutBranch
or TabEmptiedResponse.CloseWindowOrLayoutBranch))
{
if (Layout.ConsolidateBranch(this)) return item;
_dragablzItemsControl.MinHeight = minSize.Height;
_dragablzItemsControl.MinWidth = minSize.Width;

return item;
}

// Consolidate branch
if (Layout.ConsolidateBranch(this))
return item;

// Close window
if (tabEmptiedResponse is TabEmptiedResponse.CloseWindowOrLayoutBranch)
{
try
{
SetIsClosingAsPartOfDragOperation(window, true);
Expand All @@ -1124,13 +1149,9 @@ internal object RemoveItem(DragablzItem dragablzItem)
finally
{
SetIsClosingAsPartOfDragOperation(window, false);
}
}
else
{
_dragablzItemsControl.MinHeight = minSize.Height;
_dragablzItemsControl.MinWidth = minSize.Width;
}
}

return item;
}

Expand Down

0 comments on commit 7ac6fe4

Please sign in to comment.