Skip to content

Commit e6a25b4

Browse files
committed
Add InsertControl method to Window and WindowContentManager
1 parent 9c666ef commit e6a25b4

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

SharpConsoleUI/Window.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,18 @@ public void AddControl(IWindowControl content)
924924
GoToBottom();
925925
}
926926
}
927+
/// <summary>
928+
/// Inserts a control at the specified index.
929+
/// </summary>
930+
public void InsertControl(int index, IWindowControl content)
931+
{
932+
lock (_lock)
933+
{
934+
_contentManager.InsertControl(_controls, _interactiveContents, index, content, this);
935+
RenderAndGetVisibleContent();
936+
}
937+
}
938+
927939
/// <summary>
928940
/// Removes all controls from the window.
929941
/// </summary>

SharpConsoleUI/Windows/WindowContentManager.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ public void AddControl(
8080
_invalidateCallback();
8181
}
8282

83+
/// <summary>
84+
/// Inserts a control at the specified index.
85+
/// </summary>
86+
public void InsertControl(
87+
List<IWindowControl> controls,
88+
List<IInteractiveControl> interactiveControls,
89+
int index,
90+
IWindowControl control,
91+
IContainer container)
92+
{
93+
if (control == null)
94+
throw new ArgumentNullException(nameof(control));
95+
96+
_logService?.LogDebug($"Control inserted into window '{_getWindowTitle()}' at index {index}: {control.GetType().Name}", "Window");
97+
98+
control.Container = container;
99+
controls.Insert(index, control);
100+
101+
if (control is IInteractiveControl interactiveControl)
102+
{
103+
interactiveControls.Add(interactiveControl);
104+
}
105+
106+
InvalidationManager.Instance.RegisterControl(control);
107+
_invalidateLayoutCallback();
108+
_invalidateCallback();
109+
}
110+
83111
/// <summary>
84112
/// Removes a control from the control list.
85113
/// </summary>

0 commit comments

Comments
 (0)