GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat(domain): create `ReplaceContainerCommand` and its handler
Lars Berger68902e6e24cf
diff --git a/LarsWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs b/LarsWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.csnew file mode 100644index 00000000..22736503--- /dev/null+++ b/LarsWM.Domain/Containers/CommandHandlers/ReplaceContainerHandler.cs@@ -0,0 +1,37 @@+using LarsWM.Domain.Containers.Commands;+using LarsWM.Infrastructure.Bussing;++namespace LarsWM.Domain.Containers.CommandHandlers+{+ class ReplaceContainerHandler : ICommandHandler<ReplaceContainerCommand>+ {+ private ContainerService _containerService;++ public ReplaceContainerHandler(ContainerService containerService)+ {+ _containerService = containerService;+ }++ public dynamic Handle(ReplaceContainerCommand command)+ {+ var containerToReplace = command.ContainerToReplace;+ var replacementContainer = command.ReplacementContainer;+ var targetIndex = containerToReplace.SelfAndSiblings.IndexOf(containerToReplace);++ // Replace the split container with the focused window.+ containerToReplace.Parent.Children[targetIndex] = replacementContainer;+ replacementContainer.Parent = containerToReplace.Parent;+ replacementContainer.SizePercentage = containerToReplace.SizePercentage;++ // Correct focus stack references to replaced container.+ if (containerToReplace.Parent.LastFocusedContainer == containerToReplace)+ containerToReplace.Parent.LastFocusedContainer = replacementContainer;++ // TODO: Not sure whether redrawing is necessary, will see after fixing detach command.+ _containerService.SplitContainersToRedraw.Add(containerToReplace.Parent as SplitContainer);+ _containerService.SplitContainersToRedraw.Add(replacementContainer.Parent as SplitContainer);++ return CommandResponse.Ok;+ }+ }+}diff --git a/LarsWM.Domain/Containers/Commands/ReplaceContainerCommand.cs b/LarsWM.Domain/Containers/Commands/ReplaceContainerCommand.csnew file mode 100644index 00000000..cadae1db--- /dev/null+++ b/LarsWM.Domain/Containers/Commands/ReplaceContainerCommand.cs@@ -0,0 +1,16 @@+using LarsWM.Infrastructure.Bussing;++namespace LarsWM.Domain.Containers.Commands+{+ public class ReplaceContainerCommand : Command+ {+ public Container ContainerToReplace { get; }+ public Container ReplacementContainer { get; }++ public ReplaceContainerCommand(Container containerToReplace, Container replacementContainer)+ {+ ContainerToReplace = containerToReplace;+ ReplacementContainer = replacementContainer;+ }+ }+}