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 support for Commandline Mode to the CmdPal #7293

Merged
92 commits merged into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
c56eb8f
Add a ton of text regarding Commandline Mode vs Action Mode
zadjii-msft Apr 30, 2020
fe640ff
move this spec out of `drafts/`
zadjii-msft Apr 30, 2020
614d1b2
last little todos for review
zadjii-msft Apr 30, 2020
ead76d7
Merge remote-tracking branch 'origin/master' into dev/migrie/s/5400-C…
zadjii-msft May 7, 2020
2e56436
Move this section to 'future considerations'
zadjii-msft May 7, 2020
0886e8f
Merge remote-tracking branch 'origin/master' into dev/migrie/s/5400-C…
zadjii-msft May 20, 2020
11130a4
Add some notes about the advanced tab switcher and how that might int…
zadjii-msft May 20, 2020
f53553f
Merge remote-tracking branch 'origin/master' into dev/migrie/s/5400-C…
zadjii-msft May 28, 2020
0672812
good bot
zadjii-msft May 28, 2020
43bd483
Blind port these files from the old branch
zadjii-msft May 28, 2020
75af4ca
Hook up all the parsing once again
zadjii-msft May 28, 2020
33a9e32
Get names from the resources if provided as an object, not a string
zadjii-msft May 28, 2020
3627d8a
This should have been in the previous commit
zadjii-msft May 28, 2020
0416a94
Hook up the parsing of `ActionAndArgs`s to the command palette
zadjii-msft May 28, 2020
6905065
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft May 28, 2020
02f47f4
Make the action names map public, so the ToJson in AKBSerialization c…
zadjii-msft May 28, 2020
62b9a0d
Move the action into it's own sub-object
zadjii-msft May 28, 2020
207666e
Add a ton of default commands
zadjii-msft May 29, 2020
b88be45
Make sure to scroll the selected item into view
zadjii-msft May 29, 2020
00763fd
Add duplicate pane to the default commands
zadjii-msft May 29, 2020
bc546db
Add some stability
zadjii-msft May 29, 2020
e1be26b
Do this in WinRTUtils instead of hackily doing it manually
zadjii-msft May 29, 2020
a309191
Rename private methods, fix wraparound logic
zadjii-msft May 29, 2020
9905945
Return focus to the active control when closed
zadjii-msft May 29, 2020
cf6e1f2
Try to do this with a shadow, but it crashes inexplicably
zadjii-msft May 29, 2020
fa93fdc
Well, this is neat, and works, but requires 18362 and also casts a sh…
zadjii-msft May 29, 2020
1fbe8e4
Turns out, the shadow on the menuflyout isn't my fault, it's on every…
zadjii-msft May 29, 2020
6e6979a
Extract ActionAndArgs::FromJson into it's own class, so it can be re-…
zadjii-msft Jun 4, 2020
829beda
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 4, 2020
487f33e
Merge commit '6e6979abe' into dev/migrie/f/2046-Command-Palette-v2
zadjii-msft Jun 4, 2020
58be8cd
Tons of commenting
zadjii-msft Jun 4, 2020
9d411d4
Make the commands a map, so we can override on "name"
zadjii-msft Jun 4, 2020
d71d8d7
Ready for review.
zadjii-msft Jun 4, 2020
b3d8f0e
Merge remote-tracking branch 'origin/master' into dev/migrie/f/2046-C…
zadjii-msft Jun 9, 2020
67c7969
I couldn't tell you how long this took
zadjii-msft Jun 9, 2020
82f968d
If a key is bound to that action, then display the keybinding in the …
zadjii-msft Jun 9, 2020
edc8b55
Add much better key chord text to the command palette
zadjii-msft Jun 10, 2020
dd684cb
implement a weighted ordering for command palette entries
zadjii-msft Jun 10, 2020
3674c61
Add support for expanding a command into many commands for every prof…
zadjii-msft Jun 10, 2020
0b126f0
lets clean this up so it's not so horrifying.
zadjii-msft Jun 10, 2020
4420aea
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Jul 7, 2020
4e134e3
get it building again
zadjii-msft Jul 7, 2020
946d710
This works to auto-generate names from iterable commands without give…
zadjii-msft Jul 7, 2020
a5eba5a
add some stubs for tests in the future
zadjii-msft Jul 7, 2020
ac74de4
escape profile names for json before re-parsing
zadjii-msft Jul 8, 2020
7321639
re-use FromJson when expanding, as to not just duplicate the entire m…
zadjii-msft Jul 8, 2020
d953d8b
start working on nested actions
zadjii-msft Jul 8, 2020
dc7a816
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Jul 8, 2020
0c8471d
holy shit this worked on the first try
zadjii-msft Jul 8, 2020
bdd7e3b
write a test that _should_ check if an iterable command can have nest…
zadjii-msft Jul 8, 2020
93d31c2
This was a failure
zadjii-msft Jul 8, 2020
5052e64
Revert "This was a failure"
zadjii-msft Jul 8, 2020
c6a8fe9
more tests, more!
zadjii-msft Jul 9, 2020
f5659d2
this fixes `TestNestedInIterableCommand`, but `TestMixedNestedAndIter…
zadjii-msft Jul 9, 2020
077cd6e
this mysteriously fixes the mixed test, which I was pretty onfident I…
zadjii-msft Jul 9, 2020
26a1a41
man these are some great tests
zadjii-msft Jul 9, 2020
33ee177
clean up this duplicated code
zadjii-msft Jul 9, 2020
be5aee3
make sure to actually update the xaml lists as well.
zadjii-msft Jul 9, 2020
92167a5
code cleanup
zadjii-msft Jul 9, 2020
7968b2a
more tests, code cleanup
zadjii-msft Jul 9, 2020
c5208e6
finish remaining todos, also, good bot
zadjii-msft Jul 9, 2020
7cb870c
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Aug 3, 2020
8fd3e0d
These changes to defaults.json are out-of-date, and Command doesn't n…
zadjii-msft Aug 3, 2020
2763c90
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Aug 4, 2020
3d0c81c
the tiniest nit
zadjii-msft Aug 4, 2020
50bdc3d
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Aug 5, 2020
2a8d4c5
well, we definitely want this
zadjii-msft Aug 5, 2020
0719b42
This makes command expansion the TerminalPage's responsibility, but i…
zadjii-msft Aug 5, 2020
77e51af
expand commands every time the list of tabs changes
zadjii-msft Aug 5, 2020
1e9bf47
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Aug 11, 2020
b60b82b
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Aug 11, 2020
ec2db21
I guess we only really need to do this once
zadjii-msft Aug 11, 2020
c8c0032
Merge remote-tracking branch 'origin/dev/migrie/f/6856-let-terminalpa…
zadjii-msft Aug 11, 2020
b4eb86d
nits from PR
zadjii-msft Aug 11, 2020
1975e8c
Merge remote-tracking branch 'origin/master' into dev/migrie/f/comman…
zadjii-msft Aug 12, 2020
57abe29
Add a helper for find/replace-ing a string
zadjii-msft Aug 12, 2020
9981126
Clean up our string handling substantially
zadjii-msft Aug 12, 2020
c55d53e
minor nits, more tracing
zadjii-msft Aug 12, 2020
3269309
some cleaner lifetime management for these variables
zadjii-msft Aug 12, 2020
933dc7e
use a IMap to store subcommands, and then generate the vector when we…
zadjii-msft Aug 13, 2020
5198142
Fix the localtests for commands
zadjii-msft Aug 13, 2020
7b014d9
Dustin wanted every command to not necessarily have a subcommand map,…
zadjii-msft Aug 13, 2020
f880a7f
Merge remote-tracking branch 'origin/master' into dev/migrie/f/cmdpal…
zadjii-msft Aug 13, 2020
10df35e
initial commit moving work from old branch
zadjii-msft Aug 13, 2020
e968fc1
Add a message to the commandline mode as well
zadjii-msft Aug 13, 2020
3cc3b4c
Merge remote-tracking branch 'origin/master' into dev/migrie/f/cmdpal…
zadjii-msft Aug 14, 2020
33c4259
Merge remote-tracking branch 'origin/master' into dev/migrie/f/cmdpal…
zadjii-msft Aug 19, 2020
ad38d06
Changes for carlos
zadjii-msft Aug 19, 2020
6ed1204
Merge remote-tracking branch 'origin/master' into dev/migrie/f/cmdpal…
zadjii-msft Aug 21, 2020
491d8e2
Merge remote-tracking branch 'origin/master' into dev/migrie/f/cmdpal…
zadjii-msft Aug 21, 2020
55591a5
fix build
zadjii-msft Aug 21, 2020
0bdb7ff
bad if/else's that Leon caught.
zadjii-msft Aug 24, 2020
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
150 changes: 143 additions & 7 deletions src/cascadia/TerminalApp/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,57 @@ namespace winrt::TerminalApp::implementation
{
// Action Mode: Dispatch the action of the selected command.

if (const auto selectedItem = _filteredActionsView().SelectedItem())
if (_currentMode == CommandPaletteMode::ActionMode)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
_dispatchCommand(selectedItem.try_as<TerminalApp::Command>());
if (const auto selectedItem = _filteredActionsView().SelectedItem())
{
_dispatchCommand(selectedItem.try_as<TerminalApp::Command>());
}
}
else if (_currentMode == CommandPaletteMode::CommandlineMode)
{
_dispatchCommandline();
}

e.Handled(true);
}
else if (key == VirtualKey::Escape)
{
// Action Mode: Dismiss the palette if the text is empty, otherwise clear the search string.
if (_searchBox().Text().empty())
if (_currentMode == CommandPaletteMode::ActionMode)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
_dismissPalette();
// Action Mode: Dismiss the palette if the text is empty,
// otherwise clear the search string.
if (_searchBox().Text().empty())
{
_dismissPalette();
}
else
{
_searchBox().Text(L"");
}
}
else
else if (_currentMode == CommandPaletteMode::CommandlineMode)
{
_searchBox().Text(L"");
const auto currentInput = _getPostPrefixInput();
if (currentInput.empty())
{
// The user's only input "> " so far. We should just dismiss
// the palette. This is like dismissing the Action mode with
// empty input.
_dismissPalette();
}
else
{
// Clear out the current input. We'll leave a ">" in the
// input (to stay in commandline mode), and a leading space
// (if they currenly had one).
const bool hasLeadingSpace = (_searchBox().Text().size()) - (currentInput.size()) > 1;
_searchBox().Text(hasLeadingSpace ? L"> " : L">");

// This will conveniently move the cursor to the end of the
// text input for us.
_searchBox().Select(_searchBox().Text().size(), 0);
}
}

e.Handled(true);
Expand Down Expand Up @@ -319,6 +353,8 @@ namespace winrt::TerminalApp::implementation
return _allCommands;
case CommandPaletteMode::TabSwitcherMode:
return _allTabActions;
case CommandPaletteMode::CommandlineMode:
return winrt::single_threaded_vector<TerminalApp::Command>();
default:
return _allCommands;
}
Expand Down Expand Up @@ -379,6 +415,72 @@ namespace winrt::TerminalApp::implementation
}
}

// Method Description:
// - Get all the input text in _searchBox that follows the prefix character
// and any whitespace following that prefix character. This can be used in
// commandline mode to get all the useful input that the user input after
// the leading ">" prefix.
// - Note that this will behave unexpectedly in Action Mode.
// Arguments:
// - <none>
// Return Value:
// - the string of input following the prefix character.
std::wstring CommandPalette::_getPostPrefixInput()
{
const std::wstring input{ _searchBox().Text() };
if (input.empty())
{
return input;
}

const auto rawCmdline{ input.substr(1) };

// Trim leading whitespace
const auto firstNonSpace = rawCmdline.find_first_not_of(L" ");
if (firstNonSpace == std::wstring::npos)
{
// All the following characters are whitespace.
return L"";
}

return rawCmdline.substr(firstNonSpace);
}

// Method Description:
// - Dispatch the current search text as a ExecuteCommandline action.
// Arguments:
// - <none>
// Return Value:
// - <none>
void CommandPalette::_dispatchCommandline()
{
const auto input = _getPostPrefixInput();
if (input.empty())
{
return;
}
winrt::hstring cmdline{ input };

// Build the NewTab action from the values we've parsed on the commandline.
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
auto executeActionAndArgs = winrt::make_self<implementation::ActionAndArgs>();
executeActionAndArgs->Action(ShortcutAction::ExecuteCommandline);
auto args = winrt::make_self<implementation::ExecuteCommandlineArgs>();
args->Commandline(cmdline);
executeActionAndArgs->Args(*args);

TraceLoggingWrite(
g_hTerminalAppProvider, // handle to TerminalApp tracelogging provider
"CommandPaletteDispatchedCommandline",
TraceLoggingDescription("Event emitted when the user runs a commandline in the Command Palette"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance));

if (_dispatch.DoAction(*executeActionAndArgs))
{
_close();
}
}

// Method Description:
// - Helper method for closing the command palette, when the user has _not_
// selected an action. Also fires a tracelogging event indicating that the
Expand Down Expand Up @@ -409,12 +511,36 @@ namespace winrt::TerminalApp::implementation
void CommandPalette::_filterTextChanged(IInspectable const& /*sender*/,
Windows::UI::Xaml::RoutedEventArgs const& /*args*/)
{
if (_currentMode != CommandPaletteMode::TabSwitcherMode)
{
_evaluatePrefix();
}

_updateFilteredActions();
_filteredActionsView().SelectedIndex(0);

_noMatchesText().Visibility(_filteredActions.Size() > 0 ? Visibility::Collapsed : Visibility::Visible);
}

void CommandPalette::_evaluatePrefix()
{
auto newMode = CommandPaletteMode::ActionMode;

auto inputText = _searchBox().Text();
if (inputText.size() > 0)
{
if (inputText[0] == L'>')
{
newMode = CommandPaletteMode::CommandlineMode;
}
}

if (newMode != _currentMode)
{
_switchToMode(newMode);
}
}

Collections::IObservableVector<TerminalApp::Command> CommandPalette::FilteredActions()
{
return _filteredActions;
Expand Down Expand Up @@ -462,6 +588,10 @@ namespace winrt::TerminalApp::implementation
ControlName(RS_(L"TabSwitcherControlName"));
break;
}
case CommandPaletteMode::CommandlineMode:
NoMatchesText(RS_(L"CmdPalCommandlinePrompt"));
ControlName(RS_(L"CommandPaletteControlName"));
break;
case CommandPaletteMode::ActionMode:
default:
SearchBoxText(RS_(L"CommandPalette_SearchBox/PlaceholderText"));
Expand Down Expand Up @@ -617,6 +747,12 @@ namespace winrt::TerminalApp::implementation
// - <none>
void CommandPalette::_updateFilteredActions()
{
if (_currentMode == CommandPaletteMode::CommandlineMode)
{
_filteredActions.Clear();
return;
}

auto actions = _collectFilteredActions();

// Make _filteredActions look identical to actions, using only Insert and Remove.
Expand Down
8 changes: 6 additions & 2 deletions src/cascadia/TerminalApp/CommandPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace winrt::TerminalApp::implementation
enum class CommandPaletteMode
{
ActionMode = 0,
TabSwitcherMode
TabSwitcherMode,
CommandlineMode
};

struct CommandPalette : CommandPaletteT<CommandPalette>
Expand Down Expand Up @@ -75,6 +76,9 @@ namespace winrt::TerminalApp::implementation
CommandPaletteMode _currentMode;
void _switchToMode(CommandPaletteMode mode);

void _evaluatePrefix();
std::wstring _getPostPrefixInput();

// Tab Switcher
std::optional<winrt::Windows::System::VirtualKey> _anchorKey;
void GenerateCommandForTab(const uint32_t idx, bool inserted, winrt::TerminalApp::Tab& tab);
Expand All @@ -85,7 +89,7 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::UI::Xaml::Controls::ListView::SizeChanged_revoker _sizeChangedRevoker;

void _dispatchCommand(const TerminalApp::Command& command);

void _dispatchCommandline();
void _dismissPalette();
};
}
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@
<data name="TabSwitcher_NoMatchesText" xml:space="preserve">
<value>No matching tab name</value>
</data>
<data name="CmdPalCommandlinePrompt" xml:space="preserve">
<value>Enter a wt commandline to run</value>
<comment>{Locked="wt"} </comment>
</data>
<data name="CrimsonColorButton.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Crimson</value>
</data>
Expand Down