新增 Ctrl+Enter 快捷发送消息

This commit is contained in:
ZouJin 2023-04-04 19:32:29 +10:00
parent 88cd9af244
commit 33c5429a2d
4 changed files with 48 additions and 22 deletions

View File

@ -1,25 +1,27 @@
<UserControl x:Class="VPet_Simulator.Windows.TalkBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<UserControl x:Class="VPet_Simulator.Windows.TalkBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Height="500" Width="500">
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Height="500" Width="500">
<Border Background="{DynamicResource PrimaryLighter}" BorderBrush="{DynamicResource Primary}" BorderThickness="5"
VerticalAlignment="Top" Margin="5,50,5,5" CornerRadius="5" Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox x:Name="tbTalk" Style="{DynamicResource StandardTextBoxStyle}" Height="Auto"
pu:TextBoxHelper.Watermark="和桌宠说" FontSize="30" AcceptsReturn="True" TextWrapping="WrapWithOverflow"/>
pu:TextBoxHelper.Watermark="和桌宠说" FontSize="30" AcceptsReturn="True" TextWrapping="WrapWithOverflow"
PreviewKeyDown="tbTalk_KeyDown" />
<Button pu:ButtonHelper.CornerRadius="4" Content="发送" BorderThickness="2"
Background="{DynamicResource SecondaryLight}" Grid.Column="2" BorderBrush="{DynamicResource DARKPrimaryDarker}"
FontSize="30" Click="SendMessage_Click" />
<Button x:Name="btn_startup" pu:ButtonHelper.CornerRadius="4" Content="初始化桌宠聊天程序" BorderThickness="2" x:FieldModifier="public"
Background="{DynamicResource SecondaryLight}" BorderBrush="{DynamicResource DARKPrimaryDarker}"
FontSize="30" Click="StartUP_Click" Grid.ColumnSpan="3" />
Background="{DynamicResource SecondaryLight}" Grid.Column="2"
BorderBrush="{DynamicResource DARKPrimaryDarker}" FontSize="30" Click="SendMessage_Click"
ToolTip="按 Ctrl+Enter 发送" />
<Button x:Name="btn_startup" pu:ButtonHelper.CornerRadius="4" Content="初始化桌宠聊天程序" BorderThickness="2"
x:FieldModifier="public" Background="{DynamicResource SecondaryLight}"
BorderBrush="{DynamicResource DARKPrimaryDarker}" FontSize="30" Click="StartUP_Click"
Grid.ColumnSpan="3" />
</Grid>
</Border>
</UserControl>

View File

@ -225,5 +225,14 @@ namespace VPet_Simulator.Windows
Dispatcher.Invoke(() => btn_startup.Visibility = Visibility.Collapsed);
});
}
private void tbTalk_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
{
SendMessage_Click(sender, e);
e.Handled = true;
}
}
}
}

View File

@ -3,20 +3,21 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Height="500" Width="500">
<Border Background="{DynamicResource SecondaryLighter}" BorderBrush="{DynamicResource Secondary}" BorderThickness="5"
VerticalAlignment="Top" Margin="5,50,5,5" CornerRadius="5" Padding="5">
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Height="500" Width="500">
<Border Background="{DynamicResource SecondaryLighter}" BorderBrush="{DynamicResource Secondary}"
BorderThickness="5" VerticalAlignment="Top" Margin="5,50,5,5" CornerRadius="5" Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBox x:Name="tbTalk" Style="{DynamicResource StandardTextBoxStyle}" Height="Auto"
pu:TextBoxHelper.Watermark="和桌宠说" FontSize="30" AcceptsReturn="True" TextWrapping="WrapWithOverflow"/>
pu:TextBoxHelper.Watermark="和桌宠说" FontSize="30" AcceptsReturn="True" TextWrapping="WrapWithOverflow"
PreviewKeyDown="tbTalk_KeyDown" />
<Button pu:ButtonHelper.CornerRadius="4" Content="发送" BorderThickness="2"
Background="{DynamicResource PrimaryLight}" Grid.Column="2" BorderBrush="{DynamicResource DARKPrimaryDarker}"
FontSize="30" Click="SendMessage_Click" />
Background="{DynamicResource PrimaryLight}" Grid.Column="2" ToolTip="按 Ctrl+Enter 发送"
BorderBrush="{DynamicResource DARKPrimaryDarker}" FontSize="30" Click="SendMessage_Click" />
</Grid>
</Border>
</UserControl>

View File

@ -74,9 +74,23 @@ namespace VPet_Simulator.Windows
}
catch (Exception exp)
{
m.Say("API调用失败,请检查设置和网络连接\n" + exp.ToString(), GraphCore.Helper.SayType.Serious);
var e = exp.ToString();
string str = "请检查设置和网络连接";
if (e.Contains("401"))
{
str = "请检查API token设置";
}
m.Say($"API调用失败,{str}\n{e}", GraphCore.Helper.SayType.Serious);
}
Dispatcher.Invoke(() => this.IsEnabled = true);
}
private void tbTalk_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control))
{
SendMessage_Click(sender, e);
e.Handled = true;
}
}
}
}