When drag-n-drop filepath to WSL, fix the path so it's usable

This commit is contained in:
Matt Peterson 2021-10-26 19:49:56 -06:00
parent 9662bc6910
commit 3e22379a73
6 changed files with 27 additions and 0 deletions

1
src/cascadia/TerminalControl/IControlSettings.idl Normal file → Executable file
View file

@ -27,6 +27,7 @@ namespace Microsoft.Terminal.Control
interface IControlSettings requires Microsoft.Terminal.Core.ICoreSettings, Microsoft.Terminal.Control.IControlAppearance
{
String ProfileName;
String ProfileSource;
Boolean UseAcrylic;
ScrollbarState ScrollState;

22
src/cascadia/TerminalControl/TermControl.cpp Normal file → Executable file
View file

@ -2271,6 +2271,27 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
std::wstring fullPath{ item.Path() };
// Fix path for WSL
if (_settings.ProfileSource() == L"Windows.Terminal.Wsl")
{
// Use unix path separator
std::replace(fullPath.begin(), fullPath.end(), '\\', '/');
// remove colon and lowercase drive letter
if (fullPath.at(1) == ':')
{
fullPath.erase(1, 1);
fullPath.replace(0, 1, 1, std::towlower(fullPath.at(0)));
fullPath.insert(0, L"/mnt/");
}
// Remove \\wsl.localhost from the string (leaving the raw Linux filesystem path)
else if (fullPath.find(L"//wsl.localhost") != std::string::npos)
{
fullPath.erase(0, fullPath.find('/', fullPath.find('/', fullPath.find('/', fullPath.find('/') + 1) + 1) + 1));
}
}
const auto containsSpaces = std::find(fullPath.begin(),
fullPath.end(),
L' ') != fullPath.end();
@ -2283,6 +2304,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
allPaths += fullPath;
}
_core.PasteText(winrt::hstring{ allPaths });
}
}

0
src/cascadia/TerminalControl/TermControl.h Normal file → Executable file
View file

View file

@ -275,6 +275,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Fill in the remaining properties from the profile
_ProfileName = profile.Name();
_ProfileSource = profile.Source();
_UseAcrylic = profile.UseAcrylic();
_FontFace = profile.FontInfo().FontFace();

2
src/cascadia/TerminalSettingsModel/TerminalSettings.h Normal file → Executable file
View file

@ -119,6 +119,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// ------------------------ End of Core Settings -----------------------
INHERITABLE_SETTING(Model::TerminalSettings, hstring, ProfileName);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, ProfileSource);
INHERITABLE_SETTING(Model::TerminalSettings, bool, UseAcrylic, false);
INHERITABLE_SETTING(Model::TerminalSettings, double, Opacity, UseAcrylic() ? 0.5 : 1.0);
INHERITABLE_SETTING(Model::TerminalSettings, hstring, Padding, DEFAULT_PADDING);

1
src/cascadia/UnitTests_Control/MockControlSettings.h Normal file → Executable file
View file

@ -51,6 +51,7 @@ namespace ControlUnitTests
// ------------------------ End of Core Settings -----------------------
WINRT_PROPERTY(winrt::hstring, ProfileName);
WINRT_PROPERTY(winrt::hstring, ProfileSource);
WINRT_PROPERTY(bool, UseAcrylic, false);
WINRT_PROPERTY(double, Opacity, .5);
WINRT_PROPERTY(winrt::hstring, Padding, DEFAULT_PADDING);