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

Commit

Permalink
feat: make the connect button disappear if connected
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-wff committed Dec 21, 2023
1 parent 1237555 commit 4f43e86
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 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
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 @@ -213,6 +213,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

0 comments on commit 4f43e86

Please sign in to comment.