Skip to content

Commit c246bf7

Browse files
committed
Fix for macos menu and hide panel button
1 parent ad6d65e commit c246bf7

6 files changed

Lines changed: 48 additions & 37 deletions

File tree

BusLane.Tests/AppMenuTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ namespace BusLane.Tests;
55

66
public class AppMenuTests
77
{
8+
[Fact]
9+
public void AppXaml_DefinesMacApplicationAboutMenu()
10+
{
11+
// Arrange
12+
var xaml = File.ReadAllText(GetAppPath());
13+
14+
// Assert
15+
xaml.Should().Contain("<NativeMenu.Menu>");
16+
xaml.Should().Contain("<NativeMenuItem Header=\"About BusLane\" Click=\"AboutMenuItem_OnClick\"/>");
17+
}
18+
819
[Fact]
920
public void CreateMacMenu_Always_CreatesViewAndHelpMenusWithExpectedItems()
1021
{
@@ -46,4 +57,16 @@ public void CreateMacMenu_Always_CreatesViewAndHelpMenusWithExpectedItems()
4657
aboutItem.Header.Should().Be("About BusLane");
4758
aboutItem.HasClickHandlers.Should().BeTrue();
4859
}
60+
61+
private static string GetAppPath()
62+
{
63+
return Path.GetFullPath(Path.Combine(
64+
AppContext.BaseDirectory,
65+
"..",
66+
"..",
67+
"..",
68+
"..",
69+
"BusLane",
70+
"App.axaml"));
71+
}
4972
}

BusLane.Tests/Views/NavigationSidebarTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public void NavigationSidebar_RendersCollapsedRail()
6565
xaml.Should().Contain("Classes=\"sidebar-rail\"");
6666
}
6767

68+
[Fact]
69+
public void NavigationSidebar_CollapsedRailExpandButton_UsesRestoreTreatmentAndOpenLeftPanelIcon()
70+
{
71+
// Arrange
72+
var xaml = File.ReadAllText(GetSidebarPath());
73+
74+
// Assert
75+
xaml.Should().Contain("Classes=\"entity-pane-restore-command\"");
76+
xaml.Should().Contain("<LucideIcon Kind=\"PanelLeftOpen\" Size=\"18\"");
77+
xaml.Should().NotContain("<LucideIcon Kind=\"PanelRightOpen\" Size=\"18\"");
78+
}
79+
6880
[Fact]
6981
public void NavigationSidebar_DoesNotRenderDisconnectAsStandalonePrimaryBlock()
7082
{

BusLane/App.axaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
x:Class="BusLane.App"
66
Name="BusLane"
77
RequestedThemeVariant="Default">
8+
<NativeMenu.Menu>
9+
<NativeMenu>
10+
<NativeMenuItem Header="About BusLane" Click="AboutMenuItem_OnClick"/>
11+
</NativeMenu>
12+
</NativeMenu.Menu>
13+
814
<Application.Resources>
915
<ResourceDictionary>
1016

BusLane/App.axaml.cs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ private static void SetMacOSDockIcon()
9999
{
100100
objc_msgSend(sharedApp, setApplicationIconImage, image);
101101
}
102-
103-
// Remove default "About Avalonia" item from the application menu.
104-
RemoveDefaultMacOSAboutMenuItem(sharedApp);
105102
}
106103
catch
107104
{
@@ -179,41 +176,14 @@ private static async Task ShowAboutDialogAsync(Window owner)
179176
await dialog.ShowDialog(owner);
180177
}
181178

182-
private static void RemoveDefaultMacOSAboutMenuItem(IntPtr nsApp)
179+
private async void AboutMenuItem_OnClick(object? sender, EventArgs args)
183180
{
184-
try
185-
{
186-
// Get the main menu
187-
var mainMenuSelector = sel_registerName("mainMenu");
188-
var mainMenu = objc_msgSend(nsApp, mainMenuSelector);
181+
if (MainWindow is null)
182+
return;
189183

190-
if (mainMenu != IntPtr.Zero)
191-
{
192-
// Get the first item (application menu)
193-
var itemAtIndexSelector = sel_registerName("itemAtIndex:");
194-
var appMenuItem = objc_msgSend(mainMenu, itemAtIndexSelector, (IntPtr)0);
195-
196-
if (appMenuItem != IntPtr.Zero)
197-
{
198-
// Get the submenu
199-
var submenuSelector = sel_registerName("submenu");
200-
var appMenu = objc_msgSend(appMenuItem, submenuSelector);
201-
202-
if (appMenu != IntPtr.Zero)
203-
{
204-
// First entry is the default About item; remove it.
205-
var removeItemAtIndexSelector = sel_registerName("removeItemAtIndex:");
206-
objc_msgSend(appMenu, removeItemAtIndexSelector, (IntPtr)0);
207-
}
208-
}
209-
}
210-
}
211-
catch
212-
{
213-
// Silently fail if we can't modify the menu
214-
}
184+
await ShowAboutDialogAsync(MainWindow);
215185
}
216-
186+
217187
[DllImport("/usr/lib/libobjc.dylib", EntryPoint = "objc_getClass")]
218188
private static extern IntPtr objc_getClass(string className);
219189

BusLane/Views/Controls/NavigationSidebar.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,10 @@
446446
<Rectangle Canvas.Left="104" Canvas.Top="320" Width="304" Height="44" RadiusX="22" RadiusY="22" Fill="#FFFFFF"/>
447447
</Canvas>
448448
</Viewbox>
449-
<Button Classes="panel-toggle"
449+
<Button Classes="entity-pane-restore-command"
450450
Command="{Binding ToggleNavigationPanelCommand}"
451451
ToolTip.Tip="Expand navigation">
452-
<LucideIcon Kind="PanelRightOpen" Size="18"/>
452+
<LucideIcon Kind="PanelLeftOpen" Size="18"/>
453453
</Button>
454454
</StackPanel>
455455

docs/pics/MainWindow.png

-34.9 KB
Loading

0 commit comments

Comments
 (0)