mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Remove mvvm command for code quality
This commit is contained in:
parent
83fa654e27
commit
81007f79ae
5 changed files with 24 additions and 94 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<!-- 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.Linq.Async" Version="6.0.1" />
|
||||
<PackageReference Include="tlbimp-Microsoft.Search.Interop" Version="1.0.0" />
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,4 @@
|
|||
#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.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
|
@ -13,11 +8,16 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Windows;
|
||||
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
|
||||
{
|
||||
public class SettingsViewModel : BaseModel
|
||||
public partial class SettingsViewModel : BaseModel
|
||||
{
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
|
|
@ -36,7 +36,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
InitializeActionKeywordModels();
|
||||
}
|
||||
|
||||
|
||||
public void Save()
|
||||
{
|
||||
Context.API.SaveSettingJsonStorage<Settings>();
|
||||
|
|
@ -48,7 +47,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
private EnumBindingModel<Settings.ContentIndexSearchEngineOption> _selectedContentSearchEngine;
|
||||
private EnumBindingModel<Settings.PathEnumerationEngineOption> _selectedPathEnumerationEngine;
|
||||
|
||||
|
||||
public EnumBindingModel<Settings.IndexSearchEngineOption> SelectedIndexSearchEngine
|
||||
{
|
||||
get => _selectedIndexSearchEngine;
|
||||
|
|
@ -261,8 +259,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
|
||||
public ActionKeywordModel? SelectedActionKeyword { get; set; }
|
||||
|
||||
public ICommand EditActionKeywordCommand => new RelayCommand(EditActionKeyword);
|
||||
|
||||
[RelayCommand]
|
||||
private void EditActionKeyword(object obj)
|
||||
{
|
||||
if (SelectedActionKeyword is not { } actionKeyword)
|
||||
|
|
@ -307,12 +304,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
public AccessLink? SelectedQuickAccessLink { 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)
|
||||
{
|
||||
var container = containerName switch
|
||||
|
|
@ -324,6 +315,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
container.Add(link);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void EditLink(object commandParameter)
|
||||
{
|
||||
var (selectedLink, collection) = commandParameter switch
|
||||
|
|
@ -360,7 +352,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
Context.API.ShowMsgBox(warning);
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
private void AddLink(object commandParameter)
|
||||
{
|
||||
var container = commandParameter switch
|
||||
|
|
@ -385,6 +377,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
container.Add(newAccessLink);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemoveLink(object obj)
|
||||
{
|
||||
if (obj is not string container) return;
|
||||
|
|
@ -435,7 +428,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
return path;
|
||||
}
|
||||
|
||||
|
||||
internal static void OpenWindowsIndexingOptions()
|
||||
{
|
||||
var psi = new ProcessStartInfo
|
||||
|
|
@ -448,39 +440,35 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
Process.Start(psi);
|
||||
}
|
||||
|
||||
private ICommand? _openFileEditorPathCommand;
|
||||
|
||||
public ICommand OpenFileEditorPath => _openFileEditorPathCommand ??= new RelayCommand(_ =>
|
||||
[RelayCommand]
|
||||
private void OpenFileEditorPath()
|
||||
{
|
||||
var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null);
|
||||
if (path is null)
|
||||
return;
|
||||
|
||||
FileEditorPath = path;
|
||||
});
|
||||
}
|
||||
|
||||
private ICommand? _openFolderEditorPathCommand;
|
||||
|
||||
public ICommand OpenFolderEditorPath => _openFolderEditorPathCommand ??= new RelayCommand(_ =>
|
||||
[RelayCommand]
|
||||
private void OpenFolderEditorPath()
|
||||
{
|
||||
var path = PromptUserSelectPath(ResultType.File, Settings.FolderEditorPath != null ? Path.GetDirectoryName(Settings.FolderEditorPath) : null);
|
||||
if (path is null)
|
||||
return;
|
||||
|
||||
FolderEditorPath = path;
|
||||
});
|
||||
}
|
||||
|
||||
private ICommand? _openShellPathCommand;
|
||||
|
||||
public ICommand OpenShellPath => _openShellPathCommand ??= new RelayCommand(_ =>
|
||||
[RelayCommand]
|
||||
private void OpenShellPath()
|
||||
{
|
||||
var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null);
|
||||
if (path is null)
|
||||
return;
|
||||
|
||||
ShellPath = path;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public string FileEditorPath
|
||||
{
|
||||
|
|
@ -537,7 +525,6 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#region Everything FastSortWarning
|
||||
|
||||
public Visibility FastSortWarningVisibility
|
||||
|
|
@ -593,7 +580,5 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@
|
|||
Margin="{StaticResource SettingPanelItemLeftMargin}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding OpenFileEditorPath}"
|
||||
Command="{Binding OpenFileEditorPathCommand}"
|
||||
Content="{DynamicResource select}" />
|
||||
</StackPanel>
|
||||
|
||||
|
|
@ -272,7 +272,7 @@
|
|||
Margin="{StaticResource SettingPanelItemLeftMargin}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding OpenFolderEditorPath}"
|
||||
Command="{Binding OpenFolderEditorPathCommand}"
|
||||
Content="{DynamicResource select}" />
|
||||
</StackPanel>
|
||||
|
||||
|
|
@ -299,7 +299,7 @@
|
|||
Margin="{StaticResource SettingPanelItemLeftMargin}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
Command="{Binding OpenShellPath}"
|
||||
Command="{Binding OpenShellPathCommand}"
|
||||
Content="{DynamicResource select}" />
|
||||
</StackPanel>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue