Table of Contents

Class ModalStateService

Namespace
SharpConsoleUI.Core
Assembly
SharpConsoleUI.dll

Centralized service for managing modal window state. Handles modal window stack, parent-child relationships, and activation blocking.

public class ModalStateService : IDisposable
Inheritance
ModalStateService
Implements
Inherited Members

Constructors

ModalStateService(ILogService?)

Initializes a new instance of the ModalStateService class.

public ModalStateService(ILogService? logService = null)

Parameters

logService ILogService

Optional log service for diagnostic logging.

Properties

CurrentState

Gets the current modal state.

public ModalState CurrentState { get; }

Property Value

ModalState

HasModals

Gets a value indicating whether any modal windows are open.

public bool HasModals { get; }

Property Value

bool

ModalCount

Gets the number of modal windows currently open.

public int ModalCount { get; }

Property Value

int

TopmostModal

Gets the topmost modal window (if any).

public Window? TopmostModal { get; }

Property Value

Window

Methods

ClearHistory()

Clears the state history.

public void ClearHistory()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetBlockingModal(Window)

Checks if activation of a window is blocked by a modal.

public Window? GetBlockingModal(Window targetWindow)

Parameters

targetWindow Window

The window trying to be activated.

Returns

Window

The blocking modal, or null if not blocked.

GetDebugInfo()

Gets a debug string representation of current modal state.

public string GetDebugInfo()

Returns

string

A formatted string containing the current modal state information.

GetDeepestModalChild(Window)

Gets the deepest modal child of a window (recursive).

public Window? GetDeepestModalChild(Window parent)

Parameters

parent Window

The parent window.

Returns

Window

The deepest modal child, or null if no modal children exist.

GetEffectiveActivationTarget(Window)

Gets the window that should actually be activated when trying to activate a target window. This handles modal blocking by returning the deepest modal child if one exists.

public Window GetEffectiveActivationTarget(Window targetWindow)

Parameters

targetWindow Window

The window the user is trying to activate.

Returns

Window

The window that should actually be activated.

GetHistory()

Gets recent modal state history for debugging.

public IReadOnlyList<ModalState> GetHistory()

Returns

IReadOnlyList<ModalState>

A read-only list of recent modal states.

GetModalChildren(Window)

Gets all modal children of a window (direct children only).

public IReadOnlyList<Window> GetModalChildren(Window parent)

Parameters

parent Window

The parent window.

Returns

IReadOnlyList<Window>

A read-only list of modal children.

GetModalParent(Window)

Gets the parent of a modal window.

public Window? GetModalParent(Window modal)

Parameters

modal Window

The modal window.

Returns

Window

The parent window, or null if the modal has no parent.

HasOrphanModals()

Checks if there are any orphan modals (modals with no parent that block everything).

public bool HasOrphanModals()

Returns

bool

True if orphan modals exist; otherwise, false.

IsActivationBlocked(Window)

Checks if activation of a window is blocked.

public bool IsActivationBlocked(Window targetWindow)

Parameters

targetWindow Window

The window trying to be activated.

Returns

bool

True if blocked; otherwise, false.

IsModal(Window)

Checks if a window is a modal.

public bool IsModal(Window window)

Parameters

window Window

The window to check.

Returns

bool

True if the window is a modal; otherwise, false.

PopModal(Window)

Unregisters a modal window.

public void PopModal(Window modal)

Parameters

modal Window

The modal window to remove.

PushModal(Window, Window?)

Registers a modal window with its parent.

public void PushModal(Window modal, Window? parent)

Parameters

modal Window

The modal window.

parent Window

The parent window (can be null for orphan modals).

Exceptions

ArgumentNullException

Thrown when modal is null.

Events

ActivationBlocked

Occurs when window activation is blocked by a modal.

public event EventHandler<ActivationBlockedEventArgs>? ActivationBlocked

Event Type

EventHandler<ActivationBlockedEventArgs>

ModalClosed

Occurs when a modal window is closed.

public event EventHandler<ModalStateChangedEventArgs>? ModalClosed

Event Type

EventHandler<ModalStateChangedEventArgs>

ModalOpened

Occurs when a modal window is opened.

public event EventHandler<ModalStateChangedEventArgs>? ModalOpened

Event Type

EventHandler<ModalStateChangedEventArgs>

StateChanged

Occurs when modal state changes.

public event EventHandler<ModalStateChangedEventArgs>? StateChanged

Event Type

EventHandler<ModalStateChangedEventArgs>