Skip to content

Commit

Permalink
Manually pre-evaluate the starting directory when calling elevate-shim (
Browse files Browse the repository at this point in the history
#15286)

_targets #15280_

When ctrl+clicking on a profile, pre-evaluate the starting directory of
that profile, and stash that in the commandline we pass to elevate shim.

So in the case of something like "use parent process directory", we'll
run `elevate-shim new-tab -p {guid} -d "C:\\the path\\of\\terminal\\."`


Closes #15173

---------

Co-authored-by: Leonard Hecker <lhecker@microsoft.com>
  • Loading branch information
zadjii-msft and lhecker authored May 15, 2023
1 parent f6e9f91 commit 9a4f4ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ namespace winrt::TerminalApp::implementation
if (profile)
{
newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid()));
newTerminalArgs.StartingDirectory(_evaluatePathForCwd(profile.EvaluatedStartingDirectory()));
}
}

Expand Down Expand Up @@ -1168,6 +1169,11 @@ namespace winrt::TerminalApp::implementation
}
}

std::wstring TerminalPage::_evaluatePathForCwd(const std::wstring_view path)
{
return Utils::EvaluateStartingDirectory(_WindowProperties.VirtualWorkingDirectory(), path);
}

// Method Description:
// - Creates a new connection based on the profile settings
// Arguments:
Expand Down Expand Up @@ -1236,13 +1242,7 @@ namespace winrt::TerminalApp::implementation
// construction, because the connection might not spawn the child
// process until later, on another thread, after we've already
// restored the CWD to its original value.
const auto currentVirtualDir{ _WindowProperties.VirtualWorkingDirectory() };
const auto cwdString{ std::wstring_view{ currentVirtualDir } };
const auto requestedStartingDir{ settings.StartingDirectory() };
auto newWorkingDirectory = winrt::hstring{
Utils::EvaluateStartingDirectory(cwdString, std::wstring_view{ requestedStartingDir })
};

auto newWorkingDirectory{ _evaluatePathForCwd(settings.StartingDirectory()) };
auto conhostConn = TerminalConnection::ConptyConnection();
auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(settings.Commandline(),
newWorkingDirectory,
Expand Down Expand Up @@ -4255,6 +4255,9 @@ namespace winrt::TerminalApp::implementation
// whatever the default profile's GUID is.

newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid()));

newTerminalArgs.StartingDirectory(_evaluatePathForCwd(controlSettings.DefaultSettings().StartingDirectory()));

_OpenElevatedWT(newTerminalArgs);
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ namespace winrt::TerminalApp::implementation
void _OpenNewTabDropdown();
HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr);
void _CreateNewTabFromPane(std::shared_ptr<Pane> pane, uint32_t insertPosition = -1);

std::wstring _evaluatePathForCwd(std::wstring_view path);

winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings, const bool inheritCursor);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(std::shared_ptr<Pane> pane);
void _restartPaneConnection(const std::shared_ptr<Pane>& pane);
Expand Down

0 comments on commit 9a4f4ab

Please sign in to comment.