Skip to content

Commit 58612ba

Browse files
authored
Hide port if not relevant for the specified transport protocol (#42)
1 parent 3f66338 commit 58612ba

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

Source/Pages/Connection/ConnectionOptionsView.axaml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,9 @@
1616
<controls:AutoGrid Margin="-6"
1717
ColumnDefinitions="Auto,*,10,Auto,*"
1818
HorizontalAlignment="Stretch">
19-
<!-- The host -->
20-
<Label Grid.Column="0"
21-
Classes="caption"
22-
Content="Host" />
23-
<TextBox Grid.Column="1"
24-
Text="{Binding ServerOptions.Host}"
25-
Classes="value" />
26-
27-
<Label Grid.Column="3"
28-
Classes="caption"
29-
Content="Port" />
30-
<NumericUpDown Classes="value"
31-
Minimum="0"
32-
Maximum="65535"
33-
Value="{Binding ServerOptions.Port}"
34-
Grid.Column="4" />
3519

3620
<!-- The transport -->
3721
<Label Grid.Column="0"
38-
controls:AutoGrid.IsNextRow="True"
3922
Classes="caption"
4023
Content="Transport protocol" />
4124
<StackPanel Grid.Column="1"
@@ -77,6 +60,26 @@
7760
</ComboBox.ItemTemplate>
7861
</ComboBox>
7962

63+
<!-- The host -->
64+
<Label Grid.Column="0"
65+
controls:AutoGrid.IsNextRow="True"
66+
Classes="caption"
67+
Content="{Binding ServerOptions.SelectedTransport.HostDisplayValue}" />
68+
<TextBox Grid.Column="1"
69+
Text="{Binding ServerOptions.Host}"
70+
Classes="value" />
71+
72+
<Label Grid.Column="3"
73+
Classes="caption"
74+
IsVisible="{Binding ServerOptions.SelectedTransport.IsPortAvailable}"
75+
Content="Port" />
76+
<NumericUpDown Classes="value"
77+
Minimum="0"
78+
Maximum="65535"
79+
IsVisible="{Binding ServerOptions.SelectedTransport.IsPortAvailable}"
80+
Value="{Binding ServerOptions.Port}"
81+
Grid.Column="4" />
82+
8083
<!-- The timeouts -->
8184
<Label Grid.Column="0"
8285
Classes="caption"
@@ -148,7 +151,7 @@
148151
Margin="0,10,0,0">
149152
<controls:AutoGrid Margin="-6"
150153
ColumnDefinitions="Auto,*,10,Auto,*">
151-
154+
152155
<!-- Credentials -->
153156
<Label Grid.Column="0"
154157
controls:AutoGrid.IsNextRow="True"

Source/Pages/Connection/ServerOptionsViewModel.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@ public sealed class ServerOptionsViewModel : BaseViewModel
1616
EnumViewModel<MqttProtocolVersion> _selectedProtocolVersion;
1717

1818
EnumViewModel<SslProtocols> _selectedTlsVersion;
19-
EnumViewModel<Transport> _selectedTransport;
19+
TransportViewModel _selectedTransport;
2020

2121
public ServerOptionsViewModel()
2222
{
2323
Host = "localhost";
2424
Port = 1883;
2525
CommunicationTimeout = 10;
2626

27-
Transports.Add(new EnumViewModel<Transport>("TCP", Transport.TCP));
28-
Transports.Add(new EnumViewModel<Transport>("WebSocket", Transport.WebSocket));
27+
Transports.Add(new TransportViewModel("TCP", Transport.TCP)
28+
{
29+
IsPortAvailable = true,
30+
HostDisplayValue = "Host"
31+
});
32+
33+
Transports.Add(new TransportViewModel("WebSocket", Transport.WebSocket)
34+
{
35+
HostDisplayValue = "URI"
36+
});
37+
2938
_selectedTransport = Transports.First();
3039

3140
TlsVersions.Add(new EnumViewModel<SslProtocols>("no TLS", SslProtocols.None));
@@ -81,13 +90,13 @@ public EnumViewModel<SslProtocols> SelectedTlsVersion
8190
set => this.RaiseAndSetIfChanged(ref _selectedTlsVersion, value);
8291
}
8392

84-
public EnumViewModel<Transport> SelectedTransport
93+
public TransportViewModel SelectedTransport
8594
{
8695
get => _selectedTransport;
8796
set => this.RaiseAndSetIfChanged(ref _selectedTransport, value);
8897
}
8998

9099
public ObservableCollection<EnumViewModel<SslProtocols>> TlsVersions { get; } = new();
91100

92-
public ObservableCollection<EnumViewModel<Transport>> Transports { get; } = new();
101+
public ObservableCollection<TransportViewModel> Transports { get; } = new();
93102
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using MQTTnetApp.Common;
2+
3+
namespace MQTTnetApp.Pages.Connection;
4+
5+
public sealed class TransportViewModel : EnumViewModel<Transport>
6+
{
7+
public TransportViewModel(object displayValue, Transport value) : base(displayValue, value)
8+
{
9+
}
10+
11+
public object HostDisplayValue { get; set; }
12+
13+
public bool IsPortAvailable { get; set; }
14+
}

0 commit comments

Comments
 (0)