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 #52 from julien-wff/feat-more-buttons
Browse files Browse the repository at this point in the history
feat: more buttons
  • Loading branch information
julien-wff authored Dec 14, 2023
2 parents 7aea78b + d838a1e commit 2875e87
Show file tree
Hide file tree
Showing 23 changed files with 366 additions and 7 deletions.
Binary file added EasyGUI/Assets/Icons/close-circle-outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyGUI/Assets/Icons/pause-circle-outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added EasyGUI/Assets/Icons/trash-outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions EasyGUI/Controls/Buttons/DeleteButton.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="EasyGUI.Controls.Buttons.DeleteButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resx="clr-namespace:EasyGUI.Resources"
xmlns:buttons="clr-namespace:EasyGUI.Controls.Buttons"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="150">
<buttons:BaseButton ButtonText="{x:Static resx:Strings.DeleteButton_Delete}"
Click="Button_OnClick"
ButtonColor="{StaticResource RedBrush}"
ButtonIcon="/Assets/Icons/trash-outline.png"/>
</UserControl>
18 changes: 18 additions & 0 deletions EasyGUI/Controls/Buttons/DeleteButton.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Windows;

namespace EasyGUI.Controls.Buttons;

public partial class DeleteButton
{
public DeleteButton()
{
InitializeComponent();
}

public event RoutedEventHandler? Click;

private void Button_OnClick(object sender, RoutedEventArgs e)
{
Click?.Invoke(this, e);
}
}
14 changes: 14 additions & 0 deletions EasyGUI/Controls/Buttons/DiscardButton.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="EasyGUI.Controls.Buttons.DiscardButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resx="clr-namespace:EasyGUI.Resources"
xmlns:buttons="clr-namespace:EasyGUI.Controls.Buttons"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="150">
<buttons:BaseButton ButtonText="{x:Static resx:Strings.DiscardButton_Discard}"
Click="Button_OnClick"
ButtonColor="{StaticResource RedBrush}"
ButtonIcon="/Assets/Icons/close-circle-outline.png"/>
</UserControl>
18 changes: 18 additions & 0 deletions EasyGUI/Controls/Buttons/DiscardButton.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Windows;

namespace EasyGUI.Controls.Buttons;

public partial class DiscardButton
{
public DiscardButton()
{
InitializeComponent();
}

public event RoutedEventHandler? Click;

private void Button_OnClick(object sender, RoutedEventArgs e)
{
Click?.Invoke(this, e);
}
}
14 changes: 14 additions & 0 deletions EasyGUI/Controls/Buttons/PauseButton.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="EasyGUI.Controls.Buttons.PauseButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:buttons="clr-namespace:EasyGUI.Controls.Buttons"
xmlns:resx="clr-namespace:EasyGUI.Resources"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="150">
<buttons:BaseButton ButtonText="{x:Static resx:Strings.PauseButton_Pause}"
Click="Button_OnClick"
ButtonColor="{StaticResource OrangeBrush}"
ButtonIcon="/Assets/Icons/pause-circle-outline.png" />
</UserControl>
18 changes: 18 additions & 0 deletions EasyGUI/Controls/Buttons/PauseButton.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Windows;

namespace EasyGUI.Controls.Buttons;

public partial class PauseButton
{
public PauseButton()
{
InitializeComponent();
}

public event RoutedEventHandler? Click;

private void Button_OnClick(object sender, RoutedEventArgs e)
{
Click?.Invoke(this, e);
}
}
14 changes: 14 additions & 0 deletions EasyGUI/Controls/Buttons/ResumeButton.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="EasyGUI.Controls.Buttons.ResumeButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:resx="clr-namespace:EasyGUI.Resources"
xmlns:buttons="clr-namespace:EasyGUI.Controls.Buttons"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="150">
<buttons:BaseButton ButtonText="{x:Static resx:Strings.ResumeButton_Resume}"
Click="Button_OnClick"
ButtonColor="{StaticResource GreenBrush}"
ButtonIcon="/Assets/Icons/play-circle-outline.png"/>
</UserControl>
18 changes: 18 additions & 0 deletions EasyGUI/Controls/Buttons/ResumeButton.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Windows;

namespace EasyGUI.Controls.Buttons;

public partial class ResumeButton
{
public ResumeButton()
{
InitializeComponent();
}

public event RoutedEventHandler? Click;

private void Button_OnClick(object sender, RoutedEventArgs e)
{
Click?.Invoke(this, e);
}
}
6 changes: 5 additions & 1 deletion EasyGUI/Controls/JobDisplay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@
</StackPanel>

<StackPanel Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
<buttons:EditButton Click="EditButton_OnClick" x:Name="EditButton" Margin="8,0,0,0" />
<buttons:StartButton Click="StartButton_OnClick" x:Name="StartButton" Margin="8,0,0,0" />
<buttons:EditButton Click="EditButton_OnClick" x:Name="EditButton" Margin="8,0,0,0" />
<buttons:DeleteButton Click="DeleteButton_OnClick" x:Name="DeleteButton" Margin="8,0,0,0" />
<buttons:ResumeButton Click="ResumeButton_OnClick" x:Name="ResumeButton" Margin="8,0,0,0" />
<buttons:DiscardButton Click="DiscardButton_OnClick" x:Name="DiscardButton" Margin="8,0,0,0" />
<buttons:PauseButton Click="PauseButton_OnClick" x:Name="PauseButton" Margin="8,0,0,0" />
</StackPanel>
</Grid>

Expand Down
37 changes: 34 additions & 3 deletions EasyGUI/Controls/JobDisplay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public void OnJobProgress(Job job)
public event PropertyChangedEventHandler? PropertyChanged;
public event EventHandler<JobEventArgs>? JobStarted;
public event EventHandler<JobEventArgs>? JobEdited;
public event EventHandler<JobEventArgs>? JobResumed;
public event EventHandler<JobEventArgs>? JobDeleted;
public event EventHandler<JobEventArgs>? JobDiscarded;
public event EventHandler<JobEventArgs>? JobPaused;

protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
Expand Down Expand Up @@ -126,7 +130,11 @@ private void UpdateButtons()
{
var paused = Job.State != JobState.End && !Job.CurrentlyRunning;
SetElementVisibility(EditButton, Job.State == JobState.End);
SetElementVisibility(StartButton, Job.State == JobState.End || paused);
SetElementVisibility(StartButton, Job.State == JobState.End);
SetElementVisibility(DeleteButton, Job.State == JobState.End);
SetElementVisibility(ResumeButton, paused);
SetElementVisibility(DiscardButton, paused);
SetElementVisibility(PauseButton, Job.State != JobState.End && Job.CurrentlyRunning);
}

private void UpdateJobProgress()
Expand All @@ -144,8 +152,11 @@ private void UpdateJobProgress()
if (Job.State == JobState.Copy)
{
var progress = (float)Job.FilesCopied / Job.FilesCount;
JobProgressText = $"{progress:P}";
JobProgressBar.Value = progress * 100;
if (!float.IsNaN(progress))
{
JobProgressText = $"{progress:P}";
JobProgressBar.Value = progress * 100;
}
}
}

Expand Down Expand Up @@ -192,4 +203,24 @@ private void EditButton_OnClick(object sender, RoutedEventArgs e)
{
JobEdited?.Invoke(this, new JobEventArgs(Job));
}

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

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

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

private void PauseButton_OnClick(object sender, RoutedEventArgs e)
{
JobPaused?.Invoke(this, new JobEventArgs(Job));
}
}
4 changes: 4 additions & 0 deletions EasyGUI/Controls/JobsList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
Job="{Binding}"
SelectedJobs="{Binding SelectedJobs, RelativeSource={RelativeSource AncestorType=UserControl}}"
JobEdited="JobDisplay_OnJobEdited"
JobResumed="JobDisplay_OnJobResumed"
JobDeleted="JobDisplay_OnJobDeleted"
JobDiscarded="JobDisplay_OnJobDiscarded"
JobPaused="JobDisplay_OnJobPaused"
JobStarted="JobDisplay_OnJobStarted" />
</DataTemplate>
</ListView.ItemTemplate>
Expand Down
28 changes: 28 additions & 0 deletions EasyGUI/Controls/JobsList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public ObservableCollection<Job> SelectedJobs

public event EventHandler<JobEventArgs>? JobEdited;

public event EventHandler<JobEventArgs>? JobResumed;

public event EventHandler<JobEventArgs>? JobDeleted;

public event EventHandler<JobEventArgs>? JobDiscarded;

public event EventHandler<JobEventArgs>? JobPaused;

private void JobDisplay_OnJobStarted(object? sender, JobEventArgs e)
{
JobStarted?.Invoke(this, e);
Expand All @@ -69,4 +77,24 @@ private void JobDisplay_OnJobEdited(object? sender, JobEventArgs e)
{
JobEdited?.Invoke(this, e);
}

private void JobDisplay_OnJobResumed(object? sender, JobEventArgs e)
{
JobResumed?.Invoke(this, e);
}

private void JobDisplay_OnJobDeleted(object? sender, JobEventArgs e)
{
JobDeleted?.Invoke(this, e);
}

private void JobDisplay_OnJobDiscarded(object? sender, JobEventArgs e)
{
JobDiscarded?.Invoke(this, e);
}

private void JobDisplay_OnJobPaused(object? sender, JobEventArgs e)
{
JobPaused?.Invoke(this, e);
}
}
23 changes: 23 additions & 0 deletions EasyGUI/EasyGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<Resource Include="Assets\Icons\play-circle-outline.png"/>
<Resource Include="Assets\Icons\create-outline.png"/>
<Resource Include="Assets\Icons\settings-outline.png"/>
<Resource Include="Assets\Icons\trash-outline.png"/>
<Resource Include="Assets\Icons\close-circle-outline.png"/>
<Resource Include="Assets\Icons\pause-circle-outline.png"/>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -87,6 +90,26 @@
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Controls\Buttons\ResumeButton.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Controls\Buttons\DeleteButton.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Controls\Buttons\DiscardButton.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Controls\Buttons\PauseButton.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions EasyGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
Jobs="{Binding Jobs, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
SelectedJobs="{Binding SelectedJobs, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
JobEdited="JobsList_OnJobEdited"
JobResumed="JobsList_OnJobResumed"
JobDeleted="JobsList_OnJobDeleted"
JobDiscarded="JobsList_OnJobDiscarded"
JobPaused="JobsList_OnJobPaused"
JobStarted="JobsList_OnJobStarted" />
</StackPanel>

Expand Down
40 changes: 37 additions & 3 deletions EasyGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ private void CreateJobPopup_OnValidateJob(object sender, RoutedEventArgs e)
else
{
var job = Jobs.First(j => j.Id == id);
var jobIndex = Jobs.IndexOf(job);
_jobManager.EditJob(job, name, source, destination, type.Value);
Jobs.Remove(job);
Jobs.Insert(jobIndex, job);
UpdateJob(job);
}

CreateJobPopup.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -134,4 +132,40 @@ private void JobsHeader_OnSettingsButtonClick(object sender, RoutedEventArgs e)
{
SettingsPopup.Visibility = Visibility.Visible;
}

private void JobsList_OnJobResumed(object? sender, JobEventArgs e)
{
var job = e.Job;
Dispatcher.Invoke(() => _jobManager.ResumeJob(job));
}

private void JobsList_OnJobDeleted(object? sender, JobEventArgs e)
{
var job = e.Job;
Dispatcher.Invoke(() => _jobManager.DeleteJob(job));
Jobs.Remove(job);
}

private void JobsList_OnJobDiscarded(object? sender, JobEventArgs e)
{
var job = e.Job;
Dispatcher.Invoke(() =>
{
_jobManager.CancelJob(job);
UpdateJob(job);
});
}

private void JobsList_OnJobPaused(object? sender, JobEventArgs e)
{
var job = e.Job;
Dispatcher.Invoke(() => _jobManager.PauseJob(job));
}

private void UpdateJob(Job job)
{
var jobIndex = Jobs.IndexOf(job);
Jobs.Remove(job);
Jobs.Insert(jobIndex, job);
}
}
Loading

0 comments on commit 2875e87

Please sign in to comment.