sui: Improve the "use parent process directory" checkbox (#8827)
Make the "use parent process directory" checkbox rely on a computed property in the ProfileViewModel. It will be enabled when the starting directory is empty and disabled when it's not. When it's unchecked, the last-used value will be restored. If there is no last-used value, it will be set to %USERPROFILE%. Closes #8805
This commit is contained in:
parent
d45cc4c2e1
commit
acf36d0e4f
|
@ -37,6 +37,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
// into the path TextBox, we properly update the checkbox and stored
|
||||
// _lastBgImagePath. Without this, then we'll permanently hide the text
|
||||
// box, prevent it from ever being changed again.
|
||||
//
|
||||
// We do the same for the starting directory path
|
||||
PropertyChanged([this](auto&&, const Data::PropertyChangedEventArgs& args) {
|
||||
if (args.PropertyName() == L"BackgroundImagePath")
|
||||
{
|
||||
|
@ -46,6 +48,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
{
|
||||
_NotifyChanges(L"BackgroundImageSettingsVisible");
|
||||
}
|
||||
else if (args.PropertyName() == L"StartingDirectory")
|
||||
{
|
||||
_NotifyChanges(L"UseParentProcessDirectory");
|
||||
_NotifyChanges(L"UseCustomStartingDirectory");
|
||||
}
|
||||
});
|
||||
|
||||
// Cache the original BG image path. If the user clicks "Use desktop
|
||||
|
@ -55,6 +62,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
{
|
||||
_lastBgImagePath = BackgroundImagePath();
|
||||
}
|
||||
|
||||
// Do the same for the starting directory
|
||||
if (!StartingDirectory().empty())
|
||||
{
|
||||
_lastStartingDirectoryPath = StartingDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
bool ProfileViewModel::CanDeleteProfile() const
|
||||
|
@ -109,6 +122,52 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
}
|
||||
}
|
||||
|
||||
bool ProfileViewModel::UseParentProcessDirectory()
|
||||
{
|
||||
return StartingDirectory().empty();
|
||||
}
|
||||
|
||||
// This function simply returns the opposite of UseParentProcessDirectory.
|
||||
// We bind the 'IsEnabled' parameters of the textbox and browse button
|
||||
// to this because it needs to be the reverse of UseParentProcessDirectory
|
||||
// but we don't want to create a whole new converter for inverting a boolean
|
||||
bool ProfileViewModel::UseCustomStartingDirectory()
|
||||
{
|
||||
return !UseParentProcessDirectory();
|
||||
}
|
||||
|
||||
void ProfileViewModel::UseParentProcessDirectory(const bool useParent)
|
||||
{
|
||||
if (useParent)
|
||||
{
|
||||
// Stash the current value of StartingDirectory. If the user
|
||||
// checks and un-checks the "Use parent process directory" button, we want
|
||||
// the path that we display in the text box to remain unchanged.
|
||||
//
|
||||
// Only stash this value if it's not empty
|
||||
if (!StartingDirectory().empty())
|
||||
{
|
||||
_lastStartingDirectoryPath = StartingDirectory();
|
||||
}
|
||||
StartingDirectory(L"");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restore the path we had previously cached as long as it wasn't empty
|
||||
// If it was empty, set the starting directory to %USERPROFILE%
|
||||
// (we need to set it to something non-empty otherwise we will automatically
|
||||
// disable the text box)
|
||||
if (_lastStartingDirectoryPath.empty())
|
||||
{
|
||||
StartingDirectory(L"%USERPROFILE%");
|
||||
}
|
||||
else
|
||||
{
|
||||
StartingDirectory(_lastStartingDirectoryPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ProfileViewModel::BackgroundImageSettingsVisible()
|
||||
{
|
||||
return IsBaseLayer() || BackgroundImagePath() != L"";
|
||||
|
@ -213,23 +272,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
state->DeleteProfile();
|
||||
}
|
||||
|
||||
void Profiles::UseParentProcessDirectory_Check(IInspectable const& /*sender*/, RoutedEventArgs const& /*e*/)
|
||||
{
|
||||
auto state{ winrt::get_self<ProfilePageNavigationState>(_State) };
|
||||
state->Profile().StartingDirectory(L"");
|
||||
|
||||
// Disable the text box and browse button
|
||||
StartingDirectory().IsEnabled(false);
|
||||
StartingDirectoryBrowse().IsEnabled(false);
|
||||
}
|
||||
|
||||
void Profiles::UseParentProcessDirectory_Uncheck(IInspectable const& /*sender*/, RoutedEventArgs const& /*e*/)
|
||||
{
|
||||
// Enable the text box and browse button
|
||||
StartingDirectory().IsEnabled(true);
|
||||
StartingDirectoryBrowse().IsEnabled(true);
|
||||
}
|
||||
|
||||
fire_and_forget Profiles::BackgroundImage_Click(IInspectable const&, RoutedEventArgs const&)
|
||||
{
|
||||
auto lifetime = get_strong();
|
||||
|
|
|
@ -21,6 +21,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
|
||||
bool UseDesktopBGImage();
|
||||
void UseDesktopBGImage(const bool useDesktop);
|
||||
bool UseParentProcessDirectory();
|
||||
void UseParentProcessDirectory(const bool useParent);
|
||||
bool UseCustomStartingDirectory();
|
||||
bool BackgroundImageSettingsVisible();
|
||||
|
||||
GETSET_PROPERTY(bool, IsBaseLayer, false);
|
||||
|
@ -67,6 +70,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
private:
|
||||
Model::Profile _profile;
|
||||
winrt::hstring _lastBgImagePath;
|
||||
winrt::hstring _lastStartingDirectoryPath;
|
||||
};
|
||||
|
||||
struct DeleteProfileEventArgs :
|
||||
|
@ -121,8 +125,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
|||
fire_and_forget Icon_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
void BIAlignment_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
void DeleteConfirmation_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
void UseParentProcessDirectory_Check(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
void UseParentProcessDirectory_Uncheck(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
|
||||
// CursorShape visibility logic
|
||||
void CursorShape_Changed(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace Microsoft.Terminal.Settings.Editor
|
|||
Boolean CanDeleteProfile { get; };
|
||||
Boolean IsBaseLayer;
|
||||
Boolean UseDesktopBGImage;
|
||||
Boolean UseParentProcessDirectory;
|
||||
Boolean UseCustomStartingDirectory { get; };
|
||||
Boolean BackgroundImageSettingsVisible { get; };
|
||||
|
||||
OBSERVABLE_PROJECTED_SETTING(String, Name);
|
||||
|
|
|
@ -89,16 +89,17 @@ the MIT License. See LICENSE in the project root for license information. -->
|
|||
<TextBox x:Uid="Profile_StartingDirectory"
|
||||
x:Name="StartingDirectory"
|
||||
Text="{x:Bind State.Profile.StartingDirectory, Mode=TwoWay}"
|
||||
Style="{StaticResource TextBoxSettingStyle}"/>
|
||||
Style="{StaticResource TextBoxSettingStyle}"
|
||||
IsEnabled="{x:Bind State.Profile.UseCustomStartingDirectory, Mode=OneWay}"/>
|
||||
<Button x:Uid="Profile_StartingDirectoryBrowse"
|
||||
x:Name="StartingDirectoryBrowse"
|
||||
Click="StartingDirectory_Click"
|
||||
IsEnabled="{x:Bind State.Profile.UseCustomStartingDirectory, Mode=OneWay}"
|
||||
Style="{StaticResource BrowseButtonStyle}"/>
|
||||
</StackPanel>
|
||||
<CheckBox x:Uid="Profile_StartingDirectoryUseParentCheckbox"
|
||||
x:Name="StartingDirectoryUseParentCheckbox"
|
||||
Checked="UseParentProcessDirectory_Check"
|
||||
Unchecked="UseParentProcessDirectory_Uncheck"/>
|
||||
IsChecked="{x:Bind State.Profile.UseParentProcessDirectory, Mode=TwoWay}"/>
|
||||
</StackPanel>
|
||||
</ContentPresenter>
|
||||
|
||||
|
|
Loading…
Reference in a new issue