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

Add HotKeys Page to DevTools #15700

merged 2 commits into from
May 14, 2024

Conversation

stevemonaco
Copy link
Contributor

What does the pull request do?

Fixes #15390

Adds a HotKey page because there's no in-app discoverability of DevTools hotkeys. Otherwise, the user must check docs.

What is the updated/expected behavior with this PR?

devtools-hotkeys

Simple display of hotkeys, no mutability. Does not display the launch hotkey as that is mutable via DevToolOptions and would require some wiring. If the user doesn't know that hotkey, then how are they in DevTools to begin with?

Very recently, the "Styles" snapshot action was modified to "Value Frames". I reflect this in the hotkey descriptions, but other places still use Styles, including the DevTools docs page.

How was the solution implemented (if it's not obvious)?

Adds an invisible TabStripItem for the HotKeys page to avoid visual crowding and avoid adding more complex navigation.

Checklist

@@ -231,6 +236,11 @@ private set
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.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0048354-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added feature enhancement area-dev-tools backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch and removed feature labels May 13, 2024
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0048407-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@stevemonaco
Copy link
Contributor Author

0761e38 introduces HotKeyConfiguration to hold KeyGestures as named members. It doesn't include DevToolsOptions.Gesture which launches DevTools as moving that is a breaking change.

I added HotKeyConfiguration to DevToolsOptions, use it to detect keypresses in MainView, moved the functionality into separate methods, and wire it into HotKeyPageViewModel. I can still list the launch DevTools gesture from there.

It's much closer to mutability, but kept it internal so any implementer could revise. This PR doesn't support multiple gestures that can each launch the same action. Chrome DevTools has this.

@workgroupengineering
Copy link
Contributor

workgroupengineering commented May 14, 2024

possible enhanced

public enum HotKeyFunction
{
    [Description("Launch DevTools")]
    LaunchDevTools,
    [Description("Inspect Control Under Pointer")]
    InspectHoveredControl,
    [Description("Freeze Value Frames")]
    FramesFreeze,
    [Description("Unfreeze Value Frames")]
    FramesUnfreeze,
    [Description("Toggle Popup Freeze")]
    TogglePopupFreeze,
    [Description("Screenshot Selected Control")]
    ScreenshotSelectedControl
}

public class DevToolsOptions
{
    private readonly static KeyGesture DefaultLaunchDevToolsGesture = new(Key.F12);
    private readonly Dictionary<HotKeyFunction, KeyGesture> _hotkeyConfig = new()
    {
        {HotKeyFunction.LaunchDevTools,new(Key.F12) },
        {HotKeyFunction.InspectHoveredControl,new(Key.None, KeyModifiers.Shift | KeyModifiers.Control) },
        {HotKeyFunction.FramesFreeze,new(Key.S, KeyModifiers.Alt) },
        {HotKeyFunction.FramesUnfreeze,new(Key.D, KeyModifiers.Alt) },
        {HotKeyFunction.TogglePopupFreeze,new(Key.F, KeyModifiers.Alt | KeyModifiers.Control) },
        {HotKeyFunction.ScreenshotSelectedControl,new(Key.F8) },
    };



    /// <summary>
    /// Gets or sets the key gesture used to open DevTools.
    /// </summary>
    public KeyGesture Gesture
    {
        get => _hotkeyConfig.TryGetValue(HotKeyFunction.LaunchDevTools, out var gesture)
            ? gesture
            : DefaultLaunchDevToolsGesture;
        init => _hotkeyConfig[HotKeyFunction.LaunchDevTools] = value;
    }

    public IReadOnlyDictionary<HotKeyFunction, KeyGesture> HotKeyConfig
    {
        get => _hotkeyConfig;
        init
        {
            // Merge
            foreach (var kvp in value)
            {
                _hotkeyConfig[kvp.Key] = kvp.Value;
            }
        }
    }
...

}

using like:

var options = new DevToolsOptions()
{
    HotKeyConfig = new Dictionary<HotKeyFunction, KeyGesture>
    {
        { HotKeyFunction.LaunchDevTools , new(Key.F24) },
        { HotKeyFunction.InspectHoveredControl, new(Key.None, KeyModifiers.Shift | KeyModifiers.Control) },
    },
};

@maxkatz6
Copy link
Member

We probably won't have this much of hotkeys to justify a dictionary. A class looks more than enough here.
Either way, it can be changed later while it's internal.

@maxkatz6 maxkatz6 added this pull request to the merge queue May 14, 2024
Merged via the queue into AvaloniaUI:master with commit 0ae36f9 May 14, 2024
10 checks passed
@maxkatz6 maxkatz6 added feature and removed backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DevTools should display a list of hotkeys
4 participants