mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Update labels on language change and other refactor
- Bring back viewmodel construction on init - Remove redundant init code
This commit is contained in:
parent
08f17c4f05
commit
22ffc80aeb
4 changed files with 11 additions and 11 deletions
|
|
@ -6,6 +6,7 @@ using System.Text.RegularExpressions;
|
|||
using System.Windows.Controls;
|
||||
using Mages.Core;
|
||||
using Flow.Launcher.Plugin.Calculator.Views;
|
||||
using Flow.Launcher.Plugin.Calculator.ViewModels;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Calculator
|
||||
{
|
||||
|
|
@ -28,12 +29,14 @@ namespace Flow.Launcher.Plugin.Calculator
|
|||
|
||||
internal static PluginInitContext Context { get; set; } = null!;
|
||||
|
||||
private static Settings _settings;
|
||||
private Settings _settings;
|
||||
private SettingsViewModel _viewModel;
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
Context = context;
|
||||
_settings = context.API.LoadSettingJsonStorage<Settings>();
|
||||
_viewModel = new SettingsViewModel(_settings);
|
||||
|
||||
MagesEngine = new Engine(new Configuration
|
||||
{
|
||||
|
|
@ -152,7 +155,7 @@ namespace Flow.Launcher.Plugin.Calculator
|
|||
return value.ToString(numberFormatInfo);
|
||||
}
|
||||
|
||||
private static string GetDecimalSeparator()
|
||||
private string GetDecimalSeparator()
|
||||
{
|
||||
string systemDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
|
||||
return _settings.DecimalSeparator switch
|
||||
|
|
@ -197,5 +200,10 @@ namespace Flow.Launcher.Plugin.Calculator
|
|||
{
|
||||
return new CalculatorSettings(_settings);
|
||||
}
|
||||
|
||||
public void OnCultureInfoChanged(CultureInfo newCulture)
|
||||
{
|
||||
DecimalSeparatorLocalized.UpdateLabels(_viewModel.AllDecimalSeparator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,11 @@ namespace Flow.Launcher.Plugin.Calculator.ViewModels
|
|||
public SettingsViewModel(Settings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
DecimalSeparatorLocalized.UpdateLabels(AllDecimalSeparator);
|
||||
}
|
||||
|
||||
public Settings Settings { get; init; }
|
||||
|
||||
public IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
|
||||
public static IEnumerable<int> MaxDecimalPlacesRange => Enumerable.Range(1, 20);
|
||||
|
||||
public List<DecimalSeparatorLocalized> AllDecimalSeparator { get; } = DecimalSeparatorLocalized.GetValues();
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
d:DataContext="{d:DesignInstance Type=viewModels:SettingsViewModel}"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
Loaded="CalculatorSettings_Loaded"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Margin="{StaticResource SettingPanelMargin}">
|
||||
|
|
|
|||
|
|
@ -19,11 +19,5 @@ namespace Flow.Launcher.Plugin.Calculator.Views
|
|||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void CalculatorSettings_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DecimalSeparatorComboBox.SelectedItem = _settings.DecimalSeparator;
|
||||
MaxDecimalPlaces.SelectedItem = _settings.MaxDecimalPlaces;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue