perf: update view viewmodel split

dev_ocr_translate
DESKTOP-3BO4HSG\ksat 2 years ago
parent 7a4aa1deb6
commit ec121dbb58

@ -11,13 +11,10 @@
x:Name="Mwin"
Background="Transparent"
WindowStartupLocation="CenterScreen"
MouseLeftButtonDown="Window_MouseLeftButtonDown"
AllowsTransparency="True"
ShowInTaskbar="False"
ResizeMode="NoResize"
Topmost="True"
Deactivated="Window_Deactivated"
Closing="Mwin_Closing"
WindowStyle="None"
SizeToContent="Height"
Width="400"
@ -52,6 +49,16 @@
Command="{Binding EscCmd}"/>
</Window.InputBindings>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding MouseLeftDownCmd}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Deactivated">
<i:InvokeCommandAction Command="{Binding DeactivatedCmd}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Border Style="{DynamicResource BorderMainStyle}">
<Grid>
<Grid.RowDefinitions>

@ -14,15 +14,14 @@ namespace STranslate.View
private MainVM vm;
public MainWindow()
{
InitializeComponent();
//InitializeComponent();
DataContext = new MainVM(this);
vm = (MainVM)DataContext;
//if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict)
//{
// MessageBox.Show("全局快捷键有冲突,请您到设置中重新设置");
// MessageBox.Show("全局快捷键有冲突...");
//}
}
@ -32,7 +31,10 @@ namespace STranslate.View
/// <param name="e"></param>
protected override void OnSourceInitialized(EventArgs e)
{
//base.OnSourceInitialized(e);
base.OnSourceInitialized(e);
this.Hide();
HotkeysHelper.InitialHook(this);
HotkeysHelper.Register(HotkeysHelper.InputTranslateId, () =>
{
@ -54,36 +56,5 @@ namespace STranslate.View
vm.OpenMainWin();
});
}
/// <summary>
/// 移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragMove();
}
/// <summary>
/// 非激活窗口则隐藏起来
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Deactivated(object sender, EventArgs e)
{
if (vm == null) return;
if (!vm.IsTopmost)
{
vm.Speech.SpeakAsyncCancelAll();
this.Hide();
}
}
private void Mwin_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
HotkeysHelper.UnRegisterHotKey();
}
}
}

@ -18,7 +18,6 @@ namespace STranslate.ViewModel
public MainVM(Window win)
{
_Mainwin = (MainWindow)win;
OpenMainWin();
if (!ReadConfig())
{
@ -107,6 +106,20 @@ namespace STranslate.ViewModel
#endregion
#region Common
//移动
MouseLeftDownCmd = new RelayCommand((_) => true, (_) =>
{
_Mainwin.DragMove();
});
//失去焦点
DeactivatedCmd = new RelayCommand((_) => true, (_) =>
{
if (!IsTopmost)
{
Speech.SpeakAsyncCancelAll();
_Mainwin.Hide();
}
});
//source speak
SourceSpeakCmd = new RelayCommand((_) => true, (_) =>
{
@ -222,6 +235,8 @@ namespace STranslate.ViewModel
IsVisibility = false;
//语音合成销毁
Speech.Dispose();
//注销快捷键
HotkeysHelper.UnRegisterHotKey();
if (id == 0)
{
//写入配置
@ -389,6 +404,8 @@ namespace STranslate.ViewModel
#region Params
private string translateResp;
public ICommand MouseLeftDownCmd { get; private set; }
public ICommand DeactivatedCmd { get; private set; }
public ICommand SourceSpeakCmd { get; private set; }
public ICommand TargetSpeakCmd { get; private set; }
public ICommand TranslateCmd { get; private set; }

Loading…
Cancel
Save