Skip to content

Commit 106e728

Browse files
committed
refactor(UI): ♻️ simplify dialog creation and positioning logic
1 parent d30073b commit 106e728

1 file changed

Lines changed: 5 additions & 41 deletions

File tree

src/ReferenceReplacement/UI/ReferenceReplacementDialog.cs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43

54
using Elements.Core;
65

@@ -34,48 +33,31 @@ public static void OpenFromSlot(Slot creationSlot)
3433
return;
3534
}
3635

37-
_ = Create(localUser, creationSlot);
36+
ReferenceReplacementDialog dialog = new(creationSlot);
37+
dialog.PositionFor(localUser);
3838
}
3939

40-
private ReferenceReplacementDialog(User owner, Slot dialogSlot)
40+
private ReferenceReplacementDialog(Slot dialogSlot)
4141
{
42-
ArgumentNullException.ThrowIfNull(owner);
4342
_rootSlot = dialogSlot ?? throw new ArgumentNullException(nameof(dialogSlot));
4443
_rootSlot.Destroyed += OnSlotDestroyed;
45-
ClearSlot(_rootSlot);
4644

4745
(_processRootRef, _sourceRef, _targetRef) = CreateReferenceFields();
4846

4947
ConfigureRootSlot();
5048
BuildUI();
5149
UpdateStatus("Select inputs to begin.");
52-
Focus();
53-
RepositionFor(owner);
5450
}
5551

56-
public static ReferenceReplacementDialog Create(User owner, Slot dialogSlot)
57-
{
58-
return new ReferenceReplacementDialog(owner, dialogSlot);
59-
}
60-
61-
public bool IsAlive => !_disposed && !_rootSlot.IsDestroyed && !_rootSlot.IsRemoved;
52+
private bool IsAlive => !_disposed && !_rootSlot.IsDestroyed && !_rootSlot.IsRemoved;
6253

63-
public void Focus()
64-
{
65-
if (IsAlive)
66-
{
67-
_rootSlot.OrderOffset = DateTime.UtcNow.Ticks;
68-
}
69-
}
70-
71-
public void RepositionFor(User? user)
54+
private void PositionFor(User? user)
7255
{
7356
if (user == null || !IsAlive)
7457
{
7558
return;
7659
}
7760

78-
ResetRootTransform();
7961
_rootSlot.PositionInFrontOfUser(float3.Backward);
8062
if (user.LocalUserRoot != null)
8163
{
@@ -354,22 +336,4 @@ private void UpdateStatus(string message, ReferenceScanResult? detail = null)
354336
}
355337
}
356338

357-
private static void ClearSlot(Slot slot)
358-
{
359-
foreach (Slot child in slot.Children.ToArray())
360-
{
361-
child.Destroy();
362-
}
363-
364-
foreach (Component component in slot.Components.ToArray())
365-
{
366-
component.Destroy();
367-
}
368-
}
369-
370-
private void ResetRootTransform()
371-
{
372-
_rootSlot.LocalPosition = float3.Zero;
373-
_rootSlot.LocalRotation = floatQ.Identity;
374-
}
375339
}

0 commit comments

Comments
 (0)