Skip to content

Commit fe1f4fe

Browse files
committed
* Theme changes can now be previewed
* Increased default scan thread count to 5 * Design changes * Refactoring
1 parent a822b27 commit fe1f4fe

File tree

8 files changed

+121
-55
lines changed

8 files changed

+121
-55
lines changed

Advanced PortChecker/Advanced PortChecker.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Classes\Scanner\PortScanner.cs" />
8080
<Compile Include="Classes\GUI\StyleManager.cs" />
8181
<Compile Include="Classes\Utils\GridViewSorter.cs" />
82+
<Compile Include="Classes\Utils\SettingsBinder.cs" />
8283
<Compile Include="Classes\Utils\ThreadCalculator.cs" />
8384
<Compile Include="Windows\AboutWindow.xaml.cs">
8485
<DependentUpon>AboutWindow.xaml</DependentUpon>

Advanced PortChecker/App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<value>3</value>
2121
</setting>
2222
<setting name="WindowOpacity" serializeAs="String">
23-
<value>1</value>
23+
<value>100</value>
2424
</setting>
2525
<setting name="WindowResizeBorder" serializeAs="String">
2626
<value>3</value>
@@ -38,7 +38,7 @@
3838
<value>0</value>
3939
</setting>
4040
<setting name="ScanThreads" serializeAs="String">
41-
<value>2</value>
41+
<value>5</value>
4242
</setting>
4343
</Advanced_PortChecker.Properties.Settings>
4444
</userSettings>

Advanced PortChecker/Classes/GUI/StyleManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal static void ChangeStyle(DependencyObject o)
2323
if (!(o is ChromelessWindow window)) return;
2424
window.BorderThickness = new Thickness(Properties.Settings.Default.BorderThickness);
2525
window.CornerRadius = new CornerRadius(0, 0, 0, 0);
26-
window.Opacity = Properties.Settings.Default.WindowOpacity;
26+
window.Opacity = Properties.Settings.Default.WindowOpacity / 100;
2727
window.ResizeBorderThickness = new Thickness(Properties.Settings.Default.WindowResizeBorder);
2828
}
2929
catch (Exception ex)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Windows.Data;
2+
3+
namespace Advanced_PortChecker.Classes.Utils
4+
{
5+
/// <inheritdoc />
6+
/// <summary>
7+
/// Internal logic for binding settings to controls
8+
/// </summary>
9+
internal sealed class SettingsBinder : Binding
10+
{
11+
/// <inheritdoc />
12+
/// <summary>
13+
/// Initialize a new SettingsBinder
14+
/// </summary>
15+
/// <param name="path">The path that can be used to bind</param>
16+
public SettingsBinder(string path) : base(path)
17+
{
18+
Source = Properties.Settings.Default;
19+
Mode = BindingMode.TwoWay;
20+
}
21+
}
22+
}

Advanced PortChecker/Properties/Settings.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Advanced PortChecker/Properties/Settings.settings

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Value Profile="(Default)">3</Value>
1313
</Setting>
1414
<Setting Name="WindowOpacity" Type="System.Double" Scope="User">
15-
<Value Profile="(Default)">1</Value>
15+
<Value Profile="(Default)">100</Value>
1616
</Setting>
1717
<Setting Name="WindowResizeBorder" Type="System.Double" Scope="User">
1818
<Value Profile="(Default)">3</Value>
@@ -30,7 +30,7 @@
3030
<Value Profile="(Default)">0</Value>
3131
</Setting>
3232
<Setting Name="ScanThreads" Type="System.Int32" Scope="User">
33-
<Value Profile="(Default)">2</Value>
33+
<Value Profile="(Default)">5</Value>
3434
</Setting>
3535
</Settings>
3636
</SettingsFile>

Advanced PortChecker/Windows/SettingsWindow.xaml

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
8+
xmlns:utils="clr-namespace:Advanced_PortChecker.Classes.Utils"
89
mc:Ignorable="d"
910
AllowsTransparency="True"
1011
UseLayoutRounding="True"
1112
Title="Advanced PortChecker - Settings"
1213
Height="300" Width="400"
14+
Closing="SettingsWindow_OnClosing"
1315
WindowStartupLocation="CenterScreen" Icon="/Advanced PortChecker;component/globe.ico"
1416
TitleTextAlignment="Center">
1517
<Grid>
@@ -21,15 +23,18 @@
2123
AllowDragDrop="False" DefaultContextMenuItemVisibility="Hidden"
2224
TabItemSize="ShrinkToFit" TabScrollButtonVisibility="Hidden">
2325

24-
<syncfusion:TabItemExt Header="General" Image="/Advanced PortChecker;component/Resources/Images/settings.png">
26+
<syncfusion:TabItemExt Header="General"
27+
Image="/Advanced PortChecker;component/Resources/Images/settings.png">
2528
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
2629
<Grid.RowDefinitions>
2730
<RowDefinition Height="Auto" />
2831
<RowDefinition Height="Auto" />
2932
<RowDefinition Height="Auto" />
3033
</Grid.RowDefinitions>
31-
<CheckBox x:Name="ChbAutoUpdate" Content="Automatically check for updates" Margin="2" />
32-
<CheckBox Grid.Row="1" x:Name="ChbWindowDraggable" Content="Window draggable" Margin="2" />
34+
<CheckBox Content="Automatically check for updates" Margin="2"
35+
IsChecked="{utils:SettingsBinder AutoUpdate}" />
36+
<CheckBox Grid.Row="1" Content="Window draggable" Margin="2"
37+
IsChecked="{utils:SettingsBinder WindowDraggable}" />
3338
<Grid Grid.Row="2">
3439
<Grid.RowDefinitions>
3540
<RowDefinition Height="Auto" />
@@ -41,14 +46,17 @@
4146
<ColumnDefinition Width="Auto" />
4247
</Grid.ColumnDefinitions>
4348
<Label Grid.Row="0" Grid.Column="0" Content="Connection time-out:" Margin="2" />
44-
<syncfusion:IntegerTextBox Grid.Row="0" Grid.Column="1" x:Name="IntTimeOut" MinValue="1" Margin="2" />
49+
<syncfusion:IntegerTextBox Grid.Row="0" Grid.Column="1" x:Name="IntTimeOut" MinValue="1"
50+
Margin="2" />
4551
<ComboBox Grid.Row="0" Grid.Column="2" x:Name="CboTimeOut" Margin="2">
4652
<ComboBoxItem>millisecond(s)</ComboBoxItem>
4753
<ComboBoxItem>second(s)</ComboBoxItem>
4854
<ComboBoxItem>minute(s)</ComboBoxItem>
4955
</ComboBox>
5056
<Label Grid.Row="1" Grid.Column="0" Margin="2" Content="Number of scan threads:" />
51-
<syncfusion:IntegerTextBox x:Name="IntScanThreads" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="2" MinValue="1" />
57+
<syncfusion:IntegerTextBox Grid.Row="1" Grid.Column="1"
58+
Grid.ColumnSpan="2" Margin="2" MinValue="1"
59+
Value="{utils:SettingsBinder ScanThreads}" />
5260
</Grid>
5361
</Grid>
5462
</syncfusion:TabItemExt>
@@ -70,32 +78,41 @@
7078
<ColumnDefinition Width="Auto" />
7179
<ColumnDefinition />
7280
</Grid.ColumnDefinitions>
73-
<Label Margin="2" Content="Style:" />
74-
<ComboBox Margin="2" x:Name="ChbStyle" SelectedValuePath="Content" Grid.Row="0" Grid.Column="1" IsReadOnly="True">
75-
<ComboBoxItem>Metro</ComboBoxItem>
76-
<ComboBoxItem>Blend</ComboBoxItem>
77-
<ComboBoxItem>VS2010</ComboBoxItem>
78-
<ComboBoxItem>Office2003</ComboBoxItem>
79-
<ComboBoxItem>Office2007Blue</ComboBoxItem>
80-
<ComboBoxItem>Office2007Black</ComboBoxItem>
81-
<ComboBoxItem>Office2007Silver</ComboBoxItem>
82-
<ComboBoxItem>Office2010Blue</ComboBoxItem>
83-
<ComboBoxItem>Office2010Black</ComboBoxItem>
84-
<ComboBoxItem>Office2010Silver</ComboBoxItem>
85-
<ComboBoxItem>ShinyRed</ComboBoxItem>
86-
<ComboBoxItem>ShinyBlue</ComboBoxItem>
87-
<ComboBoxItem>SyncOrange</ComboBoxItem>
88-
<ComboBoxItem>Transparent</ComboBoxItem>
89-
<ComboBoxItem>None</ComboBoxItem>
81+
<Label Margin="2" Content="Style:" />
82+
<ComboBox Margin="2" SelectedValuePath="Content" Grid.Row="0" Grid.Column="1"
83+
IsReadOnly="True" SelectionChanged="ChbStyle_OnSelectionChanged"
84+
SelectedValue="{utils:SettingsBinder VisualStyle}">
85+
<ComboBoxItem Content="Metro" />
86+
<ComboBoxItem Content="Blend" />
87+
<ComboBoxItem Content="VS2010" />
88+
<ComboBoxItem Content="Office2003" />
89+
<ComboBoxItem Content="Office2007Blue" />
90+
<ComboBoxItem Content="Office2007Black" />
91+
<ComboBoxItem Content="Office2007Silver" />
92+
<ComboBoxItem Content="Office2010Blue" />
93+
<ComboBoxItem Content="Office2010Black" />
94+
<ComboBoxItem Content="Office2010Silver" />
95+
<ComboBoxItem Content="ShinyRed" />
96+
<ComboBoxItem Content="ShinyBlue" />
97+
<ComboBoxItem Content="SyncOrange" />
98+
<ComboBoxItem Content="Transparent" />
99+
<ComboBoxItem Content="None" />
90100
</ComboBox>
91101
<Label Margin="2" Grid.Row="1" Grid.Column="0" Content="Metro brush:" />
92-
<syncfusion:ColorPicker Margin="2" x:Name="CpMetroBrush" Grid.Row="1" Grid.Column="1" />
102+
<syncfusion:ColorPicker Margin="2" Grid.Row="1" Grid.Column="1"
103+
Color="{utils:SettingsBinder MetroColor}" />
93104
<Label Margin="2" Grid.Row="2" Grid.Column="0" Content="Border thickness:" />
94-
<syncfusion:IntegerTextBox Margin="2" x:Name="IntBorderThickness" Grid.Row="2" Grid.Column="1" MinValue="0" />
105+
<Slider Margin="3" Grid.Row="2" Grid.Column="1" Minimum="1"
106+
ValueChanged="SldBorderThickness_OnValueChanged"
107+
Value="{utils:SettingsBinder BorderThickness}" />
95108
<Label Margin="3" Grid.Row="3" Grid.Column="0" Content="Window opacity:" />
96-
<Slider x:Name="SldOpacity" Margin="3" Grid.Row="3" Grid.Column="1" Minimum="30" Maximum="100" Width="180" ValueChanged="SldOpacity_OnValueChanged" />
109+
<Slider x:Name="SldOpacity" Margin="3" Grid.Row="3" Grid.Column="1" Minimum="30" Maximum="100"
110+
Width="180" ValueChanged="SldOpacity_OnValueChanged"
111+
Value="{utils:SettingsBinder WindowOpacity}" />
97112
<Label Margin="3" Grid.Row="4" Grid.Column="0" Content="Resize border:" />
98-
<Slider x:Name="SldWindowResize" Margin="3" Grid.Row="4" Grid.Column="1" Minimum="2" Maximum="10" Width="180" ValueChanged="SldWindowResize_OnValueChanged" />
113+
<Slider x:Name="SldWindowResize" Margin="3" Grid.Row="4" Grid.Column="1" Minimum="2"
114+
Maximum="10" Width="180" ValueChanged="SldWindowResize_OnValueChanged"
115+
Value="{utils:SettingsBinder WindowResizeBorder}" />
99116
</Grid>
100117
</Grid>
101118
</syncfusion:TabItemExt>
@@ -109,4 +126,4 @@
109126
<Button Grid.Column="1" Click="BtnSave_Click" Margin="5" IsDefault="True" Content="Save" />
110127
</Grid>
111128
</Grid>
112-
</syncfusion:ChromelessWindow>
129+
</syncfusion:ChromelessWindow>

Advanced PortChecker/Windows/SettingsWindow.xaml.cs

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Windows;
4+
using System.Windows.Controls;
35
using System.Windows.Input;
46
using Advanced_PortChecker.Classes.GUI;
57

@@ -54,27 +56,16 @@ private void LoadSettings()
5456
break;
5557
}
5658

57-
ChbAutoUpdate.IsChecked = Properties.Settings.Default.AutoUpdate;
58-
IntScanThreads.Value = Properties.Settings.Default.ScanThreads;
59-
6059
if (Properties.Settings.Default.WindowDraggable)
6160
{
6261
// Prevent duplicate handlers
6362
MouseDown -= OnMouseDown;
6463
MouseDown += OnMouseDown;
65-
ChbWindowDraggable.IsChecked = true;
6664
}
6765
else
6866
{
6967
MouseDown -= OnMouseDown;
70-
ChbWindowDraggable.IsChecked = false;
7168
}
72-
73-
ChbStyle.SelectedValue = Properties.Settings.Default.VisualStyle;
74-
CpMetroBrush.Color = Properties.Settings.Default.MetroColor;
75-
IntBorderThickness.Value = Properties.Settings.Default.BorderThickness;
76-
SldOpacity.Value = Properties.Settings.Default.WindowOpacity * 100;
77-
SldWindowResize.Value = Properties.Settings.Default.WindowResizeBorder;
7869
}
7970
catch (Exception ex)
8071
{
@@ -115,18 +106,9 @@ private void BtnSave_Click(object sender, RoutedEventArgs e)
115106
if (IntTimeOut.Value != null) Properties.Settings.Default.TimeOut = (int)IntTimeOut.Value * 1000;
116107
break;
117108
case 2:
118-
if (IntTimeOut.Value != null) Properties.Settings.Default.TimeOut = ((int)IntTimeOut.Value * 60) * 1000;
109+
if (IntTimeOut.Value != null) Properties.Settings.Default.TimeOut = (int)IntTimeOut.Value * 60 * 1000;
119110
break;
120111
}
121-
if (ChbAutoUpdate.IsChecked != null) Properties.Settings.Default.AutoUpdate = ChbAutoUpdate.IsChecked.Value;
122-
if (ChbWindowDraggable.IsChecked != null) Properties.Settings.Default.WindowDraggable = ChbWindowDraggable.IsChecked.Value;
123-
if (IntScanThreads.Value != null) Properties.Settings.Default.ScanThreads = (int)IntScanThreads.Value;
124-
Properties.Settings.Default.VisualStyle = ChbStyle.Text;
125-
126-
Properties.Settings.Default.MetroColor = CpMetroBrush.Color;
127-
if (IntBorderThickness.Value != null) Properties.Settings.Default.BorderThickness = (int)IntBorderThickness.Value;
128-
Properties.Settings.Default.WindowOpacity = SldOpacity.Value / 100;
129-
Properties.Settings.Default.WindowResizeBorder = SldWindowResize.Value;
130112

131113
Properties.Settings.Default.Save();
132114

@@ -182,6 +164,23 @@ private void SldOpacity_OnValueChanged(object sender, RoutedPropertyChangedEvent
182164
{
183165
Opacity = SldOpacity.Value / 100;
184166
}
167+
168+
/// <summary>
169+
/// Method that is called when the border thickness should change
170+
/// </summary>
171+
/// <param name="sender">The object that called this method</param>
172+
/// <param name="e">The RoutedPropertyChangedEventArgs</param>
173+
private void SldBorderThickness_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
174+
{
175+
try
176+
{
177+
BorderThickness = new Thickness(Properties.Settings.Default.BorderThickness);
178+
}
179+
catch (Exception ex)
180+
{
181+
MessageBox.Show(ex.Message, "Advanced PortChecker", MessageBoxButton.OK, MessageBoxImage.Error);
182+
}
183+
}
185184

186185
/// <summary>
187186
/// Method that is called when the ResizeBorderThickness should change dynamically
@@ -192,5 +191,32 @@ private void SldWindowResize_OnValueChanged(object sender, RoutedPropertyChanged
192191
{
193192
ResizeBorderThickness = new Thickness(SldWindowResize.Value);
194193
}
194+
195+
/// <summary>
196+
/// Method that is called when the visual style is changed by user input
197+
/// </summary>
198+
/// <param name="sender">The object that called this method</param>
199+
/// <param name="e">The SelectionChangedEventArgs</param>
200+
private void ChbStyle_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
201+
{
202+
StyleManager.ChangeStyle(this);
203+
}
204+
205+
/// <summary>
206+
/// Method that is called when the SettingsWindow object is closing
207+
/// </summary>
208+
/// <param name="sender">The object that called this method</param>
209+
/// <param name="e">The CancelEventArgs</param>
210+
private void SettingsWindow_OnClosing(object sender, CancelEventArgs e)
211+
{
212+
try
213+
{
214+
Properties.Settings.Default.Reload();
215+
}
216+
catch (Exception ex)
217+
{
218+
MessageBox.Show(ex.Message, "Advanced PortChecker", MessageBoxButton.OK, MessageBoxImage.Error);
219+
}
220+
}
195221
}
196222
}

0 commit comments

Comments
 (0)