Skip to content

Commit 44f136c

Browse files
committed
Use binding instead of local functions
1 parent bf63dda commit 44f136c

File tree

7 files changed

+79
-183
lines changed

7 files changed

+79
-183
lines changed

Flow.Launcher/Converters/StringEqualityToVisibilityConverter.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

Flow.Launcher/Languages/en.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@
135135
<system:String x:Key="pluginSearchDelayTime">Plugin seach delay time</system:String>
136136
<system:String x:Key="pluginSearchDelayTimeTooltip">Change Plugin Seach Delay Time</system:String>
137137
<system:String x:Key="FilterComboboxLabel">Advanced Settings:</system:String>
138-
<system:String x:Key="EnabledCombobox">Enabled</system:String>
139-
<system:String x:Key="PriorityCombobox">Priority</system:String>
140-
<system:String x:Key="SearchDelayCombobox">Search Delay</system:String>
138+
<system:String x:Key="DisplayModeOnOff">Enabled</system:String>
139+
<system:String x:Key="DisplayModePriority">Priority</system:String>
140+
<system:String x:Key="DisplayModeSearchDelay">Search Delay</system:String>
141141
<system:String x:Key="currentPriority">Current Priority</system:String>
142142
<system:String x:Key="newPriority">New Priority</system:String>
143143
<system:String x:Key="priority">Priority</system:String>

Flow.Launcher/Resources/Controls/InstalledPluginDisplay.xaml

Lines changed: 25 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
6+
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
89
xmlns:ui="http://schemas.modernwpf.com/2019"
910
xmlns:viewModel="clr-namespace:Flow.Launcher.ViewModel"
10-
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
1111
d:DataContext="{d:DesignInstance viewModel:PluginViewModel}"
1212
d:DesignHeight="300"
1313
d:DesignWidth="300"
1414
mc:Ignorable="d">
1515
<UserControl.Resources>
16-
<converters:StringEqualityToVisibilityConverter x:Key="StringEqualityToVisibilityConverter" />
16+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
1717
</UserControl.Resources>
1818
<Expander
1919
Padding="0"
@@ -48,108 +48,62 @@
4848
Text="{Binding PluginPair.Metadata.Description}"
4949
TextWrapping="WrapWithOverflow" />
5050
</StackPanel>
51+
5152
<StackPanel
5253
Grid.Column="2"
5354
HorizontalAlignment="Right"
5455
Orientation="Horizontal">
55-
<!--<TextBlock
56-
Margin="0 0 8 0"
57-
VerticalAlignment="Center"
58-
FontSize="12"
59-
Foreground="{DynamicResource Color08B}"
60-
Text="{DynamicResource priority}" />
61-
<Button
62-
x:Name="PriorityButton"
63-
Margin="0 0 22 0"
64-
VerticalAlignment="Center"
65-
Command="{Binding EditPluginPriorityCommand}"
66-
Content="{Binding Priority}"
67-
Cursor="Hand"
68-
ToolTip="{DynamicResource priorityToolTip}">
69-
-->
70-
<!--#region Priority Button Style-->
71-
<!--
72-
<Button.Resources>
73-
<Style TargetType="Border">
74-
<Setter Property="CornerRadius" Value="2" />
75-
</Style>
76-
</Button.Resources>
77-
<Button.Style>
78-
<Style BasedOn="{StaticResource DefaultButtonStyle}" TargetType="Button">
79-
<Setter Property="Padding" Value="12 8" />
80-
<Setter Property="BorderThickness" Value="0" />
81-
<Setter Property="FontWeight" Value="DemiBold" />
82-
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
83-
<Style.Triggers>
84-
<DataTrigger Binding="{Binding ElementName=PriorityButton, UpdateSourceTrigger=PropertyChanged, Path=Content}" Value="0">
85-
<Setter Property="Foreground" Value="{DynamicResource Color08B}" />
86-
<Setter Property="FontWeight" Value="Normal" />
87-
</DataTrigger>
88-
</Style.Triggers>
89-
</Style>
90-
</Button.Style>
91-
-->
92-
<!--#endregion-->
93-
<!--
94-
</Button>-->
95-
<StackPanel VerticalAlignment="Center"
56+
<StackPanel
9657
x:Name="PriorityControl"
58+
VerticalAlignment="Center"
9759
Orientation="Horizontal"
98-
Visibility="{Binding DataContext.CurrentDisplayMode,
99-
RelativeSource={RelativeSource AncestorType=ListBox},
100-
Converter={StaticResource StringEqualityToVisibilityConverter},
101-
ConverterParameter=Priority}">
60+
Visibility="{Binding DataContext.IsPrioritySelected, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource BooleanToVisibilityConverter}}">
10261
<TextBlock
103-
Margin="0 0 8 0"
104-
VerticalAlignment="Center"
105-
FontSize="13" ToolTip="{DynamicResource priorityToolTip}"
106-
Foreground="{DynamicResource Color08B}"
107-
Text="{DynamicResource priority}" />
62+
Margin="0 0 8 0"
63+
VerticalAlignment="Center"
64+
FontSize="13"
65+
Foreground="{DynamicResource Color08B}"
66+
Text="{DynamicResource priority}"
67+
ToolTip="{DynamicResource priorityToolTip}" />
10868
<ui:NumberBox
10969
Margin="0 0 8 0"
110-
Maximum="999" ToolTip="{DynamicResource priorityToolTip}"
70+
Maximum="999"
11171
Minimum="-999"
112-
SpinButtonPlacementMode="Inline" />
72+
SpinButtonPlacementMode="Inline"
73+
ToolTip="{DynamicResource priorityToolTip}" />
11374
</StackPanel>
11475

11576
<StackPanel
11677
x:Name="SearchDelayControl"
117-
Orientation="Horizontal"
11878
VerticalAlignment="Center"
119-
Visibility="{Binding DataContext.CurrentDisplayMode,
120-
RelativeSource={RelativeSource AncestorType=ListBox},
121-
Converter={StaticResource StringEqualityToVisibilityConverter},
122-
ConverterParameter=SearchDelay}">
79+
Orientation="Horizontal"
80+
Visibility="{Binding DataContext.IsSearchDelaySelected, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource BooleanToVisibilityConverter}}">
12381
<TextBlock
12482
Margin="0 0 8 0"
12583
VerticalAlignment="Center"
126-
FontSize="13" ToolTip="{DynamicResource searchDelayToolTip}"
84+
FontSize="13"
12785
Foreground="{DynamicResource Color08B}"
128-
Text="{DynamicResource searchDelay}" />
129-
<cc:InstalledPluginSearchDelayCombobox
130-
Margin="0 0 8 0" />
86+
Text="{DynamicResource searchDelay}"
87+
ToolTip="{DynamicResource searchDelayToolTip}" />
88+
<cc:InstalledPluginSearchDelayCombobox Margin="0 0 8 0" />
13189
</StackPanel>
13290

91+
<!-- Put OnOffControl after PriorityControl & SearchDelayControl so that it can display correctly -->
13392
<ui:ToggleSwitch
13493
x:Name="OnOffControl"
13594
Margin="0 0 8 0"
13695
IsOn="{Binding PluginState}"
13796
OffContent="{DynamicResource disable}"
13897
OnContent="{DynamicResource enable}"
139-
Visibility="{Binding DataContext.CurrentDisplayMode,
140-
RelativeSource={RelativeSource AncestorType=ListBox},
141-
Converter={StaticResource StringEqualityToVisibilityConverter},
142-
ConverterParameter=OnOff}" />
143-
</StackPanel>
98+
Visibility="{Binding DataContext.IsOnOffSelected, RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource BooleanToVisibilityConverter}}" />
99+
</StackPanel>
144100
</Grid>
145101
</Border>
146102
</Expander.Header>
147103

148104
<StackPanel>
149105
<ContentControl Content="{Binding BottomPart1}" />
150106

151-
<!-- <ContentControl Content="{Binding BottomPart2}" /> -->
152-
153107
<Border
154108
Background="{DynamicResource Color00B}"
155109
BorderBrush="{DynamicResource Color03B}"
@@ -170,7 +124,7 @@
170124
Content="{Binding SettingControl}" />
171125
</Border>
172126

173-
<ContentControl Content="{Binding BottomPart3}" />
127+
<ContentControl Content="{Binding BottomPart2}" />
174128
</StackPanel>
175129
</Expander>
176130
</UserControl>

Flow.Launcher/SettingPages/ViewModels/SettingsPanePluginsViewModel.cs

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,26 @@ public partial class SettingsPanePluginsViewModel : BaseModel
1919
{
2020
private readonly Settings _settings;
2121

22-
private string _selectedDisplayMode = "OnOff";
23-
public string SelectedDisplayMode
22+
public class DisplayModeData : DropdownDataGeneric<DisplayMode> { }
23+
24+
public List<DisplayModeData> DisplayModes { get; } =
25+
DropdownDataGeneric<DisplayMode>.GetValues<DisplayModeData>("DisplayMode");
26+
27+
private DisplayMode _selectedDisplayMode = DisplayMode.OnOff;
28+
public DisplayMode SelectedDisplayMode
2429
{
2530
get => _selectedDisplayMode;
2631
set
2732
{
2833
if (_selectedDisplayMode != value)
2934
{
3035
_selectedDisplayMode = value;
31-
OnPropertyChanged(nameof(SelectedDisplayMode));
36+
OnPropertyChanged();
3237
UpdateDisplayModeFromSelection();
3338
}
3439
}
3540
}
3641

37-
public void UpdateDisplayModeFromSelection()
38-
{
39-
switch (SelectedDisplayMode)
40-
{
41-
case "OnOff":
42-
IsOnOffSelected = true;
43-
IsPrioritySelected = false;
44-
IsSearchDelaySelected = false;
45-
break;
46-
case "Priority":
47-
IsOnOffSelected = false;
48-
IsPrioritySelected = true;
49-
IsSearchDelaySelected = false;
50-
break;
51-
case "SearchDelay":
52-
IsOnOffSelected = false;
53-
IsPrioritySelected = false;
54-
IsSearchDelaySelected = true;
55-
break;
56-
}
57-
}
58-
5942
private bool _isOnOffSelected = true;
6043
public bool IsOnOffSelected
6144
{
@@ -65,8 +48,7 @@ public bool IsOnOffSelected
6548
if (_isOnOffSelected != value)
6649
{
6750
_isOnOffSelected = value;
68-
OnPropertyChanged(nameof(IsOnOffSelected));
69-
UpdateDisplayMode();
51+
OnPropertyChanged();
7052
}
7153
}
7254
}
@@ -80,8 +62,7 @@ public bool IsPrioritySelected
8062
if (_isPrioritySelected != value)
8163
{
8264
_isPrioritySelected = value;
83-
OnPropertyChanged(nameof(IsPrioritySelected));
84-
UpdateDisplayMode();
65+
OnPropertyChanged();
8566
}
8667
}
8768
}
@@ -95,38 +76,15 @@ public bool IsSearchDelaySelected
9576
if (_isSearchDelaySelected != value)
9677
{
9778
_isSearchDelaySelected = value;
98-
OnPropertyChanged(nameof(IsSearchDelaySelected));
99-
UpdateDisplayMode();
79+
OnPropertyChanged();
10080
}
10181
}
10282
}
10383

104-
private string _currentDisplayMode = "OnOff";
105-
public string CurrentDisplayMode
106-
{
107-
get => _currentDisplayMode;
108-
set
109-
{
110-
if (_currentDisplayMode != value)
111-
{
112-
_currentDisplayMode = value;
113-
OnPropertyChanged(nameof(CurrentDisplayMode));
114-
}
115-
}
116-
}
117-
118-
private void UpdateDisplayMode()
119-
{
120-
if (IsOnOffSelected)
121-
CurrentDisplayMode = "OnOff";
122-
else if (IsPrioritySelected)
123-
CurrentDisplayMode = "Priority";
124-
else if (IsSearchDelaySelected)
125-
CurrentDisplayMode = "SearchDelay";
126-
}
12784
public SettingsPanePluginsViewModel(Settings settings)
12885
{
12986
_settings = settings;
87+
UpdateEnumDropdownLocalizations();
13088
}
13189

13290
public string FilterText { get; set; } = string.Empty;
@@ -196,4 +154,38 @@ private async Task OpenHelperAsync()
196154

197155
await helpDialog.ShowAsync();
198156
}
157+
158+
private void UpdateEnumDropdownLocalizations()
159+
{
160+
DropdownDataGeneric<DisplayMode>.UpdateLabels(DisplayModes);
161+
}
162+
163+
private void UpdateDisplayModeFromSelection()
164+
{
165+
switch (SelectedDisplayMode)
166+
{
167+
case DisplayMode.Priority:
168+
IsOnOffSelected = false;
169+
IsPrioritySelected = true;
170+
IsSearchDelaySelected = false;
171+
break;
172+
case DisplayMode.SearchDelay:
173+
IsOnOffSelected = false;
174+
IsPrioritySelected = false;
175+
IsSearchDelaySelected = true;
176+
break;
177+
default:
178+
IsOnOffSelected = true;
179+
IsPrioritySelected = false;
180+
IsSearchDelaySelected = false;
181+
break;
182+
}
183+
}
184+
}
185+
186+
public enum DisplayMode
187+
{
188+
OnOff,
189+
Priority,
190+
SearchDelay
199191
}

Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
6-
xmlns:converters="clr-namespace:Flow.Launcher.Converters"
76
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
87
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
98
xmlns:sys="clr-namespace:System;assembly=mscorlib"
@@ -16,10 +15,6 @@
1615
FocusManager.FocusedElement="{Binding ElementName=PluginFilterTextbox}"
1716
KeyDown="SettingsPanePlugins_OnKeyDown"
1817
mc:Ignorable="d">
19-
<ui:Page.Resources>
20-
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
21-
<converters:StringEqualityToVisibilityConverter x:Key="StringEqualityToVisibilityConverter" />
22-
</ui:Page.Resources>
2318
<Grid>
2419
<Grid.RowDefinitions>
2520
<RowDefinition Height="73" />
@@ -53,19 +48,10 @@
5348
Margin="0 0 4 0"
5449
HorizontalContentAlignment="Left"
5550
Background="{DynamicResource Color00B}"
51+
DisplayMemberPath="Display"
52+
ItemsSource="{Binding DisplayModes}"
5653
SelectedValue="{Binding SelectedDisplayMode, Mode=TwoWay}"
57-
SelectedValuePath="Tag"
58-
SelectionChanged="DisplayModeComboBox_SelectionChanged">
59-
<ComboBoxItem Tag="OnOff">
60-
<TextBlock Text="{DynamicResource EnabledCombobox}" />
61-
</ComboBoxItem>
62-
<ComboBoxItem Tag="Priority">
63-
<TextBlock Text="{DynamicResource PriorityCombobox}" />
64-
</ComboBoxItem>
65-
<ComboBoxItem Tag="SearchDelay">
66-
<TextBlock Text="{DynamicResource SearchDelayCombobox}" />
67-
</ComboBoxItem>
68-
</ComboBox>
54+
SelectedValuePath="Value" />
6955
<Button
7056
Width="34"
7157
Height="34"

0 commit comments

Comments
 (0)