Skip to content

Commit 22ffc80

Browse files
Update labels on language change and other refactor
- Bring back viewmodel construction on init - Remove redundant init code
1 parent 08f17c4 commit 22ffc80

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Plugins/Flow.Launcher.Plugin.Calculator/Main.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Windows.Controls;
77
using Mages.Core;
88
using Flow.Launcher.Plugin.Calculator.Views;
9+
using Flow.Launcher.Plugin.Calculator.ViewModels;
910

1011
namespace Flow.Launcher.Plugin.Calculator
1112
{
@@ -28,12 +29,14 @@ public class Main : IPlugin, IPluginI18n, ISettingProvider
2829

2930
internal static PluginInitContext Context { get; set; } = null!;
3031

31-
private static Settings _settings;
32+
private Settings _settings;
33+
private SettingsViewModel _viewModel;
3234

3335
public void Init(PluginInitContext context)
3436
{
3537
Context = context;
3638
_settings = context.API.LoadSettingJsonStorage<Settings>();
39+
_viewModel = new SettingsViewModel(_settings);
3740

3841
MagesEngine = new Engine(new Configuration
3942
{
@@ -152,7 +155,7 @@ private static string ChangeDecimalSeparator(decimal value, string newDecimalSep
152155
return value.ToString(numberFormatInfo);
153156
}
154157

155-
private static string GetDecimalSeparator()
158+
private string GetDecimalSeparator()
156159
{
157160
string systemDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
158161
return _settings.DecimalSeparator switch
@@ -197,5 +200,10 @@ public Control CreateSettingPanel()
197200
{
198201
return new CalculatorSettings(_settings);
199202
}
203+
204+
public void OnCultureInfoChanged(CultureInfo newCulture)
205+
{
206+
DecimalSeparatorLocalized.UpdateLabels(_viewModel.AllDecimalSeparator);
207+
}
200208
}
201209
}

Plugins/Flow.Launcher.Plugin.Calculator/ViewModels/SettingsViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ public class SettingsViewModel : BaseModel
88
public SettingsViewModel(Settings settings)
99
{
1010
Settings = settings;
11-
DecimalSeparatorLocalized.UpdateLabels(AllDecimalSeparator);
1211
}
1312

1413
public Settings Settings { get; init; }
1514

16-
public IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
15+
public static IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
1716

1817
public List<DecimalSeparatorLocalized> AllDecimalSeparator { get; } = DecimalSeparatorLocalized.GetValues();
1918

Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
d:DataContext="{d:DesignInstance Type=viewModels:SettingsViewModel}"
1010
d:DesignHeight="450"
1111
d:DesignWidth="800"
12-
Loaded="CalculatorSettings_Loaded"
1312
mc:Ignorable="d">
1413

1514
<Grid Margin="{StaticResource SettingPanelMargin}">

Plugins/Flow.Launcher.Plugin.Calculator/Views/CalculatorSettings.xaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,5 @@ public CalculatorSettings(Settings settings)
1919
DataContext = _viewModel;
2020
InitializeComponent();
2121
}
22-
23-
private void CalculatorSettings_Loaded(object sender, RoutedEventArgs e)
24-
{
25-
DecimalSeparatorComboBox.SelectedItem = _settings.DecimalSeparator;
26-
MaxDecimalPlaces.SelectedItem = _settings.MaxDecimalPlaces;
27-
}
2822
}
2923
}

0 commit comments

Comments
 (0)