Skip to content

Commit 8823d5e

Browse files
committed
PluginSettingsWindow: remove InstalledPluginDisplay wrapper; bind directly to PluginViewModel; reuse controls from InstalledPluginDisplay where applicable, add new rows for Enabled/Home/Priority/Search Delay
1 parent 9a6eb36 commit 8823d5e

2 files changed

Lines changed: 209 additions & 33 deletions

File tree

Flow.Launcher/PluginSettingsWindow.xaml

Lines changed: 198 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
x:Class="Flow.Launcher.PluginSettingsWindow"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
5+
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
66
Width="920"
77
Height="320"
88
MinWidth="720"
@@ -22,6 +22,30 @@
2222
<Window.CommandBindings>
2323
<CommandBinding Command="Close" Executed="OnCloseExecuted" />
2424
</Window.CommandBindings>
25+
<Window.Resources>
26+
<Style x:Key="PluginSettingsRowBorderStyle" TargetType="Border">
27+
<Setter Property="BorderBrush" Value="{DynamicResource Color03B}" />
28+
<Setter Property="BorderThickness" Value="0 1 0 0" />
29+
</Style>
30+
<Style
31+
x:Key="PluginSettingsRowLabelStyle"
32+
BasedOn="{StaticResource SettingTitleLabel}"
33+
TargetType="TextBlock">
34+
<Setter Property="Margin" Value="{StaticResource SettingPanelItemRightMargin}" />
35+
<Setter Property="HorizontalAlignment" Value="Left" />
36+
<Setter Property="VerticalAlignment" Value="Center" />
37+
<Setter Property="DockPanel.Dock" Value="Left" />
38+
</Style>
39+
<Style
40+
x:Key="PluginSettingsRowGlyphStyle"
41+
BasedOn="{StaticResource Glyph}"
42+
TargetType="TextBlock">
43+
<Setter Property="Margin" Value="{StaticResource SettingPanelItemRightMargin}" />
44+
<Setter Property="HorizontalAlignment" Value="Left" />
45+
<Setter Property="VerticalAlignment" Value="Center" />
46+
<Setter Property="DockPanel.Dock" Value="Left" />
47+
</Style>
48+
</Window.Resources>
2549

2650
<Grid>
2751
<Border Style="{StaticResource WindowMainPanelStyle}">
@@ -151,26 +175,180 @@
151175
Grid.Row="1"
152176
Grid.Column="0"
153177
Grid.ColumnSpan="5"
154-
Margin="20 8 20 16"
155-
Background="{DynamicResource Color01B}">
156-
<ListBox
157-
x:Name="PluginListBox"
158-
Padding="0 0 7 0"
159-
Background="{DynamicResource Color01B}"
178+
Margin="20 8 20 16">
179+
<ScrollViewer
160180
FontSize="14"
161-
ItemContainerStyle="{DynamicResource PluginList}"
162-
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
163-
SnapsToDevicePixels="True"
164-
Style="{DynamicResource PluginListStyle}"
165-
VirtualizingPanel.ScrollUnit="Pixel"
166-
VirtualizingStackPanel.IsVirtualizing="True"
167-
VirtualizingStackPanel.VirtualizationMode="Recycling">
168-
<ListBox.ItemTemplate>
169-
<DataTemplate>
170-
<cc:InstalledPluginDisplay />
171-
</DataTemplate>
172-
</ListBox.ItemTemplate>
173-
</ListBox>
181+
HorizontalScrollBarVisibility="Disabled"
182+
VerticalScrollBarVisibility="Auto">
183+
<StackPanel Margin="8 0 32 0">
184+
<!-- Plugin header -->
185+
<Border
186+
Margin="0"
187+
Padding="0 12">
188+
<Grid Margin="16 12 18 12">
189+
<Grid.ColumnDefinitions>
190+
<ColumnDefinition Width="36" MinWidth="36" />
191+
<ColumnDefinition Width="*" />
192+
</Grid.ColumnDefinitions>
193+
<Image
194+
Grid.Column="0"
195+
Width="32"
196+
Height="32"
197+
VerticalAlignment="Center"
198+
Source="{Binding Image, Mode=OneWay, IsAsync=True}" />
199+
<StackPanel
200+
Grid.Column="1"
201+
Margin="16 0 0 0"
202+
VerticalAlignment="Center">
203+
<TextBlock
204+
FontSize="15"
205+
FontWeight="SemiBold"
206+
Foreground="{DynamicResource Color05B}"
207+
Text="{Binding PluginPair.Metadata.Name}"
208+
TextWrapping="Wrap"
209+
ToolTip="{Binding PluginPair.Metadata.Version}" />
210+
<TextBlock
211+
Margin="0 2 0 0"
212+
FontSize="12"
213+
Foreground="{DynamicResource Color04B}"
214+
Text="{Binding PluginPair.Metadata.Description}"
215+
TextWrapping="WrapWithOverflow" />
216+
</StackPanel>
217+
</Grid>
218+
</Border>
219+
220+
<Border
221+
Margin="0"
222+
Padding="0"
223+
CornerRadius="5 5 0 0">
224+
<Border.Style>
225+
<Style BasedOn="{StaticResource SettingGroupBox}" TargetType="Border">
226+
<Setter Property="BorderThickness" Value="0" />
227+
<Setter Property="Padding" Value="0" />
228+
<Setter Property="Margin" Value="0" />
229+
</Style>
230+
</Border.Style>
231+
<StackPanel>
232+
<!-- Enabled row -->
233+
<Border Style="{StaticResource PluginSettingsRowBorderStyle}">
234+
<DockPanel Margin="{StaticResource SettingPanelMargin}" LastChildFill="False">
235+
<TextBlock Style="{StaticResource PluginSettingsRowGlyphStyle}">
236+
&#xe7e8;
237+
</TextBlock>
238+
<TextBlock
239+
Style="{StaticResource PluginSettingsRowLabelStyle}"
240+
Text="{DynamicResource DisplayModeOnOff}" />
241+
<ui:ToggleSwitch
242+
DockPanel.Dock="Right"
243+
Margin="0 -8.5 0 -8.5"
244+
IsOn="{Binding PluginState}"
245+
OffContent="{DynamicResource disable}"
246+
OnContent="{DynamicResource enable}" />
247+
</DockPanel>
248+
</Border>
249+
250+
<!-- Home row -->
251+
<Border Style="{StaticResource PluginSettingsRowBorderStyle}">
252+
<DockPanel Margin="{StaticResource SettingPanelMargin}" LastChildFill="False">
253+
<TextBlock Style="{StaticResource PluginSettingsRowGlyphStyle}">
254+
&#xE80F;
255+
</TextBlock>
256+
<TextBlock
257+
Style="{StaticResource PluginSettingsRowLabelStyle}"
258+
Text="{DynamicResource homeTitle}" />
259+
<ui:ToggleSwitch
260+
DockPanel.Dock="Right"
261+
Margin="0 -8.5 0 -8.5"
262+
IsEnabled="{Binding HomeEnabled}"
263+
IsOn="{Binding PluginHomeState}"
264+
OffContent="{DynamicResource disable}"
265+
OnContent="{DynamicResource enable}"
266+
ToolTip="{DynamicResource homeToggleBoxToolTip}" />
267+
</DockPanel>
268+
</Border>
269+
270+
<!-- Priority row -->
271+
<Border Style="{StaticResource PluginSettingsRowBorderStyle}">
272+
<DockPanel Margin="{StaticResource SettingPanelMargin}">
273+
<TextBlock Style="{StaticResource PluginSettingsRowGlyphStyle}">
274+
&#xE74A;
275+
</TextBlock>
276+
<TextBlock
277+
Style="{StaticResource PluginSettingsRowLabelStyle}"
278+
Text="{DynamicResource priority}"
279+
ToolTip="{DynamicResource priorityToolTip}" />
280+
<ui:NumberBox
281+
MinWidth="120"
282+
Margin="0 -4.5 0 -4.5"
283+
HorizontalAlignment="Right"
284+
Maximum="999"
285+
Minimum="-999"
286+
SpinButtonPlacementMode="Inline"
287+
ToolTip="{DynamicResource priorityToolTip}"
288+
Value="{Binding Priority, Mode=TwoWay}"
289+
ValueChanged="NumberBox_OnValueChanged" />
290+
</DockPanel>
291+
</Border>
292+
293+
<!-- Search Delay row -->
294+
<Border Style="{StaticResource PluginSettingsRowBorderStyle}">
295+
<DockPanel Margin="{StaticResource SettingPanelMargin}">
296+
<TextBlock Style="{StaticResource PluginSettingsRowGlyphStyle}">
297+
&#xE961;
298+
</TextBlock>
299+
<TextBlock
300+
Style="{StaticResource PluginSettingsRowLabelStyle}"
301+
Text="{DynamicResource searchDelay}"
302+
ToolTip="{DynamicResource searchDelayToolTip}" />
303+
<ui:NumberBox
304+
Width="120"
305+
MinWidth="120"
306+
Margin="0 -4.5 0 -4.5"
307+
HorizontalAlignment="Right"
308+
IsEnabled="{Binding SearchDelayEnabled}"
309+
Maximum="1000"
310+
Minimum="0"
311+
PlaceholderText="{Binding DefaultSearchDelay}"
312+
SmallChange="10"
313+
SpinButtonPlacementMode="Compact"
314+
ToolTip="{DynamicResource searchDelayNumberBoxToolTip}"
315+
ToolTipService.InitialShowDelay="0"
316+
ToolTipService.ShowOnDisabled="True"
317+
Value="{Binding PluginSearchDelayTime, Mode=TwoWay}" />
318+
</DockPanel>
319+
</Border>
320+
</StackPanel>
321+
</Border>
322+
323+
<!-- Action keyword row -->
324+
<ContentControl Content="{Binding BottomPart1}" />
325+
326+
<!-- Plugin's own settings panel, if it has one -->
327+
<Border
328+
Margin="0"
329+
Padding="0"
330+
BorderThickness="0 1 0 0"
331+
CornerRadius="0">
332+
<Border.Style>
333+
<Style BasedOn="{StaticResource SettingGroupBox}" TargetType="Border">
334+
<Style.Triggers>
335+
<DataTrigger Binding="{Binding HasSettingControl}" Value="False">
336+
<Setter Property="Visibility" Value="Collapsed" />
337+
</DataTrigger>
338+
</Style.Triggers>
339+
</Style>
340+
</Border.Style>
341+
<ContentControl
342+
Margin="0"
343+
Padding="1"
344+
VerticalAlignment="Stretch"
345+
Content="{Binding SettingControl}" />
346+
</Border>
347+
348+
<!-- Plugin Footer -->
349+
<ContentControl Content="{Binding BottomPart2}" />
350+
</StackPanel>
351+
</ScrollViewer>
174352
</Border>
175353
</Grid>
176354
</Border>

Flow.Launcher/PluginSettingsWindow.xaml.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Windows;
43
using System.Windows.Input;
54
using CommunityToolkit.Mvvm.DependencyInjection;
65
using Flow.Launcher.Core.Plugin;
76
using Flow.Launcher.Infrastructure.UserSettings;
87
using Flow.Launcher.ViewModel;
8+
using iNKORE.UI.WPF.Modern.Controls;
99

1010
namespace Flow.Launcher;
1111

1212
public partial class PluginSettingsWindow
1313
{
1414
private readonly Settings _settings;
15-
private readonly PluginDisplayModes _displayModes = new();
1615

1716
public PluginSettingsWindow()
1817
{
1918
_settings = Ioc.Default.GetRequiredService<Settings>();
2019
InitializeComponent();
21-
PluginListBox.DataContext = _displayModes;
2220
}
2321

2422
public PluginSettingsWindow(string pluginId)
@@ -56,11 +54,19 @@ private void LoadPlugin(string pluginId)
5654
IsExpanded = true,
5755
};
5856

59-
PluginListBox.ItemsSource = new List<PluginViewModel> { pluginViewModel };
60-
PluginListBox.SelectedIndex = -1;
57+
DataContext = pluginViewModel;
6158
Title = $"{pluginPair.Metadata.Name} Settings";
6259
}
6360

61+
// This is used for Priority control to force its value to be 0 when the user clears the value.
62+
private void NumberBox_OnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
63+
{
64+
if (double.IsNaN(args.NewValue))
65+
{
66+
sender.Value = 0;
67+
}
68+
}
69+
6470
private void OnMinimizeButtonClick(object sender, RoutedEventArgs e)
6571
{
6672
WindowState = WindowState.Minimized;
@@ -119,12 +125,4 @@ protected override void OnClosed(EventArgs e)
119125

120126
base.OnClosed(e);
121127
}
122-
123-
private sealed class PluginDisplayModes
124-
{
125-
public bool IsOnOffSelected => true;
126-
public bool IsPrioritySelected => false;
127-
public bool IsSearchDelaySelected => false;
128-
public bool IsHomeOnOffSelected => false;
129-
}
130128
}

0 commit comments

Comments
 (0)