From 07ab3d945e4576f8b5c8289eff356298b1a4164b Mon Sep 17 00:00:00 2001 From: michaeljsXu Date: Sun, 6 Oct 2024 22:29:59 -0400 Subject: [PATCH 1/3] open CWD in file explorer action --- doc/cascadia/profiles.schema.json | 1 + src/cascadia/TerminalApp/AppActionHandlers.cpp | 10 ++++++++++ src/cascadia/TerminalControl/ControlCore.cpp | 6 ++++++ src/cascadia/TerminalControl/ControlCore.h | 2 ++ src/cascadia/TerminalControl/ControlCore.idl | 2 ++ src/cascadia/TerminalControl/TermControl.cpp | 5 +++++ src/cascadia/TerminalControl/TermControl.h | 1 + src/cascadia/TerminalControl/TermControl.idl | 1 + src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp | 2 ++ .../TerminalSettingsModel/AllShortcutActions.h | 3 ++- .../Resources/en-US/Resources.resw | 3 +++ src/cascadia/TerminalSettingsModel/defaults.json | 1 + 12 files changed, 36 insertions(+), 1 deletion(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 325e73f2d07..9d3b754a02a 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..8553a7b1d9e 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 cd4f5f58b81..4fe7b44de60 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 9ac8e5450c3..ad4c364928a 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 3be52269a89..33cd4f41728 100644 --- a/src/cascadia/TerminalControl/ControlCore.idl +++ b/src/cascadia/TerminalControl/ControlCore.idl @@ -178,6 +178,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 565ea02ccf6..82fdbe96334 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -2594,6 +2594,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..4699855cbf4 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" }, // Tab Management // "command": "closeTab" is unbound by default. From 584f15c1dde42babb4c89950ca43be9b29a6a5cc Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Tue, 8 Oct 2024 11:31:42 -0400 Subject: [PATCH 2/3] added id in defaults.json, action there now --- src/cascadia/TerminalSettingsModel/defaults.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index 4699855cbf4..e64e676b5e6 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -449,7 +449,7 @@ { "command": "experimental.openTasks", "id": "Terminal.OpenTasks" }, { "command": "quickFix", "id": "Terminal.QuickFix" }, { "command": { "action": "showSuggestions", "source": "all"}, "id": "Terminal.Suggestions" }, - { "command": "openCWD" }, + { "command": "openCWD", "id": "Terminal.OpenCWD" }, // Tab Management // "command": "closeTab" is unbound by default. From dad9b5432294fa92a2859ff76257ad49d891f4e9 Mon Sep 17 00:00:00 2001 From: michaeljsXu Date: Tue, 8 Oct 2024 13:53:51 -0400 Subject: [PATCH 3/3] ran code format --- src/cascadia/TerminalApp/AppActionHandlers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 8553a7b1d9e..9ff70e2a456 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -1129,7 +1129,7 @@ namespace winrt::TerminalApp::implementation } void TerminalPage::_HandleOpenCWD(const IInspectable& /*sender*/, - const ActionEventArgs& args) + const ActionEventArgs& args) { if (const auto& control{ _GetActiveControl() }) {