Добавьте файлы проекта.
This commit is contained in:
39
Lattice.Core/Context/ContextManager.cs
Normal file
39
Lattice.Core/Context/ContextManager.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Lattice.Core.Abstractions;
|
||||
|
||||
namespace Lattice.Core.Context;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сервиса управления контекстом приложения.
|
||||
/// </summary>
|
||||
public class ContextManager : 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user