Browse Source
* Add HotKeys Page to DevTools * Centralize hotkeys and hoist into DevToolsOptionspull/15722/head
committed by
GitHub
9 changed files with 231 additions and 52 deletions
@ -0,0 +1,32 @@ |
|||
using Avalonia.Input; |
|||
|
|||
namespace Avalonia.Diagnostics |
|||
{ |
|||
internal class HotKeyConfiguration |
|||
{ |
|||
/// <summary>
|
|||
/// Freezes refreshing the Value Frames inspector for the selected Control
|
|||
/// </summary>
|
|||
public KeyGesture ValueFramesFreeze { get; init; } = new(Key.S, KeyModifiers.Alt); |
|||
|
|||
/// <summary>
|
|||
/// Resumes refreshing the Value Frames inspector for the selected Control
|
|||
/// </summary>
|
|||
public KeyGesture ValueFramesUnfreeze { get; init; } = new(Key.D, KeyModifiers.Alt); |
|||
|
|||
/// <summary>
|
|||
/// Inspects the hovered Control in the Logical or Visual Tree Page
|
|||
/// </summary>
|
|||
public KeyGesture InspectHoveredControl { get; init; } = new(Key.None, KeyModifiers.Shift | KeyModifiers.Control); |
|||
|
|||
/// <summary>
|
|||
/// Toggles the freezing of Popups which prevents visible Popups from closing so they can be inspected
|
|||
/// </summary>
|
|||
public KeyGesture TogglePopupFreeze { get; init; } = new(Key.F, KeyModifiers.Alt | KeyModifiers.Control); |
|||
|
|||
/// <summary>
|
|||
/// Saves a Screenshot of the Selected Control in the Logical or Visual Tree Page
|
|||
/// </summary>
|
|||
public KeyGesture ScreenshotSelectedControl { get; init; } = new(Key.F8); |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System.Collections.ObjectModel; |
|||
using Avalonia.Input; |
|||
|
|||
namespace Avalonia.Diagnostics.ViewModels |
|||
{ |
|||
internal record HotKeyDescription(string Gesture, string BriefDescription, string? DetailedDescription = null); |
|||
|
|||
internal class HotKeyPageViewModel : ViewModelBase |
|||
{ |
|||
private ObservableCollection<HotKeyDescription>? _hotKeyDescriptions; |
|||
public ObservableCollection<HotKeyDescription>? HotKeyDescriptions |
|||
{ |
|||
get => _hotKeyDescriptions; |
|||
private set => RaiseAndSetIfChanged(ref _hotKeyDescriptions, value); |
|||
} |
|||
|
|||
public void SetOptions(DevToolsOptions options) |
|||
{ |
|||
var hotKeys = options.HotKeys; |
|||
|
|||
HotKeyDescriptions = new() |
|||
{ |
|||
new(CreateDescription(options.Gesture), "Launch DevTools", "Launches DevTools to inspect the TopLevel that received the hotkey input"), |
|||
new(CreateDescription(hotKeys.ValueFramesFreeze), "Freeze Value Frames", "Pauses refreshing the Value Frames inspector for the selected Control"), |
|||
new(CreateDescription(hotKeys.ValueFramesUnfreeze), "Unfreeze Value Frames", "Resumes refreshing the Value Frames inspector for the selected Control"), |
|||
new(CreateDescription(hotKeys.InspectHoveredControl), "Inspect Control Under Pointer", "Inspects the hovered Control in the Logical or Visual Tree Page"), |
|||
new(CreateDescription(hotKeys.TogglePopupFreeze), "Toggle Popup Freeze", "Prevents visible Popups from closing so they can be inspected"), |
|||
new(CreateDescription(hotKeys.ScreenshotSelectedControl), "Screenshot Selected Control", "Saves a Screenshot of the Selected Control in the Logical or Visual Tree Page") |
|||
}; |
|||
} |
|||
|
|||
private string CreateDescription(KeyGesture gesture) |
|||
{ |
|||
if (gesture.Key == Key.None && gesture.KeyModifiers != KeyModifiers.None) |
|||
return gesture.ToString().Replace("+None", ""); |
|||
else |
|||
return gesture.ToString(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
<UserControl xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
xmlns:vm="using:Avalonia.Diagnostics.ViewModels" |
|||
Padding="4" |
|||
x:Class="Avalonia.Diagnostics.Views.HotKeyPageView" |
|||
x:DataType="vm:HotKeyPageViewModel"> |
|||
<Grid RowDefinitions="auto,*" Grid.IsSharedSizeScope="True"> |
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition SharedSizeGroup="A" Width="auto" /> |
|||
<ColumnDefinition Width="8" /> |
|||
<ColumnDefinition SharedSizeGroup="B" Width="*" /> |
|||
</Grid.ColumnDefinitions> |
|||
|
|||
<TextBlock FontWeight="Bold" Text="Action" /> |
|||
<TextBlock Grid.Column="2" FontWeight="Bold" Text="Gesture" /> |
|||
</Grid> |
|||
|
|||
<ItemsControl Grid.Row="1" Grid.ColumnSpan="3" ItemsSource="{Binding HotKeyDescriptions}"> |
|||
<ItemsControl.ItemTemplate> |
|||
<DataTemplate> |
|||
<Grid> |
|||
<Grid.ColumnDefinitions> |
|||
<ColumnDefinition SharedSizeGroup="A" Width="auto" /> |
|||
<ColumnDefinition Width="8" /> |
|||
<ColumnDefinition SharedSizeGroup="B" Width="*" /> |
|||
</Grid.ColumnDefinitions> |
|||
|
|||
<TextBlock Text="{Binding BriefDescription}" ToolTip.Tip="{Binding DetailedDescription}" /> |
|||
<TextBlock Grid.Column="2" Text="{Binding Gesture}" /> |
|||
</Grid> |
|||
</DataTemplate> |
|||
</ItemsControl.ItemTemplate> |
|||
</ItemsControl> |
|||
</Grid> |
|||
</UserControl> |
|||
@ -0,0 +1,18 @@ |
|||
using Avalonia.Controls; |
|||
using Avalonia.Markup.Xaml; |
|||
|
|||
namespace Avalonia.Diagnostics.Views |
|||
{ |
|||
internal class HotKeyPageView : UserControl |
|||
{ |
|||
public HotKeyPageView() |
|||
{ |
|||
InitializeComponent(); |
|||
} |
|||
|
|||
private void InitializeComponent() |
|||
{ |
|||
AvaloniaXamlLoader.Load(this); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue