Improve code quality

This commit is contained in:
Jack251970 2025-06-17 16:55:23 +08:00
parent 054ee4cdbe
commit b18d0a8bdb
5 changed files with 18 additions and 60 deletions

View file

@ -1,16 +1,11 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
#nullable enable
#nullable enable
namespace Flow.Launcher.Plugin.Explorer.Views
namespace Flow.Launcher.Plugin.Explorer.ViewModels
{
public class ActionKeywordModel : INotifyPropertyChanged
public partial class ActionKeywordModel : BaseModel
{
private static Settings _settings = null!;
public event PropertyChangedEventHandler? PropertyChanged;
public static void Init(Settings settings)
{
_settings = settings;
@ -28,13 +23,7 @@ namespace Flow.Launcher.Plugin.Explorer.Views
internal Settings.ActionKeyword KeywordProperty { get; }
private void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string? keyword;
public string Keyword
{
get => keyword ??= _settings.GetActionKeyword(KeywordProperty);
@ -45,8 +34,8 @@ namespace Flow.Launcher.Plugin.Explorer.Views
OnPropertyChanged();
}
}
private bool? enabled;
private bool? enabled;
public bool Enabled
{
get => enabled ??= _settings.GetActionKeywordEnabled(KeywordProperty);

View file

@ -1,16 +1,13 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using Flow.Launcher.Plugin.Explorer.ViewModels;
namespace Flow.Launcher.Plugin.Explorer.Views
{
/// <summary>
/// Interaction logic for ActionKeywordSetting.xaml
/// </summary>
public partial class ActionKeywordSetting : INotifyPropertyChanged
[INotifyPropertyChanged]
public partial class ActionKeywordSetting
{
private ActionKeywordModel CurrentActionKeyword { get; }
@ -21,14 +18,14 @@ namespace Flow.Launcher.Plugin.Explorer.Views
{
// Set Enable to be true if user change ActionKeyword
KeywordEnabled = true;
_ = SetField(ref actionKeyword, value);
_ = SetProperty(ref actionKeyword, value);
}
}
public bool KeywordEnabled
{
get => _keywordEnabled;
set => SetField(ref _keywordEnabled, value);
set => _ = SetProperty(ref _keywordEnabled, value);
}
private string actionKeyword;
@ -116,20 +113,5 @@ namespace Flow.Launcher.Plugin.Explorer.Views
e.CancelCommand();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value))
return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
}

View file

@ -8,7 +8,6 @@
xmlns:qa="clr-namespace:Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:viewModels="clr-namespace:Flow.Launcher.Plugin.Explorer.ViewModels"
xmlns:views="clr-namespace:Flow.Launcher.Plugin.Explorer.Views"
d:DataContext="{d:DesignInstance viewModels:SettingsViewModel}"
d:DesignHeight="450"
d:DesignWidth="800"
@ -18,7 +17,7 @@
<DataTemplate x:Key="ListViewTemplateAccessLinks" DataType="qa:AccessLink">
<TextBlock Margin="0 5 0 5" Text="{Binding Path, Mode=OneTime}" />
</DataTemplate>
<DataTemplate x:Key="ListViewActionKeywords" DataType="{x:Type views:ActionKeywordModel}">
<DataTemplate x:Key="ListViewActionKeywords" DataType="{x:Type viewModels:ActionKeywordModel}">
<Grid>
<TextBlock
Margin="0 5 0 0"

View file

@ -3,7 +3,6 @@ using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@ -11,12 +10,14 @@ using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Flow.Launcher.Plugin.Explorer.Search;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Flow.Launcher.Plugin.Explorer.Views;
#nullable enable
public partial class PreviewPanel : UserControl, INotifyPropertyChanged
[INotifyPropertyChanged]
public partial class PreviewPanel : UserControl
{
private static readonly string ClassName = nameof(PreviewPanel);
@ -327,11 +328,4 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged
return yearsDiff == 1 ? Main.Context.API.GetTranslation("OneYearAgo") :
string.Format(Main.Context.API.GetTranslation("YearsAgo"), yearsDiff);
}
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

View file

@ -2,16 +2,17 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Forms;
using Flow.Launcher.Plugin.Explorer.Helper;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Flow.Launcher.Plugin.Explorer.Views;
public partial class QuickAccessLinkSettings : INotifyPropertyChanged
[INotifyPropertyChanged]
public partial class QuickAccessLinkSettings
{
private string _selectedPath;
public string SelectedPath
@ -207,11 +208,4 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged
return ResultType.Folder;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}