2020-06-26 22:38:02 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-11-06 02:37:45 +01:00
|
|
|
#include "FilteredCommand.h"
|
2020-06-26 22:38:02 +02:00
|
|
|
#include "CommandPalette.g.h"
|
|
|
|
#include "../../cascadia/inc/cppwinrt_utils.h"
|
|
|
|
|
2020-11-06 02:37:45 +01:00
|
|
|
// fwdecl unittest classes
|
|
|
|
namespace TerminalAppLocalTests
|
|
|
|
{
|
2020-11-09 19:37:19 +01:00
|
|
|
class TabTests;
|
2020-11-06 02:37:45 +01:00
|
|
|
};
|
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
namespace winrt::TerminalApp::implementation
|
|
|
|
{
|
2020-08-11 16:03:12 +02:00
|
|
|
enum class CommandPaletteMode
|
|
|
|
{
|
|
|
|
ActionMode = 0,
|
2020-08-21 17:39:40 +02:00
|
|
|
TabSearchMode,
|
2020-08-24 23:39:07 +02:00
|
|
|
TabSwitchMode,
|
|
|
|
CommandlineMode
|
2020-08-11 16:03:12 +02:00
|
|
|
};
|
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
struct CommandPalette : CommandPaletteT<CommandPalette>
|
|
|
|
{
|
|
|
|
CommandPalette();
|
|
|
|
|
2020-11-06 02:37:45 +01:00
|
|
|
Windows::Foundation::Collections::IObservableVector<winrt::TerminalApp::FilteredCommand> FilteredActions();
|
2020-08-11 16:03:12 +02:00
|
|
|
|
2020-10-06 18:56:59 +02:00
|
|
|
void SetCommands(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::Command> const& actions);
|
2020-11-05 15:28:16 +01:00
|
|
|
void SetTabActions(Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::Command> const& tabs, const bool clearList);
|
2020-08-21 17:39:40 +02:00
|
|
|
void SetKeyBindings(Microsoft::Terminal::TerminalControl::IKeyBindings bindings);
|
|
|
|
|
2020-12-03 17:15:31 +01:00
|
|
|
void EnableCommandPaletteMode(Microsoft::Terminal::Settings::Model::CommandPaletteLaunchMode const launchMode);
|
2020-06-26 22:38:02 +02:00
|
|
|
|
|
|
|
void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch);
|
|
|
|
|
2020-08-21 17:39:40 +02:00
|
|
|
bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);
|
|
|
|
|
|
|
|
void SelectNextItem(const bool moveDown);
|
|
|
|
|
2020-11-09 22:55:11 +01:00
|
|
|
void ScrollPageUp();
|
|
|
|
void ScrollPageDown();
|
|
|
|
void ScrollToTop();
|
|
|
|
void ScrollToBottom();
|
2020-10-22 06:40:57 +02:00
|
|
|
|
2020-08-11 16:03:12 +02:00
|
|
|
// Tab Switcher
|
2020-08-21 17:39:40 +02:00
|
|
|
void EnableTabSwitcherMode(const bool searchMode, const uint32_t startIdx);
|
2020-11-05 15:28:16 +01:00
|
|
|
void SetTabSwitchOrder(const Microsoft::Terminal::Settings::Model::TabSwitcherMode order);
|
2020-08-11 16:03:12 +02:00
|
|
|
|
|
|
|
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
|
|
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, NoMatchesText, _PropertyChangedHandlers);
|
2020-10-16 00:58:35 +02:00
|
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, SearchBoxPlaceholderText, _PropertyChangedHandlers);
|
|
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, PrefixCharacter, _PropertyChangedHandlers);
|
2020-08-11 16:03:12 +02:00
|
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, ControlName, _PropertyChangedHandlers);
|
2020-08-18 21:32:17 +02:00
|
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, ParentCommandName, _PropertyChangedHandlers);
|
2020-08-11 16:03:12 +02:00
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
private:
|
|
|
|
friend struct CommandPaletteT<CommandPalette>; // for Xaml to bind events
|
|
|
|
|
2020-11-06 02:37:45 +01:00
|
|
|
Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> _allCommands{ nullptr };
|
|
|
|
Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> _currentNestedCommands{ nullptr };
|
|
|
|
Windows::Foundation::Collections::IObservableVector<winrt::TerminalApp::FilteredCommand> _filteredActions{ nullptr };
|
|
|
|
Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> _nestedActionStack{ nullptr };
|
2020-08-11 16:03:12 +02:00
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
winrt::TerminalApp::ShortcutActionDispatch _dispatch;
|
2020-11-06 02:37:45 +01:00
|
|
|
Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> _commandsToFilter();
|
2020-08-11 16:03:12 +02:00
|
|
|
|
2020-10-16 00:58:35 +02:00
|
|
|
bool _lastFilterTextWasEmpty{ true };
|
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
void _filterTextChanged(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::UI::Xaml::RoutedEventArgs const& args);
|
2020-08-11 16:03:12 +02:00
|
|
|
void _previewKeyDownHandler(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);
|
2020-06-26 22:38:02 +02:00
|
|
|
void _keyDownHandler(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);
|
2020-08-11 16:03:12 +02:00
|
|
|
void _keyUpHandler(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);
|
2020-06-26 22:38:02 +02:00
|
|
|
|
2020-10-08 00:49:10 +02:00
|
|
|
void _selectedCommandChanged(Windows::Foundation::IInspectable const& sender,
|
|
|
|
Windows::UI::Xaml::RoutedEventArgs const& args);
|
|
|
|
|
Add support for iterable, nested commands (#6856)
## Summary of the Pull Request
This PR adds support for both _nested_ and _iterable_ commands in the Command palette.
![nested-commands-000](https://user-images.githubusercontent.com/18356694/87072916-2d991c00-c1e2-11ea-8917-a70e8b8b9803.gif)
* **Nested commands**: These are commands that include additional sub-commands. When the user selects on of these, the palette will update to only show the nested commands.
* **Iterable commands**: These are commands what allow the user to define only a single command, which is repeated once for every profile. (in the future, also repeated for color schemes, themes, etc.)
The above gif uses the following json:
```json
{
"name": "Split Pane...",
"commands": [
{
"iterateOn": "profiles",
"name": "Split with ${profile.name}...",
"commands": [
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "automatic" } },
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "vertical" } },
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "horizontal" } }
]
}
]
},
```
## References
## PR Checklist
* [x] Closes #3994
* [x] I work here
* [x] Tests added/passed
* [ ] Requires documentation to be updated - Sure does, but we'll finish polishing this first.
## Detailed Description of the Pull Request / Additional comments
We've now gotta keep the original json for a command around, so that once we know what all the profiles will be, we can expand the commands that need it.
We've also got to parse commands recursively, because they might have any number of child commands.
These together made the command parsing a _lot_ more complicated, but it feels good so far.
## Validation Steps Performed
* wrote a bunch of tests
* Played with it a bunch
2020-08-13 23:22:46 +02:00
|
|
|
void _updateUIForStackChange();
|
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
void _rootPointerPressed(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
|
|
|
|
void _backdropPointerPressed(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
|
|
|
|
|
|
|
|
void _listItemClicked(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Controls::ItemClickEventArgs const& e);
|
|
|
|
|
2020-11-05 01:19:52 +01:00
|
|
|
void _moveBackButtonClicked(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const&);
|
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
void _updateFilteredActions();
|
Add support for iterable, nested commands (#6856)
## Summary of the Pull Request
This PR adds support for both _nested_ and _iterable_ commands in the Command palette.
![nested-commands-000](https://user-images.githubusercontent.com/18356694/87072916-2d991c00-c1e2-11ea-8917-a70e8b8b9803.gif)
* **Nested commands**: These are commands that include additional sub-commands. When the user selects on of these, the palette will update to only show the nested commands.
* **Iterable commands**: These are commands what allow the user to define only a single command, which is repeated once for every profile. (in the future, also repeated for color schemes, themes, etc.)
The above gif uses the following json:
```json
{
"name": "Split Pane...",
"commands": [
{
"iterateOn": "profiles",
"name": "Split with ${profile.name}...",
"commands": [
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "automatic" } },
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "vertical" } },
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "horizontal" } }
]
}
]
},
```
## References
## PR Checklist
* [x] Closes #3994
* [x] I work here
* [x] Tests added/passed
* [ ] Requires documentation to be updated - Sure does, but we'll finish polishing this first.
## Detailed Description of the Pull Request / Additional comments
We've now gotta keep the original json for a command around, so that once we know what all the profiles will be, we can expand the commands that need it.
We've also got to parse commands recursively, because they might have any number of child commands.
These together made the command parsing a _lot_ more complicated, but it feels good so far.
## Validation Steps Performed
* wrote a bunch of tests
* Played with it a bunch
2020-08-13 23:22:46 +02:00
|
|
|
|
2020-11-06 02:37:45 +01:00
|
|
|
void _populateFilteredActions(Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> const& vectorToPopulate,
|
|
|
|
Windows::Foundation::Collections::IVector<Microsoft::Terminal::Settings::Model::Command> const& actions);
|
|
|
|
|
|
|
|
std::vector<winrt::TerminalApp::FilteredCommand> _collectFilteredActions();
|
Add support for iterable, nested commands (#6856)
## Summary of the Pull Request
This PR adds support for both _nested_ and _iterable_ commands in the Command palette.
![nested-commands-000](https://user-images.githubusercontent.com/18356694/87072916-2d991c00-c1e2-11ea-8917-a70e8b8b9803.gif)
* **Nested commands**: These are commands that include additional sub-commands. When the user selects on of these, the palette will update to only show the nested commands.
* **Iterable commands**: These are commands what allow the user to define only a single command, which is repeated once for every profile. (in the future, also repeated for color schemes, themes, etc.)
The above gif uses the following json:
```json
{
"name": "Split Pane...",
"commands": [
{
"iterateOn": "profiles",
"name": "Split with ${profile.name}...",
"commands": [
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "automatic" } },
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "vertical" } },
{ "command": { "action": "splitPane", "profile": "${profile.name}", "split": "horizontal" } }
]
}
]
},
```
## References
## PR Checklist
* [x] Closes #3994
* [x] I work here
* [x] Tests added/passed
* [ ] Requires documentation to be updated - Sure does, but we'll finish polishing this first.
## Detailed Description of the Pull Request / Additional comments
We've now gotta keep the original json for a command around, so that once we know what all the profiles will be, we can expand the commands that need it.
We've also got to parse commands recursively, because they might have any number of child commands.
These together made the command parsing a _lot_ more complicated, but it feels good so far.
## Validation Steps Performed
* wrote a bunch of tests
* Played with it a bunch
2020-08-13 23:22:46 +02:00
|
|
|
|
2020-06-26 22:38:02 +02:00
|
|
|
static int _getWeight(const winrt::hstring& searchText, const winrt::hstring& name);
|
|
|
|
void _close();
|
2020-07-08 01:31:31 +02:00
|
|
|
|
2020-08-11 16:03:12 +02:00
|
|
|
CommandPaletteMode _currentMode;
|
|
|
|
void _switchToMode(CommandPaletteMode mode);
|
|
|
|
|
2020-10-16 00:58:35 +02:00
|
|
|
std::wstring _getTrimmedInput();
|
2020-08-24 23:39:07 +02:00
|
|
|
void _evaluatePrefix();
|
|
|
|
|
2020-08-21 17:39:40 +02:00
|
|
|
Microsoft::Terminal::TerminalControl::IKeyBindings _bindings;
|
|
|
|
|
2020-08-11 16:03:12 +02:00
|
|
|
// Tab Switcher
|
2020-11-06 02:37:45 +01:00
|
|
|
Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> _tabActions{ nullptr };
|
2020-08-11 16:03:12 +02:00
|
|
|
uint32_t _switcherStartIdx;
|
2020-08-21 17:39:40 +02:00
|
|
|
void _anchorKeyUpHandler();
|
2020-08-11 16:03:12 +02:00
|
|
|
|
|
|
|
winrt::Windows::UI::Xaml::Controls::ListView::SizeChanged_revoker _sizeChangedRevoker;
|
|
|
|
|
2020-11-06 02:37:45 +01:00
|
|
|
void _dispatchCommand(winrt::TerminalApp::FilteredCommand const& command);
|
2020-11-25 21:30:36 +01:00
|
|
|
void _dispatchCommandline(winrt::TerminalApp::FilteredCommand const& command);
|
|
|
|
std::optional<winrt::TerminalApp::FilteredCommand> _buildCommandLineCommand(std::wstring const& commandLine);
|
|
|
|
|
2020-07-08 01:31:31 +02:00
|
|
|
void _dismissPalette();
|
2020-11-09 19:37:19 +01:00
|
|
|
|
2020-11-09 22:55:11 +01:00
|
|
|
void _scrollToIndex(uint32_t index);
|
|
|
|
uint32_t _getNumVisibleItems();
|
|
|
|
|
2020-11-25 21:30:36 +01:00
|
|
|
static constexpr int CommandLineHistoryLength = 10;
|
|
|
|
Windows::Foundation::Collections::IVector<winrt::TerminalApp::FilteredCommand> _commandLineHistory{ nullptr };
|
|
|
|
|
2020-11-09 19:37:19 +01:00
|
|
|
friend class TerminalAppLocalTests::TabTests;
|
2020-06-26 22:38:02 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace winrt::TerminalApp::factory_implementation
|
|
|
|
{
|
|
|
|
BASIC_FACTORY(CommandPalette);
|
|
|
|
}
|