Browse Source

Rename NativeMenuItem.Enabled to IsEnabled, and NeedsUpdateEvent to Opening event.

pull/3762/head
Dan Walmsley 7 years ago
parent
commit
68197f8858
  1. 2
      samples/ControlCatalog/MainWindow.xaml.cs
  2. 4
      src/Avalonia.Controls/NativeMenu.cs
  3. 14
      src/Avalonia.Controls/NativeMenuItem.cs
  4. 4
      src/Avalonia.FreeDesktop/DBusMenuExporter.cs
  5. 2
      src/Avalonia.Native/IAvnMenuItem.cs

2
samples/ControlCatalog/MainWindow.xaml.cs

@ -32,7 +32,7 @@ namespace ControlCatalog
var fileMenu = (NativeMenu.GetMenu(this).Items[0] as NativeMenuItem).Menu; var fileMenu = (NativeMenu.GetMenu(this).Items[0] as NativeMenuItem).Menu;
fileMenu.NeedsUpdate += (sender, e)=> fileMenu.Opening += (sender, e)=>
{ {
fileMenu.Items.Clear(); fileMenu.Items.Clear();
fileMenu.Items.Add(new NativeMenuItem("Test 1")); fileMenu.Items.Add(new NativeMenuItem("Test 1"));

4
src/Avalonia.Controls/NativeMenu.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Raised when the user clicks the menu and before its opened. Use this event to update the menu dynamically. /// Raised when the user clicks the menu and before its opened. Use this event to update the menu dynamically.
/// </summary> /// </summary>
public event EventHandler<EventArgs> NeedsUpdate; public event EventHandler<EventArgs> Opening;
public NativeMenu() public NativeMenu()
{ {
@ -28,7 +28,7 @@ namespace Avalonia.Controls
void INativeMenuExporterEventsImplBridge.RaiseNeedsUpdate () void INativeMenuExporterEventsImplBridge.RaiseNeedsUpdate ()
{ {
NeedsUpdate?.Invoke(this, EventArgs.Empty); Opening?.Invoke(this, EventArgs.Empty);
} }
private void Validator(NativeMenuItemBase obj) private void Validator(NativeMenuItemBase obj)

14
src/Avalonia.Controls/NativeMenuItem.cs

@ -9,7 +9,7 @@ namespace Avalonia.Controls
{ {
private string _header; private string _header;
private KeyGesture _gesture; private KeyGesture _gesture;
private bool _enabled = true; private bool _isEnabled = true;
private ICommand _command; private ICommand _command;
private bool _isChecked = false; private bool _isChecked = false;
@ -112,18 +112,18 @@ namespace Avalonia.Controls
public static readonly StyledProperty<object> CommandParameterProperty = public static readonly StyledProperty<object> CommandParameterProperty =
Button.CommandParameterProperty.AddOwner<MenuItem>(); Button.CommandParameterProperty.AddOwner<MenuItem>();
public static readonly DirectProperty<NativeMenuItem, bool> EnabledProperty = public static readonly DirectProperty<NativeMenuItem, bool> IsEnabledProperty =
AvaloniaProperty.RegisterDirect<NativeMenuItem, bool>(nameof(Enabled), o => o.Enabled, (o, v) => o.Enabled = v, true); AvaloniaProperty.RegisterDirect<NativeMenuItem, bool>(nameof(IsEnabled), o => o.IsEnabled, (o, v) => o.IsEnabled = v, true);
public bool Enabled public bool IsEnabled
{ {
get => _enabled; get => _isEnabled;
set => SetAndRaise(EnabledProperty, ref _enabled, value); set => SetAndRaise(IsEnabledProperty, ref _isEnabled, value);
} }
void CanExecuteChanged() void CanExecuteChanged()
{ {
Enabled = _command?.CanExecute(null) ?? true; IsEnabled = _command?.CanExecute(null) ?? true;
} }
public bool HasClickHandlers => Clicked != null; public bool HasClickHandlers => Clicked != null;

4
src/Avalonia.FreeDesktop/DBusMenuExporter.cs

@ -210,7 +210,7 @@ namespace Avalonia.FreeDesktop
return null; return null;
if (item.Menu != null && item.Menu.Items.Count == 0) if (item.Menu != null && item.Menu.Items.Count == 0)
return false; return false;
if (item.Enabled == false) if (item.IsEnabled == false)
return false; return false;
return null; return null;
} }
@ -321,7 +321,7 @@ namespace Avalonia.FreeDesktop
if (item is NativeMenuItem menuItem) if (item is NativeMenuItem menuItem)
{ {
if (menuItem?.Enabled == true) if (menuItem?.IsEnabled == true)
menuItem.RaiseClick(); menuItem.RaiseClick();
} }
} }

2
src/Avalonia.Native/IAvnMenuItem.cs

@ -44,7 +44,7 @@ namespace Avalonia.Native.Interop
{ {
if (item.Command != null || item.HasClickHandlers) if (item.Command != null || item.HasClickHandlers)
{ {
return item.Enabled; return item.IsEnabled;
} }
return false; return false;

Loading…
Cancel
Save