mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 00:46:12 +02:00
Add plugins search box to main page
This commit is contained in:
@@ -13,6 +13,7 @@ internal class MainWindowDataContext : INotifyPropertyChanged
|
||||
private static DesktopMagicSettings settings = new();
|
||||
|
||||
private bool isLoading = true;
|
||||
private string? pluginsSearchText;
|
||||
|
||||
public string Title =>
|
||||
#if DEBUG
|
||||
@@ -43,6 +44,16 @@ internal class MainWindowDataContext : INotifyPropertyChanged
|
||||
}
|
||||
}
|
||||
|
||||
public string? PluginsSearchText
|
||||
{
|
||||
get => pluginsSearchText;
|
||||
set
|
||||
{
|
||||
pluginsSearchText = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAutoStartEnabled
|
||||
{
|
||||
get => StartupManager.IsAutoStartEnabled();
|
||||
|
||||
@@ -20,11 +20,19 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ui:Card Padding="5" Margin="0 0 0 5">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="10" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:ToggleSwitch x:Name="editCheckBox" Height="30" VerticalAlignment="Center" Margin="5 0 0 0" Content="{DynamicResource editLayout}" Click="EditCheckBox_Click" />
|
||||
<ui:TextBox Grid.Column="2" Text="{Binding PluginsSearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextChanged="AllPluginsSearchTextBox_TextChanged" PlaceholderText="{DynamicResource searchInstalledPlugins}" Icon="{ui:SymbolIcon Search24}" IconPlacement="Right" />
|
||||
</Grid>
|
||||
</ui:Card>
|
||||
|
||||
<ScrollViewer Background="#FFBBBBBB" PreviewMouseWheel="ScrollViewer_PreviewMouseWheel" Grid.Row="1" VerticalAlignment="Stretch" VerticalContentAlignment="Top">
|
||||
<ItemsControl ItemsSource="{Binding Settings.CurrentLayout.Plugins}">
|
||||
<ItemsControl x:Name="pluginsItemsControl" ItemsSource="{Binding Settings.CurrentLayout.Plugins}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ui:CardExpander Tag="{Binding}" Margin="0 0 0 5" Expanded="OptionsCardExpander_Expanded">
|
||||
|
||||
@@ -4,10 +4,12 @@ using DesktopMagic.Helpers;
|
||||
using DesktopMagic.Plugins;
|
||||
using DesktopMagic.Settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DesktopMagic.Pages;
|
||||
|
||||
@@ -56,8 +58,8 @@ public partial class MainPage : Page
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
// Refresh the UI if needed
|
||||
_dataContext.Settings = _manager.Settings;
|
||||
ApplyPluginsFilter();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -107,6 +109,38 @@ public partial class MainPage : Page
|
||||
}
|
||||
}
|
||||
|
||||
#region Plugin Search
|
||||
|
||||
private void AllPluginsSearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
ApplyPluginsFilter();
|
||||
}
|
||||
|
||||
private void ApplyPluginsFilter()
|
||||
{
|
||||
string? searchText = _dataContext.PluginsSearchText;
|
||||
|
||||
System.ComponentModel.ICollectionView view = CollectionViewSource.GetDefaultView(pluginsItemsControl.ItemsSource);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(searchText))
|
||||
{
|
||||
view.Filter = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
view.Filter = (item) =>
|
||||
{
|
||||
if (item is KeyValuePair<uint, PluginSettings> kvp)
|
||||
{
|
||||
return kvp.Value.Metadata.Name.Contains(searchText, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Layout Management
|
||||
|
||||
private void LayoutsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user