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

236 lines
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
}
}
}
2025-05-03 14:34:58 +00:00
private bool _isHomeOnOffSelected;
public bool IsHomeOnOffSelected
{
get => _isHomeOnOffSelected;
set
{
if (_isHomeOnOffSelected != value)
{
_isHomeOnOffSelected = value;
OnPropertyChanged();
}
}
}
public SettingsPanePluginsViewModel(Settings settings)
{
_settings = settings;
2025-04-07 04:51:27 +00:00
UpdateEnumDropdownLocalizations();
}
private string filterText = string.Empty;
public string FilterText
{
get => filterText;
set
{
if (filterText != value)
{
filterText = value;
OnPropertyChanged();
}
}
}
private IList<PluginViewModel>? _pluginViewModels;
public IList<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 bool SatisfiesFilter(PluginViewModel plugin)
{
return string.IsNullOrEmpty(FilterText) ||
App.API.FuzzySearch(FilterText, plugin.PluginPair.Metadata.Name).IsSearchPrecisionScoreMet() ||
App.API.FuzzySearch(FilterText, plugin.PluginPair.Metadata.Description).IsSearchPrecisionScoreMet();
}
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
2025-05-03 14:34:58 +00:00
},
new TextBlock
{
Text = (string)Application.Current.Resources["homeTitle"],
FontSize = 18,
Margin = new Thickness(0, 24, 0, 10),
TextWrapping = TextWrapping.Wrap
},
new TextBlock
{
Text = (string)Application.Current.Resources["homeTips"],
TextWrapping = TextWrapping.Wrap
2025-04-07 03:23:50 +00:00
}
}
},
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;
2025-05-03 14:34:58 +00:00
IsHomeOnOffSelected = false;
2025-04-07 04:51:27 +00:00
break;
case DisplayMode.SearchDelay:
IsOnOffSelected = false;
IsPrioritySelected = false;
IsSearchDelaySelected = true;
2025-05-03 14:34:58 +00:00
IsHomeOnOffSelected = false;
break;
case DisplayMode.HomeOnOff:
IsOnOffSelected = false;
IsPrioritySelected = false;
IsSearchDelaySelected = false;
IsHomeOnOffSelected = true;
2025-04-07 04:51:27 +00:00
break;
default:
IsOnOffSelected = true;
IsPrioritySelected = false;
IsSearchDelaySelected = false;
2025-05-03 14:34:58 +00:00
IsHomeOnOffSelected = false;
2025-04-07 04:51:27 +00:00
break;
}
}
}
public enum DisplayMode
{
OnOff,
Priority,
2025-05-03 14:34:58 +00:00
SearchDelay,
HomeOnOff
}