From d13c3817e4c34be43ec4b70fa15645412b384c11 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sun, 23 Oct 2022 17:29:37 +0800
Subject: [PATCH] Data binding for suffixes
---
.../ProgramSuffixes.xaml | 15 +++++++-----
.../ProgramSuffixes.xaml.cs | 18 +++++++-------
.../Programs/Win32.cs | 6 ++---
.../Flow.Launcher.Plugin.Program/Settings.cs | 24 ++++++++++++++++++-
.../SuffixesConverter.cs | 2 +-
5 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml b/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml
index ff68de6b4..ef1ba3fcc 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml
@@ -9,6 +9,7 @@
Width="600"
Background="{DynamicResource PopuBGColor}"
Foreground="{DynamicResource PopupTextColor}"
+ DataContext="{Binding RelativeSource={RelativeSource Self}}"
ResizeMode="NoResize"
SizeToContent="Height"
WindowStartupLocation="CenterScreen"
@@ -166,12 +167,13 @@
FontSize="16"
FontWeight="SemiBold"
Text="{DynamicResource flowlauncher_plugin_program_suffixes_excutable_types}" />
- appref-ms
- EXE
- Lnk
+ appref-ms
+ exe
+ lnk
diff --git a/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs
index 0939bfc58..eaf3a134d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs
@@ -1,13 +1,8 @@
using System;
using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Input;
namespace Flow.Launcher.Plugin.Program
{
- ///
- /// ProgramSuffixes.xaml 的交互逻辑
- ///
public partial class ProgramSuffixes
{
private PluginInitContext context;
@@ -18,13 +13,15 @@ namespace Flow.Launcher.Plugin.Program
this.context = context;
InitializeComponent();
_settings = settings;
- tbSuffixes.Text = string.Join(Settings.SuffixSeperator.ToString(), _settings.ProgramSuffixes);
+ tbSuffixes.Text = string.Join(Settings.SuffixSeperator.ToString(), _settings.CustomSuffixes);
}
+
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
{
Close();
}
- private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
+
+ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
var suffixes = tbSuffixes.Text.Split(Settings.SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
@@ -35,12 +32,17 @@ namespace Flow.Launcher.Plugin.Program
return;
}
- _settings.ProgramSuffixes = suffixes;
+ _settings.CustomSuffixes = suffixes;
string msg = context.API.GetTranslation("flowlauncher_plugin_program_update_file_suffixes");
MessageBox.Show(msg);
DialogResult = true;
}
+
+ private void BtnReset_OnClick(object sender, RoutedEventArgs e)
+ {
+
+ }
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 54e4dfa80..79723e3b0 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -537,7 +537,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
{
var programs = Enumerable.Empty();
- var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.ProgramSuffixes);
+ var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.CustomSuffixes);
programs = programs.Concat(unregistered);
@@ -545,13 +545,13 @@ namespace Flow.Launcher.Plugin.Program.Programs
if (settings.EnableRegistrySource)
{
- var appPaths = AppPathsPrograms(settings.ProgramSuffixes);
+ var appPaths = AppPathsPrograms(settings.CustomSuffixes);
autoIndexPrograms = autoIndexPrograms.Concat(appPaths);
}
if (settings.EnableStartMenuSource)
{
- var startMenu = StartMenuPrograms(settings.ProgramSuffixes);
+ var startMenu = StartMenuPrograms(settings.CustomSuffixes);
autoIndexPrograms = autoIndexPrograms.Concat(startMenu);
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index d5f492389..244c3818f 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
namespace Flow.Launcher.Plugin.Program
{
@@ -9,7 +10,28 @@ namespace Flow.Launcher.Plugin.Program
public DateTime LastIndexTime { get; set; }
public List ProgramSources { get; set; } = new List();
public List DisabledProgramSources { get; set; } = new List();
- public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk", "url"};
+ public string[] CustomSuffixes { get; set; } = { "appref-ms", "exe", "lnk" };
+
+ public Dictionary BuiltinSuffixesStatus { get; set; } = new Dictionary{
+ { "exe", true }, { "appref-ms", true }, { "lnk", true }
+ };
+
+ public bool UseCustomSuffixes = false;
+ public bool UseCustomProtocols = false;
+
+ public string[] GetProgramExtensions()
+ {
+ List extensions = new List();
+ foreach(var item in BuiltinSuffixesStatus)
+ {
+ if (item.Value)
+ {
+ extensions.Add(item.Key);
+ }
+ }
+
+ return extensions.Concat(CustomSuffixes).DistinctBy(x => x.ToLower()).ToArray();
+ }
public bool EnableStartMenuSource { get; set; } = true;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/SuffixesConverter.cs b/Plugins/Flow.Launcher.Plugin.Program/SuffixesConverter.cs
index a5e9f75dc..28f0b1c25 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/SuffixesConverter.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/SuffixesConverter.cs
@@ -12,7 +12,7 @@ namespace Flow.Launcher.Plugin.Program
var text = value as string[];
if (text != null)
{
- return string.Join(";", text);
+ return string.Join(Settings.SuffixSeperator, text);
}
else
{