Skip to content

Commit 1302021

Browse files
Add UI for double pinyin options
1 parent ebcd7d5 commit 1302021

File tree

5 files changed

+97
-27
lines changed

5 files changed

+97
-27
lines changed

Flow.Launcher.Infrastructure/PinyinAlphabet.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public void Reload()
4545
private void CreateDoublePinyinTableFromStream(Stream jsonStream)
4646
{
4747
Dictionary<string, Dictionary<string, string>> table = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(jsonStream);
48-
if (!table.TryGetValue(_settings.DoublePinyinSchema, out var value))
48+
string schemaKey = _settings.DoublePinyinSchema.ToString(); // Convert enum to string
49+
if (!table.TryGetValue(schemaKey, out var value))
4950
{
5051
throw new InvalidOperationException("DoublePinyinSchema is invalid or double pinyin table is broken.");
5152
}
@@ -104,18 +105,13 @@ public bool ShouldTranslate(string stringToTranslate)
104105
if (content[i] >= 0x3400 && content[i] <= 0x9FD5)
105106
{
106107
string translated = _settings.UseDoublePinyin ? ToDoublePin(resultList[i]) : resultList[i];
107-
if (previousIsChinese)
108+
if (i > 0)
108109
{
109110
resultBuilder.Append(' ');
110-
map.AddNewIndex(resultBuilder.Length, translated.Length);
111-
resultBuilder.Append(translated);
112-
}
113-
else
114-
{
115-
map.AddNewIndex(resultBuilder.Length, translated.Length);
116-
resultBuilder.Append(translated);
117-
previousIsChinese = true;
118111
}
112+
map.AddNewIndex(resultBuilder.Length, translated.Length);
113+
resultBuilder.Append(translated);
114+
previousIsChinese = true;
119115
}
120116
else
121117
{

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public string Theme
8787
}
8888
}
8989
public bool UseDropShadowEffect { get; set; } = true;
90-
public BackdropTypes BackdropType{ get; set; } = BackdropTypes.None;
90+
public BackdropTypes BackdropType { get; set; } = BackdropTypes.None;
9191
public string ReleaseNotesVersion { get; set; } = string.Empty;
9292

9393
/* Appearance Settings. It should be separated from the setting later.*/
@@ -200,7 +200,7 @@ public bool ShowHistoryResultsForHomePage
200200
}
201201
}
202202
}
203-
203+
204204
public int MaxHistoryResultsToShowForHomePage { get; set; } = 5;
205205

206206
public int CustomExplorerIndex { get; set; } = 0;
@@ -313,8 +313,10 @@ public bool UseDoublePinyin
313313
}
314314
}
315315

316-
private string _doublePinyinSchema = "XiaoHe";
317-
public string DoublePinyinSchema
316+
private DoublePinyinSchemas _doublePinyinSchema = DoublePinyinSchemas.XiaoHe;
317+
318+
[JsonInclude, JsonConverter(typeof(JsonStringEnumConverter))]
319+
public DoublePinyinSchemas DoublePinyinSchema
318320
{
319321
get => _doublePinyinSchema;
320322
set
@@ -489,7 +491,7 @@ public List<RegisteredHotkeyData> RegisteredHotkeys
489491
if (!string.IsNullOrEmpty(SettingWindowHotkey))
490492
list.Add(new(SettingWindowHotkey, "SettingWindowHotkey", () => SettingWindowHotkey = ""));
491493
if (!string.IsNullOrEmpty(OpenHistoryHotkey))
492-
list.Add(new(OpenHistoryHotkey, "OpenHistoryHotkey", () => OpenHistoryHotkey = ""));
494+
list.Add(new(OpenHistoryHotkey, "OpenHistoryHotkey", () => OpenHistoryHotkey = ""));
493495
if (!string.IsNullOrEmpty(OpenContextMenuHotkey))
494496
list.Add(new(OpenContextMenuHotkey, "OpenContextMenuHotkey", () => OpenContextMenuHotkey = ""));
495497
if (!string.IsNullOrEmpty(SelectNextPageHotkey))
@@ -595,9 +597,22 @@ public enum AnimationSpeeds
595597

596598
public enum BackdropTypes
597599
{
598-
None,
600+
None,
599601
Acrylic,
600602
Mica,
601603
MicaAlt
602604
}
605+
606+
public enum DoublePinyinSchemas
607+
{
608+
XiaoHe,
609+
ZiRanMa,
610+
WeiRuan,
611+
ZhiNengABC,
612+
ZiGuangPinYin,
613+
PinYinJiaJia,
614+
XingKongJianDao,
615+
DaNiu,
616+
XiaoLang
617+
}
603618
}

Flow.Launcher/Languages/en.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@
105105
<system:String x:Key="SearchPrecisionRegular">Regular</system:String>
106106
<system:String x:Key="ShouldUsePinyin">Search with Pinyin</system:String>
107107
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese.</system:String>
108+
<system:String x:Key="ShouldUseDoublePinyin">Use Double Pinyin</system:String>
109+
<system:String x:Key="ShouldUseDoublePinyinToolTip">Allows using Double Pinyin to search. Double Pinyin is a variation of Pinyin that uses two characters.</system:String>
110+
<system:String x:Key="DoublePinyinSchema">Double Pinyin Schema</system:String>
111+
<system:String x:Key="DoublePinyinSchemasXiaoHe">Xiao He</system:String>
112+
<system:String x:Key="DoublePinyinSchemasZiRanMa">Zi Ran Ma</system:String>
113+
<system:String x:Key="DoublePinyinSchemasWeiRuan">Wei Ruan</system:String>
114+
<system:String x:Key="DoublePinyinSchemasZhiNengABC">Zhi Neng ABC</system:String>
115+
<system:String x:Key="DoublePinyinSchemasZiGuangPinYin">Zi Guang Pin Yin</system:String>
116+
<system:String x:Key="DoublePinyinSchemasPinYinJiaJia">Pin Yin Jia Jia</system:String>
117+
<system:String x:Key="DoublePinyinSchemasXingKongJianDao">Xing Kong Jian Dao</system:String>
118+
<system:String x:Key="DoublePinyinSchemasDaNiu">Da Niu</system:String>
119+
<system:String x:Key="DoublePinyinSchemasXiaoLang">Xiao Lang</system:String>
120+
108121
<system:String x:Key="AlwaysPreview">Always Preview</system:String>
109122
<system:String x:Key="AlwaysPreviewToolTip">Always open preview panel when Flow activates. Press {0} to toggle preview.</system:String>
110123
<system:String x:Key="shadowEffectNotAllowed">Shadow effect is not allowed while current theme has blur effect enabled</system:String>

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class SearchWindowScreenData : DropdownDataGeneric<SearchWindowScreens> {
3535
public class SearchWindowAlignData : DropdownDataGeneric<SearchWindowAligns> { }
3636
public class SearchPrecisionData : DropdownDataGeneric<SearchPrecisionScore> { }
3737
public class LastQueryModeData : DropdownDataGeneric<LastQueryMode> { }
38+
public class DoublePinyinSchemaData : DropdownDataGeneric<DoublePinyinSchemas> { }
3839

3940
public bool StartFlowLauncherOnSystemStartup
4041
{
@@ -177,6 +178,7 @@ private void UpdateEnumDropdownLocalizations()
177178
DropdownDataGeneric<SearchWindowAligns>.UpdateLabels(SearchWindowAligns);
178179
DropdownDataGeneric<SearchPrecisionScore>.UpdateLabels(SearchPrecisionScores);
179180
DropdownDataGeneric<LastQueryMode>.UpdateLabels(LastQueryModes);
181+
DropdownDataGeneric<DoublePinyinSchemas>.UpdateLabels(DoublePinyinSchemas);
180182
// Since we are using Binding instead of DynamicResource, we need to manually trigger the update
181183
OnPropertyChanged(nameof(AlwaysPreviewToolTip));
182184
}
@@ -262,9 +264,25 @@ private void OpenImeSettings()
262264
public bool ShouldUsePinyin
263265
{
264266
get => Settings.ShouldUsePinyin;
265-
set => Settings.ShouldUsePinyin = value;
267+
set
268+
{
269+
if (value == false && UseDoublePinyin == true)
270+
{
271+
UseDoublePinyin = false;
272+
}
273+
Settings.ShouldUsePinyin = value;
274+
}
266275
}
267276

277+
public bool UseDoublePinyin
278+
{
279+
set => Settings.UseDoublePinyin = value;
280+
get => Settings.UseDoublePinyin;
281+
}
282+
283+
public List<DoublePinyinSchemaData> DoublePinyinSchemas { get; } =
284+
DropdownDataGeneric<DoublePinyinSchemas>.GetValues<DoublePinyinSchemaData>("DoublePinyinSchemas");
285+
268286
public List<Language> Languages => _translater.LoadAvailableLanguages();
269287

270288
public string AlwaysPreviewToolTip => string.Format(

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,44 @@
347347
OnContent="{DynamicResource enable}" />
348348
</cc:Card>
349349

350-
<cc:Card
351-
Title="{DynamicResource ShouldUsePinyin}"
352-
Icon="&#xe98a;"
353-
Sub="{DynamicResource ShouldUsePinyinToolTip}">
354-
<ui:ToggleSwitch
355-
IsOn="{Binding Settings.ShouldUsePinyin}"
356-
OffContent="{DynamicResource disable}"
357-
OnContent="{DynamicResource enable}"
358-
ToolTip="{DynamicResource ShouldUsePinyinToolTip}" />
359-
</cc:Card>
350+
<cc:CardGroup Margin="0 4 0 0">
351+
<cc:Card
352+
Title="{DynamicResource ShouldUsePinyin}"
353+
Icon="&#xe98a;"
354+
Sub="{DynamicResource ShouldUsePinyinToolTip}"
355+
Type="First">
356+
<ui:ToggleSwitch
357+
IsOn="{Binding ShouldUsePinyin}"
358+
OffContent="{DynamicResource disable}"
359+
OnContent="{DynamicResource enable}"
360+
ToolTip="{DynamicResource ShouldUsePinyinToolTip}" />
361+
</cc:Card>
362+
<cc:Card
363+
Visibility="{ext:VisibleWhen {Binding ShouldUsePinyin},
364+
IsEqualToBool=True}"
365+
Title="{DynamicResource ShouldUseDoublePinyin}"
366+
Icon="&#xf085;"
367+
Sub="{DynamicResource ShouldUseDoublePinyinToolTip}"
368+
Type="Middle">
369+
<ui:ToggleSwitch
370+
IsOn="{Binding UseDoublePinyin}"
371+
OffContent="{DynamicResource disable}"
372+
OnContent="{DynamicResource enable}"
373+
ToolTip="{DynamicResource ShouldUseDoublePinyinToolTip}" />
374+
</cc:Card>
375+
<cc:Card
376+
Visibility="{ext:VisibleWhen {Binding UseDoublePinyin},
377+
IsEqualToBool=True}"
378+
Title="{DynamicResource DoublePinyinSchema}"
379+
Sub="{DynamicResource DoublePinyinSchemaToolTip}"
380+
Type="Last">
381+
<ComboBox
382+
DisplayMemberPath="Display"
383+
ItemsSource="{Binding DoublePinyinSchemas}"
384+
SelectedValue="{Binding Settings.DoublePinyinSchema}"
385+
SelectedValuePath="Value" />
386+
</cc:Card>
387+
</cc:CardGroup>
360388

361389
<cc:Card
362390
Title="{DynamicResource language}"

0 commit comments

Comments
 (0)