Skip to content

Commit b18d0a8

Browse files
committed
Improve code quality
1 parent 054ee4c commit b18d0a8

File tree

5 files changed

+18
-60
lines changed

5 files changed

+18
-60
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/ViewModels/ActionKeywordModel.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
using System.ComponentModel;
2-
using System.Runtime.CompilerServices;
1+
#nullable enable
32

4-
#nullable enable
5-
6-
namespace Flow.Launcher.Plugin.Explorer.Views
3+
namespace Flow.Launcher.Plugin.Explorer.ViewModels
74
{
8-
public class ActionKeywordModel : INotifyPropertyChanged
5+
public partial class ActionKeywordModel : BaseModel
96
{
107
private static Settings _settings = null!;
118

12-
public event PropertyChangedEventHandler? PropertyChanged;
13-
149
public static void Init(Settings settings)
1510
{
1611
_settings = settings;
@@ -28,13 +23,7 @@ internal ActionKeywordModel(Settings.ActionKeyword actionKeyword, string descrip
2823

2924
internal Settings.ActionKeyword KeywordProperty { get; }
3025

31-
private void OnPropertyChanged([CallerMemberName] string propertyName = "")
32-
{
33-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
34-
}
35-
3626
private string? keyword;
37-
3827
public string Keyword
3928
{
4029
get => keyword ??= _settings.GetActionKeyword(KeywordProperty);
@@ -45,8 +34,8 @@ public string Keyword
4534
OnPropertyChanged();
4635
}
4736
}
48-
private bool? enabled;
4937

38+
private bool? enabled;
5039
public bool Enabled
5140
{
5241
get => enabled ??= _settings.GetActionKeywordEnabled(KeywordProperty);

Plugins/Flow.Launcher.Plugin.Explorer/Views/ActionKeywordSetting.xaml.cs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using System.Collections.Generic;
2-
using System.ComponentModel;
3-
using System.Linq;
4-
using System.Runtime.CompilerServices;
1+
using System.Linq;
52
using System.Windows;
63
using System.Windows.Input;
4+
using CommunityToolkit.Mvvm.ComponentModel;
5+
using Flow.Launcher.Plugin.Explorer.ViewModels;
76

87
namespace Flow.Launcher.Plugin.Explorer.Views
98
{
10-
/// <summary>
11-
/// Interaction logic for ActionKeywordSetting.xaml
12-
/// </summary>
13-
public partial class ActionKeywordSetting : INotifyPropertyChanged
9+
[INotifyPropertyChanged]
10+
public partial class ActionKeywordSetting
1411
{
1512
private ActionKeywordModel CurrentActionKeyword { get; }
1613

@@ -21,14 +18,14 @@ public string ActionKeyword
2118
{
2219
// Set Enable to be true if user change ActionKeyword
2320
KeywordEnabled = true;
24-
_ = SetField(ref actionKeyword, value);
21+
_ = SetProperty(ref actionKeyword, value);
2522
}
2623
}
2724

2825
public bool KeywordEnabled
2926
{
3027
get => _keywordEnabled;
31-
set => SetField(ref _keywordEnabled, value);
28+
set => _ = SetProperty(ref _keywordEnabled, value);
3229
}
3330

3431
private string actionKeyword;
@@ -116,20 +113,5 @@ private void TextBox_Pasting(object sender, DataObjectPastingEventArgs e)
116113
e.CancelCommand();
117114
}
118115
}
119-
120-
public event PropertyChangedEventHandler PropertyChanged;
121-
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
122-
{
123-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
124-
}
125-
126-
private bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
127-
{
128-
if (EqualityComparer<T>.Default.Equals(field, value))
129-
return false;
130-
field = value;
131-
OnPropertyChanged(propertyName);
132-
return true;
133-
}
134116
}
135117
}

Plugins/Flow.Launcher.Plugin.Explorer/Views/ExplorerSettings.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
xmlns:qa="clr-namespace:Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks"
99
xmlns:ui="http://schemas.modernwpf.com/2019"
1010
xmlns:viewModels="clr-namespace:Flow.Launcher.Plugin.Explorer.ViewModels"
11-
xmlns:views="clr-namespace:Flow.Launcher.Plugin.Explorer.Views"
1211
d:DataContext="{d:DesignInstance viewModels:SettingsViewModel}"
1312
d:DesignHeight="450"
1413
d:DesignWidth="800"
@@ -18,7 +17,7 @@
1817
<DataTemplate x:Key="ListViewTemplateAccessLinks" DataType="qa:AccessLink">
1918
<TextBlock Margin="0 5 0 5" Text="{Binding Path, Mode=OneTime}" />
2019
</DataTemplate>
21-
<DataTemplate x:Key="ListViewActionKeywords" DataType="{x:Type views:ActionKeywordModel}">
20+
<DataTemplate x:Key="ListViewActionKeywords" DataType="{x:Type viewModels:ActionKeywordModel}">
2221
<Grid>
2322
<TextBlock
2423
Margin="0 5 0 0"

Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
using System.Globalization;
44
using System.IO;
55
using System.Linq;
6-
using System.Runtime.CompilerServices;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using System.Windows;
109
using System.Windows.Controls;
1110
using System.Windows.Media;
1211
using System.Windows.Media.Imaging;
1312
using Flow.Launcher.Plugin.Explorer.Search;
13+
using CommunityToolkit.Mvvm.ComponentModel;
1414

1515
namespace Flow.Launcher.Plugin.Explorer.Views;
1616

1717
#nullable enable
1818

19-
public partial class PreviewPanel : UserControl, INotifyPropertyChanged
19+
[INotifyPropertyChanged]
20+
public partial class PreviewPanel : UserControl
2021
{
2122
private static readonly string ClassName = nameof(PreviewPanel);
2223

@@ -327,11 +328,4 @@ private static string GetFileAge(DateTime fileDateTime)
327328
return yearsDiff == 1 ? Main.Context.API.GetTranslation("OneYearAgo") :
328329
string.Format(Main.Context.API.GetTranslation("YearsAgo"), yearsDiff);
329330
}
330-
331-
public event PropertyChangedEventHandler? PropertyChanged;
332-
333-
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
334-
{
335-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
336-
}
337331
}

Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
using System.Collections.ObjectModel;
33
using System.ComponentModel;
44
using System.Linq;
5-
using System.Runtime.CompilerServices;
65
using System.Windows;
76
using System.Windows.Forms;
87
using Flow.Launcher.Plugin.Explorer.Helper;
98
using Flow.Launcher.Plugin.Explorer.Search;
109
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
10+
using CommunityToolkit.Mvvm.ComponentModel;
1111

1212
namespace Flow.Launcher.Plugin.Explorer.Views;
1313

14-
public partial class QuickAccessLinkSettings : INotifyPropertyChanged
14+
[INotifyPropertyChanged]
15+
public partial class QuickAccessLinkSettings
1516
{
1617
private string _selectedPath;
1718
public string SelectedPath
@@ -207,11 +208,4 @@ private static ResultType GetResultType(string path)
207208
return ResultType.Folder;
208209
}
209210
}
210-
211-
public event PropertyChangedEventHandler PropertyChanged;
212-
213-
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
214-
{
215-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
216-
}
217211
}

0 commit comments

Comments
 (0)