Add settings control

This commit is contained in:
Jack251970 2025-03-26 15:33:49 +08:00
parent 0ddaea3317
commit 3f0641a583
6 changed files with 91 additions and 6 deletions

View file

@ -1,6 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_name">Process Killer</system:String>
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_description">Kill running processes from Flow Launcher</system:String>
@ -9,4 +10,6 @@
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all_count">kill {0} processes</system:String>
<system:String x:Key="flowlauncher_plugin_processkiller_kill_instances">kill all instances</system:String>
<system:String x:Key="flowlauncher_plugin_processkiller_put_visible_window_process_top">Put processes with visible windows on the top</system:String>
</ResourceDictionary>

View file

@ -1,18 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using Flow.Launcher.Plugin.ProcessKiller.ViewModels;
using Flow.Launcher.Plugin.ProcessKiller.Views;
namespace Flow.Launcher.Plugin.ProcessKiller
{
public class Main : IPlugin, IPluginI18n, IContextMenu
public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
{
private readonly ProcessHelper processHelper = new();
private static PluginInitContext _context;
internal Settings Settings;
private SettingsViewModel _viewModel;
public void Init(PluginInitContext context)
{
_context = context;
Settings = context.API.LoadSettingJsonStorage<Settings>();
_viewModel = new SettingsViewModel(Settings);
}
public List<Result> Query(Query query)
@ -83,7 +92,7 @@ namespace Flow.Launcher.Plugin.ProcessKiller
{
// Add score to prioritize processes with visible windows
// And use window title for those processes
processlist.Add(new ProcessResult(p, 200, windowTitle, null, progressNameIdTitle));
processlist.Add(new ProcessResult(p, Settings.PutVisibleWindowProcessesTop ? 200 : 0, windowTitle, null, progressNameIdTitle));
}
else
{
@ -107,7 +116,10 @@ namespace Flow.Launcher.Plugin.ProcessKiller
{
// Add score to prioritize processes with visible windows
// And use window title for those processes
score += 200;
if (Settings.PutVisibleWindowProcessesTop)
{
score += 200;
}
processlist.Add(new ProcessResult(p, score, windowTitle,
score == windowTitleMatch.Score ? windowTitleMatch : null, progressNameIdTitle));
}
@ -176,5 +188,10 @@ namespace Flow.Launcher.Plugin.ProcessKiller
return sortedResults;
}
public Control CreateSettingPanel()
{
return new SettingsControl(_viewModel);
}
}
}

View file

@ -0,0 +1,7 @@
namespace Flow.Launcher.Plugin.ProcessKiller
{
public class Settings
{
public bool PutVisibleWindowProcessesTop { get; set; } = false;
}
}

View file

@ -0,0 +1,18 @@
namespace Flow.Launcher.Plugin.ProcessKiller.ViewModels
{
public class SettingsViewModel
{
public Settings Settings { get; set; }
public SettingsViewModel(Settings settings)
{
Settings = settings;
}
public bool PutVisibleWindowProcessesTop
{
get => Settings.PutVisibleWindowProcessesTop;
set => Settings.PutVisibleWindowProcessesTop = value;
}
}
}

View file

@ -0,0 +1,22 @@
<UserControl
x:Class="Flow.Launcher.Plugin.ProcessKiller.Views.SettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="500"
mc:Ignorable="d">
<Grid Margin="{StaticResource SettingPanelMargin}">
<Grid.ColumnDefinitions />
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<CheckBox
Grid.Row="0"
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
Content="{DynamicResource flowlauncher_plugin_processkiller_put_visible_window_process_top}"
IsChecked="{Binding PutVisibleWindowProcessesTop}" />
</Grid>
</UserControl>

View file

@ -0,0 +1,18 @@
using System.Windows.Controls;
using Flow.Launcher.Plugin.ProcessKiller.ViewModels;
namespace Flow.Launcher.Plugin.ProcessKiller.Views;
public partial class SettingsControl : UserControl
{
private readonly SettingsViewModel _viewModel;
public SettingsControl(SettingsViewModel viewModel)
{
InitializeComponent();
_viewModel = viewModel;
DataContext = viewModel;
}
}