diff --git a/Flow.Launcher.Infrastructure/PinyinAlphabet.cs b/Flow.Launcher.Infrastructure/PinyinAlphabet.cs index 55c3decd0..d878a3d0e 100644 --- a/Flow.Launcher.Infrastructure/PinyinAlphabet.cs +++ b/Flow.Launcher.Infrastructure/PinyinAlphabet.cs @@ -45,7 +45,8 @@ namespace Flow.Launcher.Infrastructure private void CreateDoublePinyinTableFromStream(Stream jsonStream) { Dictionary> table = JsonSerializer.Deserialize>>(jsonStream); - if (!table.TryGetValue(_settings.DoublePinyinSchema, out var value)) + string schemaKey = _settings.DoublePinyinSchema.ToString(); // Convert enum to string + if (!table.TryGetValue(schemaKey, out var value)) { throw new InvalidOperationException("DoublePinyinSchema is invalid or double pinyin table is broken."); } @@ -104,18 +105,13 @@ namespace Flow.Launcher.Infrastructure if (content[i] >= 0x3400 && content[i] <= 0x9FD5) { string translated = _settings.UseDoublePinyin ? ToDoublePin(resultList[i]) : resultList[i]; - if (previousIsChinese) + if (i > 0) { resultBuilder.Append(' '); - map.AddNewIndex(resultBuilder.Length, translated.Length); - resultBuilder.Append(translated); - } - else - { - map.AddNewIndex(resultBuilder.Length, translated.Length); - resultBuilder.Append(translated); - previousIsChinese = true; } + map.AddNewIndex(resultBuilder.Length, translated.Length); + resultBuilder.Append(translated); + previousIsChinese = true; } else { diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 3ec765fa4..736d3a5dd 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -87,7 +87,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings } } public bool UseDropShadowEffect { get; set; } = true; - public BackdropTypes BackdropType{ get; set; } = BackdropTypes.None; + public BackdropTypes BackdropType { get; set; } = BackdropTypes.None; public string ReleaseNotesVersion { get; set; } = string.Empty; /* Appearance Settings. It should be separated from the setting later.*/ @@ -200,7 +200,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings } } } - + public int MaxHistoryResultsToShowForHomePage { get; set; } = 5; public int CustomExplorerIndex { get; set; } = 0; @@ -313,8 +313,10 @@ namespace Flow.Launcher.Infrastructure.UserSettings } } - private string _doublePinyinSchema = "XiaoHe"; - public string DoublePinyinSchema + private DoublePinyinSchemas _doublePinyinSchema = DoublePinyinSchemas.XiaoHe; + + [JsonInclude, JsonConverter(typeof(JsonStringEnumConverter))] + public DoublePinyinSchemas DoublePinyinSchema { get => _doublePinyinSchema; set @@ -489,7 +491,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings if (!string.IsNullOrEmpty(SettingWindowHotkey)) list.Add(new(SettingWindowHotkey, "SettingWindowHotkey", () => SettingWindowHotkey = "")); if (!string.IsNullOrEmpty(OpenHistoryHotkey)) - list.Add(new(OpenHistoryHotkey, "OpenHistoryHotkey", () => OpenHistoryHotkey = "")); + list.Add(new(OpenHistoryHotkey, "OpenHistoryHotkey", () => OpenHistoryHotkey = "")); if (!string.IsNullOrEmpty(OpenContextMenuHotkey)) list.Add(new(OpenContextMenuHotkey, "OpenContextMenuHotkey", () => OpenContextMenuHotkey = "")); if (!string.IsNullOrEmpty(SelectNextPageHotkey)) @@ -595,9 +597,22 @@ namespace Flow.Launcher.Infrastructure.UserSettings public enum BackdropTypes { - None, + None, Acrylic, Mica, MicaAlt } + + public enum DoublePinyinSchemas + { + XiaoHe, + ZiRanMa, + WeiRuan, + ZhiNengABC, + ZiGuangPinYin, + PinYinJiaJia, + XingKongJianDao, + DaNiu, + XiaoLang + } } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index bd4cbd282..22a3ca60b 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -105,6 +105,19 @@ Regular Search with Pinyin Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese. + Use Double Pinyin + Allows using Double Pinyin to search. Double Pinyin is a variation of Pinyin that uses two characters. + Double Pinyin Schema + Xiao He + Zi Ran Ma + Wei Ruan + Zhi Neng ABC + Zi Guang Pin Yin + Pin Yin Jia Jia + Xing Kong Jian Dao + Da Niu + Xiao Lang + Always Preview Always open preview panel when Flow activates. Press {0} to toggle preview. Shadow effect is not allowed while current theme has blur effect enabled diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index bec59a2b1..e5b70cd87 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -35,6 +35,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel public class SearchWindowAlignData : DropdownDataGeneric { } public class SearchPrecisionData : DropdownDataGeneric { } public class LastQueryModeData : DropdownDataGeneric { } + public class DoublePinyinSchemaData : DropdownDataGeneric { } public bool StartFlowLauncherOnSystemStartup { @@ -177,6 +178,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel DropdownDataGeneric.UpdateLabels(SearchWindowAligns); DropdownDataGeneric.UpdateLabels(SearchPrecisionScores); DropdownDataGeneric.UpdateLabels(LastQueryModes); + DropdownDataGeneric.UpdateLabels(DoublePinyinSchemas); // Since we are using Binding instead of DynamicResource, we need to manually trigger the update OnPropertyChanged(nameof(AlwaysPreviewToolTip)); } @@ -262,9 +264,25 @@ public partial class SettingsPaneGeneralViewModel : BaseModel public bool ShouldUsePinyin { get => Settings.ShouldUsePinyin; - set => Settings.ShouldUsePinyin = value; + set + { + if (value == false && UseDoublePinyin == true) + { + UseDoublePinyin = false; + } + Settings.ShouldUsePinyin = value; + } } + public bool UseDoublePinyin + { + set => Settings.UseDoublePinyin = value; + get => Settings.UseDoublePinyin; + } + + public List DoublePinyinSchemas { get; } = + DropdownDataGeneric.GetValues("DoublePinyinSchemas"); + public List Languages => _translater.LoadAvailableLanguages(); public string AlwaysPreviewToolTip => string.Format( diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml index d114736d5..3f29758ba 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml @@ -347,16 +347,44 @@ OnContent="{DynamicResource enable}" /> - - - + + + + + + + + + + +