Browse Source

Merge branch 'dev' of http://git.kdan.cc:8865/Windows/PDFOffice_Windows_exe into dev

ZhouJieSheng 1 year ago
parent
commit
05c3e52992

+ 33 - 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,31 @@ 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)
+            {
+                //结果置空
+                TranslateText = "";
+                if (ConverterPreview.Text.Length > 150)
+                {
+
+                    ErrorTipText = "Limit 150 characters at a time";
+                    ErrorVisible = Visibility.Visible;
+                }
+                else {
+                    ErrorVisible = Visibility.Collapsed;
+                }
+
+            }
+        }
+
         /// <summary>
         /// 文本翻译
         /// </summary>
@@ -207,12 +235,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;
             }

+ 25 - 5
PDF Office/ViewModels/Dialog/PageEditDialogs/InsertDialogViewModel.cs

@@ -1,4 +1,5 @@
-using PDF_Master.Helper;
+using Microsoft.AppCenter.Utils.Files;
+using PDF_Master.Helper;
 using PDF_Master.Model;
 using PDF_Master.Model.PageEdit;
 using Prism.Commands;
@@ -8,6 +9,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Drawing.Printing;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -320,10 +322,28 @@ namespace PDF_Master.ViewModels.Dialog.PageEditDialogs
         private void InitPageSource()
         {
             Pages = new ObservableCollection<CustomPageItem>();
-            Pages.Add(new CustomPageItem() { Name = "空白页", FilePath = "" });
-            Pages.Add(new CustomPageItem() { Name = "横线", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\HorizontalLine.jpg") });
-            Pages.Add(new CustomPageItem() { Name = "五线谱", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\Staff.jpg") });
-            Pages.Add(new CustomPageItem() { Name = "格子线", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\GridLine.jpg") });
+
+            //20230704 插入自定义弹窗,弹窗不出来的情况,保险起见 先注释掉这部分代码
+            //Pages.Add(new CustomPageItem() { Name = "空白页", FilePath = "" });
+
+            //string filePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\HorizontalLine.jpg");
+            //if (System.IO.File.Exists(filePath))
+            //{
+            //    Pages.Add(new CustomPageItem() { Name = "横线", FilePath = filePath });
+            //}
+            //filePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\Staff.jpg");
+            //if (System.IO.File.Exists(filePath))
+            //{
+            //    Pages.Add(new CustomPageItem() { Name = "五线谱", FilePath = filePath });
+            //}
+            //filePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\GridLine.jpg");
+            //if (System.IO.File.Exists(filePath))
+            //{
+            //    Pages.Add(new CustomPageItem() { Name = "格子线", FilePath = filePath });
+            //}
+            //Pages.Add(new CustomPageItem() { Name = "横线", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\HorizontalLine.jpg") });
+            //Pages.Add(new CustomPageItem() { Name = "五线谱", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\Staff.jpg") });
+            //Pages.Add(new CustomPageItem() { Name = "格子线", FilePath = System.IO.Path.Combine(Environment.CurrentDirectory, @"Resources\PageEdit\GridLine.jpg") });
         }
 
         private void cancel()

+ 29 - 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,43 @@ 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)
+            {
+                //结果置空
+                ErrorCorrectionText = "";
+                if (ConverterPreview.Text.Length > 150)
+                {
+                    ErrorTipText = "Limit 150 characters at a time";
+                    ErrorVisible = Visibility.Visible;
+                }
+                else
+                {
+                    ErrorVisible = Visibility.Collapsed;
+                }
+
+            }
+        }
+
         /// <summary>
         /// 复制到剪切板
         /// </summary>

+ 30 - 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,43 @@ 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)
+            {
+                //结果置空
+                RewriteText = "";
+                if (ConverterPreview.Text.Length > 150)
+                {
+                    ErrorTipText = "Limit 150 characters at a time";
+                    ErrorVisible = Visibility.Visible;
+                }
+                else
+                {
+                    ErrorVisible = Visibility.Collapsed;
+                }
+
+            }
+        }
+
         /// <summary>
         /// 复制到剪切板
         /// </summary>

+ 23 - 15
PDF Office/Views/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialog.xaml

@@ -1,5 +1,6 @@
 <UserControl x:Class="PDF_Master.Views.Dialog.ChatGPTAIDialogs.DocumentaryTranslationDialog"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:convert="clr-namespace:PDF_Master.DataConvert"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:cus="clr-namespace:PDF_Master.CustomControl"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -13,6 +14,11 @@
     prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
     prism:ViewModelLocator.AutoWireViewModel="True"
     mc:Ignorable="d">
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <convert:UnVisibleToBoolConvert x:Key="UnVisibleToBoolConvert" />
+        </ResourceDictionary>
+    </UserControl.Resources>
     <cus:DialogContent Header="AI Translation">
         <cus:DialogContent.Content>
             <Grid Grid.Row="1" >
@@ -20,24 +26,25 @@
                     <ColumnDefinition Width="*"></ColumnDefinition>
                     <ColumnDefinition Width="468"></ColumnDefinition>
                 </Grid.ColumnDefinitions>
-                <Border Grid.ColumnSpan="2"
-                Panel.ZIndex="1"
+                <Border x:Name="ProgressBorder" Grid.RowSpan="2" Grid.ColumnSpan="2"
+                Panel.ZIndex="1" Background="Transparent" Visibility="{Binding ProgressVisible}">
+                    <Border 
                 Width="226"
                 Height="58"
                 Background="{StaticResource color.sys.layout.dark.bg}"
                 BorderThickness="0"
                 CornerRadius="{StaticResource border-radius.8}"
                 Effect="{StaticResource shadow.neutral.m}"
-                Visibility="{Binding ProgressVisible}">
-                    <Grid Margin="16,13" Background="Transparent">
-                        <StackPanel Orientation="Horizontal">
-                            <TextBlock Foreground="{StaticResource color.sys.text.anti.norm}" Text="Translating..." />
-                            <TextBlock
+                >
+                        <Grid Margin="16,13" Background="Transparent">
+                            <StackPanel Orientation="Horizontal">
+                                <TextBlock Foreground="{StaticResource color.sys.text.anti.norm}" Text="Translating..." />
+                                <TextBlock
                             Foreground="{StaticResource color.sys.text.anti.norm}"
                             Text="{Binding Value, StringFormat={}({0})}"
                             Visibility="Collapsed" />
-                        </StackPanel>
-                        <Button
+                            </StackPanel>
+                            <Button
                         Width="12"
                         Height="12"
                         Padding="0,0,1,1"
@@ -46,9 +53,9 @@
                         Background="{StaticResource color.sys.layout.dark.bg}"
                         BorderThickness="0"
                         Visibility="Collapsed">
-                            <Path Data="M6.00006 7.06072L9.46973 10.5304L10.5304 9.46973L7.06072 6.00006L10.5304 2.53039L9.46973 1.46973L6.00006 4.9394L2.53039 1.46973L1.46973 2.53039L4.9394 6.00006L1.46973 9.46973L2.53039 10.5304L6.00006 7.06072Z" Fill="#CED0D4" />
-                        </Button>
-                        <ProgressBar
+                                <Path Data="M6.00006 7.06072L9.46973 10.5304L10.5304 9.46973L7.06072 6.00006L10.5304 2.53039L9.46973 1.46973L6.00006 4.9394L2.53039 1.46973L1.46973 2.53039L4.9394 6.00006L1.46973 9.46973L2.53039 10.5304L6.00006 7.06072Z" Fill="#CED0D4" />
+                            </Button>
+                            <ProgressBar
                         Height="4"
                         Margin="0,0,0,4"
                         VerticalAlignment="Bottom"
@@ -56,7 +63,8 @@
                         Foreground="{StaticResource color.slider.track-filled.norm}"
                         Maximum="{Binding MaxValue}"
                         Value="{Binding Value}" />
-                    </Grid>
+                        </Grid>
+                    </Border>
                 </Border>
                 <Grid>
                     <ContentControl
@@ -65,7 +73,7 @@
                 HorizontalAlignment="Stretch"
                 prism:RegionManager.RegionName="{Binding ViewerRegionName}"/>
                 </Grid>
-                    <StackPanel Grid.Column="1" Margin="16,0,0,0">
+                <StackPanel Grid.Column="1" Margin="16,0,0,0">
                     <TextBlock Text="Translation Language:" Style="{StaticResource PropertyHeaderLv2}" Height="20"></TextBlock>
                     <StackPanel Orientation="Horizontal" Margin="0,8,0,0" HorizontalAlignment="Left">
                         <ComboBox Width="200" Height="40" Margin="0,0,0,0" ItemsSource="{Binding FromlanguageFamily}" SelectedIndex="{Binding FromlanguageIndex}"></ComboBox>
@@ -107,7 +115,7 @@
             </Grid>
         </cus:DialogContent.Content>
         <cus:DialogContent.BottmBar>
-            <Grid>
+            <Grid IsEnabled="{Binding ElementName=ProgressBorder,Path=Visibility,Converter={StaticResource UnVisibleToBoolConvert}}">
                 <Button
                     Width="98"
                     Height="32"

+ 10 - 3
PDF Office/Views/Dialog/ChatGPTAIDialogs/SelectedTranslationDialog.xaml

@@ -27,14 +27,15 @@
             <RowDefinition Height="*"></RowDefinition>
         </Grid.RowDefinitions>
         <Border Grid.RowSpan="2"
-                Panel.ZIndex="1"
+                Panel.ZIndex="1" Background="Transparent" Visibility="{Binding ProgressVisible}">
+        <Border 
                 Width="226"
                 Height="58"
                 Background="{StaticResource color.sys.layout.dark.bg}"
                 BorderThickness="0"
                 CornerRadius="{StaticResource border-radius.8}"
                 Effect="{StaticResource shadow.neutral.m}"
-                Visibility="{Binding ProgressVisible}">
+                >
             <Grid Margin="16,13" Background="Transparent">
                 <StackPanel Orientation="Horizontal">
                     <TextBlock Foreground="{StaticResource color.sys.text.anti.norm}" Text="Translating..." />
@@ -64,6 +65,7 @@
                         Value="{Binding Value}" />
             </Grid>
         </Border>
+        </Border>
         <Grid Grid.Row="0">
             <StackPanel Orientation="Horizontal">
                 <TextBlock  Margin="16,0,0,0" Text="AI Translation" FontFamily="Segoe UI"
@@ -109,7 +111,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>

+ 4 - 2
PDF Office/Views/Dialog/PageEditDialogs/InsertDialog.xaml

@@ -102,6 +102,7 @@
                     <RowDefinition Height="auto" />
                     <RowDefinition Height="auto" />
                 </Grid.RowDefinitions>
+                <!--  20230704 如果设置为Hidden,可能会导致弹窗无法打开,报 图片被占用  -->
                 <ListBox
                     Padding="0,16,0,0"
                     HorizontalAlignment="Center"
@@ -109,7 +110,7 @@
                     ItemTemplate="{StaticResource CustomItem}"
                     ItemsSource="{Binding Pages}"
                     SelectedIndex="{Binding ItemSelectedIndex, Mode=TwoWay}"
-                    Visibility="Hidden">
+                    Visibility="Collapsed">
                     <ListBox.ItemContainerStyle>
                         <Style TargetType="{x:Type ListBoxItem}">
                             <Setter Property="Template" Value="{StaticResource ListBoxItemControlTemplate}" />
@@ -204,10 +205,11 @@
                             </TextBox.Resources>
                         </TextBox>
                         <TextBlock
+                            Margin="5,0"
                             VerticalAlignment="Center"
                             FontFamily="Segoe UI"
                             FontSize="14"
-                            Text="X" Margin="5,0" />
+                            Text="X" />
                         <!--<TextBox
                         Width="80"
                         Height="32"

+ 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>