Skip to content

Commit 3d1434f

Browse files
authored
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
2 parents 5f8d47c + cf97475 commit 3d1434f

File tree

6 files changed

+52
-65
lines changed

6 files changed

+52
-65
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,32 +177,16 @@ public CustomBrowserViewModel CustomBrowser
177177
public bool AlwaysPreview { get; set; } = false;
178178
public bool AlwaysStartEn { get; set; } = false;
179179

180+
private SearchPrecisionScore _querySearchPrecision = SearchPrecisionScore.Regular;
180181
[JsonInclude, JsonConverter(typeof(JsonStringEnumConverter))]
181-
public SearchPrecisionScore QuerySearchPrecision { get; private set; } = SearchPrecisionScore.Regular;
182-
183-
[JsonIgnore]
184-
public string QuerySearchPrecisionString
182+
public SearchPrecisionScore QuerySearchPrecision
185183
{
186-
get { return QuerySearchPrecision.ToString(); }
184+
get => _querySearchPrecision;
187185
set
188186
{
189-
try
190-
{
191-
var precisionScore = (SearchPrecisionScore)Enum
192-
.Parse(typeof(SearchPrecisionScore), value);
193-
194-
QuerySearchPrecision = precisionScore;
195-
StringMatcher.Instance.UserSettingSearchPrecision = precisionScore;
196-
}
197-
catch (ArgumentException e)
198-
{
199-
Logger.Log.Exception(nameof(Settings), "Failed to load QuerySearchPrecisionString value from Settings file", e);
200-
201-
QuerySearchPrecision = SearchPrecisionScore.Regular;
202-
StringMatcher.Instance.UserSettingSearchPrecision = SearchPrecisionScore.Regular;
203-
204-
throw;
205-
}
187+
_querySearchPrecision = value;
188+
if (StringMatcher.Instance != null)
189+
StringMatcher.Instance.UserSettingSearchPrecision = value;
206190
}
207191
}
208192

Flow.Launcher/Languages/en.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
<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>
7878
<system:String x:Key="querySearchPrecision">Query Search Precision</system:String>
7979
<system:String x:Key="querySearchPrecisionToolTip">Changes minimum match score required for results.</system:String>
80+
<system:String x:Key="SearchPrecisionNone">None</system:String>
81+
<system:String x:Key="SearchPrecisionLow">Low</system:String>
82+
<system:String x:Key="SearchPrecisionRegular">Regular</system:String>
8083
<system:String x:Key="ShouldUsePinyin">Search with Pinyin</system:String>
8184
<system:String x:Key="ShouldUsePinyinToolTip">Allows using Pinyin to search. Pinyin is the standard system of romanized spelling for translating Chinese.</system:String>
8285
<system:String x:Key="AlwaysPreview">Always Preview</system:String>

Flow.Launcher/Languages/ru.xaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
<?xml version="1.0"?>
2-
<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">
1+
<?xml version="1.0" ?>
2+
<ResourceDictionary
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:system="clr-namespace:System;assembly=mscorlib">
36
<!-- MainWindow -->
47
<system:String x:Key="registerHotkeyFailed">Не удалось зарегистрировать сочетание клавиш &quot;{0}&quot;. Возможно, оно используется другой программой. Измените сочетание клавиш или закройте другую программу.</system:String>
58
<system:String x:Key="MessageBoxTitle">Flow Launcher</system:String>
@@ -75,6 +78,9 @@
7578
<system:String x:Key="hideNotifyIconToolTip">Когда значок скрыт в трее, меню настройки можно открыть, щёлкнув правой кнопкой мыши на окне поиска.</system:String>
7679
<system:String x:Key="querySearchPrecision">Точность поиска запросов</system:String>
7780
<system:String x:Key="querySearchPrecisionToolTip">Изменение минимального количества совпадений при поиске, необходимого для получения результатов.</system:String>
81+
<system:String x:Key="SearchPrecisionNone">Нет</system:String>
82+
<system:String x:Key="SearchPrecisionLow">Низкая</system:String>
83+
<system:String x:Key="SearchPrecisionRegular">Обычная</system:String>
7884
<system:String x:Key="ShouldUsePinyin">Поиск с использованием пиньинь</system:String>
7985
<system:String x:Key="ShouldUsePinyinToolTip">Позволяет использовать пиньинь для поиска. Пиньинь - это стандартная система латинизированной орфографии для перевода китайского языка.</system:String>
8086
<system:String x:Key="AlwaysPreview">Всегда предпросмотр</system:String>

Flow.Launcher/SettingPages/ViewModels/DropdownDataGeneric.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace Flow.Launcher.SettingPages.ViewModels;
88
public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
99
{
1010
public string Display { get; set; }
11-
public TValue Value { get; set; }
11+
public TValue Value { get; private init; }
12+
private string LocalizationKey { get; init; }
1213

1314
public static List<TR> GetValues<TR>(string keyPrefix) where TR : DropdownDataGeneric<TValue>, new()
1415
{
@@ -19,9 +20,17 @@ public class DropdownDataGeneric<TValue> : BaseModel where TValue : Enum
1920
{
2021
var key = keyPrefix + value;
2122
var display = InternationalizationManager.Instance.GetTranslation(key);
22-
data.Add(new TR { Display = display, Value = value });
23+
data.Add(new TR { Display = display, Value = value, LocalizationKey = key });
2324
}
2425

2526
return data;
2627
}
28+
29+
public static void UpdateLabels<TR>(List<TR> options) where TR : DropdownDataGeneric<TValue>
30+
{
31+
foreach (var item in options)
32+
{
33+
item.Display = InternationalizationManager.Instance.GetTranslation(item.LocalizationKey);
34+
}
35+
}
2736
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public SettingsPaneGeneralViewModel(Settings settings, Updater updater, IPortabl
2424
Settings = settings;
2525
_updater = updater;
2626
_portable = portable;
27-
UpdateLastQueryModeDisplay();
27+
UpdateEnumDropdownLocalizations();
2828
}
2929

30-
public class SearchWindowScreen : DropdownDataGeneric<SearchWindowScreens> { }
31-
public class SearchWindowAlign : DropdownDataGeneric<SearchWindowAligns> { }
32-
// todo a better name?
33-
public class LastQueryMode : DropdownDataGeneric<Infrastructure.UserSettings.LastQueryMode> { }
30+
public class SearchWindowScreenData : DropdownDataGeneric<SearchWindowScreens> { }
31+
public class SearchWindowAlignData : DropdownDataGeneric<SearchWindowAligns> { }
32+
public class SearchPrecisionData : DropdownDataGeneric<SearchPrecisionScore> { }
33+
public class LastQueryModeData : DropdownDataGeneric<LastQueryMode> { }
3434

3535
public bool StartFlowLauncherOnSystemStartup
3636
{
@@ -55,11 +55,14 @@ public bool StartFlowLauncherOnSystemStartup
5555
}
5656

5757

58-
public List<SearchWindowScreen> SearchWindowScreens =>
59-
DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreen>("SearchWindowScreen");
58+
public List<SearchWindowScreenData> SearchWindowScreens { get; } =
59+
DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreenData>("SearchWindowScreen");
6060

61-
public List<SearchWindowAlign> SearchWindowAligns =>
62-
DropdownDataGeneric<SearchWindowAligns>.GetValues<SearchWindowAlign>("SearchWindowAlign");
61+
public List<SearchWindowAlignData> SearchWindowAligns { get; } =
62+
DropdownDataGeneric<SearchWindowAligns>.GetValues<SearchWindowAlignData>("SearchWindowAlign");
63+
64+
public List<SearchPrecisionData> SearchPrecisionScores { get; } =
65+
DropdownDataGeneric<SearchPrecisionScore>.GetValues<SearchPrecisionData>("SearchPrecision");
6366

6467
public List<int> ScreenNumbers
6568
{
@@ -98,29 +101,15 @@ public bool PortableMode
98101
}
99102
}
100103

101-
private List<LastQueryMode> _lastQueryModes = new();
104+
public List<LastQueryModeData> LastQueryModes { get; } =
105+
DropdownDataGeneric<LastQueryMode>.GetValues<LastQueryModeData>("LastQuery");
102106

103-
public List<LastQueryMode> LastQueryModes
107+
private void UpdateEnumDropdownLocalizations()
104108
{
105-
get
106-
{
107-
if (_lastQueryModes.Count == 0)
108-
{
109-
_lastQueryModes =
110-
DropdownDataGeneric<Infrastructure.UserSettings.LastQueryMode>
111-
.GetValues<LastQueryMode>("LastQuery");
112-
}
113-
114-
return _lastQueryModes;
115-
}
116-
}
117-
118-
private void UpdateLastQueryModeDisplay()
119-
{
120-
foreach (var item in LastQueryModes)
121-
{
122-
item.Display = InternationalizationManager.Instance.GetTranslation($"LastQuery{item.Value}");
123-
}
109+
DropdownDataGeneric<SearchWindowScreens>.UpdateLabels(SearchWindowScreens);
110+
DropdownDataGeneric<SearchWindowAligns>.UpdateLabels(SearchWindowAligns);
111+
DropdownDataGeneric<SearchPrecisionScore>.UpdateLabels(SearchPrecisionScores);
112+
DropdownDataGeneric<LastQueryMode>.UpdateLabels(LastQueryModes);
124113
}
125114

126115
public string Language
@@ -133,7 +122,7 @@ public string Language
133122
if (InternationalizationManager.Instance.PromptShouldUsePinyin(value))
134123
ShouldUsePinyin = true;
135124

136-
UpdateLastQueryModeDisplay();
125+
UpdateEnumDropdownLocalizations();
137126
}
138127
}
139128

@@ -143,12 +132,6 @@ public bool ShouldUsePinyin
143132
set => Settings.ShouldUsePinyin = value;
144133
}
145134

146-
public List<string> QuerySearchPrecisionStrings => Enum
147-
.GetValues(typeof(SearchPrecisionScore))
148-
.Cast<SearchPrecisionScore>()
149-
.Select(v => v.ToString())
150-
.ToList();
151-
152135
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
153136
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
154137

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@
162162
Sub="{DynamicResource querySearchPrecisionToolTip}">
163163
<ComboBox
164164
MaxWidth="200"
165-
ItemsSource="{Binding QuerySearchPrecisionStrings}"
166-
SelectedItem="{Binding Settings.QuerySearchPrecisionString}" />
165+
DisplayMemberPath="Display"
166+
ItemsSource="{Binding SearchPrecisionScores}"
167+
SelectedValue="{Binding Settings.QuerySearchPrecision}"
168+
SelectedValuePath="Value" />
167169
</cc:Card>
168170

169171
<cc:Card Title="{DynamicResource lastQueryMode}" Sub="{DynamicResource lastQueryModeToolTip}">

0 commit comments

Comments
 (0)