Skip to content

Commit c3509c3

Browse files
committed
Use property change event for settings & Use INotifyPropertyChanged instead
1 parent cdbe45d commit c3509c3

13 files changed

+81
-177
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,27 @@ public string Theme
9696
public string ResultSubFontStyle { get; set; }
9797
public string ResultSubFontWeight { get; set; }
9898
public string ResultSubFontStretch { get; set; }
99-
public string SettingWindowFont { get; set; } = Win32Helper.GetSystemDefaultFont(false);
10099
public bool UseGlyphIcons { get; set; } = true;
101100
public bool UseAnimation { get; set; } = true;
102101
public bool UseSound { get; set; } = true;
103102
public double SoundVolume { get; set; } = 50;
104103
public bool ShowBadges { get; set; } = false;
105104
public bool ShowBadgesGlobalOnly { get; set; } = false;
106105

106+
private string _settingWindowFont { get; set; } = Win32Helper.GetSystemDefaultFont(false);
107+
public string SettingWindowFont
108+
{
109+
get => _settingWindowFont;
110+
set
111+
{
112+
if (_settingWindowFont != value)
113+
{
114+
_settingWindowFont = value;
115+
OnPropertyChanged();
116+
}
117+
}
118+
}
119+
107120
public bool UseClock { get; set; } = true;
108121
public bool UseDate { get; set; } = false;
109122
public string TimeFormat { get; set; } = "hh:mm tt";

Flow.Launcher/CustomQueryHotkeySetting.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
7-
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
87
Title="{DynamicResource customeQueryHotkeyTitle}"
98
Width="530"
109
Background="{DynamicResource PopuBGColor}"
1110
DataContext="{Binding RelativeSource={RelativeSource Self}}"
11+
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1212
Foreground="{DynamicResource PopupTextColor}"
1313
Icon="Images\app.png"
1414
MouseDown="window_MouseDown"

Flow.Launcher/CustomQueryHotkeySetting.xaml.cs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,23 @@
1-
using Flow.Launcher.Helper;
2-
using Flow.Launcher.Infrastructure.UserSettings;
3-
using System.Collections.ObjectModel;
4-
using System.ComponentModel;
1+
using System.Collections.ObjectModel;
52
using System.Linq;
63
using System.Windows;
74
using System.Windows.Input;
85
using System.Windows.Controls;
6+
using Flow.Launcher.Helper;
7+
using Flow.Launcher.Infrastructure.UserSettings;
98

109
namespace Flow.Launcher
1110
{
1211
public partial class CustomQueryHotkeySetting : Window
1312
{
14-
private readonly Settings _settings;
13+
public Settings Settings { get; set; }
14+
1515
private bool update;
1616
private CustomPluginHotkey updateCustomHotkey;
17-
public event PropertyChangedEventHandler PropertyChanged;
18-
19-
public string SettingWindowFont
20-
{
21-
get => _settings.SettingWindowFont;
22-
set
23-
{
24-
if (_settings.SettingWindowFont != value)
25-
{
26-
_settings.SettingWindowFont = value;
27-
OnPropertyChanged(nameof(SettingWindowFont));
28-
}
29-
}
30-
}
31-
32-
protected virtual void OnPropertyChanged(string propertyName)
33-
{
34-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
35-
}
17+
3618
public CustomQueryHotkeySetting(Settings settings)
3719
{
38-
_settings = settings;
20+
Settings = settings;
3921
InitializeComponent();
4022
}
4123

@@ -48,13 +30,13 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
4830
{
4931
if (!update)
5032
{
51-
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
33+
Settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
5234

5335
var pluginHotkey = new CustomPluginHotkey
5436
{
5537
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
5638
};
57-
_settings.CustomPluginHotkeys.Add(pluginHotkey);
39+
Settings.CustomPluginHotkeys.Add(pluginHotkey);
5840

5941
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
6042
}
@@ -73,7 +55,7 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
7355

7456
public void UpdateItem(CustomPluginHotkey item)
7557
{
76-
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
58+
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
7759
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
7860
if (updateCustomHotkey == null)
7961
{

Flow.Launcher/CustomShortcutSetting.xaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Width="530"
88
Background="{DynamicResource PopuBGColor}"
99
DataContext="{Binding RelativeSource={RelativeSource Self}}"
10+
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1011
Foreground="{DynamicResource PopupTextColor}"
1112
Icon="Images\app.png"
1213
ResizeMode="NoResize"
@@ -56,11 +57,11 @@
5657
</Button>
5758
</Grid>
5859
</StackPanel>
59-
<StackPanel Margin="26,0,26,0">
60-
<StackPanel Grid.Row="0" Margin="0,0,0,12">
60+
<StackPanel Margin="26 0 26 0">
61+
<StackPanel Grid.Row="0" Margin="0 0 0 12">
6162
<TextBlock
6263
Grid.Column="0"
63-
Margin="0,0,0,0"
64+
Margin="0 0 0 0"
6465
FontSize="20"
6566
FontWeight="SemiBold"
6667
Text="{DynamicResource customQueryShortcut}"
@@ -73,18 +74,18 @@
7374
TextAlignment="Left"
7475
TextWrapping="WrapWithOverflow" />
7576
<TextBlock
76-
Margin="0,20,0,0"
77+
Margin="0 20 0 0"
7778
FontSize="14"
7879
Text="{DynamicResource customeQueryShortcutGuide}"
7980
TextAlignment="Left"
8081
TextWrapping="WrapWithOverflow" />
8182
<Image
8283
Width="478"
83-
Margin="0,20,0,0"
84+
Margin="0 20 0 0"
8485
Source="/Images/illustration_02.png" />
8586
</StackPanel>
8687

87-
<StackPanel Margin="0,10,0,10" Orientation="Horizontal">
88+
<StackPanel Margin="0 10 0 10" Orientation="Horizontal">
8889
<Grid Width="478">
8990
<Grid.RowDefinitions>
9091
<RowDefinition />
@@ -124,14 +125,14 @@
124125
LastChildFill="True">
125126
<Button
126127
x:Name="btnTestShortcut"
127-
Margin="0,0,10,0"
128-
Padding="10,5,10,5"
128+
Margin="0 0 10 0"
129+
Padding="10 5 10 5"
129130
Click="BtnTestShortcut_OnClick"
130131
Content="{DynamicResource preview}"
131132
DockPanel.Dock="Right" />
132133
<TextBox
133134
x:Name="tbExpand"
134-
Margin="10,0,10,0"
135+
Margin="10 0 10 0"
135136
HorizontalAlignment="Stretch"
136137
VerticalAlignment="Center"
137138
Text="{Binding Value}" />
@@ -142,21 +143,21 @@
142143
</StackPanel>
143144
<Border
144145
Grid.Row="1"
145-
Margin="0,10,0,0"
146+
Margin="0 10 0 0"
146147
Background="{DynamicResource PopupButtonAreaBGColor}"
147148
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
148-
BorderThickness="0,1,0,0">
149+
BorderThickness="0 1 0 0">
149150
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
150151
<Button
151152
x:Name="btnCancel"
152153
MinWidth="140"
153-
Margin="10,0,5,0"
154+
Margin="10 0 5 0"
154155
Click="BtnCancel_OnClick"
155156
Content="{DynamicResource cancel}" />
156157
<Button
157158
x:Name="btnAdd"
158159
MinWidth="140"
159-
Margin="5,0,10,0"
160+
Margin="5 0 10 0"
160161
Click="BtnAdd_OnClick"
161162
Style="{StaticResource AccentButtonStyle}">
162163
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />

Flow.Launcher/CustomShortcutSetting.xaml.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,22 @@
1-
using System;
2-
using System.ComponentModel;
3-
using System.Windows;
1+
using System.Windows;
42
using System.Windows.Input;
3+
using CommunityToolkit.Mvvm.DependencyInjection;
54
using Flow.Launcher.Infrastructure.UserSettings;
65
using Flow.Launcher.SettingPages.ViewModels;
76

87
namespace Flow.Launcher
98
{
109
public partial class CustomShortcutSetting : Window
1110
{
12-
private static readonly Settings _settings = Ioc.Default.GetRequiredService<Settings>();
11+
public Settings Settings { get; set; } = Ioc.Default.GetRequiredService<Settings>();
1312

1413
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
15-
public string Key { get; set; } = String.Empty;
16-
public string Value { get; set; } = String.Empty;
14+
public string Key { get; set; } = string.Empty;
15+
public string Value { get; set; } = string.Empty;
1716
private string originalKey { get; } = null;
1817
private string originalValue { get; } = null;
1918
private bool update { get; } = false;
20-
public event PropertyChangedEventHandler PropertyChanged;
21-
22-
public string SettingWindowFont
23-
{
24-
get => _settings.SettingWindowFont;
25-
set
26-
{
27-
if (_settings.SettingWindowFont != value)
28-
{
29-
_settings.SettingWindowFont = value;
30-
OnPropertyChanged(nameof(SettingWindowFont));
31-
}
32-
}
33-
}
34-
35-
protected virtual void OnPropertyChanged(string propertyName)
36-
{
37-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
38-
}
19+
3920
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
4021
{
4122
_hotkeyVm = vm;

Flow.Launcher/SelectBrowserWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Width="550"
1111
Background="{DynamicResource PopuBGColor}"
1212
DataContext="{Binding RelativeSource={RelativeSource Self}}"
13-
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
13+
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1414
Foreground="{DynamicResource PopupTextColor}"
1515
ResizeMode="NoResize"
1616
SizeToContent="Height"

Flow.Launcher/SelectBrowserWindow.xaml.cs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,25 @@
1-
using Flow.Launcher.Infrastructure.UserSettings;
2-
using System;
3-
using System.Collections.ObjectModel;
4-
using System.ComponentModel;
1+
using System.Collections.ObjectModel;
52
using System.Linq;
63
using System.Windows;
74
using System.Windows.Controls;
5+
using CommunityToolkit.Mvvm.ComponentModel;
6+
using Flow.Launcher.Infrastructure.UserSettings;
87

98
namespace Flow.Launcher
109
{
11-
public partial class SelectBrowserWindow : Window, INotifyPropertyChanged
10+
[INotifyPropertyChanged]
11+
public partial class SelectBrowserWindow : Window
1212
{
13-
private int selectedCustomBrowserIndex;
13+
public Settings Settings { get; }
1414

15-
public event PropertyChangedEventHandler PropertyChanged;
15+
private int selectedCustomBrowserIndex;
1616

17-
public Settings Settings { get; }
18-
public string SettingWindowFont
19-
{
20-
get => Settings.SettingWindowFont;
21-
set
22-
{
23-
if (Settings.SettingWindowFont != value)
24-
{
25-
Settings.SettingWindowFont = value;
26-
OnPropertyChanged(nameof(SettingWindowFont));
27-
}
28-
}
29-
}
30-
protected virtual void OnPropertyChanged(string propertyName)
31-
{
32-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
33-
}
3417
public int SelectedCustomBrowserIndex
3518
{
3619
get => selectedCustomBrowserIndex; set
3720
{
3821
selectedCustomBrowserIndex = value;
39-
PropertyChanged?.Invoke(this, new(nameof(CustomBrowser)));
22+
OnPropertyChanged(nameof(CustomBrowser));
4023
}
4124
}
4225
public ObservableCollection<CustomBrowserViewModel> CustomBrowsers { get; set; }
@@ -79,8 +62,7 @@ private void btnDelete_Click(object sender, RoutedEventArgs e)
7962
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
8063
{
8164
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
82-
Nullable<bool> result = dlg.ShowDialog();
83-
65+
var result = dlg.ShowDialog();
8466
if (result == true)
8567
{
8668
TextBox path = (TextBox)(((FrameworkElement)sender).Parent as FrameworkElement).FindName("PathTextBox");

Flow.Launcher/SelectFileManagerWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Width="600"
1111
Background="{DynamicResource PopuBGColor}"
1212
DataContext="{Binding RelativeSource={RelativeSource Self}}"
13-
FontFamily="{Binding SettingWindowFont, Mode=TwoWay}"
13+
FontFamily="{Binding Settings.SettingWindowFont, Mode=TwoWay}"
1414
Foreground="{DynamicResource PopupTextColor}"
1515
ResizeMode="NoResize"
1616
SizeToContent="Height"

Flow.Launcher/SelectFileManagerWindow.xaml.cs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,27 @@
1-
using Flow.Launcher.Infrastructure.UserSettings;
2-
using Flow.Launcher.ViewModel;
3-
using System;
4-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
52
using System.ComponentModel;
63
using System.Linq;
74
using System.Windows;
85
using System.Windows.Controls;
6+
using CommunityToolkit.Mvvm.ComponentModel;
7+
using Flow.Launcher.Infrastructure.UserSettings;
8+
using Flow.Launcher.ViewModel;
99

1010
namespace Flow.Launcher
1111
{
12-
public partial class SelectFileManagerWindow : Window, INotifyPropertyChanged
12+
[INotifyPropertyChanged]
13+
public partial class SelectFileManagerWindow : Window
1314
{
14-
private int selectedCustomExplorerIndex;
15-
16-
public event PropertyChangedEventHandler PropertyChanged;
17-
1815
public Settings Settings { get; }
1916

20-
public string SettingWindowFont
21-
{
22-
get => Settings.SettingWindowFont;
23-
set
24-
{
25-
if (Settings.SettingWindowFont != value)
26-
{
27-
Settings.SettingWindowFont = value;
28-
OnPropertyChanged(nameof(SettingWindowFont));
29-
}
30-
}
31-
}
32-
protected virtual void OnPropertyChanged(string propertyName)
33-
{
34-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
35-
}
17+
private int selectedCustomExplorerIndex;
18+
3619
public int SelectedCustomExplorerIndex
3720
{
3821
get => selectedCustomExplorerIndex; set
3922
{
4023
selectedCustomExplorerIndex = value;
41-
PropertyChanged?.Invoke(this, new(nameof(CustomExplorer)));
24+
OnPropertyChanged(nameof(CustomExplorer));
4225
}
4326
}
4427
public ObservableCollection<CustomExplorerViewModel> CustomExplorers { get; set; }
@@ -81,8 +64,7 @@ private void btnDelete_Click(object sender, RoutedEventArgs e)
8164
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
8265
{
8366
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
84-
Nullable<bool> result = dlg.ShowDialog();
85-
67+
var result = dlg.ShowDialog();
8668
if (result == true)
8769
{
8870
TextBox path = (TextBox)(((FrameworkElement)sender).Parent as FrameworkElement).FindName("PathTextBox");

0 commit comments

Comments
 (0)