using Lattice.Core.Abstractions;
namespace Lattice.Core.Services;
///
/// Реализация сервиса управления контекстом приложения.
///
public class ContextService : IContextService
{
private string _currentContext = "Common";
///
public string CurrentContext => _currentContext;
///
public event EventHandler? ContextChanged;
///
public void SetContext(string contextGroup)
{
if (string.IsNullOrWhiteSpace(contextGroup)) contextGroup = "Common";
if (_currentContext != contextGroup)
{
_currentContext = contextGroup;
ContextChanged?.Invoke(this, contextGroup);
}
}
///
public bool IsCommandVisible(string commandId, string commandContext)
{
// Базовая логика: команда видима, если её контекст совпадает с текущим
// или если команда помечена как общая ("Common" или "Global").
return commandContext == "Common" ||
commandContext == "Global" ||
commandContext == _currentContext;
}
}