perf: update the code structure

dev_deconstruction
DESKTOP-3BO4HSG\ksat 2 years ago
parent 1cb3edd2e3
commit 04ff8fc649

@ -3,6 +3,11 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/STranslate;component/Style/DictionaryButtonDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/STranslate;component/Style/DictionaryComboBoxDefault.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>

@ -0,0 +1,35 @@
using System;
using System.Threading;
using System.Windows.Input;
namespace STranslate.Helper
{
public class GetWordsHelper
{
public static String Get()
{
SendCtrlC();
Thread.Sleep(200);
return NativeMethodHelper.GetText();
}
private static void SendCtrlC()
{
//IntPtr hWnd = GetForegroundWindow();
//SetForegroundWindow(hWnd);
uint KEYEVENTF_KEYUP = 2;
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);
NativeMethodHelper.keybd_event(KeyInterop.VirtualKeyFromKey(Key.LeftAlt), 0, KEYEVENTF_KEYUP, 0);
NativeMethodHelper.keybd_event(KeyInterop.VirtualKeyFromKey(Key.RightAlt), 0, KEYEVENTF_KEYUP, 0);
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.LWin, 0, KEYEVENTF_KEYUP, 0);
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.RWin, 0, KEYEVENTF_KEYUP, 0);
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.ShiftKey, 0, KEYEVENTF_KEYUP, 0);
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, 0, 0);
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.C, 0, 0, 0);
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.C, 0, KEYEVENTF_KEYUP, 0);
NativeMethodHelper.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up
}
}
}

@ -1,9 +1,9 @@
using System; using System;
using static STranslate.Utils.NativeMethod; using static STranslate.Helper.NativeMethodHelper;
namespace STranslate.Utils namespace STranslate.Helper
{ {
public static class HotKeys public static class Hotkeys
{ {
public static class InputTranslate public static class InputTranslate
{ {
@ -21,6 +21,7 @@ namespace STranslate.Utils
public static bool Conflict = false; public static bool Conflict = false;
} }
#if false
public static class ScreenShotTranslate public static class ScreenShotTranslate
{ {
public static byte Modifiers = (byte)KeyModifiers.MOD_ALT; public static byte Modifiers = (byte)KeyModifiers.MOD_ALT;
@ -28,7 +29,7 @@ namespace STranslate.Utils
public static String Text = "S"; public static String Text = "S";
public static bool Conflict = false; public static bool Conflict = false;
} }
#endif
public static class OpenMainWindow public static class OpenMainWindow
{ {
public static byte Modifiers = (byte)KeyModifiers.MOD_ALT; public static byte Modifiers = (byte)KeyModifiers.MOD_ALT;
@ -38,7 +39,7 @@ namespace STranslate.Utils
} }
} }
internal class HotKeysUtil internal class HotkeysHelper
{ {
public static IntPtr mainFormHandle; public static IntPtr mainFormHandle;
@ -48,9 +49,11 @@ namespace STranslate.Utils
public static int CrosswordTranslateId = 855; public static int CrosswordTranslateId = 855;
public static byte CrosswordTranslateModifiers; public static byte CrosswordTranslateModifiers;
public static int CrosswordTranslateKey; public static int CrosswordTranslateKey;
#if false
public static int ScreenShotTranslateId = 856; public static int ScreenShotTranslateId = 856;
public static byte ScreenShotTranslateModifiers; public static byte ScreenShotTranslateModifiers;
public static int ScreenShotTranslateKey; public static int ScreenShotTranslateKey;
#endif
public static int OpenMainWindowId = 857; public static int OpenMainWindowId = 857;
public static byte OpenMainWindowModifiers; public static byte OpenMainWindowModifiers;
public static int OpenMainWindowKey; public static int OpenMainWindowKey;
@ -61,30 +64,33 @@ namespace STranslate.Utils
/// <param name="mainFormHandle"></param> /// <param name="mainFormHandle"></param>
public static void RegisterHotKey(IntPtr mainFormHandle) public static void RegisterHotKey(IntPtr mainFormHandle)
{ {
HotKeysUtil.mainFormHandle = mainFormHandle; HotkeysHelper.mainFormHandle = mainFormHandle;
InputTranslateModifiers = HotKeys.InputTranslate.Modifiers; InputTranslateModifiers = Hotkeys.InputTranslate.Modifiers;
InputTranslateKey = HotKeys.InputTranslate.Key; InputTranslateKey = Hotkeys.InputTranslate.Key;
CrosswordTranslateModifiers = HotKeys.CrosswordTranslate.Modifiers; CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers;
CrosswordTranslateKey = HotKeys.CrosswordTranslate.Key; CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key;
ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers;
ScreenShotTranslateKey = HotKeys.ScreenShotTranslate.Key;
if (HotKeys.InputTranslate.Key != 0) #if false
ScreenShotTranslateModifiers = Hotkeys.ScreenShotTranslate.Modifiers;
ScreenShotTranslateKey = Hotkeys.ScreenShotTranslate.Key;
if (Hotkeys.ScreenShotTranslate.Key != 0)
{ {
HotKeys.InputTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, InputTranslateId, HotKeys.InputTranslate.Modifiers, HotKeys.InputTranslate.Key); Hotkeys.ScreenShotTranslate.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, Hotkeys.ScreenShotTranslate.Modifiers, Hotkeys.ScreenShotTranslate.Key);
} }
if (HotKeys.CrosswordTranslate.Key != 0) #endif
if (Hotkeys.InputTranslate.Key != 0)
{ {
HotKeys.CrosswordTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, CrosswordTranslateId, HotKeys.CrosswordTranslate.Modifiers, HotKeys.CrosswordTranslate.Key); Hotkeys.InputTranslate.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, InputTranslateId, Hotkeys.InputTranslate.Modifiers, Hotkeys.InputTranslate.Key);
} }
if (HotKeys.ScreenShotTranslate.Key != 0) if (Hotkeys.CrosswordTranslate.Key != 0)
{ {
HotKeys.ScreenShotTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, HotKeys.ScreenShotTranslate.Modifiers, HotKeys.ScreenShotTranslate.Key); Hotkeys.CrosswordTranslate.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, CrosswordTranslateId, Hotkeys.CrosswordTranslate.Modifiers, Hotkeys.CrosswordTranslate.Key);
} }
if (HotKeys.OpenMainWindow.Key != 0) if (Hotkeys.OpenMainWindow.Key != 0)
{ {
HotKeys.OpenMainWindow.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, OpenMainWindowId, HotKeys.OpenMainWindow.Modifiers, HotKeys.OpenMainWindow.Key); Hotkeys.OpenMainWindow.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, OpenMainWindowId, Hotkeys.OpenMainWindow.Modifiers, Hotkeys.OpenMainWindow.Key);
} }
} }
@ -95,7 +101,9 @@ namespace STranslate.Utils
{ {
UnregisterHotKey(mainFormHandle, InputTranslateId); UnregisterHotKey(mainFormHandle, InputTranslateId);
UnregisterHotKey(mainFormHandle, CrosswordTranslateId); UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
#if false
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
#endif
UnregisterHotKey(mainFormHandle, OpenMainWindowId); UnregisterHotKey(mainFormHandle, OpenMainWindowId);
} }
@ -104,57 +112,59 @@ namespace STranslate.Utils
/// </summary> /// </summary>
public static void ReRegisterHotKey() public static void ReRegisterHotKey()
{ {
if (HotKeys.InputTranslate.Key == 0) if (Hotkeys.InputTranslate.Key == 0)
{ {
UnregisterHotKey(mainFormHandle, InputTranslateId); UnregisterHotKey(mainFormHandle, InputTranslateId);
} }
else if (InputTranslateModifiers != HotKeys.InputTranslate.Modifiers || InputTranslateKey != HotKeys.InputTranslate.Key) else if (InputTranslateModifiers != Hotkeys.InputTranslate.Modifiers || InputTranslateKey != Hotkeys.InputTranslate.Key)
{ {
{ {
UnregisterHotKey(mainFormHandle, InputTranslateId); UnregisterHotKey(mainFormHandle, InputTranslateId);
HotKeys.InputTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, InputTranslateId, HotKeys.InputTranslate.Modifiers, HotKeys.InputTranslate.Key); Hotkeys.InputTranslate.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, InputTranslateId, Hotkeys.InputTranslate.Modifiers, Hotkeys.InputTranslate.Key);
} }
} }
InputTranslateModifiers = HotKeys.InputTranslate.Modifiers; InputTranslateModifiers = Hotkeys.InputTranslate.Modifiers;
InputTranslateKey = HotKeys.InputTranslate.Key; InputTranslateKey = Hotkeys.InputTranslate.Key;
if (HotKeys.CrosswordTranslate.Key == 0) if (Hotkeys.CrosswordTranslate.Key == 0)
{ {
UnregisterHotKey(mainFormHandle, CrosswordTranslateId); UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
} }
else if (CrosswordTranslateModifiers != HotKeys.CrosswordTranslate.Modifiers || CrosswordTranslateKey != HotKeys.CrosswordTranslate.Key) else if (CrosswordTranslateModifiers != Hotkeys.CrosswordTranslate.Modifiers || CrosswordTranslateKey != Hotkeys.CrosswordTranslate.Key)
{ {
{ {
UnregisterHotKey(mainFormHandle, CrosswordTranslateId); UnregisterHotKey(mainFormHandle, CrosswordTranslateId);
HotKeys.CrosswordTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, CrosswordTranslateId, HotKeys.CrosswordTranslate.Modifiers, HotKeys.CrosswordTranslate.Key); Hotkeys.CrosswordTranslate.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, CrosswordTranslateId, Hotkeys.CrosswordTranslate.Modifiers, Hotkeys.CrosswordTranslate.Key);
} }
} }
CrosswordTranslateModifiers = HotKeys.CrosswordTranslate.Modifiers; CrosswordTranslateModifiers = Hotkeys.CrosswordTranslate.Modifiers;
CrosswordTranslateKey = HotKeys.CrosswordTranslate.Key; CrosswordTranslateKey = Hotkeys.CrosswordTranslate.Key;
if (HotKeys.ScreenShotTranslate.Key == 0) #if false
if (Hotkeys.ScreenShotTranslate.Key == 0)
{ {
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
} }
else if (ScreenShotTranslateModifiers != HotKeys.ScreenShotTranslate.Modifiers || ScreenShotTranslateKey != HotKeys.ScreenShotTranslate.Key) else if (ScreenShotTranslateModifiers != Hotkeys.ScreenShotTranslate.Modifiers || ScreenShotTranslateKey != Hotkeys.ScreenShotTranslate.Key)
{ {
UnregisterHotKey(mainFormHandle, ScreenShotTranslateId); UnregisterHotKey(mainFormHandle, ScreenShotTranslateId);
HotKeys.ScreenShotTranslate.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, HotKeys.ScreenShotTranslate.Modifiers, HotKeys.ScreenShotTranslate.Key); Hotkeys.ScreenShotTranslate.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, ScreenShotTranslateId, Hotkeys.ScreenShotTranslate.Modifiers, Hotkeys.ScreenShotTranslate.Key);
} }
ScreenShotTranslateModifiers = HotKeys.ScreenShotTranslate.Modifiers; ScreenShotTranslateModifiers = Hotkeys.ScreenShotTranslate.Modifiers;
ScreenShotTranslateKey = HotKeys.ScreenShotTranslate.Key; ScreenShotTranslateKey = Hotkeys.ScreenShotTranslate.Key;
#endif
if (HotKeys.OpenMainWindow.Key == 0) if (Hotkeys.OpenMainWindow.Key == 0)
{ {
UnregisterHotKey(mainFormHandle, OpenMainWindowId); UnregisterHotKey(mainFormHandle, OpenMainWindowId);
} }
else if (OpenMainWindowModifiers != HotKeys.OpenMainWindow.Modifiers || OpenMainWindowKey != HotKeys.OpenMainWindow.Key) else if (OpenMainWindowModifiers != Hotkeys.OpenMainWindow.Modifiers || OpenMainWindowKey != Hotkeys.OpenMainWindow.Key)
{ {
UnregisterHotKey(mainFormHandle, OpenMainWindowId); UnregisterHotKey(mainFormHandle, OpenMainWindowId);
HotKeys.OpenMainWindow.Conflict = !NativeMethod.RegisterHotKey(mainFormHandle, OpenMainWindowId, HotKeys.OpenMainWindow.Modifiers, HotKeys.OpenMainWindow.Key); Hotkeys.OpenMainWindow.Conflict = !NativeMethodHelper.RegisterHotKey(mainFormHandle, OpenMainWindowId, Hotkeys.OpenMainWindow.Modifiers, Hotkeys.OpenMainWindow.Key);
} }
OpenMainWindowModifiers = HotKeys.OpenMainWindow.Modifiers; OpenMainWindowModifiers = Hotkeys.OpenMainWindow.Modifiers;
OpenMainWindowKey = HotKeys.OpenMainWindow.Key; OpenMainWindowKey = Hotkeys.OpenMainWindow.Key;
} }
} }
} }

@ -1,9 +1,9 @@
using System; using System;
using System.Windows.Input;
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Windows.Input;
namespace STranslate.Utils namespace STranslate.Helper
{ {
/// <summary> /// <summary>
/// 通知 /// 通知

@ -2,9 +2,9 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace STranslate.Utils namespace STranslate.Helper
{ {
internal class NativeMethod internal class NativeMethodHelper
{ {
/// <summary> /// <summary>
/// 获取进程句柄 /// 获取进程句柄

@ -4,15 +4,16 @@ using System.IO;
using System.Reflection; using System.Reflection;
using IWshRuntimeLibrary; using IWshRuntimeLibrary;
namespace STranslate.Utils namespace STranslate.Helper
{ {
public class AutoStart public class StartupHelper
{ {
#region public method #region public method
/// <summary> /// <summary>
/// 设置开机自启 /// 设置开机自启
/// </summary> /// </summary>
public static void SetAutoStart() public static void SetStartup()
{ {
ShortCutCreate(); ShortCutCreate();
} }
@ -20,14 +21,14 @@ namespace STranslate.Utils
/// 检查是否已经设置开机自启 /// 检查是否已经设置开机自启
/// </summary> /// </summary>
/// <returns>true: 开机自启 false: 非开机自启</returns> /// <returns>true: 开机自启 false: 非开机自启</returns>
public static bool IsAutoStart() public static bool IsStartup()
{ {
return ShortCutExist(appPath, StartUpPath); return ShortCutExist(appPath, StartUpPath);
} }
/// <summary> /// <summary>
/// 取消开机自启 /// 取消开机自启
/// </summary> /// </summary>
public static void UnSetAutoStart() public static void UnSetStartup()
{ {
ShortCutDelete(appPath, StartUpPath); ShortCutDelete(appPath, StartUpPath);
} }

Before

Width:  |  Height:  |  Size: 595 B

After

Width:  |  Height:  |  Size: 595 B

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before

Width:  |  Height:  |  Size: 772 B

After

Width:  |  Height:  |  Size: 772 B

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 631 B

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

@ -26,243 +26,6 @@
<Window.Resources> <Window.Resources>
<model:VisibilityConverter x:Key="String2VisibilityConverter"/> <model:VisibilityConverter x:Key="String2VisibilityConverter"/>
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy2.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateSnakeCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy_s.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateSmallHumpCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy_h.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateLargeHumpCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="/Images/copy_h2.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!--Combox-->
<Style x:Key="IconStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="/STranslate;component/Images/#iconfont"/>
</Style>
<Style TargetType="{x:Type ComboBox}" x:Key="cmbstyle">
<Setter Property="Background" Value="White"/>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<!--ComBoxItem-->
<Style TargetType="ComboBoxItem">
<Setter Property="MinHeight" Value="22"></Setter>
<Setter Property="MinWidth" Value="40"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Border Name="Back"
CornerRadius="2"
Background="Transparent"
BorderThickness="0">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"></ContentPresenter>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Back" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter TargetName="Back" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border BorderThickness="0" CornerRadius="5" Width="80" Height="30" Background="{TemplateBinding Background}" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="grid">
<ToggleButton
Width="{Binding ElementName=grid,Path=ActualWidth}"
Height="{Binding ElementName=grid, Path=ActualHeight}"
Content="{TemplateBinding Text}" VerticalAlignment="Center"
HorizontalAlignment="Left" Margin="5,0,0,0"
BorderThickness="0"
Foreground="{TemplateBinding Foreground}"
Background="{TemplateBinding Background}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">
<ToggleButton.Style >
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="0" >
<TextBlock Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" Margin="4 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
<Grid Grid.Column="1" >
<ToggleButton IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Foreground="{TemplateBinding Foreground}"
ClickMode="Press">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<TextBlock Foreground="{TemplateBinding Foreground}" x:Name="arrow_tb" Text="&#xe61d;" Style="{StaticResource IconStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
</Trigger>
<EventTrigger RoutedEvent="Checked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Unchecked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
<Popup IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom" x:Name="Popup"
Focusable="False"
AllowsTransparency="True"
PopupAnimation="Slide">
<Border x:Name="DropDown"
CornerRadius="5"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{TemplateBinding ActualWidth}"
SnapsToDevicePixels="True">
<Border.Effect>
<DropShadowEffect Color="Black" BlurRadius="2" ShadowDepth="0" Opacity="0.5"/>
</Border.Effect>
<ScrollViewer Margin="4,6,4,6" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" CanContentScroll="True">
<!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
</ScrollViewer>
</Border>
</Popup>
</Grid>
<Border.Effect>
<DropShadowEffect ShadowDepth="-1" Opacity="0.3" Color="#FF969696" BlurRadius="2"/>
</Border.Effect>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources> </Window.Resources>
<Border Background="#fff" <Border Background="#fff"

@ -1,7 +1,6 @@
using STranslate.Utils; using STranslate.Helper;
using STranslate.ViewModel; using STranslate.ViewModel;
using System; using System;
using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Interop; using System.Windows.Interop;
@ -34,7 +33,7 @@ namespace STranslate
private void InitialTray() private void InitialTray()
{ {
notifyIcon.Text = "STranslate"; notifyIcon.Text = "STranslate";
notifyIcon.Icon = new System.Drawing.Icon(System.Windows.Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream); notifyIcon.Icon = new System.Drawing.Icon(Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream);
notifyIcon.Visible = true; notifyIcon.Visible = true;
notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick;
@ -44,6 +43,7 @@ namespace STranslate
System.Windows.Forms.MenuItem ScreenshotTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("截图翻译"); System.Windows.Forms.MenuItem ScreenshotTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("截图翻译");
ScreenshotTranslateMenuItemBTN.Click += new EventHandler(ScreenshotTranslateMenuItem_Click); ScreenshotTranslateMenuItemBTN.Click += new EventHandler(ScreenshotTranslateMenuItem_Click);
ScreenshotTranslateMenuItemBTN.Enabled = false;
System.Windows.Forms.MenuItem InputTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("输入翻译"); System.Windows.Forms.MenuItem InputTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("输入翻译");
InputTranslateMenuItemBTN.Click += new EventHandler(InputTranslateMenuItem_Click); InputTranslateMenuItemBTN.Click += new EventHandler(InputTranslateMenuItem_Click);
@ -54,7 +54,7 @@ namespace STranslate
System.Windows.Forms.MenuItem AutoStartBTN = new System.Windows.Forms.MenuItem("开机自启"); System.Windows.Forms.MenuItem AutoStartBTN = new System.Windows.Forms.MenuItem("开机自启");
AutoStartBTN.Click += new EventHandler(AutoStart_Click); AutoStartBTN.Click += new EventHandler(AutoStart_Click);
AutoStartBTN.Checked = AutoStart.IsAutoStart(); AutoStartBTN.Checked = StartupHelper.IsStartup();
System.Windows.Forms.MenuItem ExitBTN = new System.Windows.Forms.MenuItem("退出"); System.Windows.Forms.MenuItem ExitBTN = new System.Windows.Forms.MenuItem("退出");
ExitBTN.Click += new EventHandler(Exit_Click); ExitBTN.Click += new EventHandler(Exit_Click);
@ -72,9 +72,9 @@ namespace STranslate
private void AutoStart_Click(object sender, EventArgs e) private void AutoStart_Click(object sender, EventArgs e)
{ {
if (AutoStart.IsAutoStart()) AutoStart.UnSetAutoStart(); if (StartupHelper.IsStartup()) StartupHelper.UnSetStartup();
else AutoStart.SetAutoStart(); else StartupHelper.SetStartup();
(sender as System.Windows.Forms.MenuItem).Checked = AutoStart.IsAutoStart(); (sender as System.Windows.Forms.MenuItem).Checked = StartupHelper.IsStartup();
} }
@ -128,7 +128,7 @@ namespace STranslate
{ {
//base.OnSourceInitialized(e); //base.OnSourceInitialized(e);
IntPtr handle = new WindowInteropHelper(this).Handle; IntPtr handle = new WindowInteropHelper(this).Handle;
HotKeysUtil.RegisterHotKey(handle); HotkeysHelper.RegisterHotKey(handle);
HwndSource source = HwndSource.FromHwnd(handle); HwndSource source = HwndSource.FromHwnd(handle);
source.AddHook(WndProc); source.AddHook(WndProc);
@ -144,19 +144,21 @@ namespace STranslate
{ {
case 0x0312: //这个是window消息定义的 注册的热键消息 case 0x0312: //这个是window消息定义的 注册的热键消息
//Console.WriteLine(wParam.ToString()); //Console.WriteLine(wParam.ToString());
if (wParam.ToString().Equals(HotKeysUtil.InputTranslateId + "")) if (wParam.ToString().Equals(HotkeysHelper.InputTranslateId + ""))
{ {
this.InputTranslateMenuItem_Click(null, null); this.InputTranslateMenuItem_Click(null, null);
} }
else if (wParam.ToString().Equals(HotKeysUtil.CrosswordTranslateId + "")) else if (wParam.ToString().Equals(HotkeysHelper.CrosswordTranslateId + ""))
{ {
this.CrossWordTranslateMenuItem_Click(null, null); this.CrossWordTranslateMenuItem_Click(null, null);
} }
else if (wParam.ToString().Equals(HotKeysUtil.ScreenShotTranslateId + "")) #if false
else if (wParam.ToString().Equals(HotkeysHelper.ScreenShotTranslateId + ""))
{ {
this.ScreenshotTranslateMenuItem_Click(null, null); this.ScreenshotTranslateMenuItem_Click(null, null);
} }
else if (wParam.ToString().Equals(HotKeysUtil.OpenMainWindowId + "")) #endif
else if (wParam.ToString().Equals(HotkeysHelper.OpenMainWindowId + ""))
{ {
this.OpenMainWin_Click(null, null); this.OpenMainWin_Click(null, null);
} }
@ -233,7 +235,7 @@ namespace STranslate
private void CrossWordTranslateMenuItem_Click(object sender, EventArgs e) private void CrossWordTranslateMenuItem_Click(object sender, EventArgs e)
{ {
ClearTextBox(); ClearTextBox();
var sentence = GetWords.Get(); var sentence = GetWordsHelper.Get();
this.Show(); this.Show();
this.Activate(); this.Activate();
this.TextBoxInput.Text = sentence.Trim(); this.TextBoxInput.Text = sentence.Trim();
@ -277,8 +279,8 @@ namespace STranslate
this.Activate(); this.Activate();
this.TextBoxInput.Focus(); this.TextBoxInput.Focus();
} }
private BitmapImage LockImgPath = new BitmapImage(new Uri("pack://application:,,,/Images/lock3.png")); private BitmapImage LockImgPath = new BitmapImage(new Uri("pack://application:,,,/STranslate;component/Images/Button_Default/lock.png"));
private BitmapImage UnLockImgPath = new BitmapImage(new Uri("pack://application:,,,/Images/unlock3.png")); private BitmapImage UnLockImgPath = new BitmapImage(new Uri("pack://application:,,,/STranslate;component/Images/Button_Default/unlock.png"));
private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon(); private System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();
} }
} }

@ -1,20 +0,0 @@
namespace STranslate.Model
{
public class ConfigModel
{
public string service { get; set; }
public Baidu baidu { get; set; }
public DeepL deepl { get; set; }
}
public class Baidu
{
public string appid { get; set; }
public string secretKey { get; set; }
}
public class DeepL
{
public string url { get; set; }
}
}

@ -19,7 +19,7 @@ namespace STranslate.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。 // (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources {
@ -63,9 +63,9 @@ namespace STranslate.Properties {
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Bitmap copy_h { internal static System.Drawing.Bitmap _lock {
get { get {
object obj = ResourceManager.GetObject("copy_h", resourceCulture); object obj = ResourceManager.GetObject("_lock", resourceCulture);
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
@ -73,9 +73,9 @@ namespace STranslate.Properties {
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Bitmap copy_h2 { internal static System.Drawing.Bitmap copy_default {
get { get {
object obj = ResourceManager.GetObject("copy_h2", resourceCulture); object obj = ResourceManager.GetObject("copy_default", resourceCulture);
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
@ -83,9 +83,9 @@ namespace STranslate.Properties {
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Bitmap copy_s { internal static System.Drawing.Bitmap copy_large_hump {
get { get {
object obj = ResourceManager.GetObject("copy_s", resourceCulture); object obj = ResourceManager.GetObject("copy_large_hump", resourceCulture);
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
@ -93,40 +93,40 @@ namespace STranslate.Properties {
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Bitmap copy2 { internal static System.Drawing.Bitmap copy_small_hump {
get { get {
object obj = ResourceManager.GetObject("copy2", resourceCulture); object obj = ResourceManager.GetObject("copy_small_hump", resourceCulture);
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
/// <summary> /// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 /// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Icon crossword { internal static System.Drawing.Bitmap copy_snake {
get { get {
object obj = ResourceManager.GetObject("crossword", resourceCulture); object obj = ResourceManager.GetObject("copy_snake", resourceCulture);
return ((System.Drawing.Icon)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }
/// <summary> /// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Icon input { internal static System.Drawing.Icon crossword {
get { get {
object obj = ResourceManager.GetObject("input", resourceCulture); object obj = ResourceManager.GetObject("crossword", resourceCulture);
return ((System.Drawing.Icon)(obj)); return ((System.Drawing.Icon)(obj));
} }
} }
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Bitmap lock3 { internal static System.Drawing.Icon input {
get { get {
object obj = ResourceManager.GetObject("lock3", resourceCulture); object obj = ResourceManager.GetObject("input", resourceCulture);
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Icon)(obj));
} }
} }
@ -153,9 +153,9 @@ namespace STranslate.Properties {
/// <summary> /// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary> /// </summary>
internal static System.Drawing.Bitmap unlock3 { internal static System.Drawing.Bitmap unlock {
get { get {
object obj = ResourceManager.GetObject("unlock3", resourceCulture); object obj = ResourceManager.GetObject("unlock", resourceCulture);
return ((System.Drawing.Bitmap)(obj)); return ((System.Drawing.Bitmap)(obj));
} }
} }

@ -118,37 +118,37 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="copy2" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="copy_default" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\copy2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\button_default\copy_default.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="copy_h" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="copy_large_hump" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\copy_h.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\button_default\copy_large_hump.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="copy_h2" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="copy_small_hump" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\copy_h2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\button_default\copy_small_hump.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="copy_s" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="copy_snake" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\copy_s.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\button_default\copy_snake.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="crossword" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="crossword" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\crossword.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\tray\crossword.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="input" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="input" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\input.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\tray\input.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="lock3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\lock3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="screenshot" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="screenshot" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\screenshot.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\tray\screenshot.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="translate" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="translate" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\translate.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\translate.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="unlock3" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="unlock" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\unlock3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\button_default\unlock.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
<data name="window" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="window" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\window.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> <value>..\images\tray\window.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="_lock" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\button_default\lock.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data> </data>
</root> </root>

@ -82,6 +82,11 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Helper\GetWordsHelper.cs" />
<Compile Include="Helper\HotkeysHelper.cs" />
<Compile Include="Helper\MvvmHelper.cs" />
<Compile Include="Helper\NativeMethodHelper.cs" />
<Compile Include="Helper\StartupHelper.cs" />
<Compile Include="Model\TranslateInterface.cs" /> <Compile Include="Model\TranslateInterface.cs" />
<Compile Include="Model\VisibilityConverter.cs" /> <Compile Include="Model\VisibilityConverter.cs" />
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">
@ -89,13 +94,7 @@
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="Utils\AutoStart.cs" /> <Compile Include="Util\Util.cs" />
<Compile Include="Utils\GetWordsUtil.cs" />
<Compile Include="Utils\HotKeysUtil.cs" />
<Compile Include="Utils\HttpUtil.cs" />
<Compile Include="Utils\MvvmUtil.cs" />
<Compile Include="Utils\NativeMethod.cs" />
<Compile Include="Utils\TranslateUtil.cs" />
<Compile Include="ViewModel\MainVM.cs" /> <Compile Include="ViewModel\MainVM.cs" />
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -109,10 +108,17 @@
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Page Include="Style\DictionaryButtonDefault.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Style\DictionaryComboBoxDefault.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Model\BaiduModel.cs" /> <Compile Include="Model\BaiduModel.cs" />
<Compile Include="Model\ConfigModel.cs" />
<Compile Include="Model\DeeplModel.cs" /> <Compile Include="Model\DeeplModel.cs" />
<Compile Include="Model\LanguageEnum.cs" /> <Compile Include="Model\LanguageEnum.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
@ -135,37 +141,37 @@
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None> </None>
<Resource Include="Images\crossword.ico"> <Resource Include="Images\Tray\crossword.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\input.ico"> <Resource Include="Images\Tray\input.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\screenshot.ico"> <Resource Include="Images\Tray\screenshot.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\window.ico"> <Resource Include="Images\Tray\window.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\unlock3.png"> <Resource Include="Images\Button_Default\unlock.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\lock3.png"> <Resource Include="Images\Button_Default\lock.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\translate.ico"> <Resource Include="Images\translate.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\copy2.png"> <Resource Include="Images\Button_Default\copy_default.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\copy_h.png"> <Resource Include="Images\Button_Default\copy_small_hump.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\copy_h2.png"> <Resource Include="Images\Button_Default\copy_large_hump.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Images\copy_s.png"> <Resource Include="Images\Button_Default\copy_snake.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
</ItemGroup> </ItemGroup>
@ -195,5 +201,6 @@
<EmbedInteropTypes>True</EmbedInteropTypes> <EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference> </COMReference>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

@ -0,0 +1,71 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate x:Key="ButtonTemplate" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="pack://application:,,,/STranslate;component/Images/Button_Default/copy_default.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateSnakeCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="pack://application:,,,/STranslate;component/Images/Button_Default/copy_snake.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateSmallHumpCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="pack://application:,,,/STranslate;component/Images/Button_Default/copy_small_hump.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="ButtonTemplateLargeHumpCopy" TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
MaxHeight="25">
<Image Source="pack://application:,,,/STranslate;component/Images/Button_Default/copy_large_hump.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#dddddd"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ResourceDictionary>

@ -0,0 +1,174 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--引入字体文件-->
<Style x:Key="IconStyle" TargetType="TextBlock">
<Setter Property="FontFamily" Value="/STranslate;component/Images/#iconfont"/>
</Style>
<!--Combox-->
<Style TargetType="{x:Type ComboBox}" x:Key="cmbstyle">
<Setter Property="Background" Value="White"/>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<!--ComBoxItem-->
<Style TargetType="ComboBoxItem">
<Setter Property="MinHeight" Value="22"></Setter>
<Setter Property="MinWidth" Value="40"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Border Name="Back"
CornerRadius="2"
Background="Transparent"
BorderThickness="0">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"></ContentPresenter>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Back" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter TargetName="Back" Property="Background" Value="#eaeaea"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border BorderThickness="0" CornerRadius="5" Width="80" Height="30" Background="{TemplateBinding Background}" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="grid">
<ToggleButton
Width="{Binding ElementName=grid,Path=ActualWidth}"
Height="{Binding ElementName=grid, Path=ActualHeight}"
Content="{TemplateBinding Text}" VerticalAlignment="Center"
HorizontalAlignment="Left" Margin="5,0,0,0"
BorderThickness="0"
Foreground="{TemplateBinding Foreground}"
Background="{TemplateBinding Background}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">
<ToggleButton.Style >
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="0" >
<TextBlock Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" Margin="4 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
<Grid Grid.Column="1" >
<ToggleButton IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Foreground="{TemplateBinding Foreground}"
ClickMode="Press">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<TextBlock Foreground="{TemplateBinding Foreground}" x:Name="arrow_tb" Text="&#xe61d;" Style="{StaticResource IconStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
</Trigger>
<EventTrigger RoutedEvent="Checked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Unchecked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
<Popup IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom" x:Name="Popup"
Focusable="False"
AllowsTransparency="True"
PopupAnimation="Slide">
<Border x:Name="DropDown"
CornerRadius="5"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{TemplateBinding ActualWidth}"
SnapsToDevicePixels="True">
<Border.Effect>
<DropShadowEffect Color="Black" BlurRadius="2" ShadowDepth="0" Opacity="0.5"/>
</Border.Effect>
<ScrollViewer Margin="4,6,4,6" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" CanContentScroll="True">
<!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
</ScrollViewer>
</Border>
</Popup>
</Grid>
<Border.Effect>
<DropShadowEffect ShadowDepth="-1" Opacity="0.3" Color="#FF969696" BlurRadius="2"/>
</Border.Effect>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

@ -3,33 +3,17 @@ using STranslate.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web; using System.Web;
namespace STranslate.Utils namespace STranslate.Util
{ {
public class TranslateUtil public class Util
{ {
private static readonly string _url = "http://127.0.0.1:8000/translate"; #region 翻译接口
public static string Translate(string input, LanguageEnum source, LanguageEnum target)
{
var req = new DeeplReq()
{
Text = input,
SourceLang = source.ToString(),
TargetLang = target.ToString(),
};
var resp = HttpUtil.Post(_url, req);
if (resp.Code == 200)
{
return resp.Data;
}
return string.Empty;
}
public static async Task<string> TranslateDeepLAsync(string url, string text, LanguageEnum target, LanguageEnum source = LanguageEnum.AUTO) public static async Task<string> TranslateDeepLAsync(string url, string text, LanguageEnum target, LanguageEnum source = LanguageEnum.AUTO)
{ {
var req = new DeeplReq() var req = new DeeplReq()
@ -48,7 +32,7 @@ namespace STranslate.Utils
req.TargetLang = LanguageEnum.AUTO.ToString().ToLower(); req.TargetLang = LanguageEnum.AUTO.ToString().ToLower();
} }
var reqStr = JsonConvert.SerializeObject(req); var reqStr = JsonConvert.SerializeObject(req);
var respStr = await HttpUtil.PostAsync(url, reqStr); var respStr = await PostAsync(url, reqStr);
var resp = JsonConvert.DeserializeObject<DeeplResp>(respStr); var resp = JsonConvert.DeserializeObject<DeeplResp>(respStr);
if (resp == null || resp.Code != 200) if (resp == null || resp.Code != 200)
@ -96,7 +80,7 @@ namespace STranslate.Utils
myResponseStream.Close(); myResponseStream.Close();
#endif #endif
var retString = await HttpUtil.GetAsync(url); var retString = await GetAsync(url);
var resp = JsonConvert.DeserializeObject<BaiduResp>(retString); var resp = JsonConvert.DeserializeObject<BaiduResp>(retString);
if (resp.From != null) if (resp.From != null)
{ {
@ -144,5 +128,52 @@ namespace STranslate.Utils
}); });
return dict; return dict;
} }
#endregion
#region Http
/// <summary>
/// 异步Post请求
/// </summary>
/// <param name="url"></param>
/// <param name="req"></param>
/// <returns></returns>
public static async Task<string> PostAsync(string url, string req)
{
using (var client = new HttpClient())
{
var content = new StringContent(req, Encoding.UTF8, "application/json");
var respContent = await client.PostAsync(url, content);
string respStr = await respContent.Content.ReadAsStringAsync();
;
return respStr;
}
}
/// <summary>
/// 异步Get请求
/// </summary>
/// <param name="urlpath"></param>
/// <returns></returns>
public static async Task<string> GetAsync(string urlpath)
{
using (var client = new HttpClient())
{
try
{
var respContent = await client.GetAsync(urlpath);
string respStr = await respContent.Content.ReadAsStringAsync();
return respStr;
}
catch (Exception ex)
{
throw ex;
}
}
}
#endregion
} }
} }

@ -1,36 +0,0 @@
using System;
using System.Threading;
using System.Windows;
using System.Windows.Input;
namespace STranslate.Utils
{
public class GetWords
{
public static String Get()
{
SendCtrlC();
Thread.Sleep(200);
return NativeMethod.GetText();
}
private static void SendCtrlC()
{
//IntPtr hWnd = GetForegroundWindow();
//SetForegroundWindow(hWnd);
uint KEYEVENTF_KEYUP = 2;
NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(KeyInterop.VirtualKeyFromKey(Key.LeftAlt), 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(KeyInterop.VirtualKeyFromKey(Key.RightAlt), 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.LWin, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.RWin, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.ShiftKey, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, 0, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.C, 0, 0, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.C, 0, KEYEVENTF_KEYUP, 0);
NativeMethod.keybd_event(System.Windows.Forms.Keys.ControlKey, 0, KEYEVENTF_KEYUP, 0);// 'Left Control Up
}
}
}

@ -1,77 +0,0 @@
using Newtonsoft.Json;
using STranslate.Model;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace STranslate.Utils
{
public static class HttpUtil
{
public static DeeplResp Post(string url, DeeplReq req)
{
//json参数
string jsonParam = JsonConvert.SerializeObject(req);
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json;charset=UTF-8";
byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
int length = byteData.Length;
request.ContentLength = length;
Stream writer = request.GetRequestStream();
writer.Write(byteData, 0, length);
writer.Close();
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
var resp = JsonConvert.DeserializeObject<DeeplResp>(responseString);
return resp;
}
/// <summary>
/// 异步Post请求
/// </summary>
/// <param name="url"></param>
/// <param name="req"></param>
/// <returns></returns>
public static async Task<string> PostAsync(string url, string req)
{
using (var client = new HttpClient())
{
var content = new StringContent(req, Encoding.UTF8, "application/json");
var respContent = await client.PostAsync(url, content);
string respStr = await respContent.Content.ReadAsStringAsync();
;
return respStr;
}
}
/// <summary>
/// 异步Get请求
/// </summary>
/// <param name="urlpath"></param>
/// <returns></returns>
public static async Task<string> GetAsync(string urlpath)
{
using (var client = new HttpClient())
{
try
{
var respContent = await client.GetAsync(urlpath);
string respStr = await respContent.Content.ReadAsStringAsync();
return respStr;
}
catch (Exception ex)
{
throw ex;
}
}
}
}
}

@ -1,5 +1,5 @@
using STranslate.Model; using STranslate.Model;
using STranslate.Utils; using STranslate.Helper;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -22,7 +22,7 @@ namespace STranslate.ViewModel
OutputComboSelected = LanguageEnum.AUTO.GetDescription(); OutputComboSelected = LanguageEnum.AUTO.GetDescription();
//初始化接口 //初始化接口
SelectedTranslationInterface = TranslationInterface[0]; SelectedTranslationInterface = TranslationInterface[1];
//复制输入 //复制输入
CopyInputCmd = new RelayCommand((_) => true, (_) => CopyInputCmd = new RelayCommand((_) => true, (_) =>
@ -97,11 +97,11 @@ namespace STranslate.ViewModel
{ {
var autoRet = AutomaticLanguageRecognition(InputTxt); var autoRet = AutomaticLanguageRecognition(InputTxt);
IdentifyLanguage = autoRet.Item1; IdentifyLanguage = autoRet.Item1;
translateResp = await TranslateUtil.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]); translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[autoRet.Item2], LanguageEnumDict[InputComboSelected]);
} }
else else
{ {
translateResp = await TranslateUtil.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]); translateResp = await Util.Util.TranslateDeepLAsync(SelectedTranslationInterface.Api, InputTxt, LanguageEnumDict[OutputComboSelected], LanguageEnumDict[InputComboSelected]);
} }
//百度 Api //百度 Api
@ -256,7 +256,7 @@ namespace STranslate.ViewModel
public List<TranslationInterface> TranslationInterface { get => _TranslationInterface; set => UpdateProperty(ref _TranslationInterface, value); } public List<TranslationInterface> TranslationInterface { get => _TranslationInterface; set => UpdateProperty(ref _TranslationInterface, value); }
private TranslationInterface _SelectedTranslationInterface; private TranslationInterface _SelectedTranslationInterface;
public TranslationInterface SelectedTranslationInterface { get => _SelectedTranslationInterface; set => UpdateProperty(ref _SelectedTranslationInterface, value); } public TranslationInterface SelectedTranslationInterface { get => _SelectedTranslationInterface; set => UpdateProperty(ref _SelectedTranslationInterface, value); }
private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => TranslateUtil.GetEnumList<LanguageEnum>(); } private static Dictionary<string, LanguageEnum> LanguageEnumDict { get => Util.Util.GetEnumList<LanguageEnum>(); }
#endregion Params #endregion Params
} }

Loading…
Cancel
Save