diff --git a/src/KubeUI/App.axaml.cs b/src/KubeUI/App.axaml.cs index 6485072c..760d3593 100644 --- a/src/KubeUI/App.axaml.cs +++ b/src/KubeUI/App.axaml.cs @@ -101,8 +101,10 @@ public override void OnFrameworkInitializationCompleted() if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - desktop.MainWindow = MainWindow.Build(); - desktop.MainWindow.DataContext = _serviceProvider.GetRequiredService(); + var vm = _serviceProvider.GetRequiredService(); + + desktop.MainWindow = MainWindow.Build(vm); + desktop.MainWindow.DataContext = vm; TopLevel = TopLevel.GetTopLevel(desktop.MainWindow); } else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) diff --git a/src/KubeUI/Views/MainView.cs b/src/KubeUI/Views/MainView.cs index 47570bd2..96c0fcee 100644 --- a/src/KubeUI/Views/MainView.cs +++ b/src/KubeUI/Views/MainView.cs @@ -1,4 +1,5 @@ -using Dock.Avalonia.Controls; +using System.Runtime.InteropServices; +using Dock.Avalonia.Controls; namespace KubeUI.Views; @@ -45,7 +46,8 @@ protected override object Build(MainViewModel vm) => .Header(Assets.Resources.MainView_Menu_Help_About) .Command(vm.OpenAboutCommand), ]) - ]), + ]) + .IsVisible(() => !RuntimeInformation.IsOSPlatform(OSPlatform.OSX)), new DockControl() .Row(1) .Margin(4) diff --git a/src/KubeUI/Views/MainVindow.cs b/src/KubeUI/Views/MainVindow.cs index 0a5a46d1..083ca845 100644 --- a/src/KubeUI/Views/MainVindow.cs +++ b/src/KubeUI/Views/MainVindow.cs @@ -1,11 +1,50 @@ -namespace KubeUI.Views; +using AvaloniaEdit.Utils; + +namespace KubeUI.Views; public static class MainWindow { - public static Window Build() => + public static Window Build(MainViewModel vm) => (Window)new Window() .Title("KubeUI") .UseLayoutRounding(true) + .SetProp(NativeMenu.MenuProperty, new NativeMenu() + .Items([ + new NativeMenuItem() + .Header(Resources.MainView_Menu_File) + .Items([ + new NativeMenuItem() + .Header(Resources.MainView_Menu_File_Clusters) + .Command(vm.OpenClustersCommand), + new NativeMenuItem() + .Header(Resources.MainView_Menu_File_Settings) + .Command(vm.OpenSettingsCommand), + + new NativeMenuItemSeparator(), + + new NativeMenuItem() + .Header(Resources.MainView_Menu_File_Exit) + .Command(vm.CloseCommand), + ]), + new NativeMenuItem() + .Header(Resources.MainView_Menu_Window) + .Items([ + new NativeMenuItem() + .Header(Resources.MainView_Menu_Window_ResetLayout) + .Command(vm.ResetLayoutCommand), + new NativeMenuItem() + .Header(Resources.MainView_Menu_Window_SwitchTheme) + .Command(vm.SwitchThemeCommand), + ]), + new NativeMenuItem() + .Header(Resources.MainView_Menu_Help) + .Items([ + new NativeMenuItem() + .Header(Resources.MainView_Menu_Help_About) + .Command(vm.OpenAboutCommand), + ]) + ]) + ) .Content( new Panel() .Children([ @@ -14,3 +53,23 @@ public static Window Build() => ) ); } + + +public static class WindowExtensions +{ + public static NativeMenu Items(this NativeMenu menu, NativeMenuItemBase[] items) + { + menu.Items.AddRange(items); + + return menu; + } + + public static NativeMenuItem Items(this NativeMenuItem menu, NativeMenuItemBase[] items) + { + menu.Menu ??= []; + + menu.Menu.Items.AddRange(items); + + return menu; + } +}