Open current working directory action. (#18013)

## Summary of the Pull Request
Added open current directory action.
## References and Relevant Issues
Need to set this:
https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory

## Detailed Description of the Pull Request / Additional comments

## Validation Steps Performed
- Ensure shell has been configured
- Run "Open current working directory" action in command palette
- File explorer opens the correct directory

## PR Checklist
- [x] Closes #12859
- [ ] Tests added/passed
- [ ] Documentation updated
- If checked, please file a pull request on [our docs
repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
- [ ] Schema updated (if necessary)
This commit is contained in:
Michael Xu 2024-12-05 07:18:45 -05:00 committed by GitHub
parent 89bc36c021
commit 7cdf9eeafb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 36 additions and 1 deletions

View File

@ -423,6 +423,7 @@
"newWindow",
"nextTab",
"openAbout",
"openCWD",
"openNewTabDropdown",
"openSettings",
"openSystemMenu",

View File

@ -1128,6 +1128,16 @@ namespace winrt::TerminalApp::implementation
}
}
void TerminalPage::_HandleOpenCWD(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (const auto& control{ _GetActiveControl() })
{
control.OpenCWD();
args.Handled(true);
}
}
void TerminalPage::_HandleGlobalSummon(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{

View File

@ -1656,6 +1656,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
SearchMissingCommand.raise(*this, make<implementation::SearchMissingCommandEventArgs>(hstring{ missingCommand }, bufferRow));
}
void ControlCore::OpenCWD()
{
const auto workingDirectory = WorkingDirectory();
ShellExecute(nullptr, nullptr, L"explorer", workingDirectory.c_str(), nullptr, SW_SHOW);
}
void ControlCore::ClearQuickFix()
{
_cachedQuickFixes = nullptr;

View File

@ -157,6 +157,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void ClearQuickFix();
void OpenCWD();
#pragma region ICoreState
const size_t TaskbarState() const noexcept;
const size_t TaskbarProgress() const noexcept;

View File

@ -178,6 +178,8 @@ namespace Microsoft.Terminal.Control
Boolean ShouldShowSelectCommand();
Boolean ShouldShowSelectOutput();
void OpenCWD();
void ClearQuickFix();
// These events are called from some background thread

View File

@ -2675,6 +2675,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}
void TermControl::OpenCWD()
{
_core.OpenCWD();
}
void TermControl::Close()
{
if (!_IsClosing())

View File

@ -69,6 +69,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool ExpandSelectionToWord();
void RestoreFromPath(winrt::hstring path);
void PersistToPath(const winrt::hstring& path) const;
void OpenCWD();
void Close();
Windows::Foundation::Size CharacterDimensions() const;
Windows::Foundation::Size MinimumSize();

View File

@ -97,6 +97,7 @@ namespace Microsoft.Terminal.Control
void ClearBuffer(ClearBufferType clearType);
void RestoreFromPath(String path);
void PersistToPath(String path);
void OpenCWD();
void Close();
Windows.Foundation.Size CharacterDimensions { get; };
Windows.Foundation.Size MinimumSize { get; };

View File

@ -100,6 +100,7 @@ static constexpr std::string_view ToggleBroadcastInputKey{ "toggleBroadcastInput
static constexpr std::string_view OpenScratchpadKey{ "experimental.openScratchpad" };
static constexpr std::string_view OpenAboutKey{ "openAbout" };
static constexpr std::string_view QuickFixKey{ "quickFix" };
static constexpr std::string_view OpenCWDKey{ "openCWD" };
static constexpr std::string_view ActionKey{ "action" };
@ -437,6 +438,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::OpenScratchpad, RS_(L"OpenScratchpadKey") },
{ ShortcutAction::OpenAbout, RS_(L"OpenAboutCommandKey") },
{ ShortcutAction::QuickFix, RS_(L"QuickFixCommandKey") },
{ ShortcutAction::OpenCWD, RS_(L"OpenCWDCommandKey") },
};
}();

View File

@ -112,7 +112,8 @@
ON_ALL_ACTIONS(ToggleBroadcastInput) \
ON_ALL_ACTIONS(OpenScratchpad) \
ON_ALL_ACTIONS(OpenAbout) \
ON_ALL_ACTIONS(QuickFix)
ON_ALL_ACTIONS(QuickFix) \
ON_ALL_ACTIONS(OpenCWD)
#define ALL_SHORTCUT_ACTIONS_WITH_ARGS \
ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \

View File

@ -734,4 +734,7 @@
<data name="QuickFixCommandKey" xml:space="preserve">
<value>Open quick fix menu</value>
</data>
<data name="OpenCWDCommandKey" xml:space="preserve">
<value>Open current working directory</value>
</data>
</root>

View File

@ -449,6 +449,7 @@
{ "command": "experimental.openTasks", "id": "Terminal.OpenTasks" },
{ "command": "quickFix", "id": "Terminal.QuickFix" },
{ "command": { "action": "showSuggestions", "source": "all"}, "id": "Terminal.Suggestions" },
{ "command": "openCWD", "id": "Terminal.OpenCWD" },
// Tab Management
// "command": "closeTab" is unbound by default.