Browse Source
* feat(DevTools): Allow to attach DevTools at Application * fixes(DevTools): PointerOverElement when attach to Application * feat: Add AvaloniaVersion * feat: IsDevelopmentBuild * feat: Add some useful properties to Application Decorator * fixes: Hide Layout Viewer when select appliction node * fix: removed MachineId * fixes: DesignerSupportTests fails * fix(DevTools): Update XML Comment and nits * fix(DevTools): Avoid interaction of Layout Visualizer with keyboard when it is hidden. * Added some comment * fixes: Code formatting * fixes(DevTools): Strip unnecessary property from Application Decorator * fixes(ControlCatalog): remove AttachDevTools from DecoratedWindow * fixes(DevTools): Application doesn't close when the last window closed when DevTools is open * fixes: Missing Application properties decoration * fixes(DevTools): Nullable annotations * fixes(DevTools): Unified the behavior of AttachDevTools * fixes(DevTools): typo * fixes(DevTools): Null Annotation Co-authored-by: Max Katz <maxkatz6@outlook.com>pull/7270/head
committed by
GitHub
19 changed files with 593 additions and 80 deletions
@ -0,0 +1,47 @@ |
|||
namespace Avalonia.Diagnostics.Behaviors |
|||
{ |
|||
/// <summary>
|
|||
/// See discussion https://github.com/AvaloniaUI/Avalonia/discussions/6773
|
|||
/// </summary>
|
|||
static class ColumnDefinition |
|||
{ |
|||
private readonly static Avalonia.Controls.GridLength ZeroWidth = |
|||
new Avalonia.Controls.GridLength(0, Avalonia.Controls.GridUnitType.Pixel); |
|||
|
|||
private readonly static AttachedProperty<Avalonia.Controls.GridLength?> LastWidthProperty = |
|||
AvaloniaProperty.RegisterAttached<Avalonia.Controls.ColumnDefinition, Avalonia.Controls.GridLength?>("LastWidth" |
|||
, typeof(ColumnDefinition) |
|||
, default); |
|||
|
|||
public readonly static AttachedProperty<bool> IsVisibleProperty = |
|||
AvaloniaProperty.RegisterAttached<Avalonia.Controls.ColumnDefinition, bool>("IsVisible" |
|||
, typeof(ColumnDefinition) |
|||
, true |
|||
, coerce: (element, visibility) => |
|||
{ |
|||
|
|||
var lastWidth = element.GetValue(LastWidthProperty); |
|||
if (visibility == true && lastWidth is { }) |
|||
{ |
|||
element.SetValue(Avalonia.Controls.ColumnDefinition.WidthProperty, lastWidth); |
|||
} |
|||
else if (visibility == false) |
|||
{ |
|||
element.SetValue(LastWidthProperty, element.GetValue(Avalonia.Controls.ColumnDefinition.WidthProperty)); |
|||
element.SetValue(Avalonia.Controls.ColumnDefinition.WidthProperty, ZeroWidth); |
|||
} |
|||
return visibility; |
|||
} |
|||
); |
|||
|
|||
public static bool GetIsVisible(Avalonia.Controls.ColumnDefinition columnDefinition) |
|||
{ |
|||
return columnDefinition.GetValue(IsVisibleProperty); |
|||
} |
|||
|
|||
public static void SetIsVisible(Avalonia.Controls.ColumnDefinition columnDefinition, bool visibility) |
|||
{ |
|||
columnDefinition.SetValue(IsVisibleProperty, visibility); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,109 @@ |
|||
using System; |
|||
using Avalonia.Controls; |
|||
using Lifetimes = Avalonia.Controls.ApplicationLifetimes; |
|||
using App = Avalonia.Application; |
|||
|
|||
namespace Avalonia.Diagnostics.Controls |
|||
{ |
|||
class Application : AvaloniaObject |
|||
, Input.ICloseable |
|||
|
|||
{ |
|||
private readonly App _application; |
|||
private static readonly Version s_version = typeof(IAvaloniaObject).Assembly?.GetName()?.Version |
|||
?? Version.Parse("0.0.00"); |
|||
public event EventHandler? Closed; |
|||
|
|||
public Application(App application) |
|||
{ |
|||
_application = application; |
|||
|
|||
if (_application.ApplicationLifetime is Lifetimes.IControlledApplicationLifetime controller) |
|||
{ |
|||
EventHandler<Lifetimes.ControlledApplicationLifetimeExitEventArgs> eh = default!; |
|||
eh = (s, e) => |
|||
{ |
|||
controller.Exit -= eh; |
|||
Closed?.Invoke(s, e); |
|||
}; |
|||
controller.Exit += eh; |
|||
} |
|||
|
|||
} |
|||
|
|||
internal App Instance => _application; |
|||
|
|||
/// <summary>
|
|||
/// Defines the <see cref="DataContext"/> property.
|
|||
/// </summary>
|
|||
public object? DataContext => |
|||
_application.DataContext; |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the application's global data templates.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The application's global data templates.
|
|||
/// </value>
|
|||
public Avalonia.Controls.Templates.DataTemplates DataTemplates => |
|||
_application.DataTemplates; |
|||
|
|||
/// <summary>
|
|||
/// Gets the application's focus manager.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The application's focus manager.
|
|||
/// </value>
|
|||
public Input.IFocusManager? FocusManager => |
|||
_application.FocusManager; |
|||
|
|||
/// <summary>
|
|||
/// Gets the application's input manager.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The application's input manager.
|
|||
/// </value>
|
|||
public Input.InputManager? InputManager => |
|||
_application.InputManager; |
|||
|
|||
/// <summary>
|
|||
/// Gets the application clipboard.
|
|||
/// </summary>
|
|||
public Input.Platform.IClipboard? Clipboard => |
|||
_application.Clipboard; |
|||
|
|||
/// <summary>
|
|||
/// Gets the application's global resource dictionary.
|
|||
/// </summary>
|
|||
public IResourceDictionary Resources => |
|||
_application.Resources; |
|||
|
|||
/// <summary>
|
|||
/// Gets the application's global styles.
|
|||
/// </summary>
|
|||
/// <value>
|
|||
/// The application's global styles.
|
|||
/// </value>
|
|||
/// <remarks>
|
|||
/// Global styles apply to all windows in the application.
|
|||
/// </remarks>
|
|||
public Styling.Styles Styles => |
|||
_application.Styles; |
|||
|
|||
/// <summary>
|
|||
/// Application lifetime, use it for things like setting the main window and exiting the app from code
|
|||
/// Currently supported lifetimes are:
|
|||
/// - <see cref="Lifetimes.IClassicDesktopStyleApplicationLifetime"/>
|
|||
/// - <see cref="Lifetimes.ISingleViewApplicationLifetime"/>
|
|||
/// - <see cref="Lifetimes.IControlledApplicationLifetime"/>
|
|||
/// </summary>
|
|||
public Lifetimes.IApplicationLifetime? ApplicationLifetime => |
|||
_application.ApplicationLifetime; |
|||
|
|||
/// <summary>
|
|||
/// Application name to be used for various platform-specific purposes
|
|||
/// </summary>
|
|||
public string? Name => |
|||
_application.Name; |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using Avalonia.Input; |
|||
using Avalonia.Input.Raw; |
|||
|
|||
namespace Avalonia.Diagnostics |
|||
{ |
|||
static class KeyGestureExtesions |
|||
{ |
|||
public static bool Matches(this KeyGesture gesture, RawKeyEventArgs keyEvent) => |
|||
keyEvent != null && |
|||
(KeyModifiers)(keyEvent.Modifiers & RawInputModifiers.KeyboardMask) == gesture.KeyModifiers && |
|||
ResolveNumPadOperationKey(keyEvent.Key) == ResolveNumPadOperationKey(gesture.Key); |
|||
|
|||
private static Key ResolveNumPadOperationKey(Key key) |
|||
{ |
|||
switch (key) |
|||
{ |
|||
case Key.Add: |
|||
return Key.OemPlus; |
|||
case Key.Subtract: |
|||
return Key.OemMinus; |
|||
case Key.Decimal: |
|||
return Key.OemPeriod; |
|||
default: |
|||
return key; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue