Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HotKeys Page to DevTools #15700

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.ObjectModel;

namespace Avalonia.Diagnostics.ViewModels;

internal record HotKeyDescription(string Description, string LongDescription, string Gesture);
internal class HotKeyPageViewModel : ViewModelBase
{
public ObservableCollection<HotKeyDescription> HotKeys { get; } = new();

public HotKeyPageViewModel()
{
HotKeys = new()
{
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")
stevemonaco marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
10 changes: 10 additions & 0 deletions src/Avalonia.Diagnostics/Diagnostics/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal class MainViewModel : ViewModelBase, IDisposable
private readonly TreePageViewModel _logicalTree;
private readonly TreePageViewModel _visualTree;
private readonly EventsPageViewModel _events;
private readonly HotKeyPageViewModel _hotKeys;
private readonly IDisposable _pointerOverSubscription;
private ViewModelBase? _content;
private int _selectedTab;
Expand All @@ -40,6 +41,7 @@ public MainViewModel(AvaloniaObject root)
_logicalTree = new TreePageViewModel(this, LogicalTreeNode.Create(root), _pinnedProperties);
_visualTree = new TreePageViewModel(this, VisualTreeNode.Create(root), _pinnedProperties);
_events = new EventsPageViewModel(this);
_hotKeys = new HotKeyPageViewModel();

UpdateFocusedControl();

Expand Down Expand Up @@ -194,6 +196,9 @@ public int SelectedTab
case 2:
Content = _events;
break;
case 3:
Content = _hotKeys;
break;
default:
Content = _logicalTree;
break;
Expand Down Expand Up @@ -231,6 +236,11 @@ public string? PointerOverElementName
private set => RaiseAndSetIfChanged(ref _pointerOverElementName, value);
}

public void ShowHotKeys()
{
SelectedTab = 3;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit cludgy here, but changing SelectedTab is necessary so other tabs do not remain selected.

}

public void SelectControl(Control control)
{
var tree = Content as TreePageViewModel;
Expand Down
36 changes: 36 additions & 0 deletions src/Avalonia.Diagnostics/Diagnostics/Views/HotKeyPageView.axaml
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 HotKeys}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" Width="auto" />
<ColumnDefinition Width="8" />
<ColumnDefinition SharedSizeGroup="B" Width="*" />
</Grid.ColumnDefinitions>

<TextBlock Text="{Binding Description}" ToolTip.Tip="{Binding LongDescription}" />
<TextBlock Grid.Column="2" Text="{Binding Gesture}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</UserControl>
18 changes: 18 additions & 0 deletions src/Avalonia.Diagnostics/Diagnostics/Views/HotKeyPageView.axaml.cs
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);
}
}
}
2 changes: 2 additions & 0 deletions src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Header="_HotKeys" Command="{Binding ShowHotKeys}" />
</MenuItem>
<MenuItem Header="_Overlays">
<MenuItem Header="Margin/padding" Command="{Binding ToggleVisualizeMarginPadding}">
Expand Down Expand Up @@ -255,6 +256,7 @@
<TabStripItem Content="Logical Tree" />
<TabStripItem Content="Visual Tree" />
<TabStripItem Content="Events" />
<TabStripItem Content="HotKeys" IsVisible="False" />
</TabStrip>

<ContentControl Grid.Row="2"
Expand Down
Loading