Skip to content

Commit b141ceb

Browse files
committed
add an option to remember the entered IP address, closes #45
1 parent c8d1d88 commit b141ceb

5 files changed

Lines changed: 69 additions & 19 deletions

File tree

ArcExplorer/Models/ApplicationSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public enum IntegerDisplayFormat
4545
// This ensures the first run of the program tries to check for updates.
4646
public DateTime LastHashesUpdateCheckTime { get; set; } = DateTime.UnixEpoch;
4747

48+
public string? ArcIpAddress { get; set; }
49+
4850
private ApplicationSettings()
4951
{
5052

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using ArcExplorer.Models;
2+
using Avalonia.Controls.ApplicationLifetimes;
3+
using ReactiveUI;
4+
using System;
5+
6+
namespace ArcExplorer.ViewModels
7+
{
8+
public class OpenArcConnectionWindowViewModel : ViewModelBase
9+
{
10+
// TODO: Does this need property changed?
11+
public bool RememberIpAddress
12+
{
13+
get => rememberIpAddress;
14+
set => this.RaiseAndSetIfChanged(ref rememberIpAddress, value);
15+
}
16+
private bool rememberIpAddress;
17+
18+
public bool WasCancelled { get; set; } = true;
19+
20+
public string IpAddress
21+
{
22+
get => ipAddress;
23+
set => this.RaiseAndSetIfChanged(ref ipAddress, value);
24+
}
25+
private string ipAddress = "000.000.000.000";
26+
}
27+
}

ArcExplorer/Views/MainWindow.axaml.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,30 @@ public async void OpenArc()
9292

9393
public async void OpenArcNetworked()
9494
{
95-
var dialog = new OpenArcConnectionWindow();
95+
var vm = new OpenArcConnectionWindowViewModel()
96+
{
97+
IpAddress = ApplicationSettings.Instance.ArcIpAddress ?? "000.000.000.000"
98+
};
99+
100+
var dialog = new OpenArcConnectionWindow()
101+
{
102+
DataContext = vm
103+
};
104+
96105
dialog.Closed += (s, e) =>
97106
{
98-
if (!dialog.WasCancelled)
107+
if (!vm.WasCancelled)
99108
{
100-
(DataContext as MainWindowViewModel)?.OpenArcNetworked(dialog.IpAddress);
109+
// Only save settings that were actually submitted.
110+
if (vm.RememberIpAddress)
111+
{
112+
ApplicationSettings.Instance.ArcIpAddress = vm.IpAddress;
113+
}
114+
115+
(DataContext as MainWindowViewModel)?.OpenArcNetworked(vm.IpAddress);
101116
}
102117
};
118+
103119
await dialog.ShowDialog(this);
104120
}
105121

ArcExplorer/Views/OpenArcConnectionWindow.axaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
mc:Ignorable="d" d:DesignWidth="200" d:DesignHeight="100"
6-
Width="400" Height="100"
5+
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="120"
6+
Width="400" Height="120"
77
x:Class="ArcExplorer.Views.OpenArcConnectionWindow"
8-
WindowStartupLocation="CenterScreen"
98
Icon="avares://ArcExplorer/Assets/arc.ico"
109
Name="thisControl"
11-
Title="Connect to ARC">
10+
Title="Connect to ARC"
11+
WindowStartupLocation="CenterOwner">
1212
<StackPanel Margin="10">
13-
<Grid ColumnDefinitions="*,*">
14-
<TextBlock Margin="5" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">IP Address</TextBlock>
15-
<TextBox Margin="5" Grid.Column="1" VerticalAlignment="Center" Text="{Binding IpAddress}"></TextBox>
13+
<Grid ColumnDefinitions="*,*" RowDefinitions="*,*">
14+
<TextBlock Margin="5" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left">IP Address</TextBlock>
15+
<TextBox Margin="5" Grid.Column="1" VerticalAlignment="Center" Text="{Binding IpAddress}"
16+
ToolTip.Tip="The IP address for the connection. This should be your Nintendo Switch's IP Address."></TextBox>
17+
<CheckBox Margin="5" Grid.Row="1" Grid.Column="0" IsChecked="{Binding RememberIpAddress}"
18+
ToolTip.Tip="The IP address will be saved after clicking connect if checked.">Remember these settings</CheckBox>
1619
</Grid>
17-
<Grid ColumnDefinitions="*,*">
20+
<Grid ColumnDefinitions="*,*" DataContext="{Binding #thisControl}">
1821
<Button Grid.Column="0" Margin="5" Command="{Binding CancelClick}">Cancel</Button>
1922
<Button Grid.Column="1" Margin="5" Command="{Binding ConnectClick}">Connect</Button>
2023
</Grid>

ArcExplorer/Views/OpenArcConnectionWindow.axaml.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Avalonia.Controls;
1+
using ArcExplorer.Models;
2+
using ArcExplorer.ViewModels;
3+
using Avalonia.Controls;
24
using Avalonia.Markup.Xaml;
35

46
namespace ArcExplorer.Views
@@ -7,28 +9,28 @@ public class OpenArcConnectionWindow : Window
79
{
810
public OpenArcConnectionWindow()
911
{
10-
this.InitializeComponent();
12+
InitializeComponent();
1113
DataContext = this;
1214
}
1315

14-
public bool WasCancelled { get; private set; } = true;
15-
16-
public string IpAddress { get; set; } = "000.000.000.000";
17-
1816
private void InitializeComponent()
1917
{
2018
AvaloniaXamlLoader.Load(this);
2119
}
2220

2321
public void ConnectClick()
2422
{
25-
WasCancelled = false;
23+
if (DataContext is OpenArcConnectionWindowViewModel vm)
24+
vm.WasCancelled = false;
25+
2626
Close();
2727
}
2828

2929
public void CancelClick()
3030
{
31-
WasCancelled = true;
31+
if (DataContext is OpenArcConnectionWindowViewModel vm)
32+
vm.WasCancelled = true;
33+
3234
Close();
3335
}
3436
}

0 commit comments

Comments
 (0)