Skip to content

Commit 81007f7

Browse files
committed
Remove mvvm command for code quality
1 parent 83fa654 commit 81007f7

File tree

5 files changed

+24
-94
lines changed

5 files changed

+24
-94
lines changed

Flow.Launcher/ViewModel/RelayCommand.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

Plugins/Flow.Launcher.Plugin.Explorer/Flow.Launcher.Plugin.Explorer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
<ItemGroup>
4848
<!-- Do not upgrade System.Data.OleDb since we are .Net7.0 -->
49+
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
4950
<PackageReference Include="System.Data.OleDb" Version="8.0.1" />
5051
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
5152
<PackageReference Include="tlbimp-Microsoft.Search.Interop" Version="1.0.0" />

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#nullable enable
2-
using Flow.Launcher.Plugin.Explorer.Search;
3-
using Flow.Launcher.Plugin.Explorer.Search.Everything;
4-
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
5-
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
6-
using Flow.Launcher.Plugin.Explorer.Views;
72
using System;
83
using System.Collections.Generic;
94
using System.Diagnostics;
@@ -13,11 +8,16 @@
138
using System.Linq;
149
using System.Windows;
1510
using System.Windows.Forms;
16-
using System.Windows.Input;
11+
using CommunityToolkit.Mvvm.Input;
12+
using Flow.Launcher.Plugin.Explorer.Search;
13+
using Flow.Launcher.Plugin.Explorer.Search.Everything;
14+
using Flow.Launcher.Plugin.Explorer.Search.Everything.Exceptions;
15+
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
16+
using Flow.Launcher.Plugin.Explorer.Views;
1717

1818
namespace Flow.Launcher.Plugin.Explorer.ViewModels
1919
{
20-
public class SettingsViewModel : BaseModel
20+
public partial class SettingsViewModel : BaseModel
2121
{
2222
public Settings Settings { get; set; }
2323

@@ -36,7 +36,6 @@ public SettingsViewModel(PluginInitContext context, Settings settings)
3636
InitializeActionKeywordModels();
3737
}
3838

39-
4039
public void Save()
4140
{
4241
Context.API.SaveSettingJsonStorage<Settings>();
@@ -48,7 +47,6 @@ public void Save()
4847
private EnumBindingModel<Settings.ContentIndexSearchEngineOption> _selectedContentSearchEngine;
4948
private EnumBindingModel<Settings.PathEnumerationEngineOption> _selectedPathEnumerationEngine;
5049

51-
5250
public EnumBindingModel<Settings.IndexSearchEngineOption> SelectedIndexSearchEngine
5351
{
5452
get => _selectedIndexSearchEngine;
@@ -261,8 +259,7 @@ private void InitializeActionKeywordModels()
261259

262260
public ActionKeywordModel? SelectedActionKeyword { get; set; }
263261

264-
public ICommand EditActionKeywordCommand => new RelayCommand(EditActionKeyword);
265-
262+
[RelayCommand]
266263
private void EditActionKeyword(object obj)
267264
{
268265
if (SelectedActionKeyword is not { } actionKeyword)
@@ -307,12 +304,6 @@ private void EditActionKeyword(object obj)
307304
public AccessLink? SelectedQuickAccessLink { get; set; }
308305
public AccessLink? SelectedIndexSearchExcludedPath { get; set; }
309306

310-
311-
312-
public ICommand RemoveLinkCommand => new RelayCommand(RemoveLink);
313-
public ICommand EditLinkCommand => new RelayCommand(EditLink);
314-
public ICommand AddLinkCommand => new RelayCommand(AddLink);
315-
316307
public void AppendLink(string containerName, AccessLink link)
317308
{
318309
var container = containerName switch
@@ -324,6 +315,7 @@ public void AppendLink(string containerName, AccessLink link)
324315
container.Add(link);
325316
}
326317

318+
[RelayCommand]
327319
private void EditLink(object commandParameter)
328320
{
329321
var (selectedLink, collection) = commandParameter switch
@@ -360,7 +352,7 @@ private void ShowUnselectedMessage()
360352
Context.API.ShowMsgBox(warning);
361353
}
362354

363-
355+
[RelayCommand]
364356
private void AddLink(object commandParameter)
365357
{
366358
var container = commandParameter switch
@@ -385,6 +377,7 @@ private void AddLink(object commandParameter)
385377
container.Add(newAccessLink);
386378
}
387379

380+
[RelayCommand]
388381
private void RemoveLink(object obj)
389382
{
390383
if (obj is not string container) return;
@@ -435,7 +428,6 @@ private void RemoveLink(object obj)
435428
return path;
436429
}
437430

438-
439431
internal static void OpenWindowsIndexingOptions()
440432
{
441433
var psi = new ProcessStartInfo
@@ -448,39 +440,35 @@ internal static void OpenWindowsIndexingOptions()
448440
Process.Start(psi);
449441
}
450442

451-
private ICommand? _openFileEditorPathCommand;
452-
453-
public ICommand OpenFileEditorPath => _openFileEditorPathCommand ??= new RelayCommand(_ =>
443+
[RelayCommand]
444+
private void OpenFileEditorPath()
454445
{
455446
var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null);
456447
if (path is null)
457448
return;
458449

459450
FileEditorPath = path;
460-
});
461-
462-
private ICommand? _openFolderEditorPathCommand;
451+
}
463452

464-
public ICommand OpenFolderEditorPath => _openFolderEditorPathCommand ??= new RelayCommand(_ =>
453+
[RelayCommand]
454+
private void OpenFolderEditorPath()
465455
{
466456
var path = PromptUserSelectPath(ResultType.File, Settings.FolderEditorPath != null ? Path.GetDirectoryName(Settings.FolderEditorPath) : null);
467457
if (path is null)
468458
return;
469459

470460
FolderEditorPath = path;
471-
});
472-
473-
private ICommand? _openShellPathCommand;
461+
}
474462

475-
public ICommand OpenShellPath => _openShellPathCommand ??= new RelayCommand(_ =>
463+
[RelayCommand]
464+
private void OpenShellPath()
476465
{
477466
var path = PromptUserSelectPath(ResultType.File, Settings.EditorPath != null ? Path.GetDirectoryName(Settings.EditorPath) : null);
478467
if (path is null)
479468
return;
480469

481470
ShellPath = path;
482-
});
483-
471+
}
484472

485473
public string FileEditorPath
486474
{
@@ -537,7 +525,6 @@ public int MaxResult
537525
}
538526
}
539527

540-
541528
#region Everything FastSortWarning
542529

543530
public Visibility FastSortWarningVisibility
@@ -593,7 +580,5 @@ public string EverythingInstalledPath
593580
}
594581

595582
#endregion
596-
597-
598583
}
599584
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
Margin="{StaticResource SettingPanelItemLeftMargin}"
246246
HorizontalAlignment="Left"
247247
VerticalAlignment="Center"
248-
Command="{Binding OpenFileEditorPath}"
248+
Command="{Binding OpenFileEditorPathCommand}"
249249
Content="{DynamicResource select}" />
250250
</StackPanel>
251251

@@ -272,7 +272,7 @@
272272
Margin="{StaticResource SettingPanelItemLeftMargin}"
273273
HorizontalAlignment="Left"
274274
VerticalAlignment="Center"
275-
Command="{Binding OpenFolderEditorPath}"
275+
Command="{Binding OpenFolderEditorPathCommand}"
276276
Content="{DynamicResource select}" />
277277
</StackPanel>
278278

@@ -299,7 +299,7 @@
299299
Margin="{StaticResource SettingPanelItemLeftMargin}"
300300
HorizontalAlignment="Left"
301301
VerticalAlignment="Center"
302-
Command="{Binding OpenShellPath}"
302+
Command="{Binding OpenShellPathCommand}"
303303
Content="{DynamicResource select}" />
304304
</StackPanel>
305305

0 commit comments

Comments
 (0)