Browse Source

compdfkit(win) - 修复文档编辑与测量之外的保存按钮状态转换

liuaoran 8 tháng trước cách đây
mục cha
commit
e1581407ca

+ 1 - 1
Demo/Examples/Compdfkit_Tools/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -454,7 +454,7 @@ namespace Compdfkit_Tools.PDFControl
         private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             OnPropertyChanged(e.PropertyName);
-            if (e.PropertyName == "CanSave")
+            if (e.PropertyName == "CanUndo" || e.PropertyName == "CanRedo")
             {
                 OnCanSaveChanged?.Invoke(this, CanSave);
             }

+ 15 - 29
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -44,7 +44,7 @@ namespace PDFViewer
         public event EventHandler<string> AfterSaveAsFileEvent;
         public event PropertyChangedEventHandler PropertyChanged;
 
-        private bool _canSave = true;
+        private bool _canSave = false;
         /// <summary>
         /// Whether the save operation can be performed.
         /// </summary>
@@ -123,7 +123,7 @@ namespace PDFViewer
         public MainPage()
         {
             InitializeComponent();
-            this.DataContext = this; 
+            this.DataContext = this;
         }
         #endregion
 
@@ -162,13 +162,6 @@ namespace PDFViewer
                 SizeChanged -= MainPage_SizeChanged;
                 SizeChanged += MainPage_SizeChanged;
 
-                //viewControl.PDFView.Load();
-                //viewControl.PDFView.SetShowLink(true);
-
-                //viewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
-                //viewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
-
-                //viewControl.PDFView.SetFormFieldHighlight(true);
                 PasswordUI.Closed -= PasswordUI_Closed;
                 PasswordUI.Canceled -= PasswordUI_Canceled;
                 PasswordUI.Confirmed -= PasswordUI_Confirmed;
@@ -176,7 +169,6 @@ namespace PDFViewer
                 PasswordUI.Canceled += PasswordUI_Canceled;
                 PasswordUI.Confirmed += PasswordUI_Confirmed;
 
-                //viewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
                 CPDFSaclingControl.InitWithPDFViewer(viewControl);
                 ModeComboBox.SelectedIndex = 0;
 
@@ -500,7 +492,6 @@ namespace PDFViewer
                 {
                     PDFGrid.Child = regularViewerControl;
                     viewControl.SetToolType(ComPDFKit.Tool.CPDFToolManager.ToolType.Viewer);
-                    //viewControl.PDFView.SetMouseMode(MouseModes.Viewer);
                     regularViewerControl.OnCanSaveChanged -= ControlOnCanSaveChanged;
                     regularViewerControl.OnCanSaveChanged += ControlOnCanSaveChanged;
                     regularViewerControl.SetBOTAContainer(botaBarControl);
@@ -513,8 +504,6 @@ namespace PDFViewer
                 PDFGrid.Child = annotationControl;
 
                 viewControl.SetToolType(ComPDFKit.Tool.CPDFToolManager.ToolType.CreateAnnot);
-                //viewControl.PDFView.SetMouseMode(MouseModes.AnnotCreate);
-                //annotationControl.PDFViewControl.PDFView.SetToolParam(new AnnotHandlerEventArgs());
                 annotationControl.PDFViewControl = viewControl;
                 annotationControl.InitWithPDFViewer(viewControl);
                 if (annotationControl.PDFViewControl != null)
@@ -533,7 +522,7 @@ namespace PDFViewer
                 formControl.SetToolBarContainerVisibility(Visibility.Visible);
                 formControl.PdfViewControl = viewControl;
                 formControl.InitWithPDFViewer(viewControl);
-                if (formControl.PdfViewControl != null )
+                if (formControl.PdfViewControl != null)
                 {
                     PDFGrid.Child = formControl;
                     viewControl.SetToolType(ComPDFKit.Tool.CPDFToolManager.ToolType.WidgetEdit);
@@ -551,12 +540,8 @@ namespace PDFViewer
                 contentEditControl.PdfViewControl = viewControl;
                 contentEditControl.InitWithPDFViewer(viewControl);
                 displaySettingsControl.SetVisibilityWhenContentEdit(Visibility.Collapsed);
-                if (contentEditControl.pdfContentEditControl != null && contentEditControl.PdfViewControl!= null)
+                if (contentEditControl.pdfContentEditControl != null && contentEditControl.PdfViewControl != null)
                 {
-                    //viewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText | CPDFEditType.EditImage);
-                    //viewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
-                    //viewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
-                    //viewControl.PDFView?.ReloadDocument();
 
                     PDFGrid.Child = contentEditControl;
                     viewControl.SetToolType(ComPDFKit.Tool.CPDFToolManager.ToolType.ContentEdit);
@@ -666,7 +651,7 @@ namespace PDFViewer
 
             CPDFTitleBarControl.SaveFileEvent -= CPDFTitleBarControl_SaveFileEvent;
             CPDFTitleBarControl.SaveFileEvent += CPDFTitleBarControl_SaveFileEvent;
-            
+
             CPDFTitleBarControl.FlattenEvent -= CPDFTitleBarControl_FlattenEvent;
             CPDFTitleBarControl.FlattenEvent += CPDFTitleBarControl_FlattenEvent;
         }
@@ -681,12 +666,12 @@ namespace PDFViewer
                     if (CanSave)
                     {
                         SaveFile();
-                         
+
                         viewControl.PDFViewTool.IsDocumentModified = false;
                     }
                     CPDFDocument document = CPDFDocument.InitWithFilePath(viewControl.GetCPDFViewer().GetDocument().FilePath);
                     if (document?.WriteFlattenToFilePath(savePath) == true)
-                    {  
+                    {
                         System.Diagnostics.Process.Start("Explorer.exe", "/select," + savePath);
                     }
                     document?.Release();
@@ -746,6 +731,7 @@ namespace PDFViewer
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
             SaveFile();
+            CanSave = false;
         }
 
         private void OpenFile(string filePath = "")
@@ -842,9 +828,9 @@ namespace PDFViewer
         {
             if (viewControl != null && viewControl.PDFViewTool != null)
             {
-                CPDFViewer pdfviewer=viewControl.PDFViewTool.GetCPDFViewer();
-                CPDFDocument pdfDoc=pdfviewer?.GetDocument();
-                if(pdfDoc==null)
+                CPDFViewer pdfviewer = viewControl.PDFViewTool.GetCPDFViewer();
+                CPDFDocument pdfDoc = pdfviewer?.GetDocument();
+                if (pdfDoc == null)
                 {
                     return;
                 }
@@ -986,15 +972,15 @@ namespace PDFViewer
                     double newZoom = CheckZoomLevel(pdfViewer.GetZoom() + 0.01, true);
                     pdfViewer.SetZoom(newZoom);
                 }
-            } 
+            }
         }
 
         private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
         {
-            if(viewControl!=null && viewControl.PDFViewTool!=null)
+            if (viewControl != null && viewControl.PDFViewTool != null)
             {
-                CPDFViewer pdfViewer= viewControl.PDFViewTool.GetCPDFViewer();
-                if(pdfViewer!=null)
+                CPDFViewer pdfViewer = viewControl.PDFViewTool.GetCPDFViewer();
+                if (pdfViewer != null)
                 {
                     double newZoom = CheckZoomLevel(pdfViewer.GetZoom() - 0.01, false);
                     pdfViewer.SetZoom(newZoom);