Browse Source

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

lvle 1 year ago
parent
commit
9fc6392124

+ 21 - 45
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -13,6 +13,7 @@ using System.Net.Http;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
+using System.Web;
 using static Dropbox.Api.Files.SearchMatchType;
 using static Dropbox.Api.TeamLog.EventCategory;
 
@@ -20,9 +21,18 @@ namespace PDF_Master.Helper
 {
     public static class ChatGTPAIHelper
     {
+#if DEBUG
+        //测试环境
+        //纠错重写
         private static string host = "https://ai.compdf.com";
-
+        //百度翻译
         private static string translate = "http://101.132.103.13:8030";
+#else
+        //纠错重写
+        private static string host ="http://prod-cn.your-api-server.com";
+        //百度翻译
+        private static string translate ="https://api-server.compdf.com";
+#endif
 
         /// <summary>
         /// 翻译文档Key接口
@@ -39,21 +49,6 @@ namespace PDF_Master.Helper
         /// </summary>
         private static string Uri_texttranslate = translate + "/v1/translate/textTrans";
 
-        ///// <summary>
-        ///// FAQ接口
-        ///// </summary>
-        //private static string Uri_FAQ = host + "/find-faq";
-
-        ///// <summary>
-        ///// 跳转接口
-        ///// </summary>
-        //private static string Uri_GoToView = host + "/recognition";
-
-        ///// <summary>
-        ///// 摘要接口
-        ///// </summary>
-        //private static string Uri_Summary = host + "/summary";
-
         /// <summary>
         /// 错别字纠正
         /// </summary>
@@ -64,6 +59,8 @@ namespace PDF_Master.Helper
         /// </summary>
         private static string Uri_Rewrite = host + "/api/rewrite";
 
+
+        #region AI服务器对接接口
         /// <summary>
         /// 翻译指定内容,可以指定语言
         /// </summary>
@@ -234,23 +231,13 @@ namespace PDF_Master.Helper
                     //return jobject["code"].ToObject<string>().ToLower();
                     using (var client = new WebClient())
                     {
-                        string folderPath = Path.Combine(App.CurrentPath, "DownloadFile");
-                        //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除同名文件
-                        if (File.Exists(folderPath))
-                        {
-                            File.Delete(folderPath);
-                        }
-                        DirectoryInfo tempfolder = new DirectoryInfo(folderPath);
-                        if (!tempfolder.Exists)
-                        {
-                            tempfolder.Create();
-                        }
+                        string folderPath = file.FullName.Remove(file.FullName.LastIndexOf("."), file.FullName.Length- file.FullName.LastIndexOf(".")) + "_aiTranslation.pdf"; ;
                         client.DownloadProgressChanged += (sender, e) =>
                         {
 
                         };
-                        client.DownloadFile(translate, folderPath + "\\" + file.Name.Replace(file.Extension,".pdf"));
-                        return folderPath + "\\" + file.Name.Replace(file.Extension, ".pdf");
+                        client.DownloadFile(translate, folderPath);
+                        return folderPath;
                     }
                     //return "200";
                 }
@@ -358,7 +345,7 @@ namespace PDF_Master.Helper
             }
             else
             {
-                namevalue["user_id"] = "3";
+                namevalue["user_id"] = "1";
             }
             namevalue["content"] = content;
             return await PostString(Uri_Correction, namevalue, "content");
@@ -381,26 +368,12 @@ namespace PDF_Master.Helper
             }
             else
             {
-                namevalue["user_id"] = "3";
+                namevalue["user_id"] = "1";
             }
             namevalue["content"] = content;
             return await PostString(Uri_Rewrite, namevalue, "content");
         }
 
-
-        ///// <summary>
-        ///// 页面跳转
-        ///// </summary>
-        ///// <param name="content"></param>
-        ///// <returns></returns>
-        //public async static Task<string> GoToView(string content)
-        //{
-        //    System.Collections.Specialized.NameValueCollection namevalue = new System.Collections.Specialized.NameValueCollection();
-        //    //需要翻译的内容
-        //    namevalue["str"] = content;
-        //    return await PostString(Uri_GoToView, namevalue, "flag");
-        //}
-
         /// <summary>
         /// 从链接中返回存在的链接(仅返回第一个找到的链接)
         /// </summary>
@@ -461,7 +434,9 @@ namespace PDF_Master.Helper
             }
             return repsonseData;
         }
+        #endregion
 
+        #region 支持翻译的语言
         public static List<string> FromlanguageFamily { set; get; } = new List<string>();
         public static List<string> SetFromlanguageOrigin()
         {
@@ -588,6 +563,7 @@ namespace PDF_Master.Helper
                     return"";
             }
         }
+        #endregion
     }
 }
 

+ 60 - 0
PDF Office/Styles/ButtonStyle.xaml

@@ -647,4 +647,64 @@
         </Style.Triggers>
     </Style>
 
+    <Style x:Key="OpenPDFFileBtn" TargetType="{x:Type Button}">
+        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
+        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
+        <Setter Property="BorderThickness" Value="2" />
+        <Setter Property="HorizontalContentAlignment" Value="Center" />
+        <Setter Property="VerticalContentAlignment" Value="Center" />
+        <Setter Property="Background" Value="Transparent" />
+        <Setter Property="BorderBrush" Value="{StaticResource color.sys.border.neutral.lv1}" />
+        <Setter Property="IsTabStop" Value="False" />
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="{x:Type Button}">
+                    <Border
+                        x:Name="border"
+                        CornerRadius="8"
+                        Background="{TemplateBinding Background}"
+                        BorderThickness="{TemplateBinding BorderThickness}"
+                        SnapsToDevicePixels="true">
+                        <Border.BorderBrush>
+                            <VisualBrush>
+                                <VisualBrush.Visual>
+                                    <Rectangle StrokeDashArray="4 2" RadiusX="8" RadiusY="8" Stroke="{TemplateBinding BorderBrush}"
+Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"
+Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}">
+                                    </Rectangle>
+                                </VisualBrush.Visual>
+                            </VisualBrush>
+                        </Border.BorderBrush>
+                        <ContentPresenter
+                            x:Name="contentPresenter"
+                            Margin="{TemplateBinding Padding}"
+                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
+                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
+                            Focusable="False"
+                            RecognizesAccessKey="True"
+                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
+                    </Border>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+        <Style.Triggers>
+            <Trigger Property="IsDefaulted" Value="true">
+                <Setter Property="Background" Value="White" />
+            </Trigger>
+            <Trigger Property="IsMouseOver" Value="true">
+                <Setter Property="Background" Value="{StaticResource color.item-state.hov.bg}" />
+                <Setter Property="BorderBrush" Value="{StaticResource color.field.border.hov}" />
+            </Trigger>
+            <Trigger Property="IsPressed" Value="true">
+                <Setter Property="Background" Value="{StaticResource color.item-state.hov.bg}" />
+                <Setter Property="BorderBrush" Value="{StaticResource color.field.border.hov}" />
+            </Trigger>
+            <Trigger Property="IsEnabled" Value="false">
+                <Setter Property="Background" Value="{StaticResource color.field.bg.dis}" />
+                <Setter Property="BorderBrush" Value="{StaticResource color.field.border.norm}" />
+                <Setter Property="Foreground" Value="{StaticResource color.icon.base.neutral.dis}" />
+            </Trigger>
+        </Style.Triggers>
+    </Style>
+
 </ResourceDictionary>

+ 42 - 0
PDF Office/Styles/RadioButtonStyle.xaml

@@ -762,4 +762,46 @@
             </Setter.Value>
         </Setter>
     </Style>
+
+    <Style x:Key="HomeContentLeftBtn" TargetType="{x:Type  RadioButton}">
+        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
+        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
+        <Setter Property="BorderThickness" Value="0" />
+        <Setter Property="HorizontalContentAlignment" Value="Center" />
+        <Setter Property="VerticalContentAlignment" Value="Center" />
+        <Setter Property="Background" Value="Transparent" />
+        <Setter Property="BorderBrush" Value="Transparent" />
+        <Setter Property="IsTabStop" Value="False" />
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="{x:Type  RadioButton}">
+                    <Border
+                        x:Name="border"
+                        CornerRadius="8"
+                        Background="{TemplateBinding Background}"
+                        BorderBrush="{TemplateBinding BorderBrush}"
+                        BorderThickness="{TemplateBinding BorderThickness}"
+                        SnapsToDevicePixels="true">
+                        <ContentPresenter
+                            x:Name="contentPresenter"
+                            Margin="{TemplateBinding Padding}"
+                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
+                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
+                            Focusable="False"
+                            RecognizesAccessKey="True"
+                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
+                    </Border>
+                    <ControlTemplate.Triggers>
+                    <Trigger Property="IsChecked" Value="true">
+                            <Setter TargetName="border" Property="Background" Value="{StaticResource color.item-state.sel.bg.lv1}" />
+                            <Setter Property="Foreground" Value="{StaticResource color.item-state.sel.bg.lv2}" />
+                    </Trigger>
+                        <Trigger Property="IsMouseOver" Value="True">
+                            <Setter TargetName="border" Property="Background" Value="{StaticResource color.item-state.sel.bg.lv2}" />
+                        </Trigger>
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
 </ResourceDictionary>

+ 1 - 6
PDF Office/ViewModels/BottomToolContentViewModel.cs

@@ -486,12 +486,7 @@ namespace PDF_Master.ViewModels
                 return;
             }
 
-
-            ////枚举 过滤所有不合理的输入
-            //if (args.Key != Key.Enter && args.Key != Key.Oem5 && args.Key != Key.Back && args.Key != Key.OemComma && args.Key != Key.OemMinus && args.Key != Key.Subtract && !((args.Key >= Key.D0 && args.Key <= Key.D9) || (args.Key >= Key.NumPad0 && args.Key <= Key.NumPad9)))
-            //{
-            //    args.Handled = true;
-            //}
+            //输入值的预处理通过input事件里写正则来判断
 
             if (args.Key == Key.Enter)
             {

+ 8 - 1
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs

@@ -21,6 +21,8 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
 
         public CPDFViewer PDFViewer;
 
+        public ViewContentViewModel viewContentViewModel;
+
         private CPDFViewer pdfViewer = null;
 
         private string fromlanguage = "";
@@ -93,9 +95,12 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
             {
                 if (File.Exists(newfile))
                 {
-                    
+                    if (viewContentViewModel != null) {
+                        viewContentViewModel.OpenFile(new string[] { newfile });
+                    }
                 }
             }
+            RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
         }
 
         public string Title => "";
@@ -115,6 +120,8 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
         {
 
             parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
+            parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
+            
             if (pdfViewer != null)
             {
                 if (!regionManager.Regions[ViewerRegionName].Views.Contains(pdfViewer))

+ 211 - 150
PDF Office/ViewModels/Dialog/ToolsDialogs/MergeDialogViewModel.cs

@@ -119,6 +119,8 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         public DelegateCommand ClearCommand { get; set; }
         public DelegateCommand<object> SetPageSizeTypeCommand { get; set; }
 
+        public DelegateCommand CancelAddFileCommand { get; set; }
+
         public IDialogService dialogs;
 
         private PageSizeType pageSizeType = PageSizeType.kDefault;
@@ -134,6 +136,20 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             }
         }
 
+        private Visibility processVisible = Visibility.Collapsed;
+        /// <summary>
+        /// 是否显示进度条
+        /// </summary>
+        public Visibility ProcessVisible
+        {
+            get { return processVisible; }
+            set
+            {
+                SetProperty(ref processVisible, value);
+            }
+        }
+
+
         private string inputHeight;
 
         public string InputHeight
@@ -144,16 +160,41 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 SetProperty(ref inputHeight, value);
             }
         }
-        private int comboBoxSelectedIndex = 0;
 
-        public int ComboBoxSelectedIndex
-        {
-            get { return comboBoxSelectedIndex; }
-            set
-            {
-                SetProperty(ref comboBoxSelectedIndex, value);
-            }
-        }
+        private double maxValue;
+        /// <summary>
+        /// 最大文件数 用于显示进度条
+        /// </summary>
+        public double MaxValue
+        {
+            get { return maxValue; }
+            set
+            {
+                SetProperty(ref maxValue, value);
+            }
+        }
+
+        private double currentvalue;
+
+        /// <summary>
+        /// 当前进度值
+        /// </summary>
+        public double CurrentValue
+        {
+            get { return currentvalue; }
+            set
+            {
+                SetProperty(ref currentvalue, value);
+            }
+        }
+
+
+
+        /// <summary>
+        /// 是否取消添加文件
+        /// </summary>
+
+        private bool CancelAddFiles = false;
 
 
         public MergeDialogViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
@@ -167,11 +208,18 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             MergeCommand = new DelegateCommand(Merge);
             ClearCommand = new DelegateCommand(Clear);
             SetPageSizeTypeCommand = new DelegateCommand<object>(SetPageSizeType);
-        }
+            CancelAddFileCommand = new DelegateCommand(CancelAddFileOpention);
+        }
+
+
         #endregion
-
+
         #region 私有方法
-
+        private void CancelAddFileOpention()
+        {
+            CancelAddFiles = true;
+        }
+
         private void UpDataMergeObjectIndex()
         {
             for (int i = 0; i < MergeObjectlist.Count; i++)
@@ -211,16 +259,15 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         public void ButtonAddFiles(object data)
         {
             int index = Convert.ToInt32(data);
+            CancelAddFiles = false;
             switch (index)
             {
                 case 0:
                     //打开文件
-                    ComboBoxSelectedIndex = 0;//打开文件弹窗会影响UI更新,所以手动更新
                     AddFiles(OpenFile());
                     break;
                 case 1:
                     //打开文件夹
-                    ComboBoxSelectedIndex = 1;//打开文件夹弹窗会影响UI更新,所以手动更新
                     AddFiles(OpenFileFolder());
                     break;
                 case 2:
@@ -495,157 +542,171 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             UpDataMergeObjectIndex();
         }
 
-        public void AddFiles(string[] FilePath)
+        public async void AddFiles(string[] FilePath)
         {
             if (FilePath == null)
             {
                 return;
             }
             bool showDialog = false;
-            for (int i = 0; i < FilePath.Length; i++)
-            {
-                MergeObject mergeObject = new MergeObject();
-                mergeObject.FilePath = FilePath[i];
-
-                //通过路径判断文件是否已添加
-                bool IsExists = false;
-                for (int j = 0; j < MergeObjectlist.Count; j++)
-                {
-                    if (MergeObjectlist[j].FilePath == mergeObject.FilePath)
-                    {
-                        IsExists = true;
-                    }
-                }
-                if (IsExists)
-                {
-                    continue;
-                }
-                string FileType = Path.GetExtension(mergeObject.FilePath).Trim().ToLower();
-                if (string.IsNullOrEmpty(FileType))
-                {
-                    showDialog = true;
-                    //获取不到文件类型
-                    continue;
-                }
-                if (FileType != ".pdf")
-                {
-                    string imagetype = "*" + FileType;
-                    string[] x = Properties.Resources.imageex.ToLower().Split(';');
-                    List<string> list = x.ToList();
-                    int imageindex = list.IndexOf(imagetype);
-                    if (imageindex < 0)
-                    {
-                        showDialog = true;
-                        //图片格式不支持
-                        continue;
-                    };
-
-                    mergeObject.DocName = Path.GetFileName(mergeObject.FilePath);
-                    mergeObject.DocPageCount = 1 + " " + App.MainPageLoader.GetString("Merge_ItemPages");
-                    mergeObject.SDKPageCount = 1;
-                    mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
-                    try
-                    {
-                        mergeObject.DocThumbnail = new BitmapImage(new Uri(mergeObject.FilePath));
-                    }
-                    catch (Exception)
-                    {
-                        showDialog = true;
-                        //解码错误
-                        continue;
-                    }
-                }
-                else
-                {
-                    CPDFDocument doc = CPDFDocument.InitWithFilePath(mergeObject.FilePath);
-                    if (doc == null)
-                    {
-                        showDialog = true;
-                        //PDF打开失败
-                        continue;
-                    }
-
-                    ///Fix:
-                    ///情况分为:
-                    ///开启路径是当前路径:
-                    ///已解锁或本身就无密码->直接加入
-                    ///未解锁-> release
-                    ///
-                    /// 不是当前路径
-                    ///解锁或取消->
-                    ///
-
-                    if (CurrentFilePath == doc.FilePath)
-                    {
-
-                        if ((!(!doc.IsLocked && (SecurityHelper.CheckHaveAllPermissions(doc)))) &&
-                            (!(!string.IsNullOrEmpty(currentLoadedPassword) &&
-                            doc.UnlockWithPassword(currentLoadedPassword) &&
-                            (doc.CheckOwnerPassword(currentLoadedPassword) || SecurityHelper.CheckHaveAllPermissions(doc)))))
-                        {
-                            doc.Release();
-                            continue;
-                        }
-                        //添加的第一个文档有权限密码时,保存密码,避免合并时因没有密码导致合并失败
-                        //表现为在首页打开一个带权限的文档进入合并,点击合并按钮没有反应
-                        if (!string.IsNullOrEmpty(currentLoadedPassword))
-                        {
-                            mergeObject.Password = currentLoadedPassword;
-                        }
-                    }
-                    else
-                    {
-                        VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(doc, EnumPasswordKind.StatusPermissionsPassword, dialogs);
-                        if (condition.IsDiscryptied)
-                        {
-                            if (condition.Password != null)
-                            {
-                                mergeObject.Password = condition.Password;
-                                if (doc.UnlockWithPassword(condition.Password) && doc.CheckOwnerPassword(condition.Password))
-                                {
-
-                                }
-                            }
-                        }
-                        else
-                        {
-                            doc.Release();
-                            continue;
-                        }
+            ProcessVisible = Visibility.Visible;
+            MaxValue = FilePath.Length;
+            await System.Threading.Tasks.Task.Run((() =>
+            {
+                for (int i = 0; i < FilePath.Length; i++)
+                {
+                    //如果中断了文件添加,则取消循环
+                    if (CancelAddFiles)
+                    {
+                        break;
                     }
+                    MergeObject mergeObject = new MergeObject();
+                    mergeObject.FilePath = FilePath[i];
 
-                    mergeObject.DocName = doc.FileName;
-                   
-                    if (doc.PageCount > 1)
+                    //通过路径判断文件是否已添加
+                    bool IsExists = false;
+                    for (int j = 0; j < MergeObjectlist.Count; j++)
                     {
-                        mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPages");
-                        mergeObject.IsEvenPageIsEnabled = true;
+                        if (MergeObjectlist[j].FilePath == mergeObject.FilePath)
+                        {
+                            IsExists = true;
+                        }
                     }
-                    else
+                    if (IsExists)
                     {
-                        mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPage");
-                        mergeObject.IsEvenPageIsEnabled = false;
+                        continue;
                     }
-                    mergeObject.SDKPageCount = doc.PageCount;
-                    mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
+                    string FileType = Path.GetExtension(mergeObject.FilePath).Trim().ToLower();
+                    if (string.IsNullOrEmpty(FileType))
+                    {
+                        showDialog = true;
+                        //获取不到文件类型
+                        continue;
+                    }
+                    if (FileType != ".pdf")
+                    {
+                        string imagetype = "*" + FileType;
+                        string[] x = Properties.Resources.imageex.ToLower().Split(';');
+                        List<string> list = x.ToList();
+                        int imageindex = list.IndexOf(imagetype);
+                        if (imageindex < 0)
+                        {
+                            showDialog = true;
+                            //图片格式不支持
+                            continue;
+                        };
 
-                    //获取第一页缩略图
-                    CPDFPage page = doc.PageAtIndex(0);
-                    Size size = doc.GetPageSize(0);
+                        mergeObject.DocName = Path.GetFileName(mergeObject.FilePath);
+                        mergeObject.DocPageCount = 1 + " " + App.MainPageLoader.GetString("Merge_ItemPages");
+                        mergeObject.SDKPageCount = 1;
+                        mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
+                        try
+                        {
+                            mergeObject.DocThumbnail = new BitmapImage(new Uri(mergeObject.FilePath));
+                        }
+                        catch (Exception)
+                        {
+                            showDialog = true;
+                            //解码错误
+                            continue;
+                        }
+                    }
+                    else
+                    {
+                        CPDFDocument doc = CPDFDocument.InitWithFilePath(mergeObject.FilePath);
+                        if (doc == null)
+                        {
+                            showDialog = true;
+                            //PDF打开失败
+                            continue;
+                        }
 
-                    byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
-                    WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
-                    page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
-                    WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
-                    WirteBitmap.Freeze();
-                    mergeObject.DocThumbnail = WirteBitmap;
+                        ///Fix:
+                        ///情况分为:
+                        ///开启路径是当前路径:
+                        ///已解锁或本身就无密码->直接加入
+                        ///未解锁-> release
+                        ///
+                        /// 不是当前路径
+                        ///解锁或取消->
+                        ///
 
-                    doc.Release();
-                }
-                MergeObjectlist.Add(mergeObject);
-                UpDataMergeObjectIndex();
-            }
-
+                        if (CurrentFilePath == doc.FilePath)
+                        {
+
+                            if ((!(!doc.IsLocked && (SecurityHelper.CheckHaveAllPermissions(doc)))) &&
+                                (!(!string.IsNullOrEmpty(currentLoadedPassword) &&
+                                doc.UnlockWithPassword(currentLoadedPassword) &&
+                                (doc.CheckOwnerPassword(currentLoadedPassword) || SecurityHelper.CheckHaveAllPermissions(doc)))))
+                            {
+                                doc.Release();
+                                continue;
+                            }
+                            //添加的第一个文档有权限密码时,保存密码,避免合并时因没有密码导致合并失败
+                            //表现为在首页打开一个带权限的文档进入合并,点击合并按钮没有反应
+                            if (!string.IsNullOrEmpty(currentLoadedPassword))
+                            {
+                                mergeObject.Password = currentLoadedPassword;
+                            }
+                        }
+                        else
+                        {
+                            VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(doc, EnumPasswordKind.StatusPermissionsPassword, dialogs);
+                            if (condition.IsDiscryptied)
+                            {
+                                if (condition.Password != null)
+                                {
+                                    mergeObject.Password = condition.Password;
+                                    if (doc.UnlockWithPassword(condition.Password) && doc.CheckOwnerPassword(condition.Password))
+                                    {
+
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                doc.Release();
+                                continue;
+                            }
+                        }
+
+                        mergeObject.DocName = doc.FileName;
+
+                        if (doc.PageCount > 1)
+                        {
+                            mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPages");
+                            mergeObject.IsEvenPageIsEnabled = true;
+                        }
+                        else
+                        {
+                            mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPage");
+                            mergeObject.IsEvenPageIsEnabled = false;
+                        }
+                        mergeObject.SDKPageCount = doc.PageCount;
+                        mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
+
+                        //获取第一页缩略图
+                        CPDFPage page = doc.PageAtIndex(0);
+                        Size size = doc.GetPageSize(0);
+
+                        byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
+                        WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
+                        page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
+                        WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
+                        WirteBitmap.Freeze();
+                        mergeObject.DocThumbnail = WirteBitmap;
+
+                        doc.Release();
+                    }
+                    App.Current.Dispatcher.Invoke(() =>
+                    {
+                        MergeObjectlist.Add(mergeObject);
+                    });
+                    CurrentValue = i;
+                    UpDataMergeObjectIndex();
+                }
+            }));
+            ProcessVisible = Visibility.Collapsed;
             if (showDialog)
             {
                 AlertsMessage alertsMessage = new AlertsMessage();

+ 4 - 0
PDF Office/ViewModels/HomeContentViewModel.cs

@@ -66,6 +66,8 @@ namespace PDF_Master.ViewModels
 
         #endregion
 
+        public string currentViewName="";
+
         private string fileName = "Home";
         public string FileName
         {
@@ -135,6 +137,7 @@ namespace PDF_Master.ViewModels
         /// <param name="view"></param>
         public void ShowToolContent(string view)
         {
+            currentViewName = view;
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.HomeContentViewModel, this);
             if (view.Contains("ChatGPT"))
@@ -433,6 +436,7 @@ namespace PDF_Master.ViewModels
             }
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.HomeContentViewModel, this);
+            currentViewName = "Guid";
             toolregion.RequestNavigate(ToolRegionName, "Guid", param);
         }
 

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

@@ -14,11 +14,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
     public class ChatGPTAITranslationContentViewModel : BindableBase, INavigationAware
     {
 
-        HomeContentViewModel homeContentViewModel = null;
+        public HomeContentViewModel homeContentViewModel = null;
 
-        private string fromlanguage = ChatGTPAIHelper.UpdateLanguagebType(0);
+        public string fromlanguage = ChatGTPAIHelper.UpdateLanguagebType(0);
 
-        private string tolanguage = ChatGTPAIHelper.UpdateLanguagebType(1);
+        public string tolanguage = ChatGTPAIHelper.UpdateLanguagebType(1);
 
         private int fromlanguageIndex = 0;
         public int FromlanguageIndex
@@ -68,10 +68,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
             GetTolanguageOrigin();
         }
 
-        public async void selectFiles() {
+        public async void selectFiles()
+        {
             string word = Properties.Resources.wordex;
-            string pdf= Properties.Resources.pdf;
-            string allfiles = pdf+ word;
+            string pdf = Properties.Resources.pdf;
+            string allfiles = pdf + word;
             OpenFileDialog dialog = new OpenFileDialog();
             //dialog.Multiselect = true;
             dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
@@ -79,9 +80,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
            $"Microsoft Office Word({word})|{word}");
             if ((bool)dialog.ShowDialog())
             {
-               string newfile= await ChatGTPAIHelper.fileTranslate( dialog.FileName , fromlanguage, tolanguage);
-                if (!string.IsNullOrEmpty(newfile)) {
-                    if (File.Exists(newfile)) {
+                string newfile = await ChatGTPAIHelper.fileTranslate(dialog.FileName, fromlanguage, tolanguage);
+                if (!string.IsNullOrEmpty(newfile))
+                {
+                    if (File.Exists(newfile))
+                    {
                         if (homeContentViewModel != null)
                         {
                             homeContentViewModel.OpenFile(new string[] { newfile });
@@ -89,7 +92,7 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
                     }
                 }
             }
-                
+
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)

+ 29 - 6
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -723,7 +723,7 @@ namespace PDF_Master.ViewModels
         /// <summary>
         /// 鼠标滚轮缩放的缩放值
         /// </summary>
-        private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
+        private double[] zoomLevel = { 1.00f, 10, 25, 50, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000,2000,4000,10000};
 
         /// <summary>
         /// 注释-链接,提示语
@@ -1361,6 +1361,24 @@ namespace PDF_Master.ViewModels
             }
         }
 
+
+        /// <summary>
+        /// 打开文件Translation
+        /// </summary>
+        public void OpenFile(string[] newfile)
+        {
+            if (App.OpenedFileList.Contains(newfile[0]))
+            {
+                App.mainWindowViewModel.SelectItem(newfile[0]);
+            }
+            else
+            {
+                App.mainWindowViewModel.AddTabItem(newfile[0]);
+            }
+            ToolMethod.SetFileThumbImg(newfile[0]);
+
+        }
+
         /// <summary>
         /// 关闭当前窗体
         /// </summary>
@@ -1894,7 +1912,7 @@ namespace PDF_Master.ViewModels
             DialogParameters printValue = new DialogParameters();
             printValue.Add(ParameterNames.PDFViewer, PDFViewer);
             printValue.Add(ParameterNames.FilePath, PDFViewer.Document.FileName);
-            printValue.Add(ParameterNames.PrintCurrentPage, PDFViewer.CurrentIndex);
+            printValue.Add(ParameterNames.ViewContentViewModel, this);
             printValue.Add(ParameterNames.Unicode, unicode);
             dialogs.ShowDialog(DialogNames.DocumentaryTranslation, printValue, e => { });
         }
@@ -2370,13 +2388,18 @@ namespace PDF_Master.ViewModels
         public double CheckZoomLevel(double zoom, bool IsGrowth)
         {
             double standardZoom = 100;
-            if (zoom <= 0.01)
+            //最小缩放倍数 0.01倍
+            double minrate = 0.01;
+            //最大缩放倍数 100倍
+            double maxrate = 100;
+            if (zoom <= minrate)
             {
-                return 0.01;
+                return minrate;
             }
-            if (zoom >= 10)
+            //最大缩放倍数 100倍
+            if (zoom >= maxrate)
             {
-                return 10;
+                return maxrate;
             }
 
             zoom *= 100;

+ 1 - 1
PDF Office/Views/BottomToolContent.xaml

@@ -423,7 +423,7 @@
                             Width="46"
                             Height="14"
                             Margin="4,0,0,0"
-                            Padding="2,0,0,0"
+                            Padding="1,0,0,0"
                             HorizontalAlignment="Left"
                             Background="White"
                             BorderThickness="0"

File diff suppressed because it is too large
+ 646 - 603
PDF Office/Views/Dialog/ToolsDialogs/MergeDialog.xaml


+ 25 - 8
PDF Office/Views/Dialog/ToolsDialogs/MergeDialog.xaml.cs

@@ -307,9 +307,10 @@ namespace PDF_Master.Views.Dialog.ToolsDialogs
             TitlePageRange.Text = App.MainPageLoader.GetString("Merge_TitlePageRange");
             TitleSize.Text = App.MainPageLoader.GetString("Merge_TitleSize");
 
-            AddComboBoxItemText.Text = App.MainPageLoader.GetString("Merge_AddFiles");
-            AddFolderComboBoxItemText.Text = App.MainPageLoader.GetString("Merge_AddFolder");
-            AddOpenFileComboBoxItem.Text = App.MainPageLoader.GetString("Merge_AddOpenFile");
+            TxbAddFileText.Text = App.MainPageLoader.GetString("Merge_AddFiles");
+            MenuAddComboBoxItem.Header = App.MainPageLoader.GetString("Merge_AddFiles");
+            MenuAddFolderComboBoxItem.Header = App.MainPageLoader.GetString("Merge_AddFolder");
+            MenuAddOpenFileComboBoxItem.Header = App.MainPageLoader.GetString("Merge_AddOpenFile");
 
             BtnMerge.Content = App.MainPageLoader.GetString("Merge_Yes");
             BtnCancel.Content = App.MainPageLoader.GetString("Merge_No");
@@ -319,13 +320,29 @@ namespace PDF_Master.Views.Dialog.ToolsDialogs
         {
             WritableComboBox writableComboBox = sender as WritableComboBox;
             var ls = writableComboBox.DataContext as MergeObject;
-            if (ls != null) 
-            { 
-                foreach (var a in ls.SetPageRange) 
-                { 
-                Trace.WriteLine(a);
+            if (ls != null)
+            {
+                foreach (var a in ls.SetPageRange)
+                {
+                    Trace.WriteLine(a);
                 }
             }
         }
+
+        private void BtnAddFile_Initialized(object sender, EventArgs e)
+        {
+            var btn = sender as Button;
+            if (btn != null)
+            {
+                btn.ContextMenu = null;
+            }
+        }
+
+        private void BtnAddFile_Click(object sender, RoutedEventArgs e)
+        {
+            CmAddFile.PlacementTarget = BtnAddFile;
+            CmAddFile.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
+            CmAddFile.IsOpen = true;
+        }
     }
 }

+ 16 - 12
PDF Office/Views/HomeContent.xaml

@@ -58,14 +58,15 @@
         </Grid.ColumnDefinitions>
         <!--  左侧菜单栏  -->
         <StackPanel>
-            <Button
+            <RadioButton
                 x:Name="Home"
                 Height="64"
                 Margin="32,32,32,0"
                 Command="{Binding ShowToolCommand}"
                 CommandParameter="Guid"
                 Foreground="#FFFFFF"
-                Style="{StaticResource NoColorBtn}">
+                GroupName="home"
+                Style="{StaticResource HomeContentLeftBtn}">
                 
                 <StackPanel Orientation="Horizontal">
                     <Image
@@ -82,14 +83,15 @@
                         FontSize="16"
                         Text="Home" />
                 </StackPanel>
-            </Button>
-            <Button
+            </RadioButton>
+            <RadioButton
                 Height="64"
                 Margin="32,8,32,0"
                 Command="{Binding ShowToolCommand}"
                 CommandParameter="ChatGPTAITranslationContent"
                 Foreground="#FFFFFF"
-                Style="{StaticResource NoColorBtn}">
+                GroupName="home"
+                Style="{StaticResource HomeContentLeftBtn}">
                 <StackPanel Orientation="Horizontal">
                     <Image
                          Margin="0,0,8,0"
@@ -105,14 +107,15 @@
                         FontSize="16"
                         Text="AI Translation" />
                 </StackPanel>
-            </Button>
-            <Button
+            </RadioButton>
+            <RadioButton
                 Height="64"
                 Margin="32,8,32,0"
                 Command="{Binding ShowToolCommand}"
                 CommandParameter="ChatGPTAIRewritingContent"
                 Foreground="#FFFFFF"
-                Style="{StaticResource NoColorBtn}">
+                GroupName="home"
+                Style="{StaticResource HomeContentLeftBtn}">
                 <StackPanel Orientation="Horizontal">
                     <Image
                         Margin="0,0,8,0"
@@ -128,14 +131,15 @@
                         FontSize="16"
                         Text="AI Rewriting" />
                 </StackPanel>
-            </Button>
-            <Button
+            </RadioButton>
+            <RadioButton
                 Height="64"
                 Margin="32,8,32,0"
                 Command="{Binding ShowToolCommand}"
                 CommandParameter="ChatGPTAIErrorCorrectionContent"
                 Foreground="#FFFFFF"
-                Style="{StaticResource NoColorBtn}">
+                GroupName="home"
+                Style="{StaticResource HomeContentLeftBtn}">
                 <StackPanel Orientation="Horizontal">
                     <Image
                          Margin="0,0,8,0"
@@ -151,7 +155,7 @@
                         FontSize="16"
                         Text="AI Error Correction" />
                 </StackPanel>
-            </Button>
+            </RadioButton>
             <Button
                 Visibility="Collapsed"
                 x:Name="BtnOpenPDF"

+ 21 - 16
PDF Office/Views/HomeContent.xaml.cs

@@ -1,6 +1,6 @@
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
-using PDF_Master.ViewModels;
+using PDF_Master.ViewModels;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -25,7 +25,7 @@ namespace PDF_Master.Views
         public string Content { get; set; }
 
         public string Uri { get; set; }
-        public PromotionBanner(string ImagePath,string Content,string uri)
+        public PromotionBanner(string ImagePath, string Content, string uri)
         {
             this.ImagePath = ImagePath;
             this.Content = Content;
@@ -37,17 +37,18 @@ namespace PDF_Master.Views
     /// HomeContent.xaml 的交互逻辑
     /// </summary>
     public partial class HomeContent : UserControl
-    {
+    {
+        private HomeContentViewModel viewModel;
 
-        private bool IsContextMenuOpen = false;
-       
+        private bool IsContextMenuOpen = false;
+
         public HomeContent()
         {
             InitializeComponent();
-            BtnGuid.IsChecked = true;
-           
-        }
-      
+            BtnGuid.IsChecked = true;
+            viewModel = this.DataContext as HomeContentViewModel;
+        }
+
         private void ToggleBtnSelect_Click(object sender, RoutedEventArgs e)
         {
             BtnGuid.IsChecked = false;
@@ -55,17 +56,17 @@ namespace PDF_Master.Views
             BtnCloud.IsChecked = false;
 
             var btn = sender as CustomIconToggleBtn;
-            if(btn != null )
+            if (btn != null)
             {
                 btn.IsChecked = true;
-            }
-            
+            }
+
         }
 
         private void BtnCreatPDF_Initialized(object sender, EventArgs e)
         {
             var btn = sender as Button;
-            if(btn!=null)
+            if (btn != null)
             {
                 btn.ContextMenu = null;
             }
@@ -92,7 +93,7 @@ namespace PDF_Master.Views
 
         private void UserControl_DragEnter(object sender, DragEventArgs e)
         {
-            DragDropHelper.DragEnter(this,e);
+            DragDropHelper.DragEnter(this, e);
         }
 
         private void UserControl_DragOver(object sender, DragEventArgs e)
@@ -112,9 +113,13 @@ namespace PDF_Master.Views
                 DragDropHelper.Drop(this, e);
 
                 string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
-                if(file.Length>0)
+                if (file.Length > 0)
                 {
-                    (this.DataContext as HomeContentViewModel).AddFileFromDrag(file.ToList());
+                    //判断是否为Home页面
+                    if (viewModel.currentViewName == "Guid")
+                    {
+                        (this.DataContext as HomeContentViewModel).AddFileFromDrag(file.ToList());
+                    }
                 }
             }
             catch { }

+ 6 - 0
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml

@@ -28,6 +28,11 @@ Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, P
                         </VisualBrush.Visual>
                     </VisualBrush>
                 </Border.BorderBrush>
+                <Grid AllowDrop="True"
+                  Drop="Grid_Drop"
+                  DragEnter="MainPage_DragEnter"
+                  DragOver="MainPage_DragOver"
+                  DragLeave="MainPage_DragLeave"> 
                 <StackPanel>
                     <StackPanel Margin="0,72,0,0">
                         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
@@ -75,6 +80,7 @@ Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, P
                         TextWrapping="Wrap"
                         />
                 </StackPanel>
+                </Grid>
             </Border>
         </StackPanel>
     </Grid>

+ 113 - 1
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml.cs

@@ -1,4 +1,18 @@
-using System.Windows.Controls;
+using ComPDFKitViewer;
+using PDF_Master.Helper;
+using System.Data;
+using System.Windows;
+using System;
+using System.Windows.Controls;
+using System.Windows.Interop;
+using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
+using PDF_Master.ViewModels.HomePanel.ChatGPTAI;
+using Microsoft.Office.Core;
+using PDF_Master.ViewModels;
+using Microsoft.Office.Interop.Word;
+using System.IO;
+using Point = System.Windows.Point;
+using Window = System.Windows.Window;
 
 namespace PDF_Master.Views.HomePanel.ChatGPTAI
 {
@@ -7,9 +21,107 @@ namespace PDF_Master.Views.HomePanel.ChatGPTAI
     /// </summary>
     public partial class ChatGPTAITranslationContent : UserControl
     {
+        private ChatGPTAITranslationContentViewModel viewModel;
+        private IDropTargetHelper dropHelper;
         public ChatGPTAITranslationContent()
         {
             InitializeComponent();
+            viewModel = this.DataContext as ChatGPTAITranslationContentViewModel;
         }
+
+        private async void Grid_Drop(object sender, DragEventArgs e)
+        {
+
+            try
+            {
+               Point iconPoint = e.GetPosition(this);
+                dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
+            }
+            catch (Exception ex)
+            {
+
+            }
+            string dropFile = "Drop";
+            if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
+            {
+                //BtnBlank.IsEnabled = true;
+                int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
+                for (int i = 0; i < count; i++)
+                {
+                    dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); 
+                    if (dropFile.ToLower().EndsWith("pdf")|| dropFile.ToLower().EndsWith(".doc") || dropFile.ToLower().EndsWith(".docx")|| dropFile.ToLower().EndsWith(".docm")|| dropFile.ToLower().EndsWith(".dot")|| dropFile.ToLower().EndsWith(".dotx") || dropFile.ToLower().EndsWith(".dotm")) 
+                    {
+                        string newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage);
+                        if (!string.IsNullOrEmpty(newfile))
+                        {
+                            if (File.Exists(newfile))
+                            {
+                                if (viewModel.homeContentViewModel != null)
+                                { 
+                                    viewModel.homeContentViewModel.OpenFile(new string[] { newfile }); 
+                                
+                                }
+                            }
+                        }
+                                    
+                    }
+                }
+            }
+        }
+        private void MainPage_DragEnter(object sender, DragEventArgs e)
+        {
+            //BtnBlank.IsEnabled = false;
+            //页面编辑和缩略图
+            if ((e.OriginalSource as Image) != null)
+                return;
+            try
+            {
+                if (dropHelper == null)
+                {
+                    dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
+                }
+                Point iconPoint = e.GetPosition(this);
+                dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+        }
+
+        private void MainPage_DragOver(object sender, DragEventArgs e)
+        {
+
+            if ((e.OriginalSource as Image) != null)
+                return;
+            try
+            {
+                Point iconPoint = e.GetPosition(this);
+                dropHelper?.DragOver(ref iconPoint, e.Effects);
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+        }
+
+        private void MainPage_DragLeave(object sender, DragEventArgs e)
+        {
+           // BtnBlank.IsEnabled = true;
+            if ((e.OriginalSource as Image) != null)
+                return;
+            try
+            {
+                dropHelper?.DragLeave();
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+        }
+
     }
 }

File diff suppressed because it is too large
+ 3 - 3
PDF Office/Views/HomePanel/PDFTools/HomeFilesContent.xaml


+ 1 - 1
PDF Office/Views/PageEdit/PageEditContent.xaml

@@ -211,7 +211,7 @@
                     <Grid>
                         <ComboBox
                             Name="CmbPageRange"
-                            Width="117"
+                            Width="123"
                             Height="23"
                             InputMethod.IsInputMethodEnabled="False"
                             IsEditable="True"