Browse Source

Added DevToolsOptions.

With options to:

- Set the key gesture
- Show as child window
- Set the initial size

Co-Authored-By: workgroupengineering <workgroupengineering@users.noreply.github.com>
pull/5669/head
Steven Kirk 6 years ago
parent
commit
d1f44dcdf4
  1. 12
      src/Avalonia.Diagnostics/DevToolsExtensions.cs
  2. 24
      src/Avalonia.Diagnostics/Diagnostics/DevTools.cs
  3. 26
      src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs

12
src/Avalonia.Diagnostics/DevToolsExtensions.cs

@ -15,7 +15,7 @@ namespace Avalonia
/// <param name="root">The window to attach DevTools to.</param>
public static void AttachDevTools(this TopLevel root)
{
DevTools.Attach(root, new KeyGesture(Key.F12));
DevTools.Attach(root, new DevToolsOptions());
}
/// <summary>
@ -27,5 +27,15 @@ namespace Avalonia
{
DevTools.Attach(root, gesture);
}
/// <summary>
/// Attaches DevTools to a window, to be opened with the specified options.
/// </summary>
/// <param name="root">The window to attach DevTools to.</param>
/// <param name="options">additional settint of DevTools</param>
public static void AttachDevTools(this TopLevel root, DevToolsOptions options)
{
DevTools.Attach(root, options);
}
}
}

24
src/Avalonia.Diagnostics/Diagnostics/DevTools.cs

@ -6,6 +6,8 @@ using Avalonia.Diagnostics.Views;
using Avalonia.Input;
using Avalonia.Interactivity;
#nullable enable
namespace Avalonia.Diagnostics
{
public static class DevTools
@ -13,12 +15,20 @@ namespace Avalonia.Diagnostics
private static readonly Dictionary<TopLevel, Window> s_open = new Dictionary<TopLevel, Window>();
public static IDisposable Attach(TopLevel root, KeyGesture gesture)
{
return Attach(root, new DevToolsOptions()
{
Gesture = gesture,
});
}
public static IDisposable Attach(TopLevel root, DevToolsOptions options)
{
void PreviewKeyDown(object sender, KeyEventArgs e)
{
if (gesture.Matches(e))
if (options.Gesture.Matches(e))
{
Open(root);
Open(root, options);
}
}
@ -28,7 +38,9 @@ namespace Avalonia.Diagnostics
RoutingStrategies.Tunnel);
}
public static IDisposable Open(TopLevel root)
public static IDisposable Open(TopLevel root) => Open(root, new DevToolsOptions());
public static IDisposable Open(TopLevel root, DevToolsOptions options)
{
if (s_open.TryGetValue(root, out var window))
{
@ -38,15 +50,15 @@ namespace Avalonia.Diagnostics
{
window = new MainWindow
{
Width = 1024,
Height = 512,
Root = root,
Width = options.Size.Width,
Height = options.Size.Height,
};
window.Closed += DevToolsClosed;
s_open.Add(root, window);
if (root is Window inspectedWindow)
if (options.ShowAsChildWindow && root is Window inspectedWindow)
{
window.Show(inspectedWindow);
}

26
src/Avalonia.Diagnostics/Diagnostics/DevToolsOptions.cs

@ -0,0 +1,26 @@
using Avalonia.Input;
namespace Avalonia.Diagnostics
{
/// <summary>
/// Describes options used to customize DevTools.
/// </summary>
public class DevToolsOptions
{
/// <summary>
/// Gets or sets the key gesture used to open DevTools.
/// </summary>
public KeyGesture Gesture { get; set; } = new KeyGesture(Key.F12);
/// <summary>
/// Gets or sets a value indicating whether DevTools should be displayed as a child window
/// of the window being inspected. The default value is true.
/// </summary>
public bool ShowAsChildWindow { get; set; } = true;
/// <summary>
/// Gets or sets the initial size of the DevTools window. The default value is 1024x512.
/// </summary>
public Size Size { get; set; } = new Size(1024, 512);
}
}
Loading…
Cancel
Save