Browse Source

ChatGPTAI-UI逻辑优化

liyijie 1 year ago
parent
commit
27fd4d3a1a

+ 33 - 0
PDF Office/DataConvert/ColorBrushConvert.cs

@@ -32,4 +32,37 @@ namespace PDF_Master.DataConvert
             return Brushes.White.Color;
         }
     }
+
+    public class SizeBrushConvert : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (value == null)
+            {
+                return Brushes.Black;
+            }
+            else
+            {
+                if ((int)value>150)
+                {
+                    return Brushes.Red;
+                }
+                else
+                {
+                    return Brushes.Black;
+                }
+            }
+
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+
+            if ((SolidColorBrush)value != null)
+            {
+                return ((SolidColorBrush)value).Color;
+            }
+            return Brushes.White.Color;
+        }
+    }
 }

+ 46 - 0
PDF Office/DataConvert/InvertBoolConvert.cs

@@ -51,4 +51,50 @@ namespace PDF_Master.DataConvert
 
         }
     }
+
+    public class SizeToBoolConvert : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (value == null)
+            {
+                return false;
+            }
+            else
+            {
+                if ((int)value == 0) {
+                    return false;
+                }
+                    if ((int)value > 150)
+                {
+                    return false;
+                }
+                else
+                {
+                    return true;
+                }
+            }
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+
+            if (value is bool)
+            {
+                if ((bool)value)
+                {
+                    return false;
+                }
+                else
+                {
+                    return true;
+                }
+            }
+            else
+            {
+                return false;
+            }
+
+        }
+    }
 }

+ 2 - 1
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -249,7 +249,8 @@ namespace PDF_Master.Helper
                         {
 
                         };
-                        client.DownloadFile(translate, folderPath + "\\" + file.Name);
+                        client.DownloadFile(translate, folderPath + "\\" + file.Name.Replace(file.Extension,".pdf"));
+
                     }
                     return "200";
                 }

+ 2 - 13
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAITranslationContentViewModel.cs

@@ -65,25 +65,14 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
         }
 
         public async void selectFiles() {
-            string txt = Properties.Resources.txtex;
             string word = Properties.Resources.wordex;
-            string ppt = Properties.Resources.pptex;
-            string excel = Properties.Resources.excelex;
-            string html = Properties.Resources.htmlex;
-            string image = Properties.Resources.imageex;
             string pdf= Properties.Resources.pdf;
-            string allfiles = pdf+txt + word + excel + ppt + image + html;
+            string allfiles = pdf+ word;
             OpenFileDialog dialog = new OpenFileDialog();
             //dialog.Multiselect = true;
             dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
            $"Pdf({pdf})|{pdf}|" +
-           $"Microsoft Office Word({word})|{word}|" +
-           $"Microsoft Office Excel({excel})|{excel}|" +
-           $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
-           $"Txt({txt})|{txt}|" +
-           $"Picture({image})|{image}|" +
-           $"Html({html})|{html}");
-
+           $"Microsoft Office Word({word})|{word}");
             if ((bool)dialog.ShowDialog())
             {
                 await ChatGTPAIHelper.fileTranslate( dialog.FileName , fromlanguage, tolanguage);

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

@@ -1,5 +1,6 @@
 <UserControl x:Class="PDF_Master.Views.Dialog.ChatGPTAIDialogs.SelectedTranslationDialog"
              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,12 @@
     prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
     prism:ViewModelLocator.AutoWireViewModel="True"
     mc:Ignorable="d">
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <convert:SizeBrushConvert x:Key="SizeBrushConvert" />
+            <convert:SizeToBoolConvert x:Key="SizeToBoolConvert"/>
+        </ResourceDictionary>
+    </UserControl.Resources>
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="50"></RowDefinition>
@@ -63,11 +70,11 @@
                 <StackPanel Orientation="Horizontal" Margin="0,16,0,0">
                     <StackPanel>
                         <Grid Width="250" Height="180" Margin="16,0,0,0">
-                            <TextBox Name="textBoxEnterCharacters" Width="250" Height="180" Text="{Binding SelectedText}">
+                            <TextBox Name="textBoxEnterCharacters" Width="250" Height="180" Text="{Binding SelectedText}" >
                             </TextBox>
-                            <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"/>
+                            <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>
-                        <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Translate" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Margin="0,8,0,0" Command="{Binding TranslateCommand}"></Button>
+                        <Button HorizontalAlignment="Right" Width="97" Height="24" Content="Translate" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Margin="0,8,0,0" Command="{Binding TranslateCommand}" IsEnabled="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeToBoolConvert}}"></Button>
                     </StackPanel>
                     <StackPanel>
                         <TextBox  Width="250" Height="180" Margin="16,0,0,0" Text="{Binding TranslateText}">

+ 9 - 2
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIErrorCorrectionContent.xaml

@@ -1,5 +1,6 @@
 <UserControl x:Class="PDF_Master.Views.HomePanel.ChatGPTAI.ChatGPTAIErrorCorrectionContent"
             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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
@@ -11,6 +12,12 @@
       mc:Ignorable="d"  
       d:DesignHeight="760" d:DesignWidth="1032"
      >
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <convert:SizeBrushConvert x:Key="SizeBrushConvert" />
+            <convert:SizeToBoolConvert x:Key="SizeToBoolConvert"/>
+        </ResourceDictionary>
+    </UserControl.Resources>
     <Grid Margin="32,0,32,0">
         <Grid.RowDefinitions>
             <RowDefinition Height="*" />
@@ -33,12 +40,12 @@
                         TextWrapping="Wrap"
                         />
                 </StackPanel>
-                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="ErrorCorrection" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding ErrorCorrectionCommand}"></Button>
+                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="ErrorCorrection" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding ErrorCorrectionCommand}" IsEnabled="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeToBoolConvert}}"></Button>
             </Grid>
             <Grid Height="260" Margin="0,12,0,0">
                 <TextBox Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}">
                 </TextBox>
-                <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"/>
+                <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>
         </StackPanel>
         <StackPanel Grid.Row="1">

+ 10 - 3
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAIRewritingContent.xaml

@@ -1,5 +1,6 @@
 <UserControl x:Class="PDF_Master.Views.HomePanel.ChatGPTAI.ChatGPTAIRewritingContent"
              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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
@@ -11,6 +12,12 @@
       mc:Ignorable="d"  
       d:DesignHeight="760" d:DesignWidth="1032"
      >
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <convert:SizeBrushConvert x:Key="SizeBrushConvert" />
+            <convert:SizeToBoolConvert x:Key="SizeToBoolConvert"/>
+        </ResourceDictionary>
+    </UserControl.Resources>
     <Grid Margin="32,0,32,0">
         <Grid.RowDefinitions>
             <RowDefinition Height="*" />
@@ -33,12 +40,12 @@
                         TextWrapping="Wrap"
                         />
                 </StackPanel>
-                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Rewrite" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding RewriteCommand}"></Button>
+                <Button HorizontalAlignment="Right" Width="104" Height="32" Content="Rewrite" VerticalAlignment="Bottom" Style="{StaticResource Btn.cta}" Command="{Binding RewriteCommand}" IsEnabled="{Binding ElementName=textBoxEnterCharacters,Path=Text.Length, Converter={StaticResource SizeToBoolConvert}}"></Button>
             </Grid>
             <Grid  Height="260" Margin="0,12,0,0">
-                <TextBox Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}">
+                <TextBox Name="textBoxEnterCharacters"  Height="260" Text="{Binding InputText}" >
                 </TextBox>
-                <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"/>
+                <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>
         </StackPanel>
         <StackPanel Grid.Row="1">