Skip to content

Commit

Permalink
test: Fixed progress dialog test.
Browse files Browse the repository at this point in the history
  • Loading branch information
GregaMohorko committed Apr 12, 2021
1 parent bc28a0e commit f78a948
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Gregor Mohorko
Copyright (c) 2021 Gregor Mohorko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You can read the documentation and how-to's under the [Wiki](https://github.com/
- [StartPage](src/GM.WPF/GM.WPF/Controls/StartPage.xaml.cs)
- [TimeControl](src/GM.WPF/GM.WPF/Controls/TimeControl.xaml.cs)
- [TimePicker](src/GM.WPF/GM.WPF/Controls/TimePicker.xaml.cs)
- [WatermarkTextBox](src/GM.WPF/GM.WPF/Controls/WatermarkTextBox.xaml.cs)

**Dialogs**:
- [DialogPanel](src/GM.WPF/GM.WPF/Controls/Dialogs/DialogPanel.xaml.cs)
Expand Down Expand Up @@ -51,14 +52,17 @@ You can read the documentation and how-to's under the [Wiki](https://github.com/
- [FrameworkElement](src/GM.WPF/GM.WPF/Behaviors/FrameworkElementBehavior.cs)
- [Panel](src/GM.WPF/GM.WPF/Behaviors/PanelBehavior.cs)
- [TabItem](src/GM.WPF/GM.WPF/Behaviors/TabItemBehavior.cs)
- [TabControl](src/GM.WPF/GM.WPF/Behaviors/TabControlBehavior.cs)
- [TextBlock](src/GM.WPF/GM.WPF/Behaviors/TextBlockBehavior.cs)

**Converters**:
- [BoolToBool](src/GM.WPF/GM.WPF/Converters/BoolToBoolConverter.cs)
- [BoolToScrollBarVisibility](src/GM.WPF/GM.WPF/Converters/BoolToScrollBarVisibilityConverter.cs)
- [BoolToVisibility](src/GM.WPF/GM.WPF/Converters/BoolToVisibilityConverter.cs)
- [EnumToCollectionConverter](src/GM.WPF/GM.WPF/Converters/EnumToCollectionConverter.cs)
- [FunctionToString](src/GM.WPF/GM.WPF/Converters/FunctionToStringConverter.cs)
- [ICollectionToBool](src/GM.WPF/GM.WPF/Converters/ICollectionToBoolConverter.cs)
- [ICollectionToCountConverter](src/GM.WPF/GM.WPF/Converters/ICollectionToCountConverter.cs)
- [ICollectionToVisibility](src/GM.WPF/GM.WPF/Converters/ICollectionToVisibilityConverter.cs)
- [IListToIList](src/GM.WPF/GM.WPF/Converters/IListToIListConverter.cs)
- [IntToVisibility](src/GM.WPF/GM.WPF/Converters/IntToVisibilityConverter.cs)
Expand Down
2 changes: 1 addition & 1 deletion src/GM.WPF/GM.WPF.Test/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Author: Grega Mohorko
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_Dialogs">
<MenuItem Header="_Progress" IsCheckable="True" IsChecked="{Binding IsDialogProgressShown,Mode=OneWayToSource}" />
<MenuItem Header="_Progress" Click="MenuItem_Dialogs_Progress_Click" />
<MenuItem Header="_Message">
<MenuItem Header="_Normal" Click="MenuItem_Dialogs_Message_Normal_Click" />
<MenuItem Header="_Warning" Click="MenuItem_Dialogs_Message_Warning_Click" />
Expand Down
43 changes: 24 additions & 19 deletions src/GM.WPF/GM.WPF.Test/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -55,7 +56,6 @@ public MainWindow()
InitializeComponent();

var vm = new MainWindowViewModel();
vm.PropertyChanged += Vm_PropertyChanged;
ViewModel = vm;
}

Expand All @@ -66,25 +66,27 @@ public void Dispose()
IsDisposed = true;
}

private void Vm_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
var vm = (MainWindowViewModel)ViewModel;

switch(e.PropertyName) {
case nameof(MainWindowViewModel.IsDialogProgressShown):
if(vm.IsDialogProgressShown) {
var r = new Random();
_ProgressDialog.Show("Title content.", "Message content.", r.NextDouble() * 130);
} else {
_ProgressDialog.Hide();
}
break;
}
}

#region MAINMENU

#region DIALOGS
private async void MenuItem_Dialogs_Progress_Click(object sender, RoutedEventArgs e)
{
const int msTime = 3000;
_ProgressDialog.Show($"Showing for {msTime} milliseconds", null, 0);
ProgressUpdater progressUpdater = _ProgressDialog.Updater;
await Task.Run(async delegate
{
int progressSteps = 100;
int msStep = (int)Math.Round(msTime / (double)progressSteps);
progressUpdater.StartNewLoop(progressSteps);
for(int i = 0; i < progressSteps; ++i) {
progressUpdater.SetForLoop(i, true);
await Task.Delay(msStep);
}
});
_ProgressDialog.Hide();
}

private async void MenuItem_Dialogs_Message_Normal_Click(object sender, RoutedEventArgs e)
{
// using the DialogPanel
Expand Down Expand Up @@ -211,16 +213,19 @@ private async void MenuItem_Dialogs_Search_Single_Click(object sender, RoutedEve

private Random rand = new Random();

private async Task<List<string>> SearchDialogLoadingFunction(string searchText)
private async Task<List<string>> SearchDialogLoadingFunction(string searchText, CancellationToken ct, ProgressUpdater progressUpdater)
{
// simulate one second of loading
await Task.Delay(1000);
await Task.Delay(1000, ct);

// generate some random items
int count = rand.Next(2, 30);
var items = new List<string>(count);
progressUpdater?.StartNewLoop(count);
for(int i = count - 1; i >= 0; --i) {
progressUpdater?.SetForLoop(i);
items.Add($"{rand.Next(100)}-{searchText}");
ct.ThrowIfCancellationRequested();
}
return items;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GM.WPF/GM.WPF.Test/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ namespace GM.WPF.Test
{
class MainWindowViewModel : ViewModel
{
public bool IsDialogProgressShown { get; set; }

}
}
17 changes: 11 additions & 6 deletions src/GM.WPF/GM.WPF/GM.WPF.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
<description>$description$</description>
<copyright>$copyright$</copyright>
<tags>WPF MVVM controls utility extensions dialogs converters behaviors windows</tags>
<releaseNotes>Added TabItemBehavior, FrameworkElementBehavior.
Added FrameworkElementUtility.GetParent.
Marked BaseControl.DependencyVMProperty.nullifyWhenParentTabItemIsNotSelected as obsolete with a warning.
Changed ProgressOverlay to show when Message is empty.</releaseNotes>
<releaseNotes>Added WatermarkTextBox.
Added TabControlBehavior.
Added FrameworkElementUtility.GetUniqueControlKeyByVisualTree.
Added ProgressUpdater.SetForLoop with support for step message.
Added converters: EnumToCollectionConverter, ICollectionToCountConverter.
Added ViewModelChanged event to BaseControl.
Added DependencyVMPropertyReadOnly to BaseControl.
Fix: BaseControl: Null reference when view model is null.
Fix: BaseControl: DependencyVMProperty: default value: Set default value in view model when defined in the property.
Fix: DateDialog: Allow clicking OK at all times, focus input box when empty.</releaseNotes>
<dependencies>
<dependency id="GM.Utility" version="1.3.1" />
<dependency id="CommonServiceLocator" version="2.0.5" />
<dependency id="GM.Utility" version="1.3.2" />
<dependency id="GM.Windows.Utility" version="1.0.5.1" />
<dependency id="MvvmLightLibs" version="5.4.1.1" />
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions src/GM.WPF/GM.WPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]
[assembly: AssemblyVersion("1.4.3.0")]
[assembly: AssemblyFileVersion("1.4.3.0")]

0 comments on commit f78a948

Please sign in to comment.