Merge pull request #2722 from Flow-Launcher/fix-decimal

Fix bug and typo in Calculator Plugin
This commit is contained in:
Jeremy Wu 2024-05-26 12:46:38 +10:00 committed by GitHub
commit 6eb8ef687c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 28 additions and 34 deletions

View file

@ -96,13 +96,10 @@ namespace Flow.Launcher.Core.Resource
{ {
LoadLanguage(language); LoadLanguage(language);
} }
// Culture of this thread // Culture of main thread
// Use CreateSpecificCulture to preserve possible user-override settings in Windows // Use CreateSpecificCulture to preserve possible user-override settings in Windows, if Flow's language culture is the same as Windows's
CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode); CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture; CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;
// App domain
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture(language.LanguageCode);
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.DefaultThreadCurrentCulture;
// Raise event after culture is set // Raise event after culture is set
Settings.Language = language.LanguageCode; Settings.Language = language.LanguageCode;
@ -193,7 +190,7 @@ namespace Flow.Launcher.Core.Resource
{ {
p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle(); p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle();
p.Metadata.Description = pluginI18N.GetTranslatedPluginDescription(); p.Metadata.Description = pluginI18N.GetTranslatedPluginDescription();
pluginI18N.OnCultureInfoChanged(CultureInfo.DefaultThreadCurrentCulture); pluginI18N.OnCultureInfoChanged(CultureInfo.CurrentCulture);
} }
catch (Exception e) catch (Exception e)
{ {

View file

@ -44,7 +44,7 @@ public class QuerySuggestionBoxConverter : IMultiValueConverter
// Check if Text will be larger than our QueryTextBox // Check if Text will be larger than our QueryTextBox
Typeface typeface = new Typeface(queryTextBox.FontFamily, queryTextBox.FontStyle, queryTextBox.FontWeight, queryTextBox.FontStretch); Typeface typeface = new Typeface(queryTextBox.FontFamily, queryTextBox.FontStyle, queryTextBox.FontWeight, queryTextBox.FontStretch);
// TODO: Obsolete warning? // TODO: Obsolete warning?
var ft = new FormattedText(queryTextBox.Text, CultureInfo.DefaultThreadCurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, queryTextBox.FontSize, Brushes.Black); var ft = new FormattedText(queryTextBox.Text, CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, typeface, queryTextBox.FontSize, Brushes.Black);
var offset = queryTextBox.Padding.Right; var offset = queryTextBox.Padding.Right;

View file

@ -21,8 +21,6 @@ namespace Flow.Launcher.SettingPages.ViewModels;
public partial class SettingsPaneThemeViewModel : BaseModel public partial class SettingsPaneThemeViewModel : BaseModel
{ {
private CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
public Settings Settings { get; } public Settings Settings { get; }
public static string LinkHowToCreateTheme => @"https://flowlauncher.com/docs/#/how-to-create-a-theme"; public static string LinkHowToCreateTheme => @"https://flowlauncher.com/docs/#/how-to-create-a-theme";
@ -136,9 +134,9 @@ public partial class SettingsPaneThemeViewModel : BaseModel
set => Settings.DateFormat = value; set => Settings.DateFormat = value;
} }
public string ClockText => DateTime.Now.ToString(TimeFormat, Culture); public string ClockText => DateTime.Now.ToString(TimeFormat, CultureInfo.CurrentCulture);
public string DateText => DateTime.Now.ToString(DateFormat, Culture); public string DateText => DateTime.Now.ToString(DateFormat, CultureInfo.CurrentCulture);
public double WindowWidthSize public double WindowWidthSize
{ {

View file

@ -485,7 +485,6 @@ namespace Flow.Launcher.ViewModel
public Settings Settings { get; } public Settings Settings { get; }
public string ClockText { get; private set; } public string ClockText { get; private set; }
public string DateText { get; private set; } public string DateText { get; private set; }
public CultureInfo Culture => CultureInfo.DefaultThreadCurrentCulture;
private async Task RegisterClockAndDateUpdateAsync() private async Task RegisterClockAndDateUpdateAsync()
{ {
@ -494,9 +493,9 @@ namespace Flow.Launcher.ViewModel
while (await timer.WaitForNextTickAsync().ConfigureAwait(false)) while (await timer.WaitForNextTickAsync().ConfigureAwait(false))
{ {
if (Settings.UseClock) if (Settings.UseClock)
ClockText = DateTime.Now.ToString(Settings.TimeFormat, Culture); ClockText = DateTime.Now.ToString(Settings.TimeFormat, CultureInfo.CurrentCulture);
if (Settings.UseDate) if (Settings.UseDate)
DateText = DateTime.Now.ToString(Settings.DateFormat, Culture); DateText = DateTime.Now.ToString(Settings.DateFormat, CultureInfo.CurrentCulture);
} }
} }

View file

@ -1,7 +1,7 @@
using System.ComponentModel; using System.ComponentModel;
using Flow.Launcher.Core.Resource; using Flow.Launcher.Core.Resource;
namespace Flow.Launcher.Plugin.Caculator namespace Flow.Launcher.Plugin.Calculator
{ {
[TypeConverter(typeof(LocalizationConverter))] [TypeConverter(typeof(LocalizationConverter))]
public enum DecimalSeparator public enum DecimalSeparator

View file

@ -5,8 +5,8 @@
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<ProjectGuid>{59BD9891-3837-438A-958D-ADC7F91F6F7E}</ProjectGuid> <ProjectGuid>{59BD9891-3837-438A-958D-ADC7F91F6F7E}</ProjectGuid>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Flow.Launcher.Plugin.Caculator</RootNamespace> <RootNamespace>Flow.Launcher.Plugin.Calculator</RootNamespace>
<AssemblyName>Flow.Launcher.Plugin.Caculator</AssemblyName> <AssemblyName>Flow.Launcher.Plugin.Calculator</AssemblyName>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
@ -18,7 +18,7 @@
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType> <DebugType>portable</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins\Flow.Launcher.Plugin.Caculator\</OutputPath> <OutputPath>..\..\Output\Debug\Plugins\Flow.Launcher.Plugin.Calculator\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
@ -28,7 +28,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins\Flow.Launcher.Plugin.Caculator\</OutputPath> <OutputPath>..\..\Output\Release\Plugins\Flow.Launcher.Plugin.Calculator\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>

View file

@ -6,10 +6,10 @@ using System.Text.RegularExpressions;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Mages.Core; using Mages.Core;
using Flow.Launcher.Plugin.Caculator.ViewModels; using Flow.Launcher.Plugin.Calculator.ViewModels;
using Flow.Launcher.Plugin.Caculator.Views; using Flow.Launcher.Plugin.Calculator.Views;
namespace Flow.Launcher.Plugin.Caculator namespace Flow.Launcher.Plugin.Calculator
{ {
public class Main : IPlugin, IPluginI18n, ISettingProvider public class Main : IPlugin, IPluginI18n, ISettingProvider
{ {
@ -62,7 +62,7 @@ namespace Flow.Launcher.Plugin.Caculator
switch (_settings.DecimalSeparator) switch (_settings.DecimalSeparator)
{ {
case DecimalSeparator.Comma: case DecimalSeparator.Comma:
case DecimalSeparator.UseSystemLocale when CultureInfo.DefaultThreadCurrentCulture.NumberFormat.NumberDecimalSeparator == ",": case DecimalSeparator.UseSystemLocale when CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",":
expression = query.Search.Replace(",", "."); expression = query.Search.Replace(",", ".");
break; break;
default: default:
@ -158,7 +158,7 @@ namespace Flow.Launcher.Plugin.Caculator
private string GetDecimalSeparator() private string GetDecimalSeparator()
{ {
string systemDecimalSeperator = CultureInfo.DefaultThreadCurrentCulture.NumberFormat.NumberDecimalSeparator; string systemDecimalSeperator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
switch (_settings.DecimalSeparator) switch (_settings.DecimalSeparator)
{ {
case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator; case DecimalSeparator.UseSystemLocale: return systemDecimalSeperator;

View file

@ -2,7 +2,7 @@
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Flow.Launcher.Plugin.Caculator namespace Flow.Launcher.Plugin.Calculator
{ {
/// <summary> /// <summary>
/// Tries to convert all numbers in a text from one culture format to another. /// Tries to convert all numbers in a text from one culture format to another.

View file

@ -1,5 +1,5 @@
 
namespace Flow.Launcher.Plugin.Caculator namespace Flow.Launcher.Plugin.Calculator
{ {
public class Settings public class Settings
{ {

View file

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Flow.Launcher.Plugin.Caculator.ViewModels namespace Flow.Launcher.Plugin.Calculator.ViewModels
{ {
public class SettingsViewModel : BaseModel public class SettingsViewModel : BaseModel
{ {

View file

@ -1,13 +1,13 @@
<UserControl <UserControl
x:Class="Flow.Launcher.Plugin.Caculator.Views.CalculatorSettings" x:Class="Flow.Launcher.Plugin.Calculator.Views.CalculatorSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:calculator="clr-namespace:Flow.Launcher.Plugin.Caculator" xmlns:calculator="clr-namespace:Flow.Launcher.Plugin.Calculator"
xmlns:core="clr-namespace:Flow.Launcher.Core.Resource;assembly=Flow.Launcher.Core" xmlns:core="clr-namespace:Flow.Launcher.Core.Resource;assembly=Flow.Launcher.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="clr-namespace:Flow.Launcher.Infrastructure.UI;assembly=Flow.Launcher.Infrastructure" xmlns:ui="clr-namespace:Flow.Launcher.Infrastructure.UI;assembly=Flow.Launcher.Infrastructure"
xmlns:viewModels="clr-namespace:Flow.Launcher.Plugin.Caculator.ViewModels" xmlns:viewModels="clr-namespace:Flow.Launcher.Plugin.Calculator.ViewModels"
d:DesignHeight="450" d:DesignHeight="450"
d:DesignWidth="800" d:DesignWidth="800"
Loaded="CalculatorSettings_Loaded" Loaded="CalculatorSettings_Loaded"

View file

@ -1,8 +1,8 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Flow.Launcher.Plugin.Caculator.ViewModels; using Flow.Launcher.Plugin.Calculator.ViewModels;
namespace Flow.Launcher.Plugin.Caculator.Views namespace Flow.Launcher.Plugin.Calculator.Views
{ {
/// <summary> /// <summary>
/// Interaction logic for CalculatorSettings.xaml /// Interaction logic for CalculatorSettings.xaml

View file

@ -4,9 +4,9 @@
"Name": "Calculator", "Name": "Calculator",
"Description": "Provide mathematical calculations.(Try 5*3-2 in Flow Launcher)", "Description": "Provide mathematical calculations.(Try 5*3-2 in Flow Launcher)",
"Author": "cxfksword", "Author": "cxfksword",
"Version": "3.1.0", "Version": "3.1.1",
"Language": "csharp", "Language": "csharp",
"Website": "https://github.com/Flow-Launcher/Flow.Launcher", "Website": "https://github.com/Flow-Launcher/Flow.Launcher",
"ExecuteFileName": "Flow.Launcher.Plugin.Caculator.dll", "ExecuteFileName": "Flow.Launcher.Plugin.Calculator.dll",
"IcoPath": "Images\\calculator.png" "IcoPath": "Images\\calculator.png"
} }