145 lines
6.0 KiB
C#
145 lines
6.0 KiB
C#
using Lattice.Core.Abstractions;
|
|
using Lattice.Core.Models;
|
|
using Lattice.Core.Models.Enums;
|
|
using Microsoft.UI.Composition.SystemBackdrops;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Media;
|
|
|
|
namespace Lattice.Studio.Controls;
|
|
|
|
/// <summary>
|
|
/// Îñíîâíàÿ îáîëî÷êà ïðèëîæåíèÿ â ñòèëå Visual Studio 2026.
|
|
/// Îáåñïå÷èâàåò èíòåãðàöèþ íàòèâíîãî çàãîëîâêà, ñèñòåìû äîêèíãà è êîíòåêñòíûõ êîìàíä.
|
|
/// </summary>
|
|
public sealed partial class LatticeStudioShell : UserControl
|
|
{
|
|
private ILayoutService? _layoutManager;
|
|
private IContextService? _contextService;
|
|
private IEnumerable<ActionDefinition>? _allActions;
|
|
|
|
#region Dependency Properties (Ñëîòû êàñòîìèçàöèè)
|
|
|
|
public string Title { get => (string)GetValue(TitleProperty); set => SetValue(TitleProperty, value); }
|
|
public static readonly DependencyProperty TitleProperty =
|
|
DependencyProperty.Register(nameof(Title), typeof(string), typeof(LatticeStudioShell), new PropertyMetadata("Lattice IDE"));
|
|
|
|
public string Subtitle { get => (string)GetValue(SubtitleProperty); set => SetValue(SubtitleProperty, value); }
|
|
public static readonly DependencyProperty SubtitleProperty =
|
|
DependencyProperty.Register(nameof(Subtitle), typeof(string), typeof(LatticeStudioShell), new PropertyMetadata(string.Empty));
|
|
|
|
public IconSource TitleBarIcon { get => (IconSource)GetValue(TitleBarIconProperty); set => SetValue(TitleBarIconProperty, value); }
|
|
public static readonly DependencyProperty TitleBarIconProperty =
|
|
DependencyProperty.Register(nameof(TitleBarIcon), typeof(IconSource), typeof(LatticeStudioShell), new PropertyMetadata(null));
|
|
|
|
public object MenuContent { get => GetValue(MenuContentProperty); set => SetValue(MenuContentProperty, value); }
|
|
public static readonly DependencyProperty MenuContentProperty =
|
|
DependencyProperty.Register(nameof(MenuContent), typeof(object), typeof(LatticeStudioShell), new PropertyMetadata(null));
|
|
|
|
public object StatusContent { get => GetValue(StatusContentProperty); set => SetValue(StatusContentProperty, value); }
|
|
public static readonly DependencyProperty StatusContentProperty =
|
|
DependencyProperty.Register(nameof(StatusContent), typeof(object), typeof(LatticeStudioShell), new PropertyMetadata(null));
|
|
|
|
#endregion
|
|
|
|
public LatticeStudioShell()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Èíèöèàëèçèðóåò îáîëî÷êó Studio è ñâÿçûâàåò å¸ ñ ñåðâèñàìè Lattice.Core.
|
|
/// </summary>
|
|
/// <param name="layoutManager">Ýêçåìïëÿð ILayoutService äëÿ óïðàâëåíèÿ îêíàìè.</param>
|
|
/// <param name="contextService">Ýêçåìïëÿð IContextService äëÿ óïðàâëåíèÿ êíîïêàìè òóëáàðà.</param>
|
|
/// <param name="actions">Ïîëíûé ñïèñîê îïðåäåëåíèé êîìàíä (ActionDefinition).</param>
|
|
public void Initialize(ILayoutService layoutManager, IContextService contextService, IEnumerable<ActionDefinition> actions)
|
|
{
|
|
_layoutManager = layoutManager;
|
|
_contextService = contextService;
|
|
_allActions = actions;
|
|
|
|
// Ñâÿçûâàåì âèçóàëüíûé õîñò äîêèíãà ñ ëîãè÷åñêèì äâèæêîì
|
|
MainDockHost.Manager = _layoutManager;
|
|
|
|
// Ïîäïèñûâàåìñÿ íà ñìåíó êîíòåêñòà (âûçûâàåòñÿ ïðè ïåðåêëþ÷åíèè âêëàäîê â Lattice.UI)
|
|
_contextService.ContextChanged += (s, newContext) =>
|
|
{
|
|
// Îáíîâëÿåì òóëáàð â ïîòîêå ïîëüçîâàòåëüñêîãî èíòåðôåéñà
|
|
this.DispatcherQueue.TryEnqueue(() =>
|
|
{
|
|
StudioToolbar.UpdateItems(_allActions, newContext);
|
|
});
|
|
};
|
|
|
|
// Íà÷àëüíàÿ èíèöèàëèçàöèÿ òóëáàðà òåêóùèì êîíòåêñòîì
|
|
StudioToolbar.UpdateItems(_allActions, _contextService.CurrentContext);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Íàñòðàèâàåò èíòåãðàöèþ ñ íàòèâíûì îêíîì Windows 11 (TitleBar è Backdrop).
|
|
/// Âûçûâàåòñÿ èç MainWindow ïðèëîæåíèÿ.
|
|
/// </summary>
|
|
/// <param name="window">Òåêóùåå îêíî WinUI 3.</param>
|
|
public void SetupWindow(Window window)
|
|
{
|
|
// 1. Ðàñøèðÿåì êîíòåíò â îáëàñòü çàãîëîâêà (Windowing SDK 1.8)
|
|
window.ExtendsContentIntoTitleBar = true;
|
|
|
|
// 2. Óêàçûâàåì íàòèâíûé TitleBar äëÿ óïðàâëåíèÿ ïåðåòàñêèâàíèåì îêíà
|
|
if (AppTitleBar != null)
|
|
{
|
|
window.SetTitleBar(AppTitleBar);
|
|
}
|
|
|
|
// 3. Ïðèìåíÿåì Mica Alt äëÿ ôîíà â ñòèëå Visual Studio 2026
|
|
window.SystemBackdrop = new MicaBackdrop()
|
|
{
|
|
Kind = MicaKind.BaseAlt
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ïîäêëþ÷àåò ñåðâèñ óâåäîìëåíèé ê îáîëî÷êå.
|
|
/// </summary>
|
|
public void InitializeNotifications(INotificationService notificationService)
|
|
{
|
|
notificationService.NotificationReceived += (s, e) =>
|
|
{
|
|
this.DispatcherQueue.TryEnqueue(() =>
|
|
{
|
|
var infoBar = new InfoBar
|
|
{
|
|
Message = e.Message,
|
|
Severity = MapSeverity(e.Severity),
|
|
IsOpen = true,
|
|
Style = (Style)Application.Current.Resources["LatticeNotificationStyle"]
|
|
};
|
|
|
|
// Àâòîìàòè÷åñêîå çàêðûòèå
|
|
if (e.DurationSeconds > 0)
|
|
{
|
|
var timer = new DispatcherTimer
|
|
{
|
|
Interval = TimeSpan.FromSeconds(e.DurationSeconds)
|
|
};
|
|
timer.Tick += (st, et) => { infoBar.IsOpen = false; timer.Stop(); };
|
|
timer.Start();
|
|
}
|
|
|
|
// Óäàëåíèå èç ïàìÿòè ïîñëå çàêðûòèÿ
|
|
infoBar.CloseButtonClick += (sender, args) => NotificationArea.Children.Remove(infoBar);
|
|
|
|
NotificationArea.Children.Insert(0, infoBar); // Íîâûå ñâåðõó
|
|
});
|
|
};
|
|
}
|
|
private InfoBarSeverity MapSeverity(NotificationSeverity severity) => severity switch
|
|
{
|
|
NotificationSeverity.Error => InfoBarSeverity.Error,
|
|
NotificationSeverity.Warning => InfoBarSeverity.Warning,
|
|
NotificationSeverity.Success => InfoBarSeverity.Success,
|
|
_ => InfoBarSeverity.Informational
|
|
};
|
|
}
|