-
-
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.
Centralize hotkeys and hoist into DevToolsOptions
- Loading branch information
1 parent
345cc32
commit 0761e38
Showing
7 changed files
with
159 additions
and
67 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); | ||
} | ||
} |
45 changes: 32 additions & 13 deletions
45
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 |
---|---|---|
@@ -1,21 +1,40 @@ | ||
using System.Collections.ObjectModel; | ||
using Avalonia.Input; | ||
|
||
namespace Avalonia.Diagnostics.ViewModels; | ||
|
||
internal record HotKeyDescription(string Description, string LongDescription, string Gesture); | ||
internal class HotKeyPageViewModel : ViewModelBase | ||
namespace Avalonia.Diagnostics.ViewModels | ||
{ | ||
public ObservableCollection<HotKeyDescription> HotKeys { get; } = new(); | ||
internal record HotKeyDescription(string Gesture, string BriefDescription, string? DetailedDescription = null); | ||
|
||
public HotKeyPageViewModel() | ||
internal class HotKeyPageViewModel : ViewModelBase | ||
{ | ||
HotKeys = new() | ||
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) | ||
{ | ||
new("Enable Snapshot Frames", "Pauses refreshing the Value Frames inspector for the selected Control", "Alt+S"), | ||
new("Disable Snapshot Frames", "Resumes refreshing the Value Frames inspector for the selected Control", "Alt+D"), | ||
new("Inspect Control Under Pointer", "Inspects the hovered Control in the Logical or Visual Tree Page", "Ctrl+Shift"), | ||
new("Toggle Popup Freeze", "Prevents visible Popups from closing so they can be inspected", "Ctrl+Alt+F"), | ||
new("Screenshot Selected Control", "Saves a Screenshot of the Selected Control in the Logical or Visual Tree Page", "F8") | ||
}; | ||
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
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