Files
Lattice/Lattice.Core/Services/ContextService.cs
2026-01-07 23:54:00 +03:00

40 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Lattice.Core.Abstractions;
namespace Lattice.Core.Services;
/// <summary>
/// Реализация сервиса управления контекстом приложения.
/// </summary>
public class ContextService : IContextService
{
private string _currentContext = "Common";
/// <inheritdoc/>
public string CurrentContext => _currentContext;
/// <inheritdoc/>
public event EventHandler<string>? ContextChanged;
/// <inheritdoc/>
public void SetContext(string contextGroup)
{
if (string.IsNullOrWhiteSpace(contextGroup)) contextGroup = "Common";
if (_currentContext != contextGroup)
{
_currentContext = contextGroup;
ContextChanged?.Invoke(this, contextGroup);
}
}
/// <inheritdoc/>
public bool IsCommandVisible(string commandId, string commandContext)
{
// Базовая логика: команда видима, если её контекст совпадает с текущим
// или если команда помечена как общая ("Common" или "Global").
return commandContext == "Common" ||
commandContext == "Global" ||
commandContext == _currentContext;
}
}