Remove mvvm command for code quality

This commit is contained in:
Jack251970 2025-04-15 13:18:06 +08:00
parent 83fa654e27
commit 81007f79ae
5 changed files with 24 additions and 94 deletions

View file

@ -1,29 +0,0 @@
using System;
using System.Windows.Input;
namespace Flow.Launcher.ViewModel
{
public class RelayCommand : ICommand
{
private readonly Action<object> _action;
public RelayCommand(Action<object> action)
{
_action = action;
}
public virtual bool CanExecute(object parameter)
{
return true;
}
#pragma warning disable CS0067 // the event is never used
public event EventHandler CanExecuteChanged;
#pragma warning restore CS0067
public virtual void Execute(object parameter)
{
_action?.Invoke(parameter);
}
}
}

View file

@ -46,6 +46,7 @@
<ItemGroup> <ItemGroup>
<!-- Do not upgrade System.Data.OleDb since we are .Net7.0 --> <!-- Do not upgrade System.Data.OleDb since we are .Net7.0 -->
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="System.Data.OleDb" Version="8.0.1" /> <PackageReference Include="System.Data.OleDb" Version="8.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" /> <PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="tlbimp-Microsoft.Search.Interop" Version="1.0.0" /> <PackageReference Include="tlbimp-Microsoft.Search.Interop" Version="1.0.0" />

View file

@ -1,27 +0,0 @@
using System;
using System.Windows.Input;
namespace Flow.Launcher.Plugin.Explorer.ViewModels
{
internal class RelayCommand : ICommand
{
private Action<object> _action;
public RelayCommand(Action<object> action)
{
_action = action;
}
public virtual bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public virtual void Execute(object parameter)
{
_action?.Invoke(parameter);
}
}
}

View file

@ -1,9 +1,4 @@
#nullable enable #nullable enable
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.Everything;
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Flow.Launcher.Plugin.Explorer.Views;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -13,11 +8,16 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input; using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.Everything;
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Flow.Launcher.Plugin.Explorer.Views;
namespace Flow.Launcher.Plugin.Explorer.ViewModels namespace Flow.Launcher.Plugin.Explorer.ViewModels
{ {
public class SettingsViewModel : BaseModel public partial class SettingsViewModel : BaseModel
{ {
public Settings Settings { get; set; } public Settings Settings { get; set; }
@ -36,7 +36,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
InitializeActionKeywordModels(); InitializeActionKeywordModels();
} }
public void Save() public void Save()
{ {
Context.API.SaveSettingJsonStorage<Settings>(); Context.API.SaveSettingJsonStorage<Settings>();
@ -48,7 +47,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
private EnumBindingModel<Settings.ContentIndexSearchEngineOption> _selectedContentSearchEngine; private EnumBindingModel<Settings.ContentIndexSearchEngineOption> _selectedContentSearchEngine;
private EnumBindingModel<Settings.PathEnumerationEngineOption> _selectedPathEnumerationEngine; private EnumBindingModel<Settings.PathEnumerationEngineOption> _selectedPathEnumerationEngine;
public EnumBindingModel<Settings.IndexSearchEngineOption> SelectedIndexSearchEngine public EnumBindingModel<Settings.IndexSearchEngineOption> SelectedIndexSearchEngine
{ {
get => _selectedIndexSearchEngine; get => _selectedIndexSearchEngine;
@ -261,8 +259,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
public ActionKeywordModel? SelectedActionKeyword { get; set; } public ActionKeywordModel? SelectedActionKeyword { get; set; }
public ICommand EditActionKeywordCommand => new RelayCommand(EditActionKeyword); [RelayCommand]
private void EditActionKeyword(object obj) private void EditActionKeyword(object obj)
{ {
if (SelectedActionKeyword is not { } actionKeyword) if (SelectedActionKeyword is not { } actionKeyword)
@ -307,12 +304,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
public AccessLink? SelectedQuickAccessLink { get; set; } public AccessLink? SelectedQuickAccessLink { get; set; }
public AccessLink? SelectedIndexSearchExcludedPath { get; set; } public AccessLink? SelectedIndexSearchExcludedPath { get; set; }
public ICommand RemoveLinkCommand => new RelayCommand(RemoveLink);
public ICommand EditLinkCommand => new RelayCommand(EditLink);
public ICommand AddLinkCommand => new RelayCommand(AddLink);
public void AppendLink(string containerName, AccessLink link) public void AppendLink(string containerName, AccessLink link)
{ {
var container = containerName switch var container = containerName switch
@ -324,6 +315,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
container.Add(link); container.Add(link);
} }
[RelayCommand]
private void EditLink(object commandParameter) private void EditLink(object commandParameter)
{ {
var (selectedLink, collection) = commandParameter switch var (selectedLink, collection) = commandParameter switch
@ -360,7 +352,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
Context.API.ShowMsgBox(warning); Context.API.ShowMsgBox(warning);
} }
[RelayCommand]
private void AddLink(object commandParameter) private void AddLink(object commandParameter)
{ {
var container = commandParameter switch var container = commandParameter switch
@ -385,6 +377,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
container.Add(newAccessLink); container.Add(newAccessLink);
} }
[RelayCommand]
private void RemoveLink(object obj) private void RemoveLink(object obj)
{ {
if (obj is not string container) return; if (obj is not string container) return;
@ -435,7 +428,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
return path; return path;
} }
internal static void OpenWindowsIndexingOptions() internal static void OpenWindowsIndexingOptions()
{ {
var psi = new ProcessStartInfo var psi = new ProcessStartInfo
@ -448,39 +440,35 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
Process.Start(psi); Process.Start(psi);
} }
private ICommand? _openFileEditorPathCommand; [RelayCommand]
private void OpenFileEditorPath()
public ICommand OpenFileEditorPath => _openFileEditorPathCommand ??= new RelayCommand(_ =>
{ {
var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null); var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null);
if (path is null) if (path is null)
return; return;
FileEditorPath = path; FileEditorPath = path;
}); }
private ICommand? _openFolderEditorPathCommand; [RelayCommand]
private void OpenFolderEditorPath()
public ICommand OpenFolderEditorPath => _openFolderEditorPathCommand ??= new RelayCommand(_ =>
{ {
var path = PromptUserSelectPath(ResultType.File, Settings.FolderEditorPath != null ? Path.GetDirectoryName(Settings.FolderEditorPath) : null); var path = PromptUserSelectPath(ResultType.File, Settings.FolderEditorPath != null ? Path.GetDirectoryName(Settings.FolderEditorPath) : null);
if (path is null) if (path is null)
return; return;
FolderEditorPath = path; FolderEditorPath = path;
}); }
private ICommand? _openShellPathCommand; [RelayCommand]
private void OpenShellPath()
public ICommand OpenShellPath => _openShellPathCommand ??= new RelayCommand(_ =>
{ {
var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null); var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null);
if (path is null) if (path is null)
return; return;
ShellPath = path; ShellPath = path;
}); }
public string FileEditorPath public string FileEditorPath
{ {
@ -537,7 +525,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
} }
} }
#region Everything FastSortWarning #region Everything FastSortWarning
public Visibility FastSortWarningVisibility public Visibility FastSortWarningVisibility
@ -593,7 +580,5 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
} }
#endregion #endregion
} }
} }

View file

@ -245,7 +245,7 @@
Margin="{StaticResource SettingPanelItemLeftMargin}" Margin="{StaticResource SettingPanelItemLeftMargin}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Center" VerticalAlignment="Center"
Command="{Binding OpenFileEditorPath}" Command="{Binding OpenFileEditorPathCommand}"
Content="{DynamicResource select}" /> Content="{DynamicResource select}" />
</StackPanel> </StackPanel>
@ -272,7 +272,7 @@
Margin="{StaticResource SettingPanelItemLeftMargin}" Margin="{StaticResource SettingPanelItemLeftMargin}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Center" VerticalAlignment="Center"
Command="{Binding OpenFolderEditorPath}" Command="{Binding OpenFolderEditorPathCommand}"
Content="{DynamicResource select}" /> Content="{DynamicResource select}" />
</StackPanel> </StackPanel>
@ -299,7 +299,7 @@
Margin="{StaticResource SettingPanelItemLeftMargin}" Margin="{StaticResource SettingPanelItemLeftMargin}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Center" VerticalAlignment="Center"
Command="{Binding OpenShellPath}" Command="{Binding OpenShellPathCommand}"
Content="{DynamicResource select}" /> Content="{DynamicResource select}" />
</StackPanel> </StackPanel>