-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HotKeys Page to DevTools (#15700)
* Add HotKeys Page to DevTools * Centralize hotkeys and hoist into DevToolsOptions
- Loading branch information
1 parent
8fe6e08
commit 0ae36f9
Showing
9 changed files
with
231 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Avalonia.Diagnostics/Diagnostics/HotKeyConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Avalonia.Diagnostics/Diagnostics/ViewModels/HotKeyPageViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Avalonia.Diagnostics/Diagnostics/Views/HotKeyPageView.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
18 changes: 18 additions & 0 deletions
18
src/Avalonia.Diagnostics/Diagnostics/Views/HotKeyPageView.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters