Skip to content

Commit feab146

Browse files
committed
Feature: Refresh button
1 parent ade023a commit feab146

9 files changed

Lines changed: 149 additions & 106 deletions

‎Source/NETworkManager/StatusWindow.xaml‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,7 @@
6060
</mah:WindowCommands>
6161
</mah:MetroWindow.LeftWindowCommands>
6262
<mah:MetroWindow.RightWindowCommands>
63-
<mah:WindowCommands ShowSeparators="False">
64-
<Button Command="{Binding Path=ReloadCommand}"
65-
ToolTip="{x:Static Member=localization:Strings.Reload}"
66-
Cursor="Hand"
67-
Focusable="False"
68-
Margin="0,0,5,0">
69-
<StackPanel Orientation="Horizontal">
70-
<Rectangle Width="16" Height="16"
71-
Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
72-
<Rectangle.OpacityMask>
73-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Refresh}" />
74-
</Rectangle.OpacityMask>
75-
</Rectangle>
76-
</StackPanel>
77-
</Button>
63+
<mah:WindowCommands ShowSeparators="False">
7864
<Button Command="{Binding Path=ShowMainWindowCommand}"
7965
ToolTip="{x:Static Member=localization:Strings.Show}"
8066
Cursor="Hand"

‎Source/NETworkManager/StatusWindow.xaml.cs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ public double Time
9696

9797
#region ICommands & Actions
9898

99-
public ICommand ReloadCommand => new RelayCommand(_ => ReloadAction());
100-
101-
private void ReloadAction()
102-
{
103-
Check();
104-
}
105-
10699
public ICommand ShowMainWindowCommand => new RelayCommand(_ => ShowMainWindowAction());
107100

108101
private void ShowMainWindowAction()

‎Source/NETworkManager/ViewModels/IPApiDNSResolverWidgetViewModel.cs‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,9 @@ private void LoadSettings()
7070
#region ICommands & Actions
7171

7272
/// <summary>
73-
/// Gets the command to check via hotkey.
73+
/// Gets the command to check the DNS resolver.
7474
/// </summary>
75-
public ICommand CheckViaHotkeyCommand => new RelayCommand(_ => CheckViaHotkeyAction());
76-
77-
/// <summary>
78-
/// Action to check via hotkey.
79-
/// </summary>
80-
private void CheckViaHotkeyAction()
81-
{
82-
Check();
83-
}
75+
public ICommand CheckCommand => new RelayCommand(_ => Check(), _ => !IsRunning);
8476

8577
#endregion
8678

@@ -103,10 +95,6 @@ private async Task CheckAsync()
10395
if (!SettingsManager.Current.Dashboard_CheckIPApiDNSResolver)
10496
return;
10597

106-
// Don't check multiple times if already running
107-
if (IsRunning)
108-
return;
109-
11098
IsRunning = true;
11199
Result = null;
112100

‎Source/NETworkManager/ViewModels/IPApiIPGeolocationWidgetViewModel.cs‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,9 @@ private void LoadSettings()
7272
#region ICommands & Actions
7373

7474
/// <summary>
75-
/// Gets the command to check via hotkey.
75+
/// Gets the command to check the IP geolocation.
7676
/// </summary>
77-
public ICommand CheckViaHotkeyCommand => new RelayCommand(_ => CheckViaHotkeyAction());
78-
79-
/// <summary>
80-
/// Action to check via hotkey.
81-
/// </summary>
82-
private void CheckViaHotkeyAction()
83-
{
84-
Check();
85-
}
77+
public ICommand CheckCommand => new RelayCommand(_ => Check(), _ => !IsRunning);
8678

8779
#endregion
8880

@@ -105,10 +97,6 @@ private async Task CheckAsync()
10597
if (!SettingsManager.Current.Dashboard_CheckIPApiIPGeolocation)
10698
return;
10799

108-
// Don't check multiple times if already running
109-
if (IsRunning)
110-
return;
111-
112100
IsRunning = true;
113101
Result = null;
114102

‎Source/NETworkManager/ViewModels/NetworkConnectionWidgetViewModel.cs‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,22 @@ private set
476476
/// </summary>
477477
public bool CheckPublicIPAddressEnabled => SettingsManager.Current.Dashboard_CheckPublicIPAddress;
478478

479+
/// <summary>
480+
/// Gets or sets a value indicating whether a check is currently running.
481+
/// </summary>
482+
public bool IsChecking
483+
{
484+
get;
485+
private set
486+
{
487+
if (value == field)
488+
return;
489+
490+
field = value;
491+
OnPropertyChanged();
492+
}
493+
}
494+
479495
#endregion
480496

481497
#region Constructor, load settings
@@ -500,17 +516,9 @@ private void LoadSettings()
500516
#region ICommands & Actions
501517

502518
/// <summary>
503-
/// Gets the command to check connections via hotkey.
504-
/// </summary>
505-
public ICommand CheckViaHotkeyCommand => new RelayCommand(_ => CheckViaHotkeyAction());
506-
507-
/// <summary>
508-
/// Executes the check via hotkey action.
519+
/// Gets the command to check connections.
509520
/// </summary>
510-
private void CheckViaHotkeyAction()
511-
{
512-
Check();
513-
}
521+
public ICommand CheckCommand => new RelayCommand(_ => Check());
514522

515523
#endregion
516524

@@ -564,6 +572,8 @@ private async Task CheckAsync()
564572
_cancellationTokenSource = new CancellationTokenSource();
565573
var wasCanceled = false;
566574

575+
IsChecking = true;
576+
567577
try
568578
{
569579
_checkTask = RunTask(_cancellationTokenSource.Token);
@@ -576,6 +586,8 @@ private async Task CheckAsync()
576586
}
577587
finally
578588
{
589+
IsChecking = false;
590+
579591
if (!wasCanceled)
580592
Log.Info("Network connection check completed.");
581593
}

‎Source/NETworkManager/Views/DashboardView.xaml.cs‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,21 @@ public DashboardView()
2424
ContentControlSpeedTest.Content = _speedTestWidgetView;
2525

2626
// Check all widgets
27-
Check();
27+
_networkConnectionWidgetView.Check();
28+
_ipApiIPGeolocationWidgetView.Check();
29+
_ipApiDNSResolverWidgetView.Check();
2830
}
2931

3032
public void OnViewVisible()
3133
{
3234
_viewModel.OnViewVisible();
3335

34-
// Check all widgets
35-
Check();
36+
// Check network connection
37+
_networkConnectionWidgetView.Check();
3638
}
3739

3840
public void OnViewHide()
3941
{
4042
_viewModel.OnViewHide();
4143
}
42-
43-
/// <summary>
44-
/// Check all widgets
45-
/// </summary>
46-
private void Check()
47-
{
48-
_networkConnectionWidgetView.Check();
49-
_ipApiIPGeolocationWidgetView.Check();
50-
_ipApiDNSResolverWidgetView.Check();
51-
}
52-
}
44+
}

‎Source/NETworkManager/Views/IPApiDNSResolverWidgetView.xaml‎

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
1111
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
1212
xmlns:system="clr-namespace:System;assembly=mscorlib"
13+
xmlns:wpfHelpers="clr-namespace:NETworkManager.Utilities.WPF;assembly=NETworkManager.Utilities.WPF"
1314
mc:Ignorable="d" MinHeight="200"
1415
d:DataContext="{d:DesignInstance viewModels:IPApiDNSResolverWidgetViewModel}">
1516
<UserControl.InputBindings>
16-
<KeyBinding Key="F5" Command="{Binding CheckViaHotkeyCommand}" />
17+
<KeyBinding Key="F5" Command="{Binding CheckCommand}" />
1718
</UserControl.InputBindings>
1819
<UserControl.Resources>
1920
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
@@ -37,15 +38,42 @@
3738
<RowDefinition Height="Auto" />
3839
<RowDefinition Height="*" />
3940
</Grid.RowDefinitions>
40-
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" Margin="10">
41-
<Rectangle Width="32" Height="32" Fill="{DynamicResource MahApps.Brushes.Gray3}">
42-
<Rectangle.OpacityMask>
43-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=SearchWeb}" />
44-
</Rectangle.OpacityMask>
45-
</Rectangle>
46-
<TextBlock Text="{x:Static localization:Strings.DNSResolver}"
47-
Style="{StaticResource MessageTextBlock}" Margin="10,0,0,0" />
48-
</StackPanel>
41+
<Grid Grid.Row="0" Margin="10">
42+
<Grid.ColumnDefinitions>
43+
<ColumnDefinition Width="Auto" />
44+
<ColumnDefinition Width="*" />
45+
<ColumnDefinition Width="Auto" />
46+
</Grid.ColumnDefinitions>
47+
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
48+
<Rectangle Width="32" Height="32" Fill="{DynamicResource MahApps.Brushes.Gray3}">
49+
<Rectangle.OpacityMask>
50+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=SearchWeb}" />
51+
</Rectangle.OpacityMask>
52+
</Rectangle>
53+
<TextBlock Text="{x:Static localization:Strings.DNSResolver}"
54+
Style="{StaticResource MessageTextBlock}" Margin="10,0,0,0" />
55+
</StackPanel>
56+
<Button Grid.Column="2" Command="{Binding CheckCommand}"
57+
Style="{StaticResource CleanButton}"
58+
VerticalAlignment="Center">
59+
<Rectangle Width="20" Height="20"
60+
wpfHelpers:ReloadAnimationHelper.IsReloading="{Binding IsRunning}">
61+
<Rectangle.OpacityMask>
62+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Refresh}" />
63+
</Rectangle.OpacityMask>
64+
<Rectangle.Style>
65+
<Style TargetType="{x:Type Rectangle}">
66+
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />
67+
<Style.Triggers>
68+
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=IsMouseOver}" Value="True">
69+
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray5}" />
70+
</DataTrigger>
71+
</Style.Triggers>
72+
</Style>
73+
</Rectangle.Style>
74+
</Rectangle>
75+
</Button>
76+
</Grid>
4977
<Grid Grid.Column="0" Grid.Row="2" Margin="10"
5078
Visibility="{Binding Source={x:Static Member=settings:SettingsManager.Current}, Path=Dashboard_CheckIPApiDNSResolver, Converter={StaticResource ResourceKey=BooleanToVisibilityCollapsedConverter}}">
5179
<!-- Result-->

‎Source/NETworkManager/Views/IPApiIPGeolocationWidgetView.xaml‎

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
1111
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
1212
xmlns:system="clr-namespace:System;assembly=mscorlib"
13+
xmlns:wpfHelpers="clr-namespace:NETworkManager.Utilities.WPF;assembly=NETworkManager.Utilities.WPF"
1314
mc:Ignorable="d" MinHeight="200"
1415
d:DataContext="{d:DesignInstance viewModels:IPApiIPGeolocationWidgetViewModel}">
1516
<UserControl.InputBindings>
16-
<KeyBinding Key="F5" Command="{Binding CheckViaHotkeyCommand}" />
17+
<KeyBinding Key="F5" Command="{Binding CheckCommand}" />
1718
</UserControl.InputBindings>
1819
<UserControl.Resources>
1920
<converters:BooleanReverseToVisibilityCollapsedConverter x:Key="BooleanReverseToVisibilityCollapsedConverter" />
@@ -40,15 +41,42 @@
4041
<RowDefinition Height="Auto" />
4142
<RowDefinition Height="*" />
4243
</Grid.RowDefinitions>
43-
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" Margin="10">
44-
<Rectangle Width="32" Height="32" Fill="{DynamicResource MahApps.Brushes.Gray3}">
45-
<Rectangle.OpacityMask>
46-
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=MapMarkerOutline}" />
47-
</Rectangle.OpacityMask>
48-
</Rectangle>
49-
<TextBlock Text="{x:Static localization:Strings.IPGeolocation}"
50-
Style="{StaticResource MessageTextBlock}" Margin="10,0,0,0" />
51-
</StackPanel>
44+
<Grid Grid.Row="0" Margin="10">
45+
<Grid.ColumnDefinitions>
46+
<ColumnDefinition Width="Auto" />
47+
<ColumnDefinition Width="*" />
48+
<ColumnDefinition Width="Auto" />
49+
</Grid.ColumnDefinitions>
50+
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
51+
<Rectangle Width="32" Height="32" Fill="{DynamicResource MahApps.Brushes.Gray3}">
52+
<Rectangle.OpacityMask>
53+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=MapMarkerOutline}" />
54+
</Rectangle.OpacityMask>
55+
</Rectangle>
56+
<TextBlock Text="{x:Static localization:Strings.IPGeolocation}"
57+
Style="{StaticResource MessageTextBlock}" Margin="10,0,0,0" />
58+
</StackPanel>
59+
<Button Grid.Column="2" Command="{Binding CheckCommand}"
60+
Style="{StaticResource CleanButton}"
61+
VerticalAlignment="Center">
62+
<Rectangle Width="20" Height="20"
63+
wpfHelpers:ReloadAnimationHelper.IsReloading="{Binding IsRunning}">
64+
<Rectangle.OpacityMask>
65+
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Refresh}" />
66+
</Rectangle.OpacityMask>
67+
<Rectangle.Style>
68+
<Style TargetType="{x:Type Rectangle}">
69+
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray3}" />
70+
<Style.Triggers>
71+
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=IsMouseOver}" Value="True">
72+
<Setter Property="Fill" Value="{DynamicResource MahApps.Brushes.Gray5}" />
73+
</DataTrigger>
74+
</Style.Triggers>
75+
</Style>
76+
</Rectangle.Style>
77+
</Rectangle>
78+
</Button>
79+
</Grid>
5280
<Grid Grid.Column="0" Grid.Row="2" Margin="10"
5381
Visibility="{Binding Source={x:Static Member=settings:SettingsManager.Current}, Path=Dashboard_CheckIPApiIPGeolocation, Converter={StaticResource ResourceKey=BooleanToVisibilityCollapsedConverter}}">
5482
<!-- Result -->

0 commit comments

Comments
 (0)