fix: hot keys conflict message

perf: add keydown keyup
main
DESKTOP-3BO4HSG\ksat 2 years ago
parent 5fbfc19ec3
commit 74eb8755a5

@ -20,11 +20,6 @@ namespace STranslate.View
vm.Mainwin = this; vm.Mainwin = this;
InitialTray(); InitialTray();
//if (HotKeys.InputTranslate.Conflict || HotKeys.CrosswordTranslate.Conflict || HotKeys.ScreenShotTranslate.Conflict)
//{
// MessageBox.Show("全局快捷键有冲突...");
//}
} }
/// <summary> /// <summary>
@ -57,6 +52,11 @@ namespace STranslate.View
{ {
vm.OpenMainWin(); vm.OpenMainWin();
}); });
if (Hotkeys.InputTranslate.Conflict || Hotkeys.CrosswordTranslate.Conflict || Hotkeys.ScreenShotTranslate.Conflict || Hotkeys.OpenMainWindow.Conflict)
{
MessageBox.Show("全局快捷键有冲突,请前往软件首选项中修改...");
}
} }
private MainVM vm = MainVM.Instance; private MainVM vm = MainVM.Instance;
@ -77,18 +77,18 @@ namespace STranslate.View
NotifyIcon.ShowBalloonTip(500); NotifyIcon.ShowBalloonTip(500);
NotifyIcon.MouseDoubleClick += InputTranslateMenuItem_Click; NotifyIcon.MouseDoubleClick += InputTranslateMenuItem_Click;
var inputTranslateMenuItemBtn = new MenuItem("输入翻译\tAlt+A"); var inputTranslateMenuItemBtn = new MenuItem("输入翻译");
inputTranslateMenuItemBtn.Click += InputTranslateMenuItem_Click; inputTranslateMenuItemBtn.Click += InputTranslateMenuItem_Click;
var screenshotTranslateMenuItemBtn = new MenuItem("截图翻译\tAlt+S"); var screenshotTranslateMenuItemBtn = new MenuItem("截图翻译");
screenshotTranslateMenuItemBtn.Click += ScreenshotTranslateMenuItem_Click; screenshotTranslateMenuItemBtn.Click += ScreenshotTranslateMenuItem_Click;
var crossWordTranslateMenuItemBtn = new MenuItem("划词翻译\tAlt+D"); var crossWordTranslateMenuItemBtn = new MenuItem("划词翻译");
//CrossWordTranslateMenuItemBTN.Click += CrossWordTranslateMenuItem_Click; //CrossWordTranslateMenuItemBTN.Click += CrossWordTranslateMenuItem_Click;
//当失去焦点后无法从托盘处获取选中文本 //当失去焦点后无法从托盘处获取选中文本
crossWordTranslateMenuItemBtn.Enabled = false; crossWordTranslateMenuItemBtn.Enabled = false;
var openMainWinBtn = new MenuItem("显示主界面\tAlt+G"); var openMainWinBtn = new MenuItem("显示主界面");
openMainWinBtn.Click += OpenMainWin_Click; openMainWinBtn.Click += OpenMainWin_Click;
var preferenceBtn = new MenuItem("首选项"); var preferenceBtn = new MenuItem("首选项");

@ -15,12 +15,12 @@
TargetType="Button"> TargetType="Button">
<Border x:Name="border" <Border x:Name="border"
CornerRadius="5" CornerRadius="5"
Padding="4" Padding="5"
Background="#dedfde" Background="#dedfde"
MaxHeight="25"> MaxHeight="25">
<TextBlock VerticalAlignment="Center" <TextBlock VerticalAlignment="Center"
HorizontalAlignment="Center" HorizontalAlignment="Center"
Text="检查更新"/> Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}"/>
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true"> <Trigger Property="IsMouseOver" Value="true">
@ -113,7 +113,7 @@
</TabItem> </TabItem>
<!--
<TabItem Header="控制" <TabItem Header="控制"
Padding="10,2"> Padding="10,2">
@ -139,7 +139,8 @@
Grid.Row="1" Grid.Row="1"
Grid.Column="0" Grid.Column="0"
Margin="0,5,0,0" /> Margin="0,5,0,0" />
<TextBox Cursor="Arrow" <TextBox x:Name="CrossWord_TextBox"
Cursor="Arrow"
Width="200" Width="200"
Grid.Row="1" Grid.Row="1"
Grid.Column="1" Grid.Column="1"
@ -148,8 +149,12 @@
VerticalContentAlignment="Center" VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"> InputMethod.IsInputMethodEnabled="False">
<i:Interaction.Triggers> <i:Interaction.Triggers>
<i:EventTrigger EventName=""> <i:EventTrigger EventName="PreviewKeyDown">
<i:InvokeCommandAction Command="{Binding }"/> <i:InvokeCommandAction Command="{Binding PreviewKeyDownCmd}"
CommandParameter="{Binding ElementName=CrossWord_TextBox}"/>
</i:EventTrigger>
<i:EventTrigger EventName="KeyUp">
<i:InvokeCommandAction Command="{Binding CrossWordKeyUpCmd}"/>
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers> </i:Interaction.Triggers>
</TextBox> </TextBox>
@ -240,7 +245,7 @@
</StackPanel> </StackPanel>
</TabItem> </TabItem>
-->
<TabItem Header="服务" <TabItem Header="服务"
Visibility="Collapsed" Visibility="Collapsed"
@ -251,6 +256,7 @@
</GroupBox> </GroupBox>
</TabItem> </TabItem>
<TabItem Header="关于" <TabItem Header="关于"
Padding="10,2"> Padding="10,2">
<ScrollViewer VerticalScrollBarVisibility="Auto"> <ScrollViewer VerticalScrollBarVisibility="Auto">

@ -72,6 +72,12 @@ namespace STranslate.ViewModel
(o as Window)?.Close(); (o as Window)?.Close();
}); });
//重置热键
ResetHotKeysCmd = new RelayCommand((_) => true, (_) =>
{
System.Diagnostics.Debug.Print("重置快捷键");
});
OpenUrlCmd = new RelayCommand((_) => true, (o) => OpenUrlCmd = new RelayCommand((_) => true, (o) =>
{ {
try try
@ -85,6 +91,16 @@ namespace STranslate.ViewModel
MessageBox.Show($"未找到默认应用\n{ex.Message}"); MessageBox.Show($"未找到默认应用\n{ex.Message}");
} }
}); });
PreviewKeyDownCmd = new RelayCommand((_) => true, (o) =>
{
System.Diagnostics.Debug.Print($"Press key, control: {o}");
});
CrossWordKeyUpCmd = new RelayCommand((_) => true, (_) =>
{
System.Diagnostics.Debug.Print($"Key up");
});
} }
@ -108,6 +124,13 @@ namespace STranslate.ViewModel
public ICommand UpdateCmd { get; private set; } public ICommand UpdateCmd { get; private set; }
public ICommand StartupCmd { get; private set; } public ICommand StartupCmd { get; private set; }
public ICommand EscCmd { get; private set; } public ICommand EscCmd { get; private set; }
public ICommand ResetHotKeysCmd { get; private set; }
/// <summary>
/// 按键按下事件
/// </summary>
public ICommand PreviewKeyDownCmd { get; private set; }
public ICommand CrossWordKeyUpCmd { get; private set; }
private static SettingsVM _instance; private static SettingsVM _instance;
public static SettingsVM Instance => _instance ?? (_instance = new SettingsVM()); public static SettingsVM Instance => _instance ?? (_instance = new SettingsVM());

Loading…
Cancel
Save