From fd2952b44dd6df8b9573e17a7265f3df8baed4d6 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sat, 7 Jun 2025 13:52:12 +0800 Subject: [PATCH] Improve code quality --- .../Helper/PathHelper.cs | 3 +- .../Views/QuickAccessLinkSettings.xaml.cs | 34 +++++-------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Helper/PathHelper.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Helper/PathHelper.cs index 36b098d1e..7763d9662 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Helper/PathHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Helper/PathHelper.cs @@ -9,7 +9,7 @@ public static class PathHelper { public static string GetPathName(this string selectedPath) { - if (string.IsNullOrEmpty(selectedPath)) return ""; + if (string.IsNullOrEmpty(selectedPath)) return string.Empty; var path = selectedPath.EndsWith(Constants.DirectorySeparator) ? selectedPath[0..^1] : selectedPath; if (path.EndsWith(':')) @@ -18,5 +18,4 @@ public static class PathHelper return path.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) .Last(); } - } diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs index 388fc2c91..3648a86f9 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/QuickAccessLinkSettings.xaml.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; @@ -8,15 +7,12 @@ using System.Windows; using System.Windows.Forms; using Flow.Launcher.Plugin.Explorer.Helper; using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks; -using JetBrains.Annotations; namespace Flow.Launcher.Plugin.Explorer.Views; public partial class QuickAccessLinkSettings : INotifyPropertyChanged { - private string _selectedPath; - public string SelectedPath { get => _selectedPath; @@ -26,20 +22,20 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged { _selectedPath = value; OnPropertyChanged(); - if (string.IsNullOrEmpty(_selectedName)) SelectedName = _selectedPath.GetPathName(); + if (string.IsNullOrEmpty(_selectedName)) + { + SelectedName = _selectedPath.GetPathName(); + } } } } - private string _selectedName; - public string SelectedName { get { - if (string.IsNullOrEmpty(_selectedName)) return _selectedPath.GetPathName(); - return _selectedName; + return string.IsNullOrEmpty(_selectedName) ? _selectedPath.GetPathName() : _selectedName; } set { @@ -52,7 +48,7 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged } private bool IsEdit { get; set; } - [CanBeNull] private AccessLink SelectedAccessLink { get; } + private AccessLink SelectedAccessLink { get; } public ObservableCollection QuickAccessLinks { get; } @@ -62,7 +58,7 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged InitializeComponent(); } - public QuickAccessLinkSettings(ObservableCollection quickAccessLinks,AccessLink selectedAccessLink) + public QuickAccessLinkSettings(ObservableCollection quickAccessLinks, AccessLink selectedAccessLink) { IsEdit = true; _selectedName = selectedAccessLink.Name; @@ -72,15 +68,12 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged InitializeComponent(); } - - private void BtnCancel_OnClick(object sender, RoutedEventArgs e) { DialogResult = false; Close(); } - private void OnDoneButtonClick(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(SelectedName) || string.IsNullOrEmpty(SelectedPath)) @@ -121,7 +114,7 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged private void EditAccessLink() { - if (SelectedAccessLink == null)throw new ArgumentException("Access Link object is null"); + if (SelectedAccessLink == null) throw new ArgumentException("Access Link object is null"); var index = QuickAccessLinks.IndexOf(SelectedAccessLink); if (index >= 0) @@ -134,19 +127,10 @@ public partial class QuickAccessLinkSettings : INotifyPropertyChanged Close(); } -public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - - protected bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) - { - if (EqualityComparer.Default.Equals(field, value)) return false; - field = value; - OnPropertyChanged(propertyName); - return true; - } } -