Skip to content

Commit ce30315

Browse files
Use binding for ime conversion mode
1 parent a93bafe commit ce30315

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using System.Windows.Input;
5+
6+
namespace Flow.Launcher.Converters
7+
{
8+
internal class BoolToIMEConversionModeConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if (value is bool v)
13+
{
14+
if (v)
15+
{
16+
return ImeConversionModeValues.Alphanumeric;
17+
}
18+
else
19+
{
20+
return ImeConversionModeValues.DoNotCare;
21+
}
22+
}
23+
return ImeConversionModeValues.DoNotCare;
24+
}
25+
26+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
27+
{
28+
throw new NotImplementedException();
29+
}
30+
}
31+
}

Flow.Launcher/MainWindow.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
1010
xmlns:ui="http://schemas.modernwpf.com/2019"
1111
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
12+
d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
1213
Name="FlowMainWindow"
1314
Title="Flow Launcher"
1415
MinWidth="{Binding MainWindowWidth, Mode=OneWay}"
@@ -37,6 +38,7 @@
3738
<converters:QuerySuggestionBoxConverter x:Key="QuerySuggestionBoxConverter" />
3839
<converters:BorderClipConverter x:Key="BorderClipConverter" />
3940
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
41+
<converters:BoolToIMEConversionModeConverter x:Key="BoolToIMEConversionModeConverter"/>
4042
</Window.Resources>
4143
<Window.InputBindings>
4244
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
@@ -204,6 +206,7 @@
204206
PreviewKeyUp="QueryTextBox_KeyUp"
205207
Style="{DynamicResource QueryBoxStyle}"
206208
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
209+
InputMethod.PreferredImeConversionMode="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEConversionModeConverter}}"
207210
Visibility="Visible">
208211
<TextBox.CommandBindings>
209212
<CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,9 @@
2020
using System.Windows.Media;
2121
using Flow.Launcher.Infrastructure.Hotkey;
2222
using Flow.Launcher.Plugin.SharedCommands;
23-
using System.Text;
24-
using DataObject = System.Windows.DataObject;
25-
using System.Diagnostics;
26-
using Microsoft.AspNetCore.Http;
27-
using System.IO;
2823
using System.Windows.Threading;
2924
using System.Windows.Data;
3025
using ModernWpf.Controls;
31-
using System.Drawing;
32-
using System.Windows.Forms.Design.Behavior;
33-
using System.Security.Cryptography;
34-
using System.Runtime.CompilerServices;
35-
using Microsoft.VisualBasic.Devices;
36-
using Microsoft.FSharp.Data.UnitSystems.SI.UnitNames;
37-
using NLog.Targets;
38-
using YamlDotNet.Core.Tokens;
3926
using Key = System.Windows.Input.Key;
4027

4128
namespace Flow.Launcher
@@ -131,7 +118,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
131118
UpdatePosition();
132119
PreviewReset();
133120
Activate();
134-
QueryTextBox_StartEn();
135121
QueryTextBox.Focus();
136122
_settings.ActivateTimes++;
137123
if (!_viewModel.LastQuerySelected)
@@ -195,9 +181,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
195181
case nameof(Settings.Language):
196182
UpdateNotifyIconText();
197183
break;
198-
case nameof(Settings.AlwaysStartEn):
199-
QueryTextBox_StartEn();
200-
break;
201184
case nameof(Settings.Hotkey):
202185
UpdateNotifyIconText();
203186
break;
@@ -703,19 +686,5 @@ private void QueryTextBox_KeyUp(object sender, KeyEventArgs e)
703686
be.UpdateSource();
704687
}
705688
}
706-
707-
private void QueryTextBox_StartEn()
708-
{
709-
if (_settings.AlwaysStartEn)
710-
{
711-
QueryTextBox.SetValue(InputMethod.PreferredImeConversionModeProperty, ImeConversionModeValues.Alphanumeric);
712-
QueryTextBox.SetValue(InputMethod.PreferredImeStateProperty, InputMethodState.Off);
713-
}
714-
else
715-
{
716-
QueryTextBox.ClearValue(InputMethod.PreferredImeConversionModeProperty);
717-
QueryTextBox.ClearValue(InputMethod.PreferredImeStateProperty);
718-
}
719-
}
720689
}
721690
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public MainViewModel(Settings settings)
7171
case nameof(Settings.WindowSize):
7272
OnPropertyChanged(nameof(MainWindowWidth));
7373
break;
74+
case nameof(Settings.AlwaysStartEn):
75+
OnPropertyChanged(nameof(StartWithEnglishMode));
76+
break;
7477
}
7578
};
7679

@@ -514,6 +517,8 @@ public double MainWindowWidth
514517

515518
public string Image => Constant.QueryTextBoxIconImagePath;
516519

520+
public bool StartWithEnglishMode => Settings.AlwaysStartEn;
521+
517522
#endregion
518523

519524
public void Query()

0 commit comments

Comments
 (0)