Skip to content

Commit e7c6a9f

Browse files
danwalmsleygrokys
authored andcommitted
Merge pull request #7341 from AvaloniaUI/fixes/standard-osx-item-generation
Fixes/standard osx item generation
1 parent b25742b commit e7c6a9f

File tree

4 files changed

+63
-52
lines changed

4 files changed

+63
-52
lines changed

samples/ControlCatalog/App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:vm="using:ControlCatalog.ViewModels"
44
x:DataType="vm:ApplicationViewModel"
55
x:CompileBindings="True"
6+
Name="Avalonia ControlCatalog"
67
x:Class="ControlCatalog.App">
78
<Application.Styles>
89
<Style Selector="TextBlock.h1, TextBlock.h2, TextBlock.h3">

src/Avalonia.Dialogs/AboutAvaloniaDialog.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
</StackPanel>
9696
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
9797
<TextBlock Text="Chat Room | " />
98-
<Button Classes="Hyperlink" CommandParameter="https://gitter.im/AvaloniaUI/Avalonia/" />
98+
<Button Classes="Hyperlink" CommandParameter="https://t.me/Avalonia" />
9999
</StackPanel>
100100
</StackPanel>
101101
<StackPanel VerticalAlignment="Bottom" Margin="10">

src/Avalonia.Dialogs/Avalonia.Dialogs.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<SubType>Designer</SubType>
99
</AvaloniaResource>
1010
<AvaloniaResource Include="Assets\*" />
11+
<AvaloniaResource Include="**/*.xaml" />
1112
</ItemGroup>
1213

1314
<Import Project="..\..\build\BuildTargets.targets" />

src/Avalonia.Native/AvaloniaNativeMenuExporter.cs

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -70,74 +70,76 @@ private NativeMenu CreateDefaultAppMenu()
7070
var result = new NativeMenu();
7171

7272
var aboutItem = new NativeMenuItem("About Avalonia");
73-
aboutItem.Click += async (sender, e) =>
73+
74+
aboutItem.Click += async (_, _) =>
7475
{
7576
var dialog = new AboutAvaloniaDialog();
7677

77-
var mainWindow = (Application.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;
78-
79-
await dialog.ShowDialog(mainWindow);
78+
if (Application.Current is
79+
{ ApplicationLifetime: IClassicDesktopStyleApplicationLifetime { MainWindow: { } mainWindow } })
80+
{
81+
await dialog.ShowDialog(mainWindow);
82+
}
8083
};
84+
8185
result.Add(aboutItem);
8286

83-
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>();
84-
if (macOpts == null || !macOpts.DisableDefaultApplicationMenuItems)
85-
{
86-
result.Add(new NativeMenuItemSeparator());
87+
return result;
88+
}
8789

88-
var servicesMenu = new NativeMenuItem("Services");
89-
servicesMenu.Menu = new NativeMenu
90-
{
91-
[MacOSNativeMenuCommands.IsServicesSubmenuProperty] = true
92-
};
93-
result.Add(servicesMenu);
90+
private void PopulateStandardOSXMenuItems(NativeMenu appMenu)
91+
{
92+
appMenu.Add(new NativeMenuItemSeparator());
9493

95-
result.Add(new NativeMenuItemSeparator());
94+
var servicesMenu = new NativeMenuItem("Services");
95+
servicesMenu.Menu = new NativeMenu { [MacOSNativeMenuCommands.IsServicesSubmenuProperty] = true };
9696

97-
var hideItem = new NativeMenuItem("Hide " + Application.Current.Name)
98-
{
99-
Gesture = new KeyGesture(Key.H, KeyModifiers.Meta)
100-
};
101-
hideItem.Click += (sender, args) =>
102-
{
103-
_applicationCommands.HideApp();
104-
};
105-
result.Add(hideItem);
97+
appMenu.Add(servicesMenu);
10698

99+
appMenu.Add(new NativeMenuItemSeparator());
107100

108-
var hideOthersItem = new NativeMenuItem("Hide Others")
109-
{
110-
Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta | KeyModifiers.Alt)
111-
};
112-
hideOthersItem.Click += (sender, args) =>
113-
{
114-
_applicationCommands.HideOthers();
115-
};
116-
result.Add(hideOthersItem);
101+
var hideItem = new NativeMenuItem("Hide " + (Application.Current?.Name ?? "Application"))
102+
{
103+
Gesture = new KeyGesture(Key.H, KeyModifiers.Meta)
104+
};
117105

106+
hideItem.Click += (_, _) =>
107+
{
108+
_applicationCommands.HideApp();
109+
};
118110

119-
var showAllItem = new NativeMenuItem("Show All");
120-
showAllItem.Click += (sender, args) =>
121-
{
122-
_applicationCommands.ShowAll();
123-
};
124-
result.Add(showAllItem);
111+
appMenu.Add(hideItem);
125112

126-
result.Add(new NativeMenuItemSeparator());
113+
var hideOthersItem = new NativeMenuItem("Hide Others")
114+
{
115+
Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta | KeyModifiers.Alt)
116+
};
117+
hideOthersItem.Click += (_, _) =>
118+
{
119+
_applicationCommands.HideOthers();
120+
};
121+
appMenu.Add(hideOthersItem);
127122

128-
var quitItem = new NativeMenuItem("Quit")
129-
{
130-
Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta)
131-
};
132-
quitItem.Click += (sender, args) =>
133-
{
134-
_applicationCommands.ShowAll();
135-
};
136-
result.Add(quitItem);
137-
}
123+
var showAllItem = new NativeMenuItem("Show All");
124+
showAllItem.Click += (_, _) =>
125+
{
126+
_applicationCommands.ShowAll();
127+
};
138128

129+
appMenu.Add(showAllItem);
139130

140-
return result;
131+
appMenu.Add(new NativeMenuItemSeparator());
132+
133+
var quitItem = new NativeMenuItem("Quit") { Gesture = new KeyGesture(Key.Q, KeyModifiers.Meta) };
134+
quitItem.Click += (_, _) =>
135+
{
136+
if (Application.Current is { ApplicationLifetime: IControlledApplicationLifetime lifetime })
137+
{
138+
lifetime.Shutdown();
139+
}
140+
};
141+
142+
appMenu.Add(quitItem);
141143
}
142144

143145
private void DoLayoutReset(bool forceUpdate = false)
@@ -213,6 +215,13 @@ private void SetMenu(NativeMenu menu)
213215

214216
_nativeMenu.Initialize(this, appMenuHolder, "");
215217

218+
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>();
219+
220+
if (macOpts == null || !macOpts.DisableDefaultApplicationMenuItems)
221+
{
222+
PopulateStandardOSXMenuItems(menu);
223+
}
224+
216225
setMenu = true;
217226
}
218227

0 commit comments

Comments
 (0)