Skip to content

Commit 7cdf9ee

Browse files
authored
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)
1 parent 89bc36c commit 7cdf9ee

File tree

12 files changed

+36
-1
lines changed

12 files changed

+36
-1
lines changed

doc/cascadia/profiles.schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@
423423
"newWindow",
424424
"nextTab",
425425
"openAbout",
426+
"openCWD",
426427
"openNewTabDropdown",
427428
"openSettings",
428429
"openSystemMenu",

src/cascadia/TerminalApp/AppActionHandlers.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,16 @@ namespace winrt::TerminalApp::implementation
11281128
}
11291129
}
11301130

1131+
void TerminalPage::_HandleOpenCWD(const IInspectable& /*sender*/,
1132+
const ActionEventArgs& args)
1133+
{
1134+
if (const auto& control{ _GetActiveControl() })
1135+
{
1136+
control.OpenCWD();
1137+
args.Handled(true);
1138+
}
1139+
}
1140+
11311141
void TerminalPage::_HandleGlobalSummon(const IInspectable& /*sender*/,
11321142
const ActionEventArgs& args)
11331143
{

src/cascadia/TerminalControl/ControlCore.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
16561656
SearchMissingCommand.raise(*this, make<implementation::SearchMissingCommandEventArgs>(hstring{ missingCommand }, bufferRow));
16571657
}
16581658

1659+
void ControlCore::OpenCWD()
1660+
{
1661+
const auto workingDirectory = WorkingDirectory();
1662+
ShellExecute(nullptr, nullptr, L"explorer", workingDirectory.c_str(), nullptr, SW_SHOW);
1663+
}
1664+
16591665
void ControlCore::ClearQuickFix()
16601666
{
16611667
_cachedQuickFixes = nullptr;

src/cascadia/TerminalControl/ControlCore.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
157157

158158
void ClearQuickFix();
159159

160+
void OpenCWD();
161+
160162
#pragma region ICoreState
161163
const size_t TaskbarState() const noexcept;
162164
const size_t TaskbarProgress() const noexcept;

src/cascadia/TerminalControl/ControlCore.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ namespace Microsoft.Terminal.Control
178178
Boolean ShouldShowSelectCommand();
179179
Boolean ShouldShowSelectOutput();
180180

181+
void OpenCWD();
182+
181183
void ClearQuickFix();
182184

183185
// These events are called from some background thread

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
26752675
}
26762676
}
26772677

2678+
void TermControl::OpenCWD()
2679+
{
2680+
_core.OpenCWD();
2681+
}
2682+
26782683
void TermControl::Close()
26792684
{
26802685
if (!_IsClosing())

src/cascadia/TerminalControl/TermControl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
6969
bool ExpandSelectionToWord();
7070
void RestoreFromPath(winrt::hstring path);
7171
void PersistToPath(const winrt::hstring& path) const;
72+
void OpenCWD();
7273
void Close();
7374
Windows::Foundation::Size CharacterDimensions() const;
7475
Windows::Foundation::Size MinimumSize();

src/cascadia/TerminalControl/TermControl.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ namespace Microsoft.Terminal.Control
9797
void ClearBuffer(ClearBufferType clearType);
9898
void RestoreFromPath(String path);
9999
void PersistToPath(String path);
100+
void OpenCWD();
100101
void Close();
101102
Windows.Foundation.Size CharacterDimensions { get; };
102103
Windows.Foundation.Size MinimumSize { get; };

src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static constexpr std::string_view ToggleBroadcastInputKey{ "toggleBroadcastInput
100100
static constexpr std::string_view OpenScratchpadKey{ "experimental.openScratchpad" };
101101
static constexpr std::string_view OpenAboutKey{ "openAbout" };
102102
static constexpr std::string_view QuickFixKey{ "quickFix" };
103+
static constexpr std::string_view OpenCWDKey{ "openCWD" };
103104

104105
static constexpr std::string_view ActionKey{ "action" };
105106

@@ -437,6 +438,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
437438
{ ShortcutAction::OpenScratchpad, RS_(L"OpenScratchpadKey") },
438439
{ ShortcutAction::OpenAbout, RS_(L"OpenAboutCommandKey") },
439440
{ ShortcutAction::QuickFix, RS_(L"QuickFixCommandKey") },
441+
{ ShortcutAction::OpenCWD, RS_(L"OpenCWDCommandKey") },
440442
};
441443
}();
442444

src/cascadia/TerminalSettingsModel/AllShortcutActions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@
112112
ON_ALL_ACTIONS(ToggleBroadcastInput) \
113113
ON_ALL_ACTIONS(OpenScratchpad) \
114114
ON_ALL_ACTIONS(OpenAbout) \
115-
ON_ALL_ACTIONS(QuickFix)
115+
ON_ALL_ACTIONS(QuickFix) \
116+
ON_ALL_ACTIONS(OpenCWD)
116117

117118
#define ALL_SHORTCUT_ACTIONS_WITH_ARGS \
118119
ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \

0 commit comments

Comments
 (0)