Skip to content

Commit

Permalink
Merge pull request microsoft#42 from microsoft/AddPinyinPerformance
Browse files Browse the repository at this point in the history
Cherry picked pinyin performance changes from jjw24's master branch

(cherry picked from commit b9e437c)
  • Loading branch information
alekhyareddy28 authored and ryanbodrug-microsoft committed Apr 6, 2020
1 parent d73ab36 commit b6b9fad
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/modules/launcher/Wox.Core/Resource/Internationalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ public void ChangeLanguage(Language language)

}

public bool PromptShouldUsePinyin(string languageCodeToSet)
{
var languageToSet = GetLanguageByLanguageCode(languageCodeToSet);

if (Settings.ShouldUsePinyin)
return false;

if (languageToSet != AvailableLanguages.Chinese && languageToSet != AvailableLanguages.Chinese_TW)
return false;

if (MessageBox.Show("Do you want to turn on search with Pinyin?", string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
return false;

return true;
}

private void RemoveOldLanguageFiles()
{
var dicts = Application.Current.Resources.MergedDictionaries;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/launcher/Wox.Infrastructure/Alphabet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public bool ContainsChinese(string word)

if (word.Length > 40)
{
Log.Debug($"|Wox.Infrastructure.StringMatcher.ScoreForPinyin|skip too long string: {word}");
//Skip strings that are too long string for Pinyin conversion.
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class Settings : BaseModel
/// <summary>
/// when false Alphabet static service will always return empty results
/// </summary>
public bool ShouldUsePinyin { get; set; } = true;

public bool ShouldUsePinyin { get; set; } = false;

internal StringMatcher.SearchPrecisionScore QuerySearchPrecision { get; private set; } = StringMatcher.SearchPrecisionScore.Regular;

Expand Down
29 changes: 28 additions & 1 deletion src/modules/launcher/Wox/ViewModel/SettingWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -77,6 +77,33 @@ public List<LastQueryMode> LastQueryModes
}
}

public string Language
{
get
{
return Settings.Language;
}
set
{
InternationalizationManager.Instance.ChangeLanguage(value);

if (InternationalizationManager.Instance.PromptShouldUsePinyin(value))
ShouldUsePinyin = true;
}
}

public bool ShouldUsePinyin
{
get
{
return Settings.ShouldUsePinyin;
}
set
{
Settings.ShouldUsePinyin = value;
}
}

public List<string> QuerySearchPrecisionStrings
{
get
Expand Down

0 comments on commit b6b9fad

Please sign in to comment.