Skip to content

Make the ProgressDialog more readable #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions src/AntiDupl.NET.WPF/Control/ComplexProgressBar.xaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
<UserControl x:Class="AntiDupl.NET.WPF.Control.ComplexProgressBar"
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"
mc:Ignorable="d"
d:DesignHeight="50"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="50"
d:DesignWidth="200">
<Grid>
<!--The progress bar background-->
<Rectangle Stroke="#FF000000"
RenderTransformOrigin="0.5,0.5"
x:Name="ProgressBarBackground">
<!--<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="White" Offset="0" />
<GradientStop Color="Gray" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>-->
</Rectangle>
<Rectangle x:Name="ProgressBarForeground2"
<Rectangle x:Name="ProgressBarBackground"
Stroke="#FF000000"
RenderTransformOrigin="0.5,0.5" />
<!--The progress bar foreground2-->
<Rectangle x:Name="ProgressBarForeground2"
HorizontalAlignment="Left">
<Rectangle.Fill>
<SolidColorBrush Color="DarkGreen" />
<SolidColorBrush Color="DarkGreen" />
</Rectangle.Fill>
</Rectangle>
<!--The progress bar foreground-->
<Rectangle Stroke="#FF000000"
<Rectangle x:Name="ProgressBarForeground"
Stroke="#FF000000"
RenderTransformOrigin="0.5,0.5"
x:Name="ProgressBarForeground"
HorizontalAlignment="Left">
<Rectangle.Fill>
<SolidColorBrush Color="#FF01D328" />
<SolidColorBrush Color="#FF01D328" />
</Rectangle.Fill>
</Rectangle>
<Viewbox>
<!--The progress bar text display-->
<TextBlock TextAlignment="Center"
Background="Transparent"
FontFamily="Times"
Foreground="Black"
x:Name="ProgressText"
Margin="2,2,2,2" />
</Viewbox>
<!--The progress bar text display-->
<TextBlock x:Name="ProgressText"
TextAlignment="Center"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Transparent"
Foreground="Black" />
</Grid>
</UserControl>
</UserControl>
156 changes: 53 additions & 103 deletions src/AntiDupl.NET.WPF/Control/ComplexProgressBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,120 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AntiDupl.NET.WPF.Control
{
/// <summary>
/// Логика взаимодействия для ComplexProgressBar.xaml
/// </summary>
public partial class ComplexProgressBar : UserControl
{
public ComplexProgressBar()
{
InitializeComponent();
}
namespace AntiDupl.NET.WPF.Control;

public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(uint), typeof(ComplexProgressBar));

public uint Maximum
{
get
{
return (uint)GetValue(MaximumProperty);
}
set
{
SetValue(MaximumProperty, value);
}
}
/// <summary>
/// Логика взаимодействия для ComplexProgressBar.xaml
/// </summary>
public partial class ComplexProgressBar : UserControl
{
public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register(nameof(Maximum), typeof(uint), typeof(ComplexProgressBar));


public static readonly DependencyProperty CurrentFirstProperty =
DependencyProperty.Register("CurrentFirst", typeof(uint), typeof(ComplexProgressBar),
public static readonly DependencyProperty CurrentFirstProperty =
DependencyProperty.Register(nameof(CurrentFirst), typeof(uint), typeof(ComplexProgressBar),
new PropertyMetadata(OnCurrentFirstChanged));

public uint CurrentFirst
{
get
{
return (uint)GetValue(CurrentFirstProperty);
}
set
{
SetValue(CurrentFirstProperty, value);
}
}
public static readonly DependencyProperty CurrentSecondProperty =
DependencyProperty.Register(nameof(CurrentSecond), typeof(uint), typeof(ComplexProgressBar),
new PropertyMetadata(OnCurrentSecondChanged));

private static void OnCurrentFirstChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
ComplexProgressBar myControl = sender as ComplexProgressBar;
// Gestion des synchonisations des colonnes
//double width = (double)sender;
public ComplexProgressBar()
{
InitializeComponent();
ProgressText.Text = "Loading...";
}

//e.Property = (double)e.NewValue + 5;
//myControl.imgCurrent.Source = ((ImageInfoClass)e.NewValue).Image;
public uint Maximum
{
get => (uint)GetValue(MaximumProperty);
set => SetValue(MaximumProperty, value);
}

try
{
if (myControl.ActualWidth > 0)
myControl.ProgressBarForeground.Width = (myControl.ActualWidth - 2) * myControl.CurrentFirst / myControl.Maximum;
}
catch (Exception ex)
{

throw;
}
public uint CurrentFirst
{
get => (uint)GetValue(CurrentFirstProperty);
set => SetValue(CurrentFirstProperty, value);
}

// myControl.ProgressBarForeground2.Width = (myControl.ActualWidth - 2) * myControl. / myControl.Maximum;
if (myControl.Maximum > 0)
myControl.ProgressText.Text = (((double)myControl.CurrentFirst / (double)myControl.Maximum) * 100).ToString("F2") + "%";
else
myControl.ProgressText.Text = "";
}
public uint CurrentSecond
{
get => (uint)GetValue(CurrentSecondProperty);
set => SetValue(CurrentSecondProperty, value);
}

public static readonly DependencyProperty CurrentSecondProperty =
DependencyProperty.Register("CurrentSecond", typeof(uint), typeof(ComplexProgressBar),
new PropertyMetadata(OnCurrentSecondChanged));
private static void OnCurrentFirstChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
if (sender is not ComplexProgressBar myControl) return;

public uint CurrentSecond
{
get
{
return (uint)GetValue(CurrentSecondProperty);
}
set
{
SetValue(CurrentSecondProperty, value);
}
}
if (myControl.ActualWidth > 0)
myControl.ProgressBarForeground.Width =
(myControl.ActualWidth - 2) * myControl.CurrentFirst / myControl.Maximum;

private static void OnCurrentSecondChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
ComplexProgressBar myControl = sender as ComplexProgressBar;
try
{
if (myControl.ActualWidth > 0)
myControl.ProgressBarForeground2.Width = (myControl.ActualWidth - 2) * myControl.CurrentSecond / myControl.Maximum;
}
catch (Exception ex)
{

throw;
}
if (myControl.Maximum > 0)
myControl.ProgressText.Text =
(myControl.CurrentFirst / (double)myControl.Maximum * 100).ToString("F2") + "%";
else
myControl.ProgressText.Text = "";
}

}
private static void OnCurrentSecondChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
if (sender is not ComplexProgressBar myControl) return;

if (myControl.ActualWidth > 0)
myControl.ProgressBarForeground2.Width =
(myControl.ActualWidth - 2) * myControl.CurrentSecond / myControl.Maximum;
}
}
}
62 changes: 25 additions & 37 deletions src/AntiDupl.NET.WPF/View/ProgressDialog.xaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,43 @@
<Window x:Class="AntiDupl.NET.WPF.View.ProgressDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:AntiDupl.NET.WPF.Control"
Title="ProgressDialog" Height="100" Width="600" >
xmlns:viewModel="clr-namespace:AntiDupl.NET.WPF.ViewModel"
xmlns:control="clr-namespace:AntiDupl.NET.WPF.Control"
Title="ProgressDialog" Height="80" Width="600">
<Window.DataContext>
<viewModel:ProgressDialogViewModel/>
</Window.DataContext>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="0.7*"/> <!--path-->
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="0.05" MinWidth="50"/>
<ColumnDefinition Width="0.05" MinWidth="50"/>
<ColumnDefinition Width="0.10" MinWidth="100"/>
<ColumnDefinition Width="0.75*" MinWidth="300"/>
<ColumnDefinition Width="0.05" MinWidth="50"/>
</Grid.ColumnDefinitions>
<!--<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/> LogItems
</Grid.RowDefinitions>-->

<Border Grid.Column="0" BorderBrush="LightGray" BorderThickness="1">
<TextBlock
VerticalAlignment="Center"
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="{Binding Path=ProgressMax, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
Text="{Binding ProgressMax, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</Border>
<Border Grid.Column="1" BorderBrush="LightGray" BorderThickness="1">
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="{Binding Path=Progress, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
Text="{Binding Progress, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</Border>
<Border Grid.Column="2" BorderBrush="LightGray" BorderThickness="1" >
<control:ComplexProgressBar CurrentFirst="{Binding Progress, Mode=OneWay}"
CurrentSecond="{Binding CurrentSecond, Mode=OneWay}"
Maximum="{Binding ProgressMax, Mode=OneWay}"/>
</Border>
<!--<Border Grid.Column="2" BorderBrush="LightGray" BorderThickness="1">
<TextBlock
VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="{Binding Path=State, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</Border>-->
<controls:ComplexProgressBar
Grid.Column="2"
CurrentFirst="{Binding Progress, Mode=OneWay}"
CurrentSecond="{Binding CurrentSecond, Mode=OneWay}"
Maximum="{Binding ProgressMax, Mode=OneWay}"
Height="50"/>
<!-- Progress Message -->
<Border Grid.Column="3"
BorderBrush="LightGray" BorderThickness="1" >
<TextBlock Text="{Binding Path=ProgressMessage, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center" />
<Border Grid.Column="3" BorderBrush="LightGray" BorderThickness="1" >
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Left"
TextWrapping="Wrap"
Text="{Binding ProgressMessage, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</Border>
<!--<ProgressBar Grid.Row="2" Value="{Binding Path=Progress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Maximum="{Binding Path=ProgressMax, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Height="50"/>-->

<Button Grid.Column="4" Content="Cancel" Command="{Binding Path=CancelCommand}" />
<Button Grid.Column="4" Content="Cancel" Command="{Binding CancelCommand}" />
<!--<TextBlock Text="{Binding Path=LogMessage, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Center" />-->

Expand Down
46 changes: 25 additions & 21 deletions src/AntiDupl.NET.WPF/View/ProgressDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using AntiDupl.NET.WPF.ViewModel;

namespace AntiDupl.NET.WPF.View
namespace AntiDupl.NET.WPF.View;

/// <summary>
/// Логика взаимодействия для ProgressDialog.xaml
/// </summary>
public partial class ProgressDialog : Window
{
/// <summary>
/// Логика взаимодействия для ProgressDialog.xaml
/// </summary>
public partial class ProgressDialog : Window
public ProgressDialog()
{
InitializeComponent();
}

protected override void OnClosing(CancelEventArgs e)
{
public ProgressDialog()
{
InitializeComponent();
}
base.OnClosing(e);

//find out, if the close button was pressed or if the window was closed by win.close()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is bad practise write anything in window file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not! It depends on what has to be done!

if (new StackTrace().GetFrames().FirstOrDefault(x => x.GetMethod() == typeof(Window).GetMethod("Close")) != null) return;

//if close button was pressed, cancel execution
var vm = (ProgressDialogViewModel)DataContext;
vm.CancelCommand.Execute(null);
e.Cancel = true;
}
}
}
Loading