Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from julien-wff/feat-remote-client-displays
Browse files Browse the repository at this point in the history
feat: improve remote client displays
  • Loading branch information
julien-wff authored Dec 21, 2023
2 parents 21615c9 + 4765039 commit e615d7f
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 3 deletions.
2 changes: 1 addition & 1 deletion EasyGUI/Controls/JobsHeader.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<StackPanel Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
<buttons:StartButton x:Name="StartButton" Click="StartButton_OnClick"/>
<buttons:ConnectButton Margin="8,0,0,0" Click="ConnectButton_OnClick"/>
<buttons:ConnectButton x:Name="ConnectButton" Margin="8,0,0,0" Click="ConnectButton_OnClick"/>
<buttons:SettingsButton Margin="8,0,0,0" Click="SettingsButton_OnClick" />
<buttons:CreateButton Margin="8,0,0,0" Click="CreateButton_OnClick" />
</StackPanel>
Expand Down
21 changes: 20 additions & 1 deletion EasyGUI/Controls/JobsHeader.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public partial class JobsHeader : INotifyPropertyChanged
new PropertyMetadata(default(ObservableCollection<Job>))
);

private static readonly DependencyProperty IsRemoteProperty = DependencyProperty.Register(
nameof(IsRemote),
typeof(bool),
typeof(JobsHeader),
new PropertyMetadata(default(bool))
);

public JobsHeader()
{
InitializeComponent();
Expand All @@ -76,6 +83,16 @@ public ObservableCollection<Job> SelectedJobs
}
}

public bool IsRemote
{
get => (bool)GetValue(IsRemoteProperty);
set
{
SetValue(IsRemoteProperty, value);
OnPropertyChanged();
}
}

public event PropertyChangedEventHandler? PropertyChanged;

public event RoutedEventHandler CreateButtonClick
Expand Down Expand Up @@ -111,7 +128,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

if (propertyName == nameof(SelectedJobs))
if (propertyName is nameof(SelectedJobs) or nameof(IsRemote))
{
UpdateButtonsDisplay();
}
Expand All @@ -123,6 +140,8 @@ private void UpdateButtonsDisplay()
SelectedJobs.Count > 1 && SelectedJobs.All(j => j.State is JobState.End or JobState.Paused)
? Visibility.Visible
: Visibility.Collapsed;

ConnectButton.Visibility = IsRemote ? Visibility.Collapsed : Visibility.Visible;
}

private void ToggleButton_OnChecked(object sender, RoutedEventArgs e)
Expand Down
9 changes: 8 additions & 1 deletion EasyGUI/Controls/RemoteConnectPopup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
xmlns:buttons="clr-namespace:EasyGUI.Controls.Buttons"
xmlns:resx="clr-namespace:EasyGUI.Resources"
mc:Ignorable="d"
d:DesignHeight="720" d:DesignWidth="1280">
d:DesignHeight="720" d:DesignWidth="1280"
Loaded="RemoteConnectPopup_OnLoaded">
<Grid>
<Grid Background="Black" Opacity=".75" ZIndex="10" />
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" ZIndex="11" Width="350">
Expand All @@ -25,6 +26,12 @@
Margin="0,0,0,16"
Foreground="{StaticResource RedBrush}" />

<TextBlock
Margin="0,0,0,16"
x:Name="ServerIpTextBlock"
Visibility="Collapsed"
TextWrapping="Wrap" />

<TextBlock Margin="0,0,0,4" Text="{x:Static resx:Strings.RemoteConnectPopup_Host}" />
<Grid>
<TextBox
Expand Down
54 changes: 54 additions & 0 deletions EasyGUI/Controls/RemoteConnectPopup.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.ComponentModel;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using EasyGUI.Events;
using EasyLib.Files;
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using Strings = EasyGUI.Resources.Strings;

Expand All @@ -27,6 +29,13 @@ public partial class RemoteConnectPopup : INotifyPropertyChanged
new PropertyMetadata(default(string))
);

private static readonly DependencyProperty HostIpProperty = DependencyProperty.Register(
nameof(HostIp),
typeof(string),
typeof(RemoteConnectPopup),
new PropertyMetadata(default(string))
);

public RemoteConnectPopup()
{
InitializeComponent();
Expand All @@ -52,10 +61,35 @@ public string? ErrorMessage
}
}

public string? HostIp
{
get => (string?)GetValue(HostIpProperty);
set
{
SetValue(HostIpProperty, value);
Console.WriteLine(value);
OnPropertyChanged();
}
}

public event PropertyChangedEventHandler? PropertyChanged;

public event EventHandler<RemoteConnectEventArgs>? Connect;

private static string? GetLocalIpAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}

return null;
}

private void CancelButton_OnClick(object sender, RoutedEventArgs e)
{
Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -127,6 +161,18 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName
? Visibility.Collapsed
: Visibility.Visible;
}

if (propertyName == nameof(HostIp))
{
ServerIpTextBlock.Visibility = string.IsNullOrWhiteSpace(HostIp)
? Visibility.Collapsed
: Visibility.Visible;

ServerIpTextBlock.Text = string.Format(
Strings.RemoteConnectPopup_HostAddress,
HostIp
);
}
}

private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
Expand All @@ -143,4 +189,12 @@ private void UIElement_OnKeyDown(object sender, KeyEventArgs e)
ValidateButton_OnClick(sender, e);
}
}

private void RemoteConnectPopup_OnLoaded(object sender, RoutedEventArgs e)
{
if (ConfigManager.Instance.ServerPort is not null)
{
HostIp = $"{GetLocalIpAddress()}:{ConfigManager.Instance.ServerPort}";
}
}
}
1 change: 1 addition & 0 deletions EasyGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<StackPanel Margin="16">
<controls:Header Margin="0,0,0,32" />
<controls:JobsHeader
x:Name="JobsHeader"
Jobs="{Binding Jobs, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
SelectedJobs="{Binding SelectedJobs, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
CreateButtonClick="JobsHeader_OnCreateButtonClick"
Expand Down
1 change: 1 addition & 0 deletions EasyGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private void RemoteConnectPopup_OnConnect(object? sender, RemoteConnectEventArgs

// Change the job manager
_jobManager = remoteJobManager;
JobsHeader.IsRemote = true;

// Close the popup
RemoteConnectPopup.Visibility = Visibility.Collapsed;
Expand Down
9 changes: 9 additions & 0 deletions EasyGUI/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions EasyGUI/Resources/Strings.fr.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions EasyGUI/Resources/Strings.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,7 @@ Nous nous excusons pour la gêne occasionnée.</value>
<data name="SettingsPopup_ServerPort" xml:space="preserve">
<value>Port du server</value>
</data>
<data name="RemoteConnectPopup_HostAddress" xml:space="preserve">
<value>Adresse locale de l'instance : {0}</value>
</data>
</root>
3 changes: 3 additions & 0 deletions EasyGUI/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,7 @@ We are sorry for this inconvenience.</value>
<data name="SettingsPopup_ServerPort" xml:space="preserve">
<value>Server port</value>
</data>
<data name="RemoteConnectPopup_HostAddress" xml:space="preserve">
<value>Local instance address: {0}</value>
</data>
</root>

0 comments on commit e615d7f

Please sign in to comment.