Browse Source

fix formatting

pull/6560/head
Takoooooo 4 years ago
parent
commit
afd7203087
  1. 6
      samples/ControlCatalog/ViewModels/ApplicationViewModel.cs
  2. 3
      src/Avalonia.Controls/Platform/ITrayIconImpl.cs
  3. 10
      src/Avalonia.Controls/TrayIcon.cs
  4. 6
      src/Avalonia.Native/TrayIconImpl.cs
  5. 24
      src/Avalonia.X11/X11TrayIconImpl.cs
  6. 6
      src/Windows/Avalonia.Win32/Win32NativeToManagedMenuExporter.cs

6
samples/ControlCatalog/ViewModels/ApplicationViewModel.cs

@ -10,17 +10,17 @@ namespace ControlCatalog.ViewModels
{ {
ExitCommand = MiniCommand.Create(() => ExitCommand = MiniCommand.Create(() =>
{ {
if(Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
{ {
lifetime.Shutdown(); lifetime.Shutdown();
} }
}); });
ToggleCommand = MiniCommand.Create(() => { }); ToggleCommand = MiniCommand.Create(() => { });
} }
public MiniCommand ExitCommand { get; } public MiniCommand ExitCommand { get; }
public MiniCommand ToggleCommand { get; } public MiniCommand ToggleCommand { get; }
} }
} }

3
src/Avalonia.Controls/Platform/ITrayIconImpl.cs

@ -1,5 +1,4 @@
using System; using System;
using Avalonia.Controls;
using Avalonia.Controls.Platform; using Avalonia.Controls.Platform;
#nullable enable #nullable enable
@ -21,7 +20,7 @@ namespace Avalonia.Platform
/// <summary> /// <summary>
/// Sets if the tray icon is visible or not. /// Sets if the tray icon is visible or not.
/// </summary> /// </summary>
void SetIsVisible (bool visible); void SetIsVisible(bool visible);
/// <summary> /// <summary>
/// Gets the MenuExporter to allow native menus to be exported to the TrayIcon. /// Gets the MenuExporter to allow native menus to be exported to the TrayIcon.

10
src/Avalonia.Controls/TrayIcon.cs

@ -30,22 +30,22 @@ namespace Avalonia.Controls
} }
} }
public TrayIcon () : this(PlatformManager.CreateTrayIcon()) public TrayIcon() : this(PlatformManager.CreateTrayIcon())
{ {
} }
static TrayIcon () static TrayIcon()
{ {
IconsProperty.Changed.Subscribe(args => IconsProperty.Changed.Subscribe(args =>
{ {
if (args.Sender is Application) if (args.Sender is Application)
{ {
if(args.OldValue.Value != null) if (args.OldValue.Value != null)
{ {
RemoveIcons(args.OldValue.Value); RemoveIcons(args.OldValue.Value);
} }
if(args.NewValue.Value != null) if (args.NewValue.Value != null)
{ {
args.NewValue.Value.CollectionChanged += Icons_CollectionChanged; args.NewValue.Value.CollectionChanged += Icons_CollectionChanged;
} }
@ -161,7 +161,7 @@ namespace Avalonia.Controls
{ {
base.OnPropertyChanged(change); base.OnPropertyChanged(change);
if(change.Property == IconProperty) if (change.Property == IconProperty)
{ {
_impl?.SetIcon(Icon.PlatformImpl); _impl?.SetIcon(Icon.PlatformImpl);
} }

6
src/Avalonia.Native/TrayIconImpl.cs

@ -11,7 +11,7 @@ namespace Avalonia.Native
internal class TrayIconImpl : ITrayIconImpl internal class TrayIconImpl : ITrayIconImpl
{ {
private readonly IAvnTrayIcon _native; private readonly IAvnTrayIcon _native;
public TrayIconImpl(IAvaloniaNativeFactory factory) public TrayIconImpl(IAvaloniaNativeFactory factory)
{ {
_native = factory.CreateTrayIcon(); _native = factory.CreateTrayIcon();
@ -28,7 +28,7 @@ namespace Avalonia.Native
public unsafe void SetIcon(IWindowIconImpl? icon) public unsafe void SetIcon(IWindowIconImpl? icon)
{ {
if(icon is null) if (icon is null)
{ {
_native.SetIcon(null, IntPtr.Zero); _native.SetIcon(null, IntPtr.Zero);
} }
@ -40,7 +40,7 @@ namespace Avalonia.Native
var imageData = ms.ToArray(); var imageData = ms.ToArray();
fixed(void* ptr = imageData) fixed (void* ptr = imageData)
{ {
_native.SetIcon(ptr, new IntPtr(imageData.Length)); _native.SetIcon(ptr, new IntPtr(imageData.Length));
} }

24
src/Avalonia.X11/X11TrayIconImpl.cs

@ -53,7 +53,8 @@ namespace Avalonia.X11
public async void CreateTrayIcon() public async void CreateTrayIcon()
{ {
if (_connection is null) return; if (_connection is null)
return;
try try
{ {
@ -68,7 +69,8 @@ namespace Avalonia.X11
"DBUS: org.kde.StatusNotifierWatcher service is not available on this system. System Tray Icons will not work without it."); "DBUS: org.kde.StatusNotifierWatcher service is not available on this system. System Tray Icons will not work without it.");
} }
if (_statusNotifierWatcher is null) return; if (_statusNotifierWatcher is null)
return;
var pid = Process.GetCurrentProcess().Id; var pid = Process.GetCurrentProcess().Id;
var tid = s_TrayIconInstanceId++; var tid = s_TrayIconInstanceId++;
@ -92,7 +94,8 @@ namespace Avalonia.X11
public async void DestroyTrayIcon() public async void DestroyTrayIcon()
{ {
if (_connection is null) return; if (_connection is null)
return;
_connection.UnregisterObject(_statusNotifierItemDbusObj); _connection.UnregisterObject(_statusNotifierItemDbusObj);
await _connection.UnregisterServiceAsync(_sysTrayServiceName); await _connection.UnregisterServiceAsync(_sysTrayServiceName);
_isActive = false; _isActive = false;
@ -107,8 +110,10 @@ namespace Avalonia.X11
public void SetIcon(IWindowIconImpl? icon) public void SetIcon(IWindowIconImpl? icon)
{ {
if (_isDisposed) return; if (_isDisposed)
if (!(icon is X11IconData x11icon)) return; return;
if (!(icon is X11IconData x11icon))
return;
var w = (int)x11icon.Data[0]; var w = (int)x11icon.Data[0];
var h = (int)x11icon.Data[1]; var h = (int)x11icon.Data[1];
@ -132,7 +137,8 @@ namespace Avalonia.X11
public void SetIsVisible(bool visible) public void SetIsVisible(bool visible)
{ {
if (_isDisposed || !_ctorFinished) return; if (_isDisposed || !_ctorFinished)
return;
if (visible & !_isActive) if (visible & !_isActive)
{ {
@ -147,7 +153,8 @@ namespace Avalonia.X11
public void SetToolTipText(string? text) public void SetToolTipText(string? text)
{ {
if (_isDisposed || text is null) return; if (_isDisposed || text is null)
return;
_tooltipText = text; _tooltipText = text;
_statusNotifierItemDbusObj?.SetTitleAndTooltip(_tooltipText); _statusNotifierItemDbusObj?.SetTitleAndTooltip(_tooltipText);
} }
@ -258,7 +265,8 @@ namespace Avalonia.X11
public void SetTitleAndTooltip(string? text) public void SetTitleAndTooltip(string? text)
{ {
if (text is null) return; if (text is null)
return;
_backingProperties.Id = text; _backingProperties.Id = text;
_backingProperties.Category = "ApplicationStatus"; _backingProperties.Category = "ApplicationStatus";

6
src/Windows/Avalonia.Win32/Win32NativeToManagedMenuExporter.cs

@ -21,13 +21,13 @@ namespace Avalonia.Win32
{ {
if (menuItem is NativeMenuItemSeparator) if (menuItem is NativeMenuItemSeparator)
{ {
yield return new MenuItem { Header = "-" }; yield return new MenuItem { Header = "-" };
} }
else if (menuItem is NativeMenuItem item) else if (menuItem is NativeMenuItem item)
{ {
var newItem = new MenuItem { Header = item.Header, Icon = item.Icon, Command = item.Command, CommandParameter = item.CommandParameter }; var newItem = new MenuItem { Header = item.Header, Icon = item.Icon, Command = item.Command, CommandParameter = item.CommandParameter };
if(item.Menu != null) if (item.Menu != null)
{ {
newItem.Items = Populate(item.Menu); newItem.Items = Populate(item.Menu);
} }
@ -43,7 +43,7 @@ namespace Avalonia.Win32
public IEnumerable<MenuItem>? GetMenu() public IEnumerable<MenuItem>? GetMenu()
{ {
if(_nativeMenu != null) if (_nativeMenu != null)
{ {
return Populate(_nativeMenu); return Populate(_nativeMenu);
} }

Loading…
Cancel
Save