Skip to content

Commit 3f0641a

Browse files
committed
Add settings control
1 parent 0ddaea3 commit 3f0641a

File tree

6 files changed

+91
-6
lines changed

6 files changed

+91
-6
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:system="clr-namespace:System;assembly=mscorlib">
1+
<ResourceDictionary
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:system="clr-namespace:System;assembly=mscorlib">
45

56
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_name">Process Killer</system:String>
67
<system:String x:Key="flowlauncher_plugin_processkiller_plugin_description">Kill running processes from Flow Launcher</system:String>
@@ -9,4 +10,6 @@
910
<system:String x:Key="flowlauncher_plugin_processkiller_kill_all_count">kill {0} processes</system:String>
1011
<system:String x:Key="flowlauncher_plugin_processkiller_kill_instances">kill all instances</system:String>
1112

13+
<system:String x:Key="flowlauncher_plugin_processkiller_put_visible_window_process_top">Put processes with visible windows on the top</system:String>
14+
1215
</ResourceDictionary>

Plugins/Flow.Launcher.Plugin.ProcessKiller/Main.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Windows.Controls;
5+
using Flow.Launcher.Plugin.ProcessKiller.ViewModels;
6+
using Flow.Launcher.Plugin.ProcessKiller.Views;
47

58
namespace Flow.Launcher.Plugin.ProcessKiller
69
{
7-
public class Main : IPlugin, IPluginI18n, IContextMenu
10+
public class Main : IPlugin, IPluginI18n, IContextMenu, ISettingProvider
811
{
912
private readonly ProcessHelper processHelper = new();
1013

1114
private static PluginInitContext _context;
1215

16+
internal Settings Settings;
17+
18+
private SettingsViewModel _viewModel;
19+
1320
public void Init(PluginInitContext context)
1421
{
1522
_context = context;
23+
Settings = context.API.LoadSettingJsonStorage<Settings>();
24+
_viewModel = new SettingsViewModel(Settings);
1625
}
1726

1827
public List<Result> Query(Query query)
@@ -83,7 +92,7 @@ private List<Result> CreateResultsFromQuery(Query query)
8392
{
8493
// Add score to prioritize processes with visible windows
8594
// And use window title for those processes
86-
processlist.Add(new ProcessResult(p, 200, windowTitle, null, progressNameIdTitle));
95+
processlist.Add(new ProcessResult(p, Settings.PutVisibleWindowProcessesTop ? 200 : 0, windowTitle, null, progressNameIdTitle));
8796
}
8897
else
8998
{
@@ -107,7 +116,10 @@ private List<Result> CreateResultsFromQuery(Query query)
107116
{
108117
// Add score to prioritize processes with visible windows
109118
// And use window title for those processes
110-
score += 200;
119+
if (Settings.PutVisibleWindowProcessesTop)
120+
{
121+
score += 200;
122+
}
111123
processlist.Add(new ProcessResult(p, score, windowTitle,
112124
score == windowTitleMatch.Score ? windowTitleMatch : null, progressNameIdTitle));
113125
}
@@ -176,5 +188,10 @@ private List<Result> CreateResultsFromQuery(Query query)
176188

177189
return sortedResults;
178190
}
191+
192+
public Control CreateSettingPanel()
193+
{
194+
return new SettingsControl(_viewModel);
195+
}
179196
}
180197
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Flow.Launcher.Plugin.ProcessKiller
2+
{
3+
public class Settings
4+
{
5+
public bool PutVisibleWindowProcessesTop { get; set; } = false;
6+
}
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Flow.Launcher.Plugin.ProcessKiller.ViewModels
2+
{
3+
public class SettingsViewModel
4+
{
5+
public Settings Settings { get; set; }
6+
7+
public SettingsViewModel(Settings settings)
8+
{
9+
Settings = settings;
10+
}
11+
12+
public bool PutVisibleWindowProcessesTop
13+
{
14+
get => Settings.PutVisibleWindowProcessesTop;
15+
set => Settings.PutVisibleWindowProcessesTop = value;
16+
}
17+
}
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<UserControl
2+
x:Class="Flow.Launcher.Plugin.ProcessKiller.Views.SettingsControl"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
d:DesignHeight="300"
8+
d:DesignWidth="500"
9+
mc:Ignorable="d">
10+
11+
<Grid Margin="{StaticResource SettingPanelMargin}">
12+
<Grid.ColumnDefinitions />
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="auto" />
15+
</Grid.RowDefinitions>
16+
<CheckBox
17+
Grid.Row="0"
18+
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
19+
Content="{DynamicResource flowlauncher_plugin_processkiller_put_visible_window_process_top}"
20+
IsChecked="{Binding PutVisibleWindowProcessesTop}" />
21+
</Grid>
22+
</UserControl>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Windows.Controls;
2+
using Flow.Launcher.Plugin.ProcessKiller.ViewModels;
3+
4+
namespace Flow.Launcher.Plugin.ProcessKiller.Views;
5+
6+
public partial class SettingsControl : UserControl
7+
{
8+
private readonly SettingsViewModel _viewModel;
9+
10+
public SettingsControl(SettingsViewModel viewModel)
11+
{
12+
InitializeComponent();
13+
14+
_viewModel = viewModel;
15+
16+
DataContext = viewModel;
17+
}
18+
}

0 commit comments

Comments
 (0)