Display conversion progress on the taskbar item.

This commit is contained in:
Adrien Allard committed 2018-06-06 08:58:36 +02:00
1 parent ca6e2c8919
commit e689705d91
2 files changed
+45 -3

No files matched your search

@@ -11,6 +11,8 @@
x:Name="FileConverterMainWindow" Height="500" Width="950" MinHeight="250" MinWidth="500" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico">
<Window.Resources>
<valueConverters:ConversionStateToBrush x:Key="ConversionStateToColor" />
<valueConverters:ConversionJobsToProgressState x:Key="ConversionJobsToProgressState" />
<valueConverters:ConversionJobsToProgressValue x:Key="ConversionJobsToProgressValue" />
<generic:ValueConverterGroup x:Key="EnumEqualsToVisibility">
<generic:ValueToString/>
@@ -21,6 +23,11 @@
<Window.Title>
<Binding Converter="{StaticResource ApplicationVersionToApplicationName}" Mode="OneWay" Path="(local:Application.ApplicationVersion)"/>
</Window.Title>
<Window.TaskbarItemInfo>
<TaskbarItemInfo
ProgressState="{Binding ConvertionJobs, Converter={StaticResource ConversionJobsToProgressState}, ElementName=FileConverterMainWindow}"
ProgressValue="{Binding ConvertionJobs, Converter={StaticResource ConversionJobsToProgressValue}, ElementName=FileConverterMainWindow}" />
</Window.TaskbarItemInfo>
<Grid Margin="10">
<Grid.RowDefinitions>
@@ -44,7 +51,7 @@
</Grid>
<ScrollViewer x:Name="ScrollViewer" Grid.Row="1" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<ItemsControl x:Name="ConverterJobsList">
<ItemsControl ItemsSource="{Binding ConvertionJobs, ElementName=FileConverterMainWindow}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Background="{Binding State, ConverterParameter=Background, Converter={StaticResource ConversionStateToColor}}" Margin="0,4">
@@ -3,9 +3,11 @@
namespace FileConverter
{
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using System.Windows;
using FileConverter.ConversionJobs;
using FileConverter.Annotations;
using FileConverter.Windows;
@@ -16,17 +18,17 @@ namespace FileConverter
private UpgradeWindow upgradeWindow;
private string informationMessage;
private ObservableCollection<ConversionJob> conversionJobs;
public MainWindow()
{
this.InitializeComponent();
Application application = Application.Current as Application;
this.ConvertionJobs = new ObservableCollection<ConversionJob>(application.ConvertionJobs);
application.OnApplicationTerminate += this.Application_OnApplicationTerminate;
this.ConverterJobsList.ItemsSource = application.ConvertionJobs;
if (application.HideMainWindow)
{
this.Hide();
@@ -60,6 +62,24 @@ namespace FileConverter
}
}
public ObservableCollection<ConversionJob> ConvertionJobs
{
get
{
return this.conversionJobs;
}
private set
{
this.conversionJobs = value;
foreach (var job in this.conversionJobs)
{
job.PropertyChanged += this.ConversionJob_PropertyChanged;
}
}
}
public void OnNewVersionReleased(UpgradeVersionDescription upgradeVersionDescription)
{
this.ShowUpgradeWindow();
@@ -80,6 +100,11 @@ namespace FileConverter
{
base.OnClosing(eventArgs);
foreach (var job in this.conversionJobs)
{
job.PropertyChanged -= this.ConversionJob_PropertyChanged;
}
Application application = Application.Current as Application;
if (application.UpgradeVersionDescription != null && application.UpgradeVersionDescription.NeedToUpgrade && !application.UpgradeVersionDescription.InstallerDownloadDone)
@@ -90,6 +115,16 @@ namespace FileConverter
}
}
private void ConversionJob_PropertyChanged(object sender, PropertyChangedEventArgs eventArgs)
{
if (eventArgs.PropertyName != "State" && eventArgs.PropertyName != "Progress")
{
return;
}
this.OnPropertyChanged(nameof(this.ConvertionJobs));
}
private void SettingsButton_OnClick(object sender, RoutedEventArgs e)
{
this.ShowSettingsWindow();