Переглянути джерело

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

ZhouJieSheng 1 рік тому
батько
коміт
6559e88308

+ 76 - 31
PDF Office/Helper/ChatGTPAIHelper.cs

@@ -29,10 +29,12 @@ namespace PDF_Master.Helper
 #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 = "https://ai.compdf.com";
@@ -69,14 +71,16 @@ namespace PDF_Master.Helper
         /// chatGPT错误码
         /// </summary>
         public static string ChatGPTCode = "";
+
         #region AI服务器对接接口
+
         /// <summary>
         /// 获取
         /// </summary>
         /// <param name="content"></param>
         /// <param name="filename"></param>
         /// <returns></returns>
-        public async static Task<string> fileKeyTranslate(string content, string filename)
+        public static async Task<string> fileKeyTranslate(string content, string filename)
         {
             string Code = "Code" + "300";
             ServicePointManager.DefaultConnectionLimit = 200;
@@ -132,7 +136,6 @@ namespace PDF_Master.Helper
             }
             try
             {
-
                 // 获取HTTP响应
                 HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
                 using (StreamReader reader = new StreamReader(response2.GetResponseStream()))
@@ -156,8 +159,6 @@ namespace PDF_Master.Helper
                         return translation;
                     }
                     return "Code" + jobject["code"].ToObject<string>().ToLower();
-
-
                 }
             }
             catch (WebException ex)
@@ -167,7 +168,6 @@ namespace PDF_Master.Helper
                 {
                     //从网络异常信息里解析错误,后面的逻辑根据错误码判断会更准确
                     statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
-
                 }
                 Trace.WriteLine("HTTP异常:" + ex.Message);
                 if (statusCode == 401)
@@ -210,8 +210,6 @@ namespace PDF_Master.Helper
             return path;
         }
 
-
-
         /// <summary>
         /// 翻译指定内容,可以指定语言
         /// </summary>
@@ -325,7 +323,6 @@ namespace PDF_Master.Helper
                             folderPath = CommonHelper.CreateFilePath(folderPath);
                             client.DownloadProgressChanged += (sender, e) =>
                             {
-
                             };
                             client.DownloadFile(translate, folderPath);
                             clossProcess();
@@ -360,10 +357,8 @@ namespace PDF_Master.Helper
             {
                 return "300";
             }
-
         }
 
-
         /// <summary>
         /// 翻译指定内容,可以指定语言
         /// </summary>
@@ -373,7 +368,6 @@ namespace PDF_Master.Helper
         /// <returns></returns>
         public static String textTranslate(string content, string fromlanguage, string tolanguage, ref string translate)
         {
-
             HttpWebResponse response = null;
             ServicePointManager.DefaultConnectionLimit = 200;
             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Uri_texttranslate);
@@ -453,7 +447,6 @@ namespace PDF_Master.Helper
             {
                 return "300";
             }
-
         }
 
         /// <summary>
@@ -461,9 +454,8 @@ namespace PDF_Master.Helper
         /// </summary>
         /// <param name="content"></param>
         /// <returns></returns>
-        public async static Task<string> Correction(string content)
+        public static async Task<string> Correction(string content)
         {
-
             intProcess(true, "Correcting...");
             App.mainWindowViewModel.Value = 1;
             ServicePointManager.DefaultConnectionLimit = 200;
@@ -499,9 +491,8 @@ namespace PDF_Master.Helper
         /// </summary>
         /// <param name="content"></param>
         /// <returns></returns>
-        public async static Task<string> Rewrite(string content)
+        public static async Task<string> Rewrite(string content)
         {
-
             intProcess(true, "Rewriting...");
             App.mainWindowViewModel.Value = 1;
             ServicePointManager.DefaultConnectionLimit = 200;
@@ -565,7 +556,7 @@ namespace PDF_Master.Helper
         /// <param name="request">请求体</param>
         /// /// <param name="key">值</param>
         /// <returns></returns>
-        private async static Task<string> PostStringHttpWeb(MultipartFormDataContent formData, HttpWebRequest request, string key = "message")
+        private static async Task<string> PostStringHttpWeb(MultipartFormDataContent formData, HttpWebRequest request, string key = "message")
         {
             App.mainWindowViewModel.Value = 6;
             string repsonseData = "";
@@ -575,7 +566,6 @@ namespace PDF_Master.Helper
             }
             try
             {
-
                 // 获取HTTP响应
                 HttpWebResponse response2 = (HttpWebResponse)request.GetResponse();
                 using (StreamReader reader = new StreamReader(response2.GetResponseStream()))
@@ -605,9 +595,6 @@ namespace PDF_Master.Helper
                     //repsonseData = Regex.Unescape(unicode);
                     repsonseData = unicode;
                     clossProcess();
-                   
-
-
                 }
             }
             catch (WebException ex)
@@ -627,7 +614,8 @@ namespace PDF_Master.Helper
                 clossProcess();
                 return null;
             }
-            catch {
+            catch
+            {
                 ChatGPTCode = "300";
                 clossProcess();
             }
@@ -635,14 +623,13 @@ namespace PDF_Master.Helper
             return repsonseData;
         }
 
-
         /// <summary>
         /// 从接口获取信息,获取message对应value值,WebClient没有设置请求时间参数换一种方案
         /// </summary>
         /// <param name="url"></param>
         /// <param name="namevalue"></param>
         /// <returns></returns>
-        private async static Task<string> PostStringWebClient(string url, System.Collections.Specialized.NameValueCollection namevalue, string key = "message")
+        private static async Task<string> PostStringWebClient(string url, System.Collections.Specialized.NameValueCollection namevalue, string key = "message")
         {
             App.mainWindowViewModel.Value = 5;
             string repsonseData = "";
@@ -706,6 +693,25 @@ namespace PDF_Master.Helper
             }
         }
 
+        /// <summary>
+        /// 初始进度条
+        /// </summary>
+        /// <param name="isprocess">是否需要进度条</param>
+        /// <param name="progressTitle">文案</param>
+        /// <param name="maxValue">进度条最大值</param>
+        /// <param name="ProcessCloseBtnVisible">进度条关闭按钮是否可见</param>
+        public static void SetIntProcess(bool isprocess = true, string progressTitle = "Splitting...", int maxValue = 10, System.Windows.Visibility ProcessCloseBtnVisible = System.Windows.Visibility.Collapsed)
+        {
+            if (isprocess)
+            {
+                App.mainWindowViewModel.ProgressTitle = progressTitle;
+                App.mainWindowViewModel.MaxValue = maxValue;
+                App.mainWindowViewModel.Value = 0;
+                App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
+                App.mainWindowViewModel.ProcessCloseBtnVisible = ProcessCloseBtnVisible;
+            }
+        }
+
         /// <summary>
         /// 关闭进度条
         /// </summary>
@@ -716,6 +722,17 @@ namespace PDF_Master.Helper
             App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
         }
 
+        /// <summary>
+        /// 关闭进度条
+        /// </summary>
+        /// <param name="value">进度条当前值</param>
+        public static void clossProcess(int value = 9)
+        {
+            App.mainWindowViewModel.Value = value;
+            App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
+            App.mainWindowViewModel.ProcessCloseBtnVisible = System.Windows.Visibility.Visible;
+        }
+
         /// <summary>
         /// 判断word文档页面大小,如果接口有问题则交给服务器判断
         /// </summary>
@@ -751,14 +768,14 @@ namespace PDF_Master.Helper
                     }
                 }
                 return true;
-
             }
             catch
             {
                 return true;
             }
         }
-        #endregion
+
+        #endregion AI服务器对接接口
 
         #region 支持翻译的语言
 
@@ -766,6 +783,7 @@ namespace PDF_Master.Helper
         /// 当前语言列表
         /// </summary>
         public static List<string> FromlanguageFamily { set; get; } = new List<string>();
+
         public static List<string> SetFromlanguageOrigin()
         {
             FromlanguageFamily.Clear();
@@ -803,6 +821,7 @@ namespace PDF_Master.Helper
         /// 需要翻译成对应语言列表
         /// </summary>
         public static List<string> TolanguageFamily { set; get; } = new List<string>();
+
         public static List<string> SetTolanguageOrigin()
         {
             TolanguageFamily.Clear();
@@ -845,61 +864,88 @@ namespace PDF_Master.Helper
             {
                 case 0:
                     return "auto";
+
                 case 1:
                     return "en";
+
                 case 2:
                     return "zh";
+
                 case 3:
                     return "cht";
+
                 case 4:
                     return "jp";
+
                 case 5:
                     return "kor";
+
                 case 6:
                     return "fra";
+
                 case 7:
                     return "spa";
+
                 case 8:
                     return "it";
+
                 case 9:
                     return "de";
+
                 case 10:
                     return "pt";
+
                 case 11:
                     return "ru";
+
                 case 12:
                     return "vie";
+
                 case 13:
                     return "th";
+
                 case 14:
                     return "ara";
+
                 case 15:
                     return "el";
+
                 case 16:
                     return "bul";
+
                 case 17:
                     return "fin";
+
                 case 18:
                     return "slo";
+
                 case 19:
                     return "nl";
+
                 case 20:
                     return "cs";
+
                 case 21:
                     return "swe";
+
                 case 22:
                     return "pl";
+
                 case 23:
                     return "dan";
+
                 case 24:
                     return "rom";
+
                 case 25:
                     return "hu";
+
                 default:
                     return "";
             }
         }
-        #endregion
+
+        #endregion 支持翻译的语言
 
         #region 错误码
 
@@ -923,7 +969,6 @@ namespace PDF_Master.Helper
             return code;
         }
 
-        #endregion
+        #endregion 错误码
     }
-}
-
+}

+ 2 - 0
PDF Office/Helper/ServiceHelper.cs

@@ -324,6 +324,7 @@ namespace PDF_Master.Helper
                     {
                         App.mainWindowViewModel.UserVis = Visibility.Collapsed;
                         App.mainWindowViewModel.LoginVis = Visibility.Visible;
+                        App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
                         App.mainWindowViewModel.OphVis = Visibility.Visible;
 
                         if (Settings.Default.UserDate.IsLoginoff == false)
@@ -338,6 +339,7 @@ namespace PDF_Master.Helper
                 {
                     App.mainWindowViewModel.UserVis = Visibility.Collapsed;
                     App.mainWindowViewModel.LoginVis = Visibility.Visible;
+                    App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
                     App.mainWindowViewModel.OphVis = Visibility.Visible;
                 }
             }

+ 12 - 37
PDF Office/ViewModels/BOTA/BookmarkContentViewModel.cs

@@ -256,9 +256,10 @@ namespace PDF_Master.ViewModels.BOTA
                     {
                         TextBox textBox = (TextBox)keyEventArgs.OriginalSource;
                         ListBoxItem listViewItem = CommonHelper.FindVisualParent<ListBoxItem>(textBox);
-                        UpdateTitle(listViewItem, textBox);
                         TextBlock textBlock = CommonHelper.FindVisualChild<TextBlock>(listViewItem);
-                        textBlock.Text = textBox.Text;
+
+                        UpdateTitle(listViewItem, textBox, textBlock);
+
                         textBlock.Visibility = Visibility.Visible;
                     }
                 }
@@ -341,23 +342,26 @@ namespace PDF_Master.ViewModels.BOTA
                 //连续快捷键Ctrl+B 两次添加书签时会报错,暂时没有好的方式判断disconnecteditem 先异常捕获处理一下
                 TextBox textBox = null;
                 ListBoxItem listViewItem = null;
+                TextBlock textBlock = null;
                 if (obj is CompositeCommandParameter parameter)
                 {
                     if (parameter.Parameter is TextBox textBox1)
                     {
                         textBox = textBox1;
                         listViewItem = CommonHelper.FindVisualParent<ListViewItem>(textBox);
+                        textBlock = CommonHelper.FindVisualChild<TextBlock>(listViewItem);
                     }
                 }
                 if (obj is ListBoxItem item)
                 {
                     listViewItem = item;
                     textBox = CommonHelper.FindVisualChild<TextBox>(item);
+                    textBlock = CommonHelper.FindVisualChild<TextBlock>(item);
                 }
 
                 CPDFBookmark bookmark = (CPDFBookmark)listViewItem.DataContext;
 
-                UpdateTitle(listViewItem, textBox);
+                UpdateTitle(listViewItem, textBox, textBlock);
             }
             catch { }
         }
@@ -367,7 +371,7 @@ namespace PDF_Master.ViewModels.BOTA
         /// </summary>
         /// <param name="listViewItem"></param>
         /// <param name="textBox"></param>
-        private void UpdateTitle(ListBoxItem listViewItem, TextBox textBox)
+        private void UpdateTitle(ListBoxItem listViewItem, TextBox textBox, TextBlock textBlock)
         {
             if (listViewItem != null)
             {
@@ -381,6 +385,7 @@ namespace PDF_Master.ViewModels.BOTA
                 {
                     data.Title = textBox.Text.Trim();
                     PDFViewer.UndoManager.CanSave = true;
+                    textBlock.Text = textBox.Text;
                 }
             }
         }
@@ -415,10 +420,11 @@ namespace PDF_Master.ViewModels.BOTA
             string mark = string.Format(info, (index + 1).ToString());
 
             System.Windows.Controls.ListBox listView = obj as System.Windows.Controls.ListBox;
-            listView.SelectedItems.Clear();
+
             IsHasBookmark = IsExistBookmark(listView);// await Task.Run(() => IsExistBookmark(listView));
             if (IsHasBookmark == false)
             {
+                listView.SelectedItems.Clear();
                 CPDFBookmark bookmark = new CPDFBookmark();
                 bookmark.Title = mark;
                 bookmark.Date = DateTime.Now.ToString(@"yyyyMMddHHmmsszzz\'").Replace(':', '\'') + "\n";
@@ -434,38 +440,6 @@ namespace PDF_Master.ViewModels.BOTA
                     Bookmarklist.CollectionChanged += Bookmarklist_CollectionChanged;
                     isAddBookMark = false;
                 }
-                //DialogParameters value = new DialogParameters();
-                //value.Add(ParameterNames.Bookmark, mark);
-                //value.Add(ParameterNames.Title, "创建一个新的书签");
-                //dialogs.ShowDialog(DialogNames.AddBookmarkDialog, value, e =>
-                //{
-                //    if (e.Result == ButtonResult.OK && e.Parameters != null)
-                //    {
-                //        if (e.Parameters.ContainsKey(ParameterNames.Bookmark))
-                //        {
-                //            mark = e.Parameters.GetValue<string>(ParameterNames.Bookmark).ToString();
-                //            CPDFBookmark bookmark = new CPDFBookmark();
-                //            bookmark.Title = mark;
-                //            bookmark.Date = DateTime.Now.ToString(@"yyyyMMddHHmmsszzz\'").Replace(':', '\'') + "\n";
-                //            bookmark.PageIndex = PDFViewer.CurrentIndex;
-                //            AddCPDFBookmark = bookmark;
-                //            if (PDFViewer.Document.AddBookmark(bookmark))
-                //            {
-                //                PDFViewer.UndoManager.CanSave = true;
-
-                //                Bookmarklist.Add(bookmark);
-
-                //                Bookmarklist = new ObservableCollection<CPDFBookmark>(Bookmarklist.OrderBy(item => item.PageIndex));
-                //                Bookmarklist.CollectionChanged += Bookmarklist_CollectionChanged;
-                //            }
-                //        }
-                //        isAddBookMark = false;
-                //    }
-                //    if (e.Result == ButtonResult.Cancel)
-                //    {
-                //        isAddBookMark = true;
-                //    }
-                //});
             }
         }
 
@@ -501,6 +475,7 @@ namespace PDF_Master.ViewModels.BOTA
                             listItems.Add(listViewItem);
                         }
                     }
+
                     if (myListBoxItem.IsSelected == false)
                     {
                         myListBoxItem.IsSelected = true;

+ 2 - 0
PDF Office/ViewModels/Dialog/ServiceDialog/SubscriptionDialogViewModel.cs

@@ -265,6 +265,7 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
                 {
                     App.mainWindowViewModel.UserVis = Visibility.Collapsed;
                     App.mainWindowViewModel.LoginVis = Visibility.Visible;
+                    App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
                     App.mainWindowViewModel.OphVis = Visibility.Visible;
 
                     if (Settings.Default.UserDate.IsLoginoff == false)
@@ -279,6 +280,7 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
             {
                 App.mainWindowViewModel.UserVis = Visibility.Collapsed;
                 App.mainWindowViewModel.LoginVis = Visibility.Visible;
+                App.mainWindowViewModel.RegisterVis = Visibility.Collapsed;
                 App.mainWindowViewModel.OphVis = Visibility.Visible;
             }
 

+ 12 - 0
PDF Office/ViewModels/Dialog/SettingsDialogViewModel.cs

@@ -1008,6 +1008,12 @@ namespace PDF_Master.ViewModels.Dialog
             {
                 case 0:
                     Descript.Reset();
+                    //未付费用户不进行自动保存
+                    if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)
+                    {
+                        AutoSaveEnable = false;
+                        Descript.AutoSave = false;
+                    }
                     break;
                 case 1:
                     View.Reset();
@@ -1029,6 +1035,12 @@ namespace PDF_Master.ViewModels.Dialog
         {
             View.Reset();
             Descript.Reset();
+            //未付费用户不进行自动保存
+            if (!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1)
+            {
+                AutoSaveEnable = false;
+                Descript.AutoSave = false;
+            }
             Annote.Reset();
             InitAnnote();
             InitView();

+ 2 - 0
PDF Office/ViewModels/MainWindowViewModel.cs

@@ -476,6 +476,7 @@ namespace PDF_Master.ViewModels
 
                     UserVis = Visibility.Collapsed;
                     LoginVis = Visibility.Visible;
+                    RegisterVis = Visibility.Collapsed;
                     OphVis = Visibility.Visible;
                     if (Settings.Default.UserDate.IsLoginoff == false)
                     {
@@ -498,6 +499,7 @@ namespace PDF_Master.ViewModels
             {
 
                 LoginVis = Visibility.Visible;
+                RegisterVis = Visibility.Collapsed;
                 OphVis = Visibility.Visible;
                 OpenLogin();
             }

+ 16 - 2
PDF Office/ViewModels/PageEdit/PageEditContentViewModel.cs

@@ -1,4 +1,5 @@
 using ComPDFKit.PDFDocument;
+using ComPDFKit_Conversion.Converter;
 using ComPDFKitViewer.PdfViewer;
 using Dropbox.Api.Team;
 using Microsoft.Win32;
@@ -2549,13 +2550,17 @@ namespace PDF_Master.ViewModels.PageEdit
                     Directory.CreateDirectory(directory);
                 }
                 string filename = "";
+                int index = 0;
                 if (data.Mode == HomePageSplitDialogModel.SplitMode.AveragePages)
                 {
                     int perPages = Convert.ToInt32(data.GetModeCount);
-                    int SplitCount = (int)Math.Ceiling((double)PageCount / (double)perPages);
+                    int splitCount = (int)Math.Ceiling((double)PageCount / (double)perPages);
+                    index = splitCount;
+                    ChatGTPAIHelper.SetIntProcess(true, "Splitting...", index, System.Windows.Visibility.Visible);
+
                     //TODO:命名规则是否要调整
                     selectedfile = data.FileName + " " + "1.pdf";
-                    for (int i = 0; i < SplitCount; i++)
+                    for (int i = 0; i < splitCount; i++)
                     {
                         int startNum = i * perPages + 1;
                         int endNum = Math.Min(PageCount, (i + 1) * perPages);
@@ -2585,6 +2590,10 @@ namespace PDF_Master.ViewModels.PageEdit
                 {
                     int docCount = Convert.ToInt32(data.GetModeCount);
                     int avePages = (int)Math.Floor((double)PageCount / (double)docCount);
+
+                    index = avePages;
+                    ChatGTPAIHelper.SetIntProcess(true, "Splitting...", index, System.Windows.Visibility.Visible);
+
                     int remain = PageCount % docCount;
                     int startNum = 1;
                     //TODO:命名规则是否要调整
@@ -2645,6 +2654,10 @@ namespace PDF_Master.ViewModels.PageEdit
                     //如果是自定义输入页面范围的话,直接解析
                     CommonHelper.GetPagesInRange(ref pageList1, pageRange, PageCount, new char[] { ',' }, new char[] { '-' });
 
+                    index = pageList1.Count;
+                    ChatGTPAIHelper.SetIntProcess(true, "Splitting...", index, System.Windows.Visibility.Visible);
+
+
                     #region //part1
 
                     selectedfile = "";
@@ -2707,6 +2720,7 @@ namespace PDF_Master.ViewModels.PageEdit
 
                 //显示文件夹,并选中一个文件
                 Process.Start("explorer", "/select,\"" + selectedfile + "\"");
+                ChatGTPAIHelper.clossProcess(index);
             }
             catch
             {

+ 8 - 5
PDF Office/ViewModels/Tools/TextEditToolContentViewModel.cs

@@ -26,6 +26,7 @@ using PDF_Master.EventAggregators;
 using Prism.Events;
 using System.Windows.Media.Imaging;
 using PDFReader_WPF.Helper;
+using PDF_Master.Properties;
 
 namespace PDF_Master.ViewModels.Tools
 {
@@ -364,13 +365,14 @@ namespace PDF_Master.ViewModels.Tools
         public void AddContent(object obj)
         {
             if (PDFViewer == null || obj == null || obj as CustomIconToggleBtn == null) return;
-            //添加付费拦截锁,限制编辑操作
-            if (!ServiceHelper.IAPBeforeFunction())
+            //判断是否已退出登录,限制编辑操作
+            if (!App.IsLogin)
             {
                 IsImgEdit = false;
                 IsTextEdit = false;
                 PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.None);
-                PDFViewer.ReloadDocument();
+                PDFViewer.ReloadDocument();              
+                App.mainWindowViewModel.OpenLogin();
                 return;
             }
             var btn = obj as CustomIconToggleBtn;
@@ -662,13 +664,14 @@ namespace PDF_Master.ViewModels.Tools
         //左键激活逻辑
         private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
         {
-            //添加付费拦截锁,限制编辑操作
-            if (!ServiceHelper.IAPBeforeFunction())
+            //判断是否已退出登录,限制编辑操作
+            if (!App.IsLogin)
             {
                 IsImgEdit = false;
                 IsTextEdit = false;
                 PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.None);
                 PDFViewer.ReloadDocument();
+                App.mainWindowViewModel.OpenLogin();
                 return;
             }
             if (e != null && e.Count > 0)

+ 12 - 9
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -3082,7 +3082,9 @@ namespace PDF_Master.ViewModels
 
                     if (App.OpenedFileList.Contains(dlg.FileName))
                     {
-                        //提示文件已经被打开
+                        //文件已经被打开
+                        AlertsMessage alertsMessage = new AlertsMessage();
+                        alertsMessage.ShowDialog("保存失败", "文件被其它程序占用,无法完成操作请用不同的名称或不同文件夹保存该文档", App.ServiceLoader.GetString("Text_yes"), IconType.Tip);
                     }
                     else
                     {
@@ -3155,10 +3157,9 @@ namespace PDF_Master.ViewModels
                             DoAfterSaveAs(dlg.FileName);
                         }
                         else
-                        {
-                            //提示文件被其他软件占用 无法保存
-                            //
-                            //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
+                        {   //提示文件被其他软件占用 无法保存          
+                            AlertsMessage alertsMessage = new AlertsMessage();
+                            alertsMessage.ShowDialog("保存失败", "文件被其它程序占用,无法完成操作请用不同的名称或不同文件夹保存该文档", App.ServiceLoader.GetString("Text_yes"), IconType.Tip);
                         }
                     }
                     return result;
@@ -3206,7 +3207,9 @@ namespace PDF_Master.ViewModels
 
                     if (App.OpenedFileList.Contains(dlg.FileName))
                     {
-                        //提示文件已经被打开
+                        //文件已经被占用
+                        AlertsMessage alertsMessage = new AlertsMessage();
+                        alertsMessage.ShowDialog("保存失败", "文件被其它程序占用,无法完成操作请用不同的名称或不同文件夹保存该文档", App.ServiceLoader.GetString("Text_yes"), IconType.Tip);
                     }
                     else
                     {
@@ -3284,9 +3287,9 @@ namespace PDF_Master.ViewModels
                         }
                         else
                         {
-                            //提示文件被其他软件占用 无法保存
-                            //
-                            //Ex.Show(App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), "", Winform.MessageBoxButtons.OKCancel, new string[] { App.MainPageLoader.GetString("Main_SaveAs"), App.MainPageLoader.GetString("Main_Cancel") });
+                            //文件已经被占用
+                            AlertsMessage alertsMessage = new AlertsMessage();
+                            alertsMessage.ShowDialog("保存失败", "文件被其它程序占用,无法完成操作请用不同的名称或不同文件夹保存该文档", App.ServiceLoader.GetString("Text_yes"), IconType.Tip);
                         }
                     }
                     return result;

+ 8 - 28
PDF Office/Views/BOTA/BookmarkContent.xaml.cs

@@ -101,6 +101,7 @@ namespace PDF_Master.Views.BOTA
                 }
                 else if (e.ClickCount == 1)
                 {
+                    isRename = false;
                     CleanHistotyListBoxItem(listBoxItem, textBlock);
 
                     viewModel.ListViewItemMouseDownCommand.Execute(sender);
@@ -205,7 +206,6 @@ namespace PDF_Master.Views.BOTA
                 BookMarkListView.ItemContainerGenerator.StatusChanged -= ItemContainerGenerator_StatusChanged;
                 viewModel.LostFocusCommand.Execute(listItem);
 
-                //CleanSelectAll(null);
                 TextBlock textBlock = CommonHelper.FindVisualChild<TextBlock>(listItem);
                 TextBox text = CommonHelper.FindVisualChild<TextBox>(listItem);
 
@@ -216,8 +216,12 @@ namespace PDF_Master.Views.BOTA
                         listItem.IsSelected = false;
                         if (isRename)
                         {
-                            listItem.IsSelected = true;
                             isRename = false;
+                            listItem.IsSelected = true;
+                        }
+                        if (listItem.IsSelected == false)
+                        {
+                            textBlock.Visibility = Visibility.Visible;
                         }
                     }
                     else
@@ -228,41 +232,16 @@ namespace PDF_Master.Views.BOTA
                             isAdd = false;
                         }
                     }
-                    //if (text.IsSelectionActive == true)
-                    //{
-                    //    textBlock.Visibility = Visibility.Visible;
-                    //}
                 }
                 else
                 {
                     if (isCleanSelectAll == false)
                     {
                         //点击空白
-                        textBlock.Text = text.Text;
+                        //textBlock.Text = text.Text;
                         listItem.IsSelected = true;
                     }
                 }
-
-                //if (histotyListBoxItem != null)
-                //{
-                //    histotyListBoxItem.IsSelected = false;
-                //    TextBlock textBlock1 = CommonHelper.FindVisualChild<TextBlock>(histotyListBoxItem);
-                //    textBlock1.Visibility = Visibility.Visible;
-                //    textBlock1.Focusable = true;
-                //}
-
-                //TextBlock textBlock = CommonHelper.FindVisualChild<TextBlock>(listItem);
-                //TextBox text = CommonHelper.FindVisualChild<TextBox>(listItem);
-                //if (textBlock.Visibility == Visibility.Collapsed)
-                //{
-                //    listItem.IsSelected = false;
-                //    //textBlock.Visibility = Visibility.Visible;
-                //}
-                //else
-                //{
-                //    listItem.IsSelected = true;
-                //    //textBlock.Visibility = Visibility.Collapsed;
-                //}
             }
         }
 
@@ -373,6 +352,7 @@ namespace PDF_Master.Views.BOTA
         public void BtnAddBookmark_Click(object sender, RoutedEventArgs e)
         {
             isAdd = true;
+            isRename = false;
             viewModel.AddBookmarkCommand.Execute(BookMarkListView);
             if (viewModel.IsHasBookmark == false)
             {

+ 120 - 29
PDF Office/Views/Dialog/ToolsDialogs/MergeDialog.xaml.cs

@@ -1,4 +1,5 @@
-using PDF_Master.CustomControl;
+using ImTools;
+using PDF_Master.CustomControl;
 using PDF_Master.Helper;
 using PDF_Master.Model.Dialog.ToolsDialogs;
 using PDF_Master.ViewModels.Dialog.ToolsDialogs;
@@ -6,6 +7,7 @@ using System;
 using System.Collections.Generic;
 using System.Data;
 using System.Diagnostics;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Text.RegularExpressions;
@@ -229,20 +231,46 @@ namespace PDF_Master.Views.Dialog.ToolsDialogs
                 return;
             }
             foreach (string f in file)
-            {
-                System.IO.FileInfo info = new System.IO.FileInfo(f);
-                //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
-                if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
-                {
-                    DragDropHelper.DragEnter(this, e);
-                    IsFile = true;
-                }
-                //图片格式
-                else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(f).ToLower()) && info.Length > 0)
-                {
-
-                    DragDropHelper.DragEnter(this, e);
-                    IsFile = true;
+            {
+                bool isFolder = Directory.Exists(f);
+                if (isFolder)
+                {
+                    foreach (string fi in Directory.GetFiles(f)) // 这里使用 "*.jpg" 作为搜索模式,可以根据需要修改
+                    {
+                        // 处理图片文件,这里只是简单地输出文件路径
+
+                        System.IO.FileInfo info = new System.IO.FileInfo(fi);
+                        //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
+                        if (System.IO.Path.GetExtension(fi).ToLower() == ".pdf" && info.Length > 0)
+                        {
+                            DragDropHelper.DragEnter(this, e);
+                            IsFile = true;
+                        }
+                        //图片格式
+                        else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(fi).ToLower()) && info.Length > 0)
+                        {
+
+                            DragDropHelper.DragEnter(this, e);
+                            IsFile = true;
+                        }
+                    }
+                }
+                else
+                {
+                    System.IO.FileInfo info = new System.IO.FileInfo(f);
+                    //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
+                    if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
+                    {
+                        DragDropHelper.DragEnter(this, e);
+                        IsFile = true;
+                    }
+                    //图片格式
+                    else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(f).ToLower()) && info.Length > 0)
+                    {
+
+                        DragDropHelper.DragEnter(this, e);
+                        IsFile = true;
+                    }
                 }
             }
         }
@@ -253,7 +281,18 @@ namespace PDF_Master.Views.Dialog.ToolsDialogs
             {
                 DragDropHelper.Drop(this, e);
                 string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
-                (DataContext as MergeDialogViewModel).AddFiles(file);
+                bool isFolder = Directory.Exists(file[0]);
+                if (isFolder)
+                {
+                    string file1 = file[0];
+                    List<string> names = new List<string>();
+                    TraverseFiles(file1, names);
+                    (DataContext as MergeDialogViewModel).AddFiles(names.ToArray());
+                }
+                else {
+                    (DataContext as MergeDialogViewModel).AddFiles(file);
+                }
+                
             }
         }
 
@@ -267,20 +306,47 @@ namespace PDF_Master.Views.Dialog.ToolsDialogs
             }
             foreach (string f in file)
             {
-                System.IO.FileInfo info = new System.IO.FileInfo(f);
-                //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
-                if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
-                {
-                    DragDropHelper.DragEnter(this, e);
-                    IsFile = true;
-                }
-                //图片格式
-                else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(f).ToLower()) && info.Length > 0)
-                {
-
-                    DragDropHelper.DragEnter(this, e);
-                    IsFile = true;
+                bool isFolder = Directory.Exists(f);
+                if (isFolder)
+                {
+                    foreach (string fi in Directory.GetFiles(f)) // 这里使用 "*.jpg" 作为搜索模式,可以根据需要修改
+                    {
+                        // 处理图片文件,这里只是简单地输出文件路径
+
+                        System.IO.FileInfo info = new System.IO.FileInfo(fi);
+                        //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
+                        if (System.IO.Path.GetExtension(fi).ToLower() == ".pdf" && info.Length > 0)
+                        {
+                            DragDropHelper.DragEnter(this, e);
+                            IsFile = true;
+                        }
+                        //图片格式
+                        else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(fi).ToLower()) && info.Length > 0)
+                        {
+
+                            DragDropHelper.DragEnter(this, e);
+                            IsFile = true;
+                        }
+                    }
+                }
+                else
+                {
+                    System.IO.FileInfo info = new System.IO.FileInfo(f);
+                    //只要拖拽进来的文件里包含有pdf格式文件,就允许拖入
+                    if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
+                    {
+                        DragDropHelper.DragEnter(this, e);
+                        IsFile = true;
+                    }
+                    //图片格式
+                    else if (Properties.Resources.imageex.Contains(System.IO.Path.GetExtension(f).ToLower()) && info.Length > 0)
+                    {
+
+                        DragDropHelper.DragEnter(this, e);
+                        IsFile = true;
+                    }
                 }
+                
             }
         }
 
@@ -345,5 +411,30 @@ namespace PDF_Master.Views.Dialog.ToolsDialogs
             CmAddFile.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
             CmAddFile.IsOpen = true;
         }
+        /// <summary>
+        /// 文件夹遍历
+        /// </summary>
+        /// <param name="folderPath"></param>
+        /// <param name="names"></param>
+        public void TraverseFiles(string folderPath, List<string> names)
+        {
+            // 获取当前文件夹下的所有文件
+            string[] files = Directory.GetFiles(folderPath);
+
+            foreach (string file in files)
+            {
+                // 处理文件
+                names.Add(file);
+            }
+
+            // 获取当前文件夹下的所有子文件夹
+            string[] subFolders = Directory.GetDirectories(folderPath);
+
+            foreach (string subFolder in subFolders)
+            {
+                // 递归遍历子文件夹中的文件
+                TraverseFiles(subFolder, names);
+            }
+        }
     }
 }