File tree Expand file tree Collapse file tree 8 files changed +45
-1
lines changed
native/Avalonia.Native/src/OSX Expand file tree Collapse file tree 8 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,9 @@ class AvnAppMenuItem : public ComSingleObject<IAvnMenuItem, &IID_IAvnMenuItem>
51
51
virtual HRESULT SetAction (IAvnPredicateCallback* predicate, IAvnActionCallback* callback) override;
52
52
53
53
virtual HRESULT SetIsChecked (bool isChecked) override;
54
-
54
+
55
+ virtual HRESULT SetIsVisible (bool isVisible) override;
56
+
55
57
virtual HRESULT SetToggleType (AvnMenuItemToggleType toggleType) override;
56
58
57
59
virtual HRESULT SetIcon (void * data, size_t length) override;
Original file line number Diff line number Diff line change @@ -205,6 +205,17 @@ - (void)didSelectItem:(nullable id)sender
205
205
}
206
206
}
207
207
208
+ HRESULT AvnAppMenuItem::SetIsVisible (bool isVisible)
209
+ {
210
+ START_COM_CALL;
211
+
212
+ @autoreleasepool
213
+ {
214
+ [_native setHidden: !isVisible];
215
+ return S_OK;
216
+ }
217
+ }
218
+
208
219
HRESULT AvnAppMenuItem::SetToggleType (AvnMenuItemToggleType toggleType)
209
220
{
210
221
START_COM_CALL;
Original file line number Diff line number Diff line change 75
75
<NativeMenuItem Header =" Option 3" ToggleType =" CheckBox" IsChecked =" True" />
76
76
<NativeMenuItem Icon =" /Assets/test_icon.ico" Header =" Restore Defaults" Command =" {Binding RestoreDefault}" />
77
77
<NativeMenuItem Header =" Disabled option" IsEnabled =" False" />
78
+ <NativeMenuItem Header =" Hidden option" IsVisible =" False" />
78
79
</NativeMenu >
79
80
</NativeMenuItem >
80
81
<NativeMenuItem Header =" Exit" Command =" {Binding ExitCommand}" />
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ internal class NativeMenuBarPresenter : Menu
26
26
[ ! MenuItem . IconProperty ] = nativeItem . GetObservable ( NativeMenuItem . IconProperty )
27
27
. Select ( i => i is { } bitmap ? new Image { Source = bitmap } : null ) . ToBinding ( ) ,
28
28
[ ! MenuItem . IsEnabledProperty ] = nativeItem . GetObservable ( NativeMenuItem . IsEnabledProperty ) . ToBinding ( ) ,
29
+ [ ! MenuItem . IsVisibleProperty ] = nativeItem . GetObservable ( NativeMenuItem . IsVisibleProperty ) . ToBinding ( ) ,
29
30
[ ! MenuItem . CommandProperty ] = nativeItem . GetObservable ( NativeMenuItem . CommandProperty ) . ToBinding ( ) ,
30
31
[ ! MenuItem . CommandParameterProperty ] =
31
32
nativeItem . GetObservable ( NativeMenuItem . CommandParameterProperty ) . ToBinding ( ) ,
Original file line number Diff line number Diff line change @@ -144,6 +144,21 @@ public bool IsEnabled
144
144
set => SetValue ( IsEnabledProperty , value ) ;
145
145
}
146
146
147
+ /// <summary>
148
+ /// Defines the <see cref="IsVisible"/> property.
149
+ /// </summary>
150
+ public static readonly StyledProperty < bool > IsVisibleProperty =
151
+ Visual . IsVisibleProperty . AddOwner < NativeMenuItem > ( ) ;
152
+
153
+ /// <summary>
154
+ /// Gets or sets a value indicating whether this menu item is visible.
155
+ /// </summary>
156
+ public bool IsVisible
157
+ {
158
+ get => GetValue ( IsVisibleProperty ) ;
159
+ set => SetValue ( IsVisibleProperty , value ) ;
160
+ }
161
+
147
162
void CanExecuteChanged ( )
148
163
{
149
164
SetCurrentValue ( IsEnabledProperty , Command ? . CanExecute ( CommandParameter ) ?? true ) ;
Original file line number Diff line number Diff line change @@ -243,6 +243,13 @@ private int GetId(NativeMenuItemBase item)
243
243
return new DBusVariantItem ( "b" , new DBusBoolItem ( false ) ) ;
244
244
return null ;
245
245
}
246
+
247
+ if ( name == "visible" ) {
248
+ if ( ! item . IsVisible )
249
+ return new DBusVariantItem ( "b" , new DBusBoolItem ( false ) ) ;
250
+ return new DBusVariantItem ( "b" , new DBusBoolItem ( true ) ) ;
251
+ }
252
+
246
253
if ( name == "shortcut" )
247
254
{
248
255
if ( item . Gesture is null )
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ private void UpdateTitle(string title)
40
40
41
41
private void UpdateToolTip ( string toolTip ) => SetToolTip ( toolTip ?? "" ) ;
42
42
43
+ private void UpdateIsVisible ( bool isVisible ) => SetIsVisible ( isVisible . AsComBool ( ) ) ;
43
44
private void UpdateIsChecked ( bool isChecked ) => SetIsChecked ( isChecked . AsComBool ( ) ) ;
44
45
45
46
private void UpdateToggleType ( NativeMenuItemToggleType toggleType )
@@ -121,6 +122,8 @@ internal void Initialize(NativeMenuItemBase nativeMenuItem)
121
122
122
123
UpdateIsChecked ( item . IsChecked ) ;
123
124
125
+ UpdateIsVisible ( item . IsVisible ) ;
126
+
124
127
_propertyDisposables . Add ( ManagedMenuItem . GetObservable ( NativeMenuItem . HeaderProperty )
125
128
. Subscribe ( x => UpdateTitle ( x ) ) ) ;
126
129
@@ -139,6 +142,9 @@ internal void Initialize(NativeMenuItemBase nativeMenuItem)
139
142
_propertyDisposables . Add ( ManagedMenuItem . GetObservable ( NativeMenuItem . IsCheckedProperty )
140
143
. Subscribe ( x => UpdateIsChecked ( x ) ) ) ;
141
144
145
+ _propertyDisposables . Add ( ManagedMenuItem . GetObservable ( NativeMenuItem . IsVisibleProperty )
146
+ . Subscribe ( x => UpdateIsVisible ( x ) ) ) ;
147
+
142
148
_propertyDisposables . Add ( ManagedMenuItem . GetObservable ( NativeMenuItem . IconProperty )
143
149
. Subscribe ( x => UpdateIcon ( x ) ) ) ;
144
150
}
Original file line number Diff line number Diff line change @@ -1026,6 +1026,7 @@ interface IAvnMenuItem : IUnknown
1026
1026
HRESULT SetGesture(AvnKey key, AvnInputModifiers modifiers);
1027
1027
HRESULT SetAction(IAvnPredicateCallback* predicate, IAvnActionCallback* callback);
1028
1028
HRESULT SetIsChecked(bool isChecked);
1029
+ HRESULT SetIsVisible(bool isVisible);
1029
1030
HRESULT SetToggleType(AvnMenuItemToggleType toggleType);
1030
1031
HRESULT SetIcon(void* data, size_t length);
1031
1032
}
You can’t perform that action at this time.
0 commit comments