Skip to content

Commit d13c381

Browse files
Data binding for suffixes
1 parent d5be961 commit d13c381

File tree

5 files changed

+46
-19
lines changed

5 files changed

+46
-19
lines changed

Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Width="600"
1010
Background="{DynamicResource PopuBGColor}"
1111
Foreground="{DynamicResource PopupTextColor}"
12+
DataContext="{Binding RelativeSource={RelativeSource Self}}"
1213
ResizeMode="NoResize"
1314
SizeToContent="Height"
1415
WindowStartupLocation="CenterScreen"
@@ -166,12 +167,13 @@
166167
FontSize="16"
167168
FontWeight="SemiBold"
168169
Text="{DynamicResource flowlauncher_plugin_program_suffixes_excutable_types}" />
169-
<CheckBox Name="apprefMS" Margin="10,0,0,0">appref-ms</CheckBox>
170-
<CheckBox Name="EXE" Margin="10,0,0,0">EXE</CheckBox>
171-
<CheckBox Name="LNK" Margin="10,0,0,0">Lnk</CheckBox>
170+
<CheckBox Name="apprefMS" Margin="10,0,0,0" IsChecked="{Binding _settings.BuiltinSuffixesStatus[appref-ms]}">appref-ms</CheckBox>
171+
<CheckBox Name="exe" Margin="10,0,0,0" IsChecked="{Binding _settings.BuiltinSuffixesStatus[exe]}">exe</CheckBox>
172+
<CheckBox Name="lnk" Margin="10,0,0,0" IsChecked="{Binding _settings.BuiltinSuffixesStatus[lnk]}">lnk</CheckBox>
172173
<CheckBox
173174
Name="CustomFiles"
174175
Margin="10,0,0,0"
176+
IsChecked="{Binding _settings.UseCustomSuffixes}"
175177
Content="{DynamicResource flowlauncher_plugin_program_suffixes_custom_file_types}" />
176178
<TextBox
177179
x:Name="tbSuffixes"
@@ -197,6 +199,7 @@
197199
<CheckBox
198200
Name="CustomProtocol"
199201
Margin="10,0,0,0"
202+
IsChecked="{Binding _settings.UseCustomProtocols}"
200203
Content="{DynamicResource flowlauncher_plugin_program_suffixes_custom_urls}" />
201204
<TextBox
202205
x:Name="tbProtocols"
@@ -214,11 +217,11 @@
214217
BorderThickness="0,1,0,0">
215218
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
216219
<Button
217-
x:Name="btnResetl"
220+
x:Name="btnReset"
218221
Height="30"
219222
MinWidth="140"
220223
Margin="0,0,5,0"
221-
Click="BtnCancel_OnClick"
224+
Click="BtnReset_OnClick"
222225
Content="{DynamicResource flowlauncher_plugin_program_reset}" />
223226
<Button
224227
x:Name="btnCancel"
@@ -233,7 +236,7 @@
233236
MinWidth="140"
234237
Margin="5,0,0,0"
235238
HorizontalAlignment="Right"
236-
Click="ButtonBase_OnClick"
239+
Click="BtnAdd_OnClick"
237240
Content="{DynamicResource flowlauncher_plugin_program_update}"
238241
Style="{DynamicResource AccentButtonStyle}" />
239242
</StackPanel>
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using System;
22
using System.Windows;
3-
using System.Windows.Controls;
4-
using System.Windows.Input;
53

64
namespace Flow.Launcher.Plugin.Program
75
{
8-
/// <summary>
9-
/// ProgramSuffixes.xaml 的交互逻辑
10-
/// </summary>
116
public partial class ProgramSuffixes
127
{
138
private PluginInitContext context;
@@ -18,13 +13,15 @@ public ProgramSuffixes(PluginInitContext context, Settings settings)
1813
this.context = context;
1914
InitializeComponent();
2015
_settings = settings;
21-
tbSuffixes.Text = string.Join(Settings.SuffixSeperator.ToString(), _settings.ProgramSuffixes);
16+
tbSuffixes.Text = string.Join(Settings.SuffixSeperator.ToString(), _settings.CustomSuffixes);
2217
}
18+
2319
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
2420
{
2521
Close();
2622
}
27-
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
23+
24+
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
2825
{
2926
var suffixes = tbSuffixes.Text.Split(Settings.SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
3027

@@ -35,12 +32,17 @@ private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
3532
return;
3633
}
3734

38-
_settings.ProgramSuffixes = suffixes;
35+
_settings.CustomSuffixes = suffixes;
3936

4037
string msg = context.API.GetTranslation("flowlauncher_plugin_program_update_file_suffixes");
4138
MessageBox.Show(msg);
4239

4340
DialogResult = true;
4441
}
42+
43+
private void BtnReset_OnClick(object sender, RoutedEventArgs e)
44+
{
45+
46+
}
4547
}
4648
}

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,21 @@ public static Win32[] All(Settings settings)
537537
{
538538
var programs = Enumerable.Empty<Win32>();
539539

540-
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);
540+
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.CustomSuffixes);
541541

542542
programs = programs.Concat(unregistered);
543543

544544
var autoIndexPrograms = Enumerable.Empty<Win32>();
545545

546546
if (settings.EnableRegistrySource)
547547
{
548-
var appPaths = AppPathsPrograms(settings.ProgramSuffixes);
548+
var appPaths = AppPathsPrograms(settings.CustomSuffixes);
549549
autoIndexPrograms = autoIndexPrograms.Concat(appPaths);
550550
}
551551

552552
if (settings.EnableStartMenuSource)
553553
{
554-
var startMenu = StartMenuPrograms(settings.ProgramSuffixes);
554+
var startMenu = StartMenuPrograms(settings.CustomSuffixes);
555555
autoIndexPrograms = autoIndexPrograms.Concat(startMenu);
556556
}
557557

Plugins/Flow.Launcher.Plugin.Program/Settings.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
45

56
namespace Flow.Launcher.Plugin.Program
67
{
@@ -9,7 +10,28 @@ public class Settings
910
public DateTime LastIndexTime { get; set; }
1011
public List<ProgramSource> ProgramSources { get; set; } = new List<ProgramSource>();
1112
public List<DisabledProgramSource> DisabledProgramSources { get; set; } = new List<DisabledProgramSource>();
12-
public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk", "url"};
13+
public string[] CustomSuffixes { get; set; } = { "appref-ms", "exe", "lnk" };
14+
15+
public Dictionary<string, bool> BuiltinSuffixesStatus { get; set; } = new Dictionary<string, bool>{
16+
{ "exe", true }, { "appref-ms", true }, { "lnk", true }
17+
};
18+
19+
public bool UseCustomSuffixes = false;
20+
public bool UseCustomProtocols = false;
21+
22+
public string[] GetProgramExtensions()
23+
{
24+
List<string> extensions = new List<string>();
25+
foreach(var item in BuiltinSuffixesStatus)
26+
{
27+
if (item.Value)
28+
{
29+
extensions.Add(item.Key);
30+
}
31+
}
32+
33+
return extensions.Concat(CustomSuffixes).DistinctBy(x => x.ToLower()).ToArray();
34+
}
1335

1436
public bool EnableStartMenuSource { get; set; } = true;
1537

Plugins/Flow.Launcher.Plugin.Program/SuffixesConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1212
var text = value as string[];
1313
if (text != null)
1414
{
15-
return string.Join(";", text);
15+
return string.Join(Settings.SuffixSeperator, text);
1616
}
1717
else
1818
{

0 commit comments

Comments
 (0)