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

Commit

Permalink
feat: disable buttons on operation
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-wff committed Dec 15, 2023
1 parent 36592fa commit fcd5fd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions EasyGUI/Controls/Buttons/BaseButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
CornerRadius="6">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
<Setter Property="Cursor" Value="No" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>

Expand Down
16 changes: 16 additions & 0 deletions EasyGUI/Controls/JobDisplay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName
UpdateJobProgress();
UpdateBreadcrumbs();
UpdateButtons();
SetButtonsState(true);
}

if (propertyName == nameof(SelectedJobs) && !_selectedJobsLocked)
Expand Down Expand Up @@ -138,6 +139,16 @@ private void UpdateButtons()
SetElementVisibility(PauseButton, Job.State != JobState.End && Job.CurrentlyRunning);
}

private void SetButtonsState(bool enabled)
{
EditButton.IsEnabled = enabled;
StartButton.IsEnabled = enabled;
DeleteButton.IsEnabled = enabled;
ResumeButton.IsEnabled = enabled;
DiscardButton.IsEnabled = enabled;
PauseButton.IsEnabled = enabled;
}

private void UpdateJobProgress()
{
if (Job.State == JobState.End)
Expand Down Expand Up @@ -168,6 +179,7 @@ private static void SetElementVisibility(UIElement element, bool visible)

private void StartButton_OnClick(object sender, RoutedEventArgs e)
{
SetButtonsState(false);
JobStarted?.Invoke(this, new JobEventArgs(Job));
}

Expand Down Expand Up @@ -207,21 +219,25 @@ private void EditButton_OnClick(object sender, RoutedEventArgs e)

private void ResumeButton_OnClick(object sender, RoutedEventArgs e)
{
SetButtonsState(false);
JobResumed?.Invoke(this, new JobEventArgs(Job));
}

private void DeleteButton_OnClick(object sender, RoutedEventArgs e)
{
SetButtonsState(false);
JobDeleted?.Invoke(this, new JobEventArgs(Job));
}

private void DiscardButton_OnClick(object sender, RoutedEventArgs e)
{
SetButtonsState(false);
JobDiscarded?.Invoke(this, new JobEventArgs(Job));
}

private void PauseButton_OnClick(object sender, RoutedEventArgs e)
{
SetButtonsState(false);
JobPaused?.Invoke(this, new JobEventArgs(Job));
}

Expand Down

0 comments on commit fcd5fd3

Please sign in to comment.