Flow.Launcher/Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs

191 lines
5.7 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
2025-04-07 03:23:50 +00:00
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using Flow.Launcher.Core.Plugin;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.ViewModel;
2025-04-07 03:23:50 +00:00
using ModernWpf.Controls;
#nullable enable
namespace Flow.Launcher.SettingPages.ViewModels;
2025-04-07 03:23:50 +00:00
public partial class SettingsPanePluginsViewModel : BaseModel
{
private readonly Settings _settings;
2025-04-07 04:51:27 +00:00
public class DisplayModeData : DropdownDataGeneric<DisplayMode> { }
public List<DisplayModeData> DisplayModes { get; } =
DropdownDataGeneric<DisplayMode>.GetValues<DisplayModeData>("DisplayMode");
private DisplayMode _selectedDisplayMode = DisplayMode.OnOff;
public DisplayMode SelectedDisplayMode
2025-04-04 16:46:47 +00:00
{
get => _selectedDisplayMode;
set
{
if (_selectedDisplayMode != value)
{
_selectedDisplayMode = value;
2025-04-07 04:51:27 +00:00
OnPropertyChanged();
2025-04-04 16:46:47 +00:00
UpdateDisplayModeFromSelection();
}
}
}
2025-03-31 13:44:46 +00:00
private bool _isOnOffSelected = true;
public bool IsOnOffSelected
{
get => _isOnOffSelected;
set
{
if (_isOnOffSelected != value)
{
_isOnOffSelected = value;
2025-04-07 04:51:27 +00:00
OnPropertyChanged();
2025-03-31 13:44:46 +00:00
}
}
}
private bool _isPrioritySelected;
public bool IsPrioritySelected
{
get => _isPrioritySelected;
set
{
if (_isPrioritySelected != value)
{
_isPrioritySelected = value;
2025-04-07 04:51:27 +00:00
OnPropertyChanged();
2025-03-31 13:44:46 +00:00
}
}
}
private bool _isSearchDelaySelected;
public bool IsSearchDelaySelected
{
get => _isSearchDelaySelected;
set
{
if (_isSearchDelaySelected != value)
{
_isSearchDelaySelected = value;
2025-04-07 04:51:27 +00:00
OnPropertyChanged();
2025-03-31 13:44:46 +00:00
}
}
}
public SettingsPanePluginsViewModel(Settings settings)
{
_settings = settings;
2025-04-07 04:51:27 +00:00
UpdateEnumDropdownLocalizations();
}
public string FilterText { get; set; } = string.Empty;
public PluginViewModel? SelectedPlugin { get; set; }
private IEnumerable<PluginViewModel>? _pluginViewModels;
private IEnumerable<PluginViewModel> PluginViewModels => _pluginViewModels ??= PluginManager.AllPlugins
.OrderBy(plugin => plugin.Metadata.Disabled)
.ThenBy(plugin => plugin.Metadata.Name)
.Select(plugin => new PluginViewModel
{
PluginPair = plugin,
2025-03-30 05:59:06 +00:00
PluginSettingsObject = _settings.PluginSettings.GetPluginSettings(plugin.Metadata.ID)
})
2025-03-30 05:59:06 +00:00
.Where(plugin => plugin.PluginSettingsObject != null)
.ToList();
public List<PluginViewModel> FilteredPluginViewModels => PluginViewModels
.Where(v =>
string.IsNullOrEmpty(FilterText) ||
2025-04-09 05:05:43 +00:00
App.API.FuzzySearch(FilterText, v.PluginPair.Metadata.Name).IsSearchPrecisionScoreMet() ||
App.API.FuzzySearch(FilterText, v.PluginPair.Metadata.Description).IsSearchPrecisionScoreMet()
)
.ToList();
2025-04-07 03:23:50 +00:00
[RelayCommand]
2025-04-15 04:21:56 +00:00
private async Task OpenHelperAsync(Button button)
2025-04-07 03:23:50 +00:00
{
var helpDialog = new ContentDialog()
{
2025-04-15 04:21:56 +00:00
Owner = Window.GetWindow(button),
2025-04-07 03:23:50 +00:00
Content = new StackPanel
{
Children =
{
new TextBlock
{
Text = (string)Application.Current.Resources["priority"],
2025-04-07 03:23:50 +00:00
FontSize = 18,
Margin = new Thickness(0, 0, 0, 10),
TextWrapping = TextWrapping.Wrap
},
new TextBlock
{
Text = (string)Application.Current.Resources["priority_tips"],
TextWrapping = TextWrapping.Wrap
},
new TextBlock
{
Text = (string)Application.Current.Resources["searchDelay"],
2025-04-07 03:23:50 +00:00
FontSize = 18,
Margin = new Thickness(0, 24, 0, 10),
TextWrapping = TextWrapping.Wrap
},
new TextBlock
{
2025-04-07 06:26:35 +00:00
Text = (string)Application.Current.Resources["searchDelayTimeTips"],
2025-04-07 03:23:50 +00:00
TextWrapping = TextWrapping.Wrap
}
}
},
PrimaryButtonText = (string)Application.Current.Resources["commonOK"],
CornerRadius = new CornerRadius(8),
Style = (Style)Application.Current.Resources["ContentDialog"]
};
await helpDialog.ShowAsync();
}
2025-04-07 04:51:27 +00:00
private void UpdateEnumDropdownLocalizations()
{
DropdownDataGeneric<DisplayMode>.UpdateLabels(DisplayModes);
}
private void UpdateDisplayModeFromSelection()
{
switch (SelectedDisplayMode)
{
case DisplayMode.Priority:
IsOnOffSelected = false;
IsPrioritySelected = true;
IsSearchDelaySelected = false;
break;
case DisplayMode.SearchDelay:
IsOnOffSelected = false;
IsPrioritySelected = false;
IsSearchDelaySelected = true;
break;
default:
IsOnOffSelected = true;
IsPrioritySelected = false;
IsSearchDelaySelected = false;
break;
}
}
}
public enum DisplayMode
{
OnOff,
Priority,
SearchDelay
}