Skip to content

Commit 9b500db

Browse files
committed
Feature: DNS Lookup - Input server
1 parent 3d3fee3 commit 9b500db

File tree

8 files changed

+92
-62
lines changed

8 files changed

+92
-62
lines changed

Source/NETworkManager.Converters/DNSServerConnectionInfoProfileToString.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Source/NETworkManager.Models/Network/DNSServer.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ public static class DNSServer
1313
/// <returns>List of common dns servers.</returns>
1414
public static List<DNSServerConnectionInfoProfile> GetDefaultList()
1515
{
16-
return new List<DNSServerConnectionInfoProfile>
17-
{
16+
return
17+
[
1818
new(), // Windows DNS server
19-
new("Cloudflare", new List<ServerConnectionInfo>
20-
{
19+
new("Cloudflare",
20+
[
2121
new("1.1.1.1", 53, TransportProtocol.Udp),
2222
new("1.0.0.1", 53, TransportProtocol.Udp)
23-
}),
24-
new("DNS.Watch", new List<ServerConnectionInfo>
25-
{
23+
]),
24+
new("DNS.Watch",
25+
[
2626
new("84.200.69.80", 53, TransportProtocol.Udp),
2727
new("84.200.70.40", 53, TransportProtocol.Udp)
28-
}),
29-
new("Google Public DNS", new List<ServerConnectionInfo>
30-
{
28+
]),
29+
new("Google Public DNS",
30+
[
3131
new("8.8.8.8", 53, TransportProtocol.Udp),
3232
new("8.8.4.4", 53, TransportProtocol.Udp)
33-
}),
34-
new("Level3", new List<ServerConnectionInfo>
35-
{
33+
]),
34+
new("Level3",
35+
[
3636
new("209.244.0.3", 53, TransportProtocol.Udp),
3737
new("209.244.0.4", 53, TransportProtocol.Udp)
38-
}),
39-
new("Verisign", new List<ServerConnectionInfo>
40-
{
38+
]),
39+
new("Verisign",
40+
[
4141
new("64.6.64.6", 53, TransportProtocol.Udp),
4242
new("64.6.65.6", 53, TransportProtocol.Udp)
43-
})
44-
};
43+
])
44+
];
4545
}
4646
}

Source/NETworkManager.Models/Network/DNSServerConnectionInfoProfile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class DNSServerConnectionInfoProfile : ServerConnectionInfoProfile
1313
/// </summary>
1414
public DNSServerConnectionInfoProfile()
1515
{
16+
Name = "[Windows DNS]";
1617
UseWindowsDNSServer = true;
1718
}
1819

@@ -28,5 +29,5 @@ public DNSServerConnectionInfoProfile(string name, List<ServerConnectionInfo> se
2829
/// <summary>
2930
/// Use the DNS server from Windows.
3031
/// </summary>
31-
public bool UseWindowsDNSServer { get; set; }
32+
public bool UseWindowsDNSServer { get; set; }
3233
}

Source/NETworkManager.Models/Network/ServerConnectionInfoProfile.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ public ServerConnectionInfoProfile(string name, List<ServerConnectionInfo> serve
3333
/// <summary>
3434
/// List of servers as <see cref="ServerConnectionInfo" />.
3535
/// </summary>
36-
public List<ServerConnectionInfo> Servers { get; set; } = new();
36+
public List<ServerConnectionInfo> Servers { get; set; } = [];
37+
38+
public override string ToString()
39+
{
40+
return Name;
41+
}
3742
}

Source/NETworkManager.Settings/SettingsInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ public ObservableCollection<DNSServerConnectionInfoProfile> DNSLookup_DNSServers
17531753
}
17541754
}
17551755

1756-
private DNSServerConnectionInfoProfile _dnsLookup_SelectedDNSServer = new();
1756+
private DNSServerConnectionInfoProfile _dnsLookup_SelectedDNSServer = null;
17571757

17581758
public DNSServerConnectionInfoProfile DNSLookup_SelectedDNSServer
17591759
{

Source/NETworkManager/ViewModels/DNSLookupSettingsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class DNSLookupSettingsViewModel : ViewModelBase
2828

2929
public ICollectionView DNSServers { get; }
3030

31-
private DNSServerConnectionInfoProfile _selectedDNSServer = new();
31+
private DNSServerConnectionInfoProfile _selectedDNSServer = null;
3232

3333
public DNSServerConnectionInfoProfile SelectedDNSServer
3434
{

Source/NETworkManager/ViewModels/DNSLookupViewModel.cs

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Collections.ObjectModel;
1717
using System.ComponentModel;
1818
using System.Linq;
19+
using System.Net;
1920
using System.Threading.Tasks;
2021
using System.Windows;
2122
using System.Windows.Data;
@@ -57,24 +58,69 @@ public string Host
5758
public ICollectionView DNSServers { get; }
5859

5960
private DNSServerConnectionInfoProfile _dnsServer = new();
60-
6161
public DNSServerConnectionInfoProfile DNSServer
6262
{
6363
get => _dnsServer;
64-
set
64+
private set
6565
{
66-
if (value == _dnsServer)
66+
if (_dnsServer == value)
6767
return;
68+
69+
_dnsServer = value ?? new DNSServerConnectionInfoProfile();
6870

6971
if (!_isLoading)
70-
SettingsManager.Current.DNSLookup_SelectedDNSServer = value;
72+
SettingsManager.Current.DNSLookup_SelectedDNSServer = _dnsServer;
73+
74+
OnPropertyChanged();
75+
}
76+
}
77+
78+
private DNSServerConnectionInfoProfile _selectedListProfile;
79+
public DNSServerConnectionInfoProfile SelectedListProfile
80+
{
81+
get => _selectedListProfile;
82+
set
83+
{
84+
if (_selectedListProfile == value)
85+
return;
86+
87+
if (value != null)
88+
{
89+
DNSServer = value;
90+
DNSServerQuickInput = value.ToString(); // uses your override
91+
}
7192

72-
_dnsServer = value;
93+
_selectedListProfile = value;
7394
OnPropertyChanged();
7495
}
7596
}
7697

77-
private List<QueryType> _queryTypes = new();
98+
// Text box content
99+
private string _dnsServerQuickInput = string.Empty;
100+
public string DNSServerQuickInput
101+
{
102+
get => _dnsServerQuickInput;
103+
set
104+
{
105+
if (_dnsServerQuickInput == value)
106+
return;
107+
108+
_dnsServerQuickInput = value?.Trim() ?? string.Empty;
109+
OnPropertyChanged();
110+
111+
// As soon as user types → deselect any list item
112+
SelectedListProfile = null;
113+
114+
// Create custom profile from raw IP
115+
if (IPAddress.TryParse(_dnsServerQuickInput, out IPAddress x))
116+
{
117+
// Temporarily switch to this custom profile
118+
DNSServer = new DNSServerConnectionInfoProfile("CUSTOM", [new ServerConnectionInfo(x.ToString(), 53)]);
119+
}
120+
}
121+
}
122+
123+
private List<QueryType> _queryTypes = [];
78124

79125
public List<QueryType> QueryTypes
80126
{
@@ -220,10 +266,14 @@ public DNSLookupViewModel(IDialogCoordinator instance, Guid tabId, string host)
220266
ListSortDirection.Descending));
221267
DNSServers.SortDescriptions.Add(new SortDescription(nameof(DNSServerConnectionInfoProfile.Name),
222268
ListSortDirection.Ascending));
223-
DNSServer = DNSServers.SourceCollection.Cast<DNSServerConnectionInfoProfile>()
269+
var initialDNSServer = DNSServers.SourceCollection.Cast<DNSServerConnectionInfoProfile>()
224270
.FirstOrDefault(x => x.Name == SettingsManager.Current.DNSLookup_SelectedDNSServer.Name) ??
225271
DNSServers.SourceCollection.Cast<DNSServerConnectionInfoProfile>().First();
226272

273+
DNSServer = initialDNSServer;
274+
SelectedListProfile = initialDNSServer;
275+
DNSServerQuickInput = initialDNSServer.ToString();
276+
227277
ResultsView = CollectionViewSource.GetDefaultView(Results);
228278
ResultsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(DNSLookupRecordInfo.NameServerAsString)));
229279
ResultsView.SortDescriptions.Add(new SortDescription(nameof(DNSLookupRecordInfo.NameServerIPAddress),

Source/NETworkManager/Views/DNSLookupView.xaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<UserControl.Resources>
2020
<converters:BooleanReverseConverter x:Key="BooleanReverseConverter" />
2121
<converters:BooleanToVisibilityCollapsedConverter x:Key="BooleanToVisibilityCollapsedConverter" />
22-
<converters:DNSServerConnectionInfoProfileToString x:Key="DNSServerConnectionInfoProfileToString" />
2322
</UserControl.Resources>
2423
<Grid Margin="10">
2524
<Grid.RowDefinitions>
@@ -71,15 +70,13 @@
7170
</ComboBox>
7271
<TextBlock Grid.Column="4" Grid.Row="0" Text="{x:Static localization:Strings.DNSServer}"
7372
Style="{DynamicResource DefaultTextBlock}" VerticalAlignment="Center" />
74-
<ComboBox x:Name="ComboBoxDNSServers" Grid.Column="6" Grid.Row="0" ItemsSource="{Binding DNSServers}"
75-
SelectedItem="{Binding DNSServer}">
76-
<ComboBox.ItemTemplate>
77-
<DataTemplate>
78-
<TextBlock
79-
Text="{Binding Path=., Converter={StaticResource DNSServerConnectionInfoProfileToString}}"
80-
d:DataContext="{d:DesignInstance network:DNSServerConnectionInfoProfile}" />
81-
</DataTemplate>
82-
</ComboBox.ItemTemplate>
73+
<ComboBox x:Name="ComboBoxDNSServers"
74+
Grid.Column="6" Grid.Row="0"
75+
ItemsSource="{Binding DNSServers}"
76+
SelectedItem="{Binding SelectedListProfile}"
77+
Text="{Binding DNSServerQuickInput, UpdateSourceTrigger=PropertyChanged}"
78+
IsEditable="True"
79+
IsTextSearchEnabled="False">
8380
</ComboBox>
8481
<TextBlock Grid.Column="8" Grid.Row="0" Text="{x:Static localization:Strings.Type}"
8582
Style="{DynamicResource DefaultTextBlock}" VerticalAlignment="Center" />

0 commit comments

Comments
 (0)