Browse Source
IsVisible for NativeMenuItem(s) (#14567)
* IsVisible for nativemenuitems
* implementation for windows
* Update native/Avalonia.Native/src/OSX/menu.mm
Co-authored-by: jp2masa <jp2masa@users.noreply.github.com>
* Update menu.h
* address review changes
* add hidden option to ControlCatalog
---------
Co-authored-by: jp2masa <jp2masa@users.noreply.github.com>
Co-authored-by: Max Katz <maxkatz6@outlook.com>
pull/14664/head
Rosentti
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with
45 additions and
1 deletions
-
native/Avalonia.Native/src/OSX/menu.h
-
native/Avalonia.Native/src/OSX/menu.mm
-
samples/ControlCatalog/App.xaml
-
src/Avalonia.Controls/NativeMenuBarPresenter.cs
-
src/Avalonia.Controls/NativeMenuItem.cs
-
src/Avalonia.FreeDesktop/DBusMenuExporter.cs
-
src/Avalonia.Native/IAvnMenuItem.cs
-
src/Avalonia.Native/avn.idl
|
|
|
@ -51,7 +51,9 @@ public: |
|
|
|
virtual HRESULT SetAction (IAvnPredicateCallback* predicate, IAvnActionCallback* callback) override; |
|
|
|
|
|
|
|
virtual HRESULT SetIsChecked (bool isChecked) override; |
|
|
|
|
|
|
|
|
|
|
|
virtual HRESULT SetIsVisible (bool isVisible) override; |
|
|
|
|
|
|
|
virtual HRESULT SetToggleType (AvnMenuItemToggleType toggleType) override; |
|
|
|
|
|
|
|
virtual HRESULT SetIcon (void* data, size_t length) override; |
|
|
|
|
|
|
|
@ -205,6 +205,17 @@ HRESULT AvnAppMenuItem::SetIsChecked (bool isChecked) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HRESULT AvnAppMenuItem::SetIsVisible (bool isVisible) |
|
|
|
{ |
|
|
|
START_COM_CALL; |
|
|
|
|
|
|
|
@autoreleasepool |
|
|
|
{ |
|
|
|
[_native setHidden:!isVisible]; |
|
|
|
return S_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HRESULT AvnAppMenuItem::SetToggleType(AvnMenuItemToggleType toggleType) |
|
|
|
{ |
|
|
|
START_COM_CALL; |
|
|
|
|
|
|
|
@ -75,6 +75,7 @@ |
|
|
|
<NativeMenuItem Header="Option 3" ToggleType="CheckBox" IsChecked="True" /> |
|
|
|
<NativeMenuItem Icon="/Assets/test_icon.ico" Header="Restore Defaults" Command="{Binding RestoreDefault}" /> |
|
|
|
<NativeMenuItem Header="Disabled option" IsEnabled="False" /> |
|
|
|
<NativeMenuItem Header="Hidden option" IsVisible="False" /> |
|
|
|
</NativeMenu> |
|
|
|
</NativeMenuItem> |
|
|
|
<NativeMenuItem Header="Exit" Command="{Binding ExitCommand}" /> |
|
|
|
|
|
|
|
@ -26,6 +26,7 @@ internal class NativeMenuBarPresenter : Menu |
|
|
|
[!MenuItem.IconProperty] = nativeItem.GetObservable(NativeMenuItem.IconProperty) |
|
|
|
.Select(i => i is { } bitmap ? new Image { Source = bitmap } : null).ToBinding(), |
|
|
|
[!MenuItem.IsEnabledProperty] = nativeItem.GetObservable(NativeMenuItem.IsEnabledProperty).ToBinding(), |
|
|
|
[!MenuItem.IsVisibleProperty] = nativeItem.GetObservable(NativeMenuItem.IsVisibleProperty).ToBinding(), |
|
|
|
[!MenuItem.CommandProperty] = nativeItem.GetObservable(NativeMenuItem.CommandProperty).ToBinding(), |
|
|
|
[!MenuItem.CommandParameterProperty] = |
|
|
|
nativeItem.GetObservable(NativeMenuItem.CommandParameterProperty).ToBinding(), |
|
|
|
|
|
|
|
@ -144,6 +144,21 @@ namespace Avalonia.Controls |
|
|
|
set => SetValue(IsEnabledProperty, value); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="IsVisible"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<bool> IsVisibleProperty = |
|
|
|
Visual.IsVisibleProperty.AddOwner<NativeMenuItem>(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a value indicating whether this menu item is visible.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsVisible |
|
|
|
{ |
|
|
|
get => GetValue(IsVisibleProperty); |
|
|
|
set => SetValue(IsVisibleProperty, value); |
|
|
|
} |
|
|
|
|
|
|
|
void CanExecuteChanged() |
|
|
|
{ |
|
|
|
SetCurrentValue(IsEnabledProperty, Command?.CanExecute(CommandParameter) ?? true); |
|
|
|
|
|
|
|
@ -243,6 +243,13 @@ namespace Avalonia.FreeDesktop |
|
|
|
return new DBusVariantItem("b", new DBusBoolItem(false)); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
if (name == "visible") { |
|
|
|
if (!item.IsVisible) |
|
|
|
return new DBusVariantItem("b", new DBusBoolItem(false)); |
|
|
|
return new DBusVariantItem("b", new DBusBoolItem(true)); |
|
|
|
} |
|
|
|
|
|
|
|
if (name == "shortcut") |
|
|
|
{ |
|
|
|
if (item.Gesture is null) |
|
|
|
|
|
|
|
@ -40,6 +40,7 @@ namespace Avalonia.Native.Interop.Impl |
|
|
|
|
|
|
|
private void UpdateToolTip(string toolTip) => SetToolTip(toolTip ?? ""); |
|
|
|
|
|
|
|
private void UpdateIsVisible(bool isVisible) => SetIsVisible(isVisible.AsComBool()); |
|
|
|
private void UpdateIsChecked(bool isChecked) => SetIsChecked(isChecked.AsComBool()); |
|
|
|
|
|
|
|
private void UpdateToggleType(NativeMenuItemToggleType toggleType) |
|
|
|
@ -121,6 +122,8 @@ namespace Avalonia.Native.Interop.Impl |
|
|
|
|
|
|
|
UpdateIsChecked(item.IsChecked); |
|
|
|
|
|
|
|
UpdateIsVisible(item.IsVisible); |
|
|
|
|
|
|
|
_propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.HeaderProperty) |
|
|
|
.Subscribe(x => UpdateTitle(x))); |
|
|
|
|
|
|
|
@ -139,6 +142,9 @@ namespace Avalonia.Native.Interop.Impl |
|
|
|
_propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.IsCheckedProperty) |
|
|
|
.Subscribe(x => UpdateIsChecked(x))); |
|
|
|
|
|
|
|
_propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.IsVisibleProperty) |
|
|
|
.Subscribe(x => UpdateIsVisible(x))); |
|
|
|
|
|
|
|
_propertyDisposables.Add(ManagedMenuItem.GetObservable(NativeMenuItem.IconProperty) |
|
|
|
.Subscribe(x => UpdateIcon(x))); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1026,6 +1026,7 @@ interface IAvnMenuItem : IUnknown |
|
|
|
HRESULT SetGesture(AvnKey key, AvnInputModifiers modifiers); |
|
|
|
HRESULT SetAction(IAvnPredicateCallback* predicate, IAvnActionCallback* callback); |
|
|
|
HRESULT SetIsChecked(bool isChecked); |
|
|
|
HRESULT SetIsVisible(bool isVisible); |
|
|
|
HRESULT SetToggleType(AvnMenuItemToggleType toggleType); |
|
|
|
HRESULT SetIcon(void* data, size_t length); |
|
|
|
} |
|
|
|
|