소스 검색

输入时超出150字符-给予提示

liyijie 1 년 전
부모
커밋
afc072ae50

+ 30 - 4
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/SelectedTranslationDialogViewModel.cs

@@ -14,6 +14,7 @@ using Microsoft.Office.Core;
 using System.Threading.Tasks;
 using System.Windows;
 using PDF_Master.Properties;
+using PDF_Master.CustomControl;
 
 namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 {
@@ -86,7 +87,7 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
                 SetProperty(ref progressVisible, value);
             }
         }
-        
+
 
         private double processvalue = 0;
 
@@ -166,12 +167,14 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
         #region 委托声明
         public DelegateCommand TranslateCommand { get; set; }
         public DelegateCommand CopyCommand { get; set; }
+        public DelegateCommand<object> textBoxEnterCharactersTextChangedCommad { get; set; }
 
         #endregion
         public SelectedTranslationDialogViewModel()
         {
             TranslateCommand = new DelegateCommand(translate);
             CopyCommand = new DelegateCommand(copy);
+            textBoxEnterCharactersTextChangedCommad = new DelegateCommand<object>(textBoxEnterCharactersTextChanged);
             init();
         }
         #region 逻辑函数
@@ -185,6 +188,28 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             GetTolanguageOrigin();
         }
 
+        /// <summary>
+        /// 检查文字是否超出范围
+        /// </summary>
+        /// <param name="e"></param>
+        private void textBoxEnterCharactersTextChanged(object e)
+        {
+            var ConverterPreview = e as TextBoxEx;
+            if (ConverterPreview != null)
+            {
+                if (ConverterPreview.Text.Length > 150)
+                {
+
+                    ErrorTipText = "Limit 150 characters at a time";
+                    ErrorVisible = Visibility.Visible;
+                }
+                else {
+                    ErrorVisible = Visibility.Collapsed;
+                }
+
+            }
+        }
+
         /// <summary>
         /// 文本翻译
         /// </summary>
@@ -207,12 +232,13 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             string translatetext = "";
             string Code = "";
             Value = 4;
-            await Task.Run( delegate
+            await Task.Run(delegate
             {
-                Code=ChatGTPAIHelper.textTranslate(SelectedText, fromlanguage, tolanguage, ref translatetext);
+                Code = ChatGTPAIHelper.textTranslate(SelectedText, fromlanguage, tolanguage, ref translatetext);
             });
             Value = 7;
-            if (Code != "200") {
+            if (Code != "200")
+            {
                 ErrorTipText = Code;
                 ErrorVisible = Visibility.Visible;
             }

+ 28 - 1
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContentViewModel.cs

@@ -1,4 +1,5 @@
-using PDF_Master.Helper;
+using PDF_Master.CustomControl;
+using PDF_Master.Helper;
 using PDF_Master.Model;
 using PDF_Master.Properties;
 using Prism.Commands;
@@ -85,16 +86,42 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 
         public DelegateCommand ErrorCorrectionCommand { get; set; }
 
+        public DelegateCommand<object> textBoxEnterCharactersTextChangedCommad { get; set; }
+
         #endregion
 
         public ChatGPTAIErrorCorrectionContentViewModel()
         {
             CopyCommand = new DelegateCommand(copy);
             ErrorCorrectionCommand = new DelegateCommand(errorCorrection);
+            textBoxEnterCharactersTextChangedCommad = new DelegateCommand<object>(textBoxEnterCharactersTextChanged);
         }
 
         #region 逻辑函数
 
+        /// <summary>
+        /// 检查文字是否超出范围
+        /// </summary>
+        /// <param name="e"></param>
+        private void textBoxEnterCharactersTextChanged(object e)
+        {
+            var ConverterPreview = e as TextBoxEx;
+            if (ConverterPreview != null)
+            {
+                if (ConverterPreview.Text.Length > 150)
+                {
+
+                    ErrorTipText = "Limit 150 characters at a time";
+                    ErrorVisible = Visibility.Visible;
+                }
+                else
+                {
+                    ErrorVisible = Visibility.Collapsed;
+                }
+
+            }
+        }
+
         /// <summary>
         /// 复制到剪切板
         /// </summary>

+ 29 - 1
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAIRewritingContentViewModel.cs

@@ -1,4 +1,5 @@
-using PDF_Master.Helper;
+using PDF_Master.CustomControl;
+using PDF_Master.Helper;
 using PDF_Master.Model;
 using PDF_Master.Properties;
 using Prism.Commands;
@@ -86,15 +87,42 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
 
         public DelegateCommand RewriteCommand { get; set; }
 
+        public DelegateCommand<object> textBoxEnterCharactersTextChangedCommad { get; set; }
+
         #endregion
 
         public ChatGPTAIRewritingContentViewModel()
         {
             CopyCommand = new DelegateCommand(copy);
             RewriteCommand = new DelegateCommand(rewrite);
+            textBoxEnterCharactersTextChangedCommad = new DelegateCommand<object>(textBoxEnterCharactersTextChanged);
         }
 
         #region 逻辑函数
+
+        /// <summary>
+        /// 检查文字是否超出范围
+        /// </summary>
+        /// <param name="e"></param>
+        private void textBoxEnterCharactersTextChanged(object e)
+        {
+            var ConverterPreview = e as TextBoxEx;
+            if (ConverterPreview != null)
+            {
+                if (ConverterPreview.Text.Length > 150)
+                {
+
+                    ErrorTipText = "Limit 150 characters at a time";
+                    ErrorVisible = Visibility.Visible;
+                }
+                else
+                {
+                    ErrorVisible = Visibility.Collapsed;
+                }
+
+            }
+        }
+
         /// <summary>
         /// 复制到剪切板
         /// </summary>

+ 6 - 1
PDF Office/Views/Dialog/ChatGPTAIDialogs/SelectedTranslationDialog.xaml

@@ -109,7 +109,12 @@
                 <StackPanel Orientation="Horizontal" Margin="0,16,0,0">
                     <StackPanel>
                         <Grid Width="250" Height="180" Margin="16,0,0,0">
-                            <cus:TextBoxEx x:Name="textBoxEnterCharacters" Width="250" Height="180" Text="{Binding SelectedText}" FontFamily="Segoe UI" ShowClose="False" PlaceholderText="Please enter text content here..." VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8">
+                            <cus:TextBoxEx x:Name="textBoxEnterCharacters" Width="250" Height="180" Text="{Binding SelectedText}" FontFamily="Segoe UI" ShowClose="False" PlaceholderText="Please enter text content here..." VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8" >
+                                <i:Interaction.Triggers>
+                                    <i:EventTrigger EventName="TextChanged">
+                                        <i:InvokeCommandAction Command="{Binding textBoxEnterCharactersTextChangedCommad}" CommandParameter="{Binding ElementName=textBoxEnterCharacters}" />
+                                    </i:EventTrigger>
+                                </i:Interaction.Triggers>
                             </cus:TextBoxEx>
                             <TextBlock x:Name="SizeTextBlock" Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0}/150}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8" Foreground="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeBrushConvert}}"/>
                         </Grid>

+ 6 - 1
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContent.xaml

@@ -5,7 +5,7 @@
       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:local="clr-namespace:PDF_Master.Views.HomePanel.ChatGPTAI"
+      xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
       xmlns:converter="clr-namespace:PDF_Master.DataConvert"
       xmlns:prism ="http://prismlibrary.com/"
       prism:ViewModelLocator.AutoWireViewModel="True"
@@ -41,6 +41,11 @@
             </Grid>
             <Grid Height="260" Margin="0,12,0,0">
                 <cus:TextBoxEx x:Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}" FontFamily="Segoe UI" ShowClose="False" PlaceholderText="Please enter text content here..." VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8">
+                    <i:Interaction.Triggers>
+                        <i:EventTrigger EventName="TextChanged">
+                            <i:InvokeCommandAction Command="{Binding textBoxEnterCharactersTextChangedCommad}" CommandParameter="{Binding ElementName=textBoxEnterCharacters}" />
+                        </i:EventTrigger>
+                    </i:Interaction.Triggers>
                 </cus:TextBoxEx>
                 <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0}/150}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,12,8" Foreground="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeBrushConvert}}"/>
             </Grid>

+ 6 - 1
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIRewritingContent.xaml

@@ -5,7 +5,7 @@
       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:local="clr-namespace:PDF_Master.Views.HomePanel.ChatGPTAI"
+      xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
       xmlns:converter="clr-namespace:PDF_Master.DataConvert"
       xmlns:prism ="http://prismlibrary.com/"
       prism:ViewModelLocator.AutoWireViewModel="True"
@@ -41,6 +41,11 @@
             </Grid>
             <Grid  Height="260" Margin="0,12,0,0" >
                 <cus:TextBoxEx x:Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}"  FontFamily="Segoe UI" ShowClose="False" PlaceholderText="Please enter text content here..." VerticalContentAlignment="Top" HorizontalContentAlignment="Left" TextWrapping="Wrap" Padding="8">
+                    <i:Interaction.Triggers>
+                        <i:EventTrigger EventName="TextChanged">
+                            <i:InvokeCommandAction Command="{Binding textBoxEnterCharactersTextChangedCommad}" CommandParameter="{Binding ElementName=textBoxEnterCharacters}" />
+                        </i:EventTrigger>
+                    </i:Interaction.Triggers>
                 </cus:TextBoxEx>
                 <TextBlock Text="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length,StringFormat={}{0}/150}" Foreground="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeBrushConvert}}" Panel.ZIndex="1" Height="22" FontSize="14" HorizontalAlignment="Right"  VerticalAlignment="Bottom" Margin="0,0,12,8"/>
             </Grid>