mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
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:
commit
3d1434f66e
6 changed files with 52 additions and 65 deletions
|
|
@ -177,32 +177,16 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
public bool AlwaysPreview { get; set; } = false;
|
||||
public bool AlwaysStartEn { get; set; } = false;
|
||||
|
||||
private SearchPrecisionScore _querySearchPrecision = SearchPrecisionScore.Regular;
|
||||
[JsonInclude, JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public SearchPrecisionScore QuerySearchPrecision { get; private set; } = SearchPrecisionScore.Regular;
|
||||
|
||||
[JsonIgnore]
|
||||
public string QuerySearchPrecisionString
|
||||
public SearchPrecisionScore QuerySearchPrecision
|
||||
{
|
||||
get { return QuerySearchPrecision.ToString(); }
|
||||
get => _querySearchPrecision;
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
var precisionScore = (SearchPrecisionScore)Enum
|
||||
.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;
|
||||
}
|
||||
_querySearchPrecision = value;
|
||||
if (StringMatcher.Instance != null)
|
||||
StringMatcher.Instance.UserSettingSearchPrecision = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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="querySearchPrecision">Query Search Precision</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="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>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
<?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">
|
||||
<?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">
|
||||
<!-- MainWindow -->
|
||||
<system:String x:Key="registerHotkeyFailed">Не удалось зарегистрировать сочетание клавиш "{0}". Возможно, оно используется другой программой. Измените сочетание клавиш или закройте другую программу.</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="querySearchPrecision">Точность поиска запросов</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="ShouldUsePinyinToolTip">Позволяет использовать пиньинь для поиска. Пиньинь - это стандартная система латинизированной орфографии для перевода китайского языка.</system:String>
|
||||
<system:String x:Key="AlwaysPreview">Всегда предпросмотр</system:String>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ namespace Flow.Launcher.SettingPages.ViewModels;
|
|||
public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
|
@ -19,9 +20,17 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
|
|||
{
|
||||
var key = keyPrefix + value;
|
||||
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;
|
||||
}
|
||||
|
||||
public static void UpdateLabels<TR>(List<TR> options) where TR : DropdownDataGeneric<TValue>
|
||||
{
|
||||
foreach (var item in options)
|
||||
{
|
||||
item.Display = InternationalizationManager.Instance.GetTranslation(item.LocalizationKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
Settings = settings;
|
||||
_updater = updater;
|
||||
_portable = portable;
|
||||
UpdateLastQueryModeDisplay();
|
||||
UpdateEnumDropdownLocalizations();
|
||||
}
|
||||
|
||||
public class SearchWindowScreen : DropdownDataGeneric<SearchWindowScreens> { }
|
||||
public class SearchWindowAlign : DropdownDataGeneric<SearchWindowAligns> { }
|
||||
// todo a better name?
|
||||
public class LastQueryMode : DropdownDataGeneric<Infrastructure.UserSettings.LastQueryMode> { }
|
||||
public class SearchWindowScreenData : DropdownDataGeneric<SearchWindowScreens> { }
|
||||
public class SearchWindowAlignData : DropdownDataGeneric<SearchWindowAligns> { }
|
||||
public class SearchPrecisionData : DropdownDataGeneric<SearchPrecisionScore> { }
|
||||
public class LastQueryModeData : DropdownDataGeneric<LastQueryMode> { }
|
||||
|
||||
public bool StartFlowLauncherOnSystemStartup
|
||||
{
|
||||
|
|
@ -55,11 +55,14 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
}
|
||||
|
||||
|
||||
public List<SearchWindowScreen> SearchWindowScreens =>
|
||||
DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreen>("SearchWindowScreen");
|
||||
public List<SearchWindowScreenData> SearchWindowScreens { get; } =
|
||||
DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreenData>("SearchWindowScreen");
|
||||
|
||||
public List<SearchWindowAlign> SearchWindowAligns =>
|
||||
DropdownDataGeneric<SearchWindowAligns>.GetValues<SearchWindowAlign>("SearchWindowAlign");
|
||||
public List<SearchWindowAlignData> SearchWindowAligns { get; } =
|
||||
DropdownDataGeneric<SearchWindowAligns>.GetValues<SearchWindowAlignData>("SearchWindowAlign");
|
||||
|
||||
public List<SearchPrecisionData> SearchPrecisionScores { get; } =
|
||||
DropdownDataGeneric<SearchPrecisionScore>.GetValues<SearchPrecisionData>("SearchPrecision");
|
||||
|
||||
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
|
||||
{
|
||||
if (_lastQueryModes.Count == 0)
|
||||
{
|
||||
_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}");
|
||||
}
|
||||
DropdownDataGeneric<SearchWindowScreens>.UpdateLabels(SearchWindowScreens);
|
||||
DropdownDataGeneric<SearchWindowAligns>.UpdateLabels(SearchWindowAligns);
|
||||
DropdownDataGeneric<SearchPrecisionScore>.UpdateLabels(SearchPrecisionScores);
|
||||
DropdownDataGeneric<LastQueryMode>.UpdateLabels(LastQueryModes);
|
||||
}
|
||||
|
||||
public string Language
|
||||
|
|
@ -133,7 +122,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
if (InternationalizationManager.Instance.PromptShouldUsePinyin(value))
|
||||
ShouldUsePinyin = true;
|
||||
|
||||
UpdateLastQueryModeDisplay();
|
||||
UpdateEnumDropdownLocalizations();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -143,12 +132,6 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
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 IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||
|
||||
|
|
|
|||
|
|
@ -162,8 +162,10 @@
|
|||
Sub="{DynamicResource querySearchPrecisionToolTip}">
|
||||
<ComboBox
|
||||
MaxWidth="200"
|
||||
ItemsSource="{Binding QuerySearchPrecisionStrings}"
|
||||
SelectedItem="{Binding Settings.QuerySearchPrecisionString}" />
|
||||
DisplayMemberPath="Display"
|
||||
ItemsSource="{Binding SearchPrecisionScores}"
|
||||
SelectedValue="{Binding Settings.QuerySearchPrecision}"
|
||||
SelectedValuePath="Value" />
|
||||
</cc:Card>
|
||||
|
||||
<cc:Card Title="{DynamicResource lastQueryMode}" Sub="{DynamicResource lastQueryModeToolTip}">
|
||||
|
|
|
|||
Loading…
Reference in a new issue