From ce303156fb89bda9fadbe4c23dfd310187849195 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 20 Dec 2022 22:35:07 +0800
Subject: [PATCH] Use binding for ime conversion mode
---
.../BoolToIMEConversionModeConverter.cs | 31 +++++++++++++++++++
Flow.Launcher/MainWindow.xaml | 3 ++
Flow.Launcher/MainWindow.xaml.cs | 31 -------------------
Flow.Launcher/ViewModel/MainViewModel.cs | 5 +++
4 files changed, 39 insertions(+), 31 deletions(-)
create mode 100644 Flow.Launcher/Converters/BoolToIMEConversionModeConverter.cs
diff --git a/Flow.Launcher/Converters/BoolToIMEConversionModeConverter.cs b/Flow.Launcher/Converters/BoolToIMEConversionModeConverter.cs
new file mode 100644
index 000000000..f3771e6d9
--- /dev/null
+++ b/Flow.Launcher/Converters/BoolToIMEConversionModeConverter.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+using System.Windows.Input;
+
+namespace Flow.Launcher.Converters
+{
+ internal class BoolToIMEConversionModeConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is bool v)
+ {
+ if (v)
+ {
+ return ImeConversionModeValues.Alphanumeric;
+ }
+ else
+ {
+ return ImeConversionModeValues.DoNotCare;
+ }
+ }
+ return ImeConversionModeValues.DoNotCare;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml
index 3941c5e0a..eca9fcdca 100644
--- a/Flow.Launcher/MainWindow.xaml
+++ b/Flow.Launcher/MainWindow.xaml
@@ -9,6 +9,7 @@
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
+ d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
Name="FlowMainWindow"
Title="Flow Launcher"
MinWidth="{Binding MainWindowWidth, Mode=OneWay}"
@@ -37,6 +38,7 @@
+
@@ -204,6 +206,7 @@
PreviewKeyUp="QueryTextBox_KeyUp"
Style="{DynamicResource QueryBoxStyle}"
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+ InputMethod.PreferredImeConversionMode="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEConversionModeConverter}}"
Visibility="Visible">
diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs
index e639b668c..a645a702c 100644
--- a/Flow.Launcher/MainWindow.xaml.cs
+++ b/Flow.Launcher/MainWindow.xaml.cs
@@ -20,22 +20,9 @@ using Flow.Launcher.Infrastructure;
using System.Windows.Media;
using Flow.Launcher.Infrastructure.Hotkey;
using Flow.Launcher.Plugin.SharedCommands;
-using System.Text;
-using DataObject = System.Windows.DataObject;
-using System.Diagnostics;
-using Microsoft.AspNetCore.Http;
-using System.IO;
using System.Windows.Threading;
using System.Windows.Data;
using ModernWpf.Controls;
-using System.Drawing;
-using System.Windows.Forms.Design.Behavior;
-using System.Security.Cryptography;
-using System.Runtime.CompilerServices;
-using Microsoft.VisualBasic.Devices;
-using Microsoft.FSharp.Data.UnitSystems.SI.UnitNames;
-using NLog.Targets;
-using YamlDotNet.Core.Tokens;
using Key = System.Windows.Input.Key;
namespace Flow.Launcher
@@ -131,7 +118,6 @@ namespace Flow.Launcher
UpdatePosition();
PreviewReset();
Activate();
- QueryTextBox_StartEn();
QueryTextBox.Focus();
_settings.ActivateTimes++;
if (!_viewModel.LastQuerySelected)
@@ -195,9 +181,6 @@ namespace Flow.Launcher
case nameof(Settings.Language):
UpdateNotifyIconText();
break;
- case nameof(Settings.AlwaysStartEn):
- QueryTextBox_StartEn();
- break;
case nameof(Settings.Hotkey):
UpdateNotifyIconText();
break;
@@ -703,19 +686,5 @@ namespace Flow.Launcher
be.UpdateSource();
}
}
-
- private void QueryTextBox_StartEn()
- {
- if (_settings.AlwaysStartEn)
- {
- QueryTextBox.SetValue(InputMethod.PreferredImeConversionModeProperty, ImeConversionModeValues.Alphanumeric);
- QueryTextBox.SetValue(InputMethod.PreferredImeStateProperty, InputMethodState.Off);
- }
- else
- {
- QueryTextBox.ClearValue(InputMethod.PreferredImeConversionModeProperty);
- QueryTextBox.ClearValue(InputMethod.PreferredImeStateProperty);
- }
- }
}
}
diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs
index e05e47041..09bba6e5c 100644
--- a/Flow.Launcher/ViewModel/MainViewModel.cs
+++ b/Flow.Launcher/ViewModel/MainViewModel.cs
@@ -71,6 +71,9 @@ namespace Flow.Launcher.ViewModel
case nameof(Settings.WindowSize):
OnPropertyChanged(nameof(MainWindowWidth));
break;
+ case nameof(Settings.AlwaysStartEn):
+ OnPropertyChanged(nameof(StartWithEnglishMode));
+ break;
}
};
@@ -514,6 +517,8 @@ namespace Flow.Launcher.ViewModel
public string Image => Constant.QueryTextBoxIconImagePath;
+ public bool StartWithEnglishMode => Settings.AlwaysStartEn;
+
#endregion
public void Query()