Browse Source

保存- 压缩、转档、合并前自动保存

ZhouJieSheng 1 year ago
parent
commit
9459757c5f

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

@@ -206,6 +206,20 @@ namespace PDF_Master.ViewModels
             }
         }
 
+        private Visibility processCloseBtnVisible = Visibility.Visible;
+        /// <summary>
+        /// 进度条控件的关闭按钮是否可见
+        /// </summary>
+        public Visibility ProcessCloseBtnVisible
+        {
+            get { return processCloseBtnVisible; }
+            set
+            {
+                SetProperty(ref processCloseBtnVisible, value);
+            }
+        }
+
+
         /// <summary>
         /// 进度条关闭的事件
         /// </summary>
@@ -466,6 +480,47 @@ namespace PDF_Master.ViewModels
             return true;
         }
 
+        /// <summary>
+        /// 设置value值小于MaxValue值时 自动显示
+        /// Value值 大于等于MaxValue值时,自动隐藏
+        /// </summary>
+        public async void SetProcessValue(string title,double value,double maxvalue,bool showClose = true)
+        {
+            ProgressTitle = title;
+            if(value<0)
+            {
+                //异常处理
+                this.Value = 0;
+            }
+
+            if (maxvalue < 0)
+            {
+                //异常处理
+                this.MaxValue = 0;
+            }
+
+            if(value<maxvalue)
+            {
+                this.Value = value;
+                this.MaxValue = maxvalue;
+                if(IsProcessVisible!=Visibility.Visible)
+                {
+                    IsProcessVisible = Visibility.Visible;
+                }
+            }
+            else
+            {
+                //进度完成后自动隐藏
+                this.Value = value;
+                this.MaxValue = maxvalue;
+                //为了能看到进度条实际到100的效果
+                await Task.Delay(150);
+                IsProcessVisible = Visibility.Collapsed;
+            }
+
+            processCloseBtnVisible = showClose ? Visibility.Visible : Visibility.Collapsed;
+        }
+
         public void CloseTabItem(object item)
         {
             //获取x号所在的maincontentviewmodel对象

+ 4 - 1
PDF Office/ViewModels/Tools/ConverterBarContentViewModel.cs

@@ -64,7 +64,7 @@ namespace PDF_Master.ViewModels.Tools
             ToConverterCommand = new DelegateCommand<object>(toconverter);
         }
 
-        private void toconverter(object sender)
+        private async void toconverter(object sender)
         {//判断本地有没有token,没有显示登录,有再判断登录状态
             if (Settings.Default.AppProperties.LoginToken != "")
             {
@@ -91,6 +91,9 @@ namespace PDF_Master.ViewModels.Tools
                 return;
             }
 
+            //转档前 如果需要 自动保存
+            await viewContentViewModel.SaveBeforeOption();
+
             var args = sender as Button;
             if (args != null)
             {

+ 10 - 8
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -99,7 +99,7 @@ namespace PDF_Master.ViewModels.Tools
         {
             T_SetPassWord = App.MainPageLoader.GetString("Security_SetPassword");
             T_RemovePassword = App.MainPageLoader.GetString("Security_RemovePassword");
-            T_Compress= App.MainPageLoader.GetString("ToolsBar_Compress");
+            T_Compress = App.MainPageLoader.GetString("ToolsBar_Compress");
             T_Security = App.MainPageLoader.GetString("ToolsBar_Security");
             T_Merge = App.MainPageLoader.GetString("ToolsBar_Merge");
             T_Crop = App.MainPageLoader.GetString("ToolsBar_Crop");
@@ -188,8 +188,9 @@ namespace PDF_Master.ViewModels.Tools
             }
         }
 
-        private void OpenCompressDialog()
+        private async void OpenCompressDialog()
         {
+            await  viewContentViewModel.SaveBeforeOption();
             DialogParameters value = new DialogParameters();
             value.Add(ParameterNames.PDFViewer, PDFViewer);
             dialogs.ShowDialog(DialogNames.CompressDialog, value, e =>
@@ -239,8 +240,9 @@ namespace PDF_Master.ViewModels.Tools
         //        document.Release();
         //    }
         //}
-        private void MergeDialog()
+        private async void MergeDialog()
         {
+            await viewContentViewModel.SaveBeforeOption();
             DialogParameters value = new DialogParameters();
             value.Add(ParameterNames.PDFViewer, PDFViewer);
             value.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
@@ -249,10 +251,10 @@ namespace PDF_Master.ViewModels.Tools
         }
 
         private void OpenSetPasswordDialog()
-        { 
+        {
             VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(PDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
             if (result.IsDiscryptied)
-            { 
+            {
                 if (result.Password != null)
                 {
                     PDFViewer.Document.CheckOwnerPassword(result.Password);
@@ -274,7 +276,7 @@ namespace PDF_Master.ViewModels.Tools
                         this.eventAggregator.GetEvent<ShowTipEvent>().Publish(new ShowTipEventArgs() { enumTipKind = EnumTipKind.StatusSetPasswordSuccessfully, Unicode = unicode });
                     }
                 });
-            } 
+            }
         }
 
         private void OpenCancelPasswordDialog()
@@ -334,7 +336,7 @@ namespace PDF_Master.ViewModels.Tools
 
         private async Task WaitCropCurrentPageWM()
         {
-            
+
             //判断本地有没有token,没有显示登录,有再判断登录状态
             if (Settings.Default.AppProperties.LoginToken != "")
             {
@@ -375,7 +377,7 @@ namespace PDF_Master.ViewModels.Tools
 
         private async Task WaitCropAllPagesWM()
         {
-           
+
             //判断本地有没有token,没有显示登录,有再判断登录状态
             if (Settings.Default.AppProperties.LoginToken != "")
             {

+ 19 - 0
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -2593,6 +2593,25 @@ namespace PDF_Master.ViewModels
                 return false;
         }
 
+        /// <summary>
+        /// 转档、压缩、合并前自动保存
+        /// </summary>
+        public async Task<bool> SaveBeforeOption()
+        {
+            if (PDFViewer.UndoManager.CanSave)
+            {
+                string title = "Saving File";
+                App.mainWindowViewModel.SetProcessValue(title, 80, 100, false);
+                //让保存的效果更明显
+                await Task.Delay(200);
+                //合并前自动保存一次
+                saveFile();
+                App.mainWindowViewModel.SetProcessValue(title, 100, 100, false);
+            }
+            //方便其他调用的地方可以异步 await调用,增加显示保存过程的效果
+            return true;
+        }
+
         /// <summary>
         /// 另存为Flatten
         /// </summary>

+ 2 - 1
PDF Office/Views/MainWindow.xaml

@@ -446,7 +446,8 @@
                         VerticalAlignment="Top"
                         Background="{StaticResource color.sys.layout.dark.bg}"
                         BorderThickness="0"
-                        Command="{Binding CloseOCRCommand}">
+                        Command="{Binding CloseOCRCommand}"
+                        Visibility="{Binding ProcessCloseBtnVisible}">
                         <Path Data="M6.00006 7.06072L9.46973 10.5304L10.5304 9.46973L7.06072 6.00006L10.5304 2.53039L9.46973 1.46973L6.00006 4.9394L2.53039 1.46973L1.46973 2.53039L4.9394 6.00006L1.46973 9.46973L2.53039 10.5304L6.00006 7.06072Z" Fill="#CED0D4" />
                     </Button>
                     <ProgressBar