mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
[Hosts]Indicate when an entry input field is invalid (#31407)
* [Hosts]Indicate when an entry input field is invalid * Minor styling fix * Update src/modules/Hosts/Hosts/Strings/en-us/Resources.resw Co-authored-by: Davide Giacometti <davide.giacometti@outlook.it> * Update src/modules/Hosts/Hosts/Strings/en-us/Resources.resw Co-authored-by: Davide Giacometti <davide.giacometti@outlook.it> * Change messages to "Has to be" --------- Co-authored-by: Niels Laute <niels.laute@live.nl> Co-authored-by: Davide Giacometti <davide.giacometti@outlook.it>
This commit is contained in:
@@ -450,7 +450,23 @@
|
||||
<TextBox
|
||||
x:Uid="Address"
|
||||
IsSpellCheckEnabled="False"
|
||||
Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||
Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
|
||||
<TextBox.Description>
|
||||
<StackPanel
|
||||
Margin="0,4"
|
||||
Orientation="Horizontal"
|
||||
Spacing="4"
|
||||
Visibility="{Binding IsAddressValid, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
|
||||
<FontIcon
|
||||
Margin="0,0,0,0"
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
FontSize="14"
|
||||
Foreground="{ThemeResource SystemFillColorCautionBrush}"
|
||||
Glyph="" />
|
||||
<TextBlock x:Uid="EntryAddressIsInvalidWarning" />
|
||||
</StackPanel>
|
||||
</TextBox.Description>
|
||||
</TextBox>
|
||||
<TextBox
|
||||
x:Uid="Hosts"
|
||||
AcceptsReturn="False"
|
||||
@@ -459,7 +475,22 @@
|
||||
ScrollViewer.VerticalScrollBarVisibility="Visible"
|
||||
ScrollViewer.VerticalScrollMode="Enabled"
|
||||
Text="{Binding Hosts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextWrapping="Wrap" />
|
||||
TextWrapping="Wrap">
|
||||
<TextBox.Description>
|
||||
<StackPanel
|
||||
Margin="0,4"
|
||||
Orientation="Horizontal"
|
||||
Spacing="4"
|
||||
Visibility="{Binding IsHostsValid, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
|
||||
<FontIcon
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
FontSize="14"
|
||||
Foreground="{ThemeResource SystemFillColorCautionBrush}"
|
||||
Glyph="" />
|
||||
<TextBlock x:Uid="EntryHostsIsInvalidWarning" />
|
||||
</StackPanel>
|
||||
</TextBox.Description>
|
||||
</TextBox>
|
||||
<TextBox
|
||||
x:Uid="Comment"
|
||||
AcceptsReturn="False"
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Hosts.Models
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(Valid))]
|
||||
[NotifyPropertyChangedFor(nameof(IsAddressValid))]
|
||||
private string _address;
|
||||
|
||||
partial void OnAddressChanged(string value)
|
||||
@@ -36,6 +37,7 @@ namespace Hosts.Models
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(Valid))]
|
||||
[NotifyPropertyChangedFor(nameof(IsHostsValid))]
|
||||
private string _hosts;
|
||||
|
||||
partial void OnHostsChanged(string value)
|
||||
@@ -61,6 +63,10 @@ namespace Hosts.Models
|
||||
|
||||
public bool Valid => Validate(true);
|
||||
|
||||
public bool IsAddressValid => ValidateAddressField();
|
||||
|
||||
public bool IsHostsValid => ValidateHostsField(true);
|
||||
|
||||
public string Line { get; private set; }
|
||||
|
||||
public AddressType Type { get; private set; }
|
||||
@@ -152,6 +158,16 @@ namespace Hosts.Models
|
||||
};
|
||||
}
|
||||
|
||||
private bool ValidateAddressField()
|
||||
{
|
||||
return Type != AddressType.Invalid;
|
||||
}
|
||||
|
||||
private bool ValidateHostsField(bool validateHostsLength)
|
||||
{
|
||||
return ValidationHelper.ValidHosts(Hosts, validateHostsLength);
|
||||
}
|
||||
|
||||
public bool Validate(bool validateHostsLength)
|
||||
{
|
||||
if (Equals("102.54.94.97", "rhino.acme.com", "source server") || Equals("38.25.63.10", "x.acme.com", "x client host"))
|
||||
@@ -159,7 +175,7 @@ namespace Hosts.Models
|
||||
return false;
|
||||
}
|
||||
|
||||
return Type != AddressType.Invalid && ValidationHelper.ValidHosts(Hosts, validateHostsLength);
|
||||
return ValidateAddressField() && ValidateHostsField(validateHostsLength);
|
||||
}
|
||||
|
||||
private bool Equals(string address, string hosts, string comment)
|
||||
|
||||
@@ -299,6 +299,12 @@
|
||||
<value>Entries contain too many hosts</value>
|
||||
<comment>"Hosts" refers to the system hosts file, do not loc</comment>
|
||||
</data>
|
||||
<data name="EntryAddressIsInvalidWarning.Text" xml:space="preserve">
|
||||
<value>Has to be a valid IPv4 or IPv6 address</value>
|
||||
</data>
|
||||
<data name="EntryHostsIsInvalidWarning.Text" xml:space="preserve">
|
||||
<value>Has to be one or more valid host names separated by spaces</value>
|
||||
</data>
|
||||
<data name="UpdateBtn" xml:space="preserve">
|
||||
<value>Update</value>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user