diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index c0b659ccc42..67c5e7aaae2 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -423,6 +423,7 @@ "newWindow", "nextTab", "openAbout", + "openCWD", "openNewTabDropdown", "openSettings", "openSystemMenu", diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 8675fb98bac..9ff70e2a456 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -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) { diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 91db886cebb..df59f8051eb 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1643,6 +1643,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation SearchMissingCommand.raise(*this, make(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; diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index 2e9f2490d9d..80d4cf0ddd8 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -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; diff --git a/src/cascadia/TerminalControl/ControlCore.idl b/src/cascadia/TerminalControl/ControlCore.idl index ee1a4787e22..befc3c089f1 100644 --- a/src/cascadia/TerminalControl/ControlCore.idl +++ b/src/cascadia/TerminalControl/ControlCore.idl @@ -177,6 +177,8 @@ namespace Microsoft.Terminal.Control Boolean ShouldShowSelectCommand(); Boolean ShouldShowSelectOutput(); + void OpenCWD(); + void ClearQuickFix(); // These events are called from some background thread diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index f76c8c59403..83f59d6a800 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -2615,6 +2615,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation } } + void TermControl::OpenCWD() + { + _core.OpenCWD(); + } + void TermControl::Close() { if (!_IsClosing()) diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index d8a44161dbf..2c7e736ca22 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -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(); diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl index c60b5884540..da63b8b6b06 100644 --- a/src/cascadia/TerminalControl/TermControl.idl +++ b/src/cascadia/TerminalControl/TermControl.idl @@ -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; }; diff --git a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp index 5d2bd486266..b8ccf1c761b 100644 --- a/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp +++ b/src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp @@ -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") }, }; }(); diff --git a/src/cascadia/TerminalSettingsModel/AllShortcutActions.h b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h index daeb1f399bd..b9855d9e308 100644 --- a/src/cascadia/TerminalSettingsModel/AllShortcutActions.h +++ b/src/cascadia/TerminalSettingsModel/AllShortcutActions.h @@ -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) \ diff --git a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw index 77c98c7da0a..eda7808fc81 100644 --- a/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw @@ -734,4 +734,7 @@ Open quick fix menu + + Open current working directory + diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index 1d2b8f2c472..e64e676b5e6 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -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.