Merge pull request #2732 from Flow-Launcher/settings-comboboxes-realtime-localization

Real-time updates to ComboBox localization in general pane of settings after changing the language
This commit is contained in:
DB P 2024-05-28 10:03:55 +09:00 committed by GitHub
commit 3d1434f66e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 52 additions and 65 deletions

View file

@ -177,32 +177,16 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public bool AlwaysPreview { get; set; } = false; public bool AlwaysPreview { get; set; } = false;
public bool AlwaysStartEn { get; set; } = false; public bool AlwaysStartEn { get; set; } = false;
private SearchPrecisionScore _querySearchPrecision = SearchPrecisionScore.Regular;
[JsonInclude, JsonConverter(typeof(JsonStringEnumConverter))] [JsonInclude, JsonConverter(typeof(JsonStringEnumConverter))]
public SearchPrecisionScore QuerySearchPrecision { get; private set; } = SearchPrecisionScore.Regular; public SearchPrecisionScore QuerySearchPrecision
[JsonIgnore]
public string QuerySearchPrecisionString
{ {
get { return QuerySearchPrecision.ToString(); } get => _querySearchPrecision;
set set
{ {
try _querySearchPrecision = value;
{ if (StringMatcher.Instance != null)
var precisionScore = (SearchPrecisionScore)Enum StringMatcher.Instance.UserSettingSearchPrecision = value;
.Parse(typeof(SearchPrecisionScore), value);
QuerySearchPrecision = precisionScore;
StringMatcher.Instance.UserSettingSearchPrecision = precisionScore;
}
catch (ArgumentException e)
{
Logger.Log.Exception(nameof(Settings), "Failed to load QuerySearchPrecisionString value from Settings file", e);
QuerySearchPrecision = SearchPrecisionScore.Regular;
StringMatcher.Instance.UserSettingSearchPrecision = SearchPrecisionScore.Regular;
throw;
}
} }
} }

View file

@ -77,6 +77,9 @@
<system:String x:Key="hideNotifyIconToolTip">When the icon is hidden from the tray, the Settings menu can be opened by right-clicking on the search window.</system:String> <system:String x:Key="hideNotifyIconToolTip">When the icon is hidden from the tray, the Settings menu can be opened by right-clicking on the search window.</system:String>
<system:String x:Key="querySearchPrecision">Query Search Precision</system:String> <system:String x:Key="querySearchPrecision">Query Search Precision</system:String>
<system:String x:Key="querySearchPrecisionToolTip">Changes minimum match score required for results.</system:String> <system:String x:Key="querySearchPrecisionToolTip">Changes minimum match score required for results.</system:String>
<system:String x:Key="SearchPrecisionNone">None</system:String>
<system:String x:Key="SearchPrecisionLow">Low</system:String>
<system:String x:Key="SearchPrecisionRegular">Regular</system:String>
<system:String x:Key="ShouldUsePinyin">Search with Pinyin</system:String> <system:String x:Key="ShouldUsePinyin">Search with Pinyin</system:String>
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese.</system:String> <system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese.</system:String>
<system:String x:Key="AlwaysPreview">Always Preview</system:String> <system:String x:Key="AlwaysPreview">Always Preview</system:String>

View file

@ -1,5 +1,8 @@
<?xml version="1.0"?> <?xml version="1.0" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib"> <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- MainWindow --> <!-- MainWindow -->
<system:String x:Key="registerHotkeyFailed">Не удалось зарегистрировать сочетание клавиш &quot;{0}&quot;. Возможно, оно используется другой программой. Измените сочетание клавиш или закройте другую программу.</system:String> <system:String x:Key="registerHotkeyFailed">Не удалось зарегистрировать сочетание клавиш &quot;{0}&quot;. Возможно, оно используется другой программой. Измените сочетание клавиш или закройте другую программу.</system:String>
<system:String x:Key="MessageBoxTitle">Flow Launcher</system:String> <system:String x:Key="MessageBoxTitle">Flow Launcher</system:String>
@ -75,6 +78,9 @@
<system:String x:Key="hideNotifyIconToolTip">Когда значок скрыт в трее, меню настройки можно открыть, щёлкнув правой кнопкой мыши на окне поиска.</system:String> <system:String x:Key="hideNotifyIconToolTip">Когда значок скрыт в трее, меню настройки можно открыть, щёлкнув правой кнопкой мыши на окне поиска.</system:String>
<system:String x:Key="querySearchPrecision">Точность поиска запросов</system:String> <system:String x:Key="querySearchPrecision">Точность поиска запросов</system:String>
<system:String x:Key="querySearchPrecisionToolTip">Изменение минимального количества совпадений при поиске, необходимого для получения результатов.</system:String> <system:String x:Key="querySearchPrecisionToolTip">Изменение минимального количества совпадений при поиске, необходимого для получения результатов.</system:String>
<system:String x:Key="SearchPrecisionNone">Нет</system:String>
<system:String x:Key="SearchPrecisionLow">Низкая</system:String>
<system:String x:Key="SearchPrecisionRegular">Обычная</system:String>
<system:String x:Key="ShouldUsePinyin">Поиск с использованием пиньинь</system:String> <system:String x:Key="ShouldUsePinyin">Поиск с использованием пиньинь</system:String>
<system:String x:Key="ShouldUsePinyinToolTip">Позволяет использовать пиньинь для поиска. Пиньинь - это стандартная система латинизированной орфографии для перевода китайского языка.</system:String> <system:String x:Key="ShouldUsePinyinToolTip">Позволяет использовать пиньинь для поиска. Пиньинь - это стандартная система латинизированной орфографии для перевода китайского языка.</system:String>
<system:String x:Key="AlwaysPreview">Всегда предпросмотр</system:String> <system:String x:Key="AlwaysPreview">Всегда предпросмотр</system:String>

View file

@ -8,7 +8,8 @@ namespace Flow.Launcher.SettingPages.ViewModels;
public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
{ {
public string Display { get; set; } public string Display { get; set; }
public TValue Value { get; set; } public TValue Value { get; private init; }
private string LocalizationKey { get; init; }
public static List<TR> GetValues<TR>(string keyPrefix) where TR : DropdownDataGeneric<TValue>, new() public static List<TR> GetValues<TR>(string keyPrefix) where TR : DropdownDataGeneric<TValue>, new()
{ {
@ -19,9 +20,17 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
{ {
var key = keyPrefix + value; var key = keyPrefix + value;
var display = InternationalizationManager.Instance.GetTranslation(key); var display = InternationalizationManager.Instance.GetTranslation(key);
data.Add(new TR { Display = display, Value = value }); data.Add(new TR { Display = display, Value = value, LocalizationKey = key });
} }
return data; return data;
} }
public static void UpdateLabels<TR>(List<TR> options) where TR : DropdownDataGeneric<TValue>
{
foreach (var item in options)
{
item.Display = InternationalizationManager.Instance.GetTranslation(item.LocalizationKey);
}
}
} }

View file

@ -24,13 +24,13 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
Settings = settings; Settings = settings;
_updater = updater; _updater = updater;
_portable = portable; _portable = portable;
UpdateLastQueryModeDisplay(); UpdateEnumDropdownLocalizations();
} }
public class SearchWindowScreen : DropdownDataGeneric<SearchWindowScreens> { } public class SearchWindowScreenData : DropdownDataGeneric<SearchWindowScreens> { }
public class SearchWindowAlign : DropdownDataGeneric<SearchWindowAligns> { } public class SearchWindowAlignData : DropdownDataGeneric<SearchWindowAligns> { }
// todo a better name? public class SearchPrecisionData : DropdownDataGeneric<SearchPrecisionScore> { }
public class LastQueryMode : DropdownDataGeneric<Infrastructure.UserSettings.LastQueryMode> { } public class LastQueryModeData : DropdownDataGeneric<LastQueryMode> { }
public bool StartFlowLauncherOnSystemStartup public bool StartFlowLauncherOnSystemStartup
{ {
@ -55,11 +55,14 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
} }
public List<SearchWindowScreen> SearchWindowScreens => public List<SearchWindowScreenData> SearchWindowScreens { get; } =
DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreen>("SearchWindowScreen"); DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreenData>("SearchWindowScreen");
public List<SearchWindowAlign> SearchWindowAligns => public List<SearchWindowAlignData> SearchWindowAligns { get; } =
DropdownDataGeneric<SearchWindowAligns>.GetValues<SearchWindowAlign>("SearchWindowAlign"); DropdownDataGeneric<SearchWindowAligns>.GetValues<SearchWindowAlignData>("SearchWindowAlign");
public List<SearchPrecisionData> SearchPrecisionScores { get; } =
DropdownDataGeneric<SearchPrecisionScore>.GetValues<SearchPrecisionData>("SearchPrecision");
public List<int> ScreenNumbers public List<int> ScreenNumbers
{ {
@ -98,29 +101,15 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
} }
} }
private List<LastQueryMode> _lastQueryModes = new(); public List<LastQueryModeData> LastQueryModes { get; } =
DropdownDataGeneric<LastQueryMode>.GetValues<LastQueryModeData>("LastQuery");
public List<LastQueryMode> LastQueryModes private void UpdateEnumDropdownLocalizations()
{ {
get DropdownDataGeneric<SearchWindowScreens>.UpdateLabels(SearchWindowScreens);
{ DropdownDataGeneric<SearchWindowAligns>.UpdateLabels(SearchWindowAligns);
if (_lastQueryModes.Count == 0) DropdownDataGeneric<SearchPrecisionScore>.UpdateLabels(SearchPrecisionScores);
{ DropdownDataGeneric<LastQueryMode>.UpdateLabels(LastQueryModes);
_lastQueryModes =
DropdownDataGeneric<Infrastructure.UserSettings.LastQueryMode>
.GetValues<LastQueryMode>("LastQuery");
}
return _lastQueryModes;
}
}
private void UpdateLastQueryModeDisplay()
{
foreach (var item in LastQueryModes)
{
item.Display = InternationalizationManager.Instance.GetTranslation($"LastQuery{item.Value}");
}
} }
public string Language public string Language
@ -133,7 +122,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
if (InternationalizationManager.Instance.PromptShouldUsePinyin(value)) if (InternationalizationManager.Instance.PromptShouldUsePinyin(value))
ShouldUsePinyin = true; ShouldUsePinyin = true;
UpdateLastQueryModeDisplay(); UpdateEnumDropdownLocalizations();
} }
} }
@ -143,12 +132,6 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
set => Settings.ShouldUsePinyin = value; set => Settings.ShouldUsePinyin = value;
} }
public List<string> QuerySearchPrecisionStrings => Enum
.GetValues(typeof(SearchPrecisionScore))
.Cast<SearchPrecisionScore>()
.Select(v => v.ToString())
.ToList();
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages(); public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16); public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);

View file

@ -162,8 +162,10 @@
Sub="{DynamicResource querySearchPrecisionToolTip}"> Sub="{DynamicResource querySearchPrecisionToolTip}">
<ComboBox <ComboBox
MaxWidth="200" MaxWidth="200"
ItemsSource="{Binding QuerySearchPrecisionStrings}" DisplayMemberPath="Display"
SelectedItem="{Binding Settings.QuerySearchPrecisionString}" /> ItemsSource="{Binding SearchPrecisionScores}"
SelectedValue="{Binding Settings.QuerySearchPrecision}"
SelectedValuePath="Value" />
</cc:Card> </cc:Card>
<cc:Card Title="{DynamicResource lastQueryMode}" Sub="{DynamicResource lastQueryModeToolTip}"> <cc:Card Title="{DynamicResource lastQueryMode}" Sub="{DynamicResource lastQueryModeToolTip}">