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

Spec allowing keyboard shortcuts for commands #109

Open
joadoumie opened this issue Oct 23, 2024 · 5 comments
Open

Spec allowing keyboard shortcuts for commands #109

joadoumie opened this issue Oct 23, 2024 · 5 comments
Assignees
Labels
Area-API Anything having to do with the actual interface the extensions use to communicate with the host

Comments

@joadoumie
Copy link
Collaborator

Commands should have a notion of keyboard modifiers as exists in PT Run today:

        public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
        {
            if (!(selectedResult?.ContextData is TerminalProfile))
            {
                return new List<ContextMenuResult>();
            }

            var result = new List<ContextMenuResult>();

            if (selectedResult.ContextData is TerminalProfile profile)
            {
                result.Add(new ContextMenuResult
                {
                    Title = Resources.run_as_administrator,
                    Glyph = "\xE7EF",
                    FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
                    AcceleratorKey = Key.Enter,
                    AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
                    Action = _ =>
                    {
                        LaunchElevated(profile.Terminal.AppUserModelId, profile.Name);
                        return true;
                    },
                });
            }

            return result;
        }

This is how existing PT Plugins can input keyboard modifiers / accelerators.

Commands should have specific keyboard modifiers associated with the command.

@joadoumie
Copy link
Collaborator Author

@zadjii-msft I think what would be really cool is if the keyboard modifier logic is baked into Command interface, that way when we can have a bunch of Helper commands that when a developer leverages them in their extensions the keyboard modifiers are the same. This may be exactly what you had in mind already to be fair.

@zadjii-msft zadjii-msft added the Area-API Anything having to do with the actual interface the extensions use to communicate with the host label Oct 23, 2024
@zadjii-msft
Copy link
Owner

Eh, I'm not so sure about putting them on Command itself. What happens if a developer puts a shortcut on a Command which is the default action of a TopLevelCommand? Does that make the shortcut work from the L0? (I don't think it should) What if multiple extensions all specify the same shortcut on their L0 commands?

@zadjii-msft
Copy link
Owner

Though it does look like I deleted this from the "final" version of the spec before I left on leave. I think I mentally bookmarked this as a post-MLP feature.

I'll put this on me to spec out, then a second issue to actually implement it.

@zadjii-msft zadjii-msft self-assigned this Oct 23, 2024
@zadjii-msft zadjii-msft changed the title Allow extensions (and core) to outline keyboard modifiers for commands Spec allowing keyboard shortcuts for commands Oct 23, 2024
@zadjii-msft
Copy link
Owner

Ah, I did write the following blurb:

interface ICommandContextItem requires IContextItem {
ICommand Command { get; };
String Tooltip { get; };
Boolean IsCritical { get; }; // todo: better name for "make this red"
// TODO-future: we should allow app developers to specify a default keybinding for each of these actions
}

@joadoumie
Copy link
Collaborator Author

Totally make sense to have the keyboard binding be to the contextitem imo too.

As much as possible it's really nice if commands that may be reused around all the different surfaces / extensions were to have the same keyboard modifiers... maybe it's as simple as having handy ContextItems that people can reuse through different surfaces that just wrap specific commands that folks also use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-API Anything having to do with the actual interface the extensions use to communicate with the host
Projects
None yet
Development

No branches or pull requests

2 participants