GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): change `ReplaceContainerCommand` to only allow one replacement container
Lars Berger8efd66298049
diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.csindex c4558fd1..7211093e 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/ChangeContainerLayoutHandler.cs@@ -1,4 +1,4 @@-using System.Collections.Generic;+using System.Collections.Generic;using System.Linq;using GlazeWM.Domain.Common.Enums;using GlazeWM.Domain.Containers.Commands;@@ -67,7 +67,7 @@ namespace GlazeWM.Domain.Containers.CommandHandlers// Replace the window with the wrapping split container. The window has to be attached to// the split container after the replacement.- _bus.Invoke(new ReplaceContainerCommand(parent, window.Index, new List<Container>() { splitContainer }));+ _bus.Invoke(new ReplaceContainerCommand(parent, window.Index, splitContainer));_bus.Invoke(new AttachContainerCommand(splitContainer, window));}diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.csindex bc8e8a69..79382aea 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs@@ -6,41 +6,40 @@ namespace GlazeWM.Domain.Containers.CommandHandlers{class ReplaceContainerHandler : ICommandHandler<ReplaceContainerCommand>{+ private Bus _bus;private ContainerService _containerService;- public ReplaceContainerHandler(ContainerService containerService)+ public ReplaceContainerHandler(Bus bus, ContainerService containerService){+ _bus = bus;_containerService = containerService;}public CommandResponse Handle(ReplaceContainerCommand command){var parentContainer = command.ParentContainer;- var replacementContainers = command.ReplacementContainers;+ var replacementContainer = command.ReplacementContainer;var childIndex = command.ChildIndex;- // TODO: Consider detaching `ReplacementContainer` if it already has a parent.+ // Detach `ReplacementContainer` if it already has a parent.+ if (replacementContainer.Parent != null)+ _bus.Invoke(new DetachContainerCommand(replacementContainer));var containerToReplace = parentContainer.Children[childIndex];- foreach (var replacementContainer in replacementContainers)- {- replacementContainer.Parent = parentContainer;- (replacementContainer as IResizable).SizePercentage =- (containerToReplace as IResizable).SizePercentage * (replacementContainer as IResizable).SizePercentage;- }-// Replace the container at the given index.- var index = parentContainer.Children.IndexOf(containerToReplace);- parentContainer.Children.InsertRange(index, replacementContainers);- parentContainer.RemoveChild(containerToReplace);+ parentContainer.Children.Replace(containerToReplace, replacementContainer);+ replacementContainer.Parent = parentContainer;++ if (replacementContainer is IResizable && containerToReplace is IResizable)+ (replacementContainer as IResizable).SizePercentage =+ (containerToReplace as IResizable).SizePercentage;// Correct any focus order references to the replaced container.- parentContainer.ChildFocusOrder.Replace(- containerToReplace, containerToReplace.LastFocusedChild ?? replacementContainers[0]- );+ parentContainer.ChildFocusOrder.Replace(containerToReplace, replacementContainer);_containerService.ContainersToRedraw.Add(parentContainer);+ _containerService.ContainersToRedraw.Add(replacementContainer.Parent);return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Containers/Commands/ReplaceContainerCommand.cs b/GlazeWM.Domain/Containers/Commands/ReplaceContainerCommand.csindex 800123c4..47ad3978 100644--- a/GlazeWM.Domain/Containers/Commands/ReplaceContainerCommand.cs+++ b/GlazeWM.Domain/Containers/Commands/ReplaceContainerCommand.cs@@ -1,5 +1,4 @@-using System.Collections.Generic;-using GlazeWM.Infrastructure.Bussing;+using GlazeWM.Infrastructure.Bussing;namespace GlazeWM.Domain.Containers.Commands{@@ -7,13 +6,13 @@ namespace GlazeWM.Domain.Containers.Commands{public Container ParentContainer { get; }public int ChildIndex { get; }- public List<Container> ReplacementContainers { get; }+ public Container ReplacementContainer { get; }- public ReplaceContainerCommand(Container parentContainer, int childIndex, List<Container> replacementContainers)+ public ReplaceContainerCommand(Container parentContainer, int childIndex, Container replacementContainer){ParentContainer = parentContainer;ChildIndex = childIndex;- ReplacementContainers = replacementContainers;+ ReplacementContainer = replacementContainer;}}}