Skip to content

Commit

Permalink
Disable duplicate button without selected profile (#12096)
Browse files Browse the repository at this point in the history
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request

- Settings > Add a new profile
- Disable "Duplicate" button until a profile is selected

![Duplicate](https://user-images.githubusercontent.com/25966642/148303450-a084cd5f-7f1c-4de3-86bd-602b9336649e.gif)

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? -->
## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Should take care of #12056, once we can get a build to the a11y team (MAINTAINER EDIT: we unfortunately can't just say "closes #foo" for issues like this one, we need another team to validate the following build.)
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] 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.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

(cherry picked from commit a766798)
  • Loading branch information
davidegiacometti authored and DHowett committed Jan 21, 2022
1 parent c197ca5 commit b30137b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/cascadia/TerminalSettingsEditor/AddProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_State.RequestDuplicate(selected.try_as<Model::Profile>().Guid());
}
}

void AddProfile::ProfilesSelectionChanged(const IInspectable& /*sender*/,
const Windows::UI::Xaml::RoutedEventArgs& /*eventArgs*/)
{
if (!_IsProfileSelected)
{
IsProfileSelected(true);
}
}
}
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettingsEditor/AddProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

void AddNewClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void DuplicateClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void ProfilesSelectionChanged(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);

WINRT_PROPERTY(Editor::AddProfilePageNavigationState, State, nullptr);
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
WINRT_OBSERVABLE_PROPERTY(bool, IsProfileSelected, _PropertyChangedHandlers, nullptr);
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsEditor/AddProfile.idl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ namespace Microsoft.Terminal.Settings.Editor
event AddNewArgs AddNew;
};

[default_interface] runtimeclass AddProfile : Windows.UI.Xaml.Controls.Page
[default_interface] runtimeclass AddProfile : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged
{
AddProfile();
AddProfilePageNavigationState State { get; };
Boolean IsProfileSelected { get; };
}
}
4 changes: 3 additions & 1 deletion src/cascadia/TerminalSettingsEditor/AddProfile.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<local:SettingContainer x:Uid="AddProfile_Duplicate">
<muxc:RadioButtons x:Name="Profiles"
AutomationProperties.AccessibilityView="Content"
ItemsSource="{x:Bind State.Settings.AllProfiles, Mode=OneWay}">
ItemsSource="{x:Bind State.Settings.AllProfiles, Mode=OneWay}"
SelectionChanged="ProfilesSelectionChanged">
<muxc:RadioButtons.ItemTemplate>
<DataTemplate x:DataType="model:Profile">
<Grid HorizontalAlignment="Stretch"
Expand Down Expand Up @@ -72,6 +73,7 @@
AutomationProperties.AutomationId="AddProfile_DuplicateButton"
AutomationProperties.Name="{Binding Tag, RelativeSource={RelativeSource Self}}"
Click="DuplicateClick"
IsEnabled="{x:Bind IsProfileSelected, Mode=OneWay}"
Style="{StaticResource AccentButtonStyle}">
<Button.Content>
<StackPanel Orientation="Horizontal">
Expand Down

0 comments on commit b30137b

Please sign in to comment.