Browse Source

compdfkit(win) - 数字签名主窗口注释补充和代码调整

weixiangjie 1 year ago
parent
commit
ce208e079e
1 changed files with 208 additions and 65 deletions
  1. 208 65
      Demo/Examples/DigitalSignature/MainWindow.xaml.cs

+ 208 - 65
Demo/Examples/DigitalSignature/MainWindow.xaml.cs

@@ -40,18 +40,20 @@ namespace DigitalSignature
         private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation | BOTATools.Signature);
         private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
         private SignatureStatusBarControl signatureStatusBarControl = new SignatureStatusBarControl();
-
         private PanelState panelState = PanelState.GetInstance();
+        
         public event EventHandler<bool> OnCanSaveChanged;
-
-
         public event PropertyChangedEventHandler PropertyChanged;
         protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
         }
+        
+        #region Properties
 
-
+        /// <summary>
+        /// Whether the save operation can be performed.
+        /// </summary>
         private bool _canSave = false;
         public bool CanSave
         {
@@ -62,7 +64,10 @@ namespace DigitalSignature
                 OnPropertyChanged();
             }
         }
-
+        
+        /// <summary>
+        /// Whether the left panel is expanded.
+        /// </summary>
         public bool LeftToolPanelButtonIsChecked
         {
             get => panelState.IsLeftPanelExpand;
@@ -73,6 +78,9 @@ namespace DigitalSignature
             }
         }
 
+        /// <summary>
+        /// Whether the right panel is expanded.
+        /// </summary>
         public bool RightToolPanelButtonIsChecked
         {
             get
@@ -86,6 +94,9 @@ namespace DigitalSignature
             }
         }
 
+        /// <summary>
+        /// Whether the view setting panel is expanded.
+        /// </summary>
         public bool ViewSettingBtnIsChecked
         {
             get
@@ -99,6 +110,8 @@ namespace DigitalSignature
             }
         }
 
+        #endregion
+
         public MainWindow()
         {
             InitializeComponent();
@@ -107,30 +120,13 @@ namespace DigitalSignature
             digitalSignatureControl.AfterFillSignature += DigitalSignatureControl_AfterFillSignature;
             Closing += MainWindow_Closing;
         }
-        
-        private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
-        {
-            if(CanSave)
-            {
-                MessageBoxResult result = MessageBox.Show("Do you want to save the changes to the document?", "Save", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
-                if (result == MessageBoxResult.Yes)
-                {
-                    SaveFile();
-                }
-                else if (result == MessageBoxResult.Cancel)
-                {
-                    e.Cancel = true;
-                }
-            }
-        }
-
-        private void DigitalSignatureControl_AfterFillSignature(object sender, string e)
-        {
-            OpenFile(e);
-        }
 
         #region Load Document
 
+        /// <summary>
+        /// Open a PDF file.
+        /// </summary>
+        /// <param name="filePath">The path of the PDF file.</param>
         private void OpenFile(string filePath = "")
         {
             if (string.IsNullOrEmpty(filePath))
@@ -173,6 +169,9 @@ namespace DigitalSignature
             }
         }
 
+        /// <summary>
+        /// Load the default PDF file when the application is started.
+        /// </summary>
         private void LoadDefaultDocument()
         {
             string defaultFilePath = "PDF32000_2008.pdf";
@@ -180,6 +179,9 @@ namespace DigitalSignature
             LoadDocument();
         }
 
+        /// <summary>
+        /// Load the custom controls for the PDF viewer.
+        /// </summary>
         private void LoadCustomControl()
         {
             regularViewerControl.PdfViewControl = pdfViewer;
@@ -202,9 +204,11 @@ namespace DigitalSignature
             digitalSignatureControl.LoadUndoManagerEvent(pdfViewer.PDFView);
             signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
             regularViewerControl.SetSignatureStatusBarControl(signatureStatusBarControl);
-            
         }
 
+        /// <summary>
+        /// Load current PDF file and initialize event handlers.
+        /// </summary>
         private void LoadDocument()
         {
             if (pdfViewer.PDFView.Document == null)
@@ -245,44 +249,12 @@ namespace DigitalSignature
             panelState.PropertyChanged -= PanelState_PropertyChanged;
             panelState.PropertyChanged += PanelState_PropertyChanged;
         }
-        
-        private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
-        {
-            if (e.PropertyName == "RightPanel")
-            {
-                OnPropertyChanged(nameof(RightToolPanelButtonIsChecked));
-                OnPropertyChanged(nameof(ViewSettingBtnIsChecked));
-            }
-        }
-
-        public void BotaControlOnDeleteSignatureEvent(object sender, EventArgs e)
-        {
-            pdfViewer.PDFView.UndoManager.CanSave = true;
-            DigitalSignatureControl_OnSignatureStatusChanged(sender, e);
-            //this.CanSave = true;
-        }
-        
-        private void DigitalSignatureControl_OnSignatureStatusChanged(object sender, EventArgs e)
-        {
-            SignatureHelper.InitEffectiveSignatureList(pdfViewer.PDFView.Document);
-            SignatureHelper.VerifySignatureList(pdfViewer.PDFView.Document);
-            signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
-            botaBarControl.LoadSignatureList();
-        }
-
-        private void DigitalSignatureControl_OnCanSaveChanged(object sender, bool e)
-        {
-            this.CanSave = e;
-        }
-
-        private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
-        {
-            if (e.Key == "Zoom")
-            {
-                CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
-            }
-        }
 
+        /// <summary>
+        /// Event handler for confirming the password. Open the PDF file if the password is correct.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void PasswordUI_Confirmed(object sender, string e)
         {
             if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
@@ -304,12 +276,22 @@ namespace DigitalSignature
             }
         }
 
+        /// <summary>
+        /// Event handler for canceling password input.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void PasswordUI_Canceled(object sender, EventArgs e)
         {
             PopupBorder.Visibility = Visibility.Collapsed;
             PasswordUI.Visibility = Visibility.Collapsed;
         }
 
+        /// <summary>
+        /// Event handler for closing the password input dialog.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void PasswordUI_Closed(object sender, EventArgs e)
         {
             PopupBorder.Visibility = Visibility.Collapsed;
@@ -317,22 +299,116 @@ namespace DigitalSignature
         }
         #endregion
 
+        #region Commands
+
+        /// <summary>
+        /// Command for the OpenFileBtn click event. Opens a PDF file.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void OpenFile_Click(object sender, RoutedEventArgs e)
         {
             OpenFile();
         }
 
+        /// <summary>
+        /// Command for opening a PDF file saved with a signature.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void DigitalSignatureControl_AfterFillSignature(object sender, string e)
+        {
+            OpenFile(e);
+        }
+        
+        /// <summary>
+        /// When the RightPanel state is changed, decide whether to display the ViewSettingPanel or RightToolPanel.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            if (e.PropertyName == "RightPanel")
+            {
+                OnPropertyChanged(nameof(RightToolPanelButtonIsChecked));
+                OnPropertyChanged(nameof(ViewSettingBtnIsChecked));
+            }
+        }
+
+        /// <summary>
+        /// Event handler for deleting a signature from the BOTA. Set the CanSave property to true and update the signature status.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void BotaControlOnDeleteSignatureEvent(object sender, EventArgs e)
+        {
+            pdfViewer.PDFView.UndoManager.CanSave = true;
+            DigitalSignatureControl_OnSignatureStatusChanged(sender, e);
+            //this.CanSave = true;
+        }
+        
+        /// <summary>
+        /// Event handler for updating a signature. Update the signature status.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void DigitalSignatureControl_OnSignatureStatusChanged(object sender, EventArgs e)
+        {
+            SignatureHelper.InitEffectiveSignatureList(pdfViewer.PDFView.Document);
+            SignatureHelper.VerifySignatureList(pdfViewer.PDFView.Document);
+            signatureStatusBarControl.SetStatus(SignatureHelper.SignatureList);
+            botaBarControl.LoadSignatureList();
+        }
+
+        /// <summary>
+        /// Event handler for updating the CanSave property.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void DigitalSignatureControl_OnCanSaveChanged(object sender, bool e)
+        {
+            this.CanSave = e;
+        }
+
+        /// <summary>
+        /// Event handler for the ZoomInBtn click event. Zoom in the PDF file.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
+        {
+            if (e.Key == "Zoom")
+            {
+                CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
+            }
+        }
+        
+        /// <summary>
+        /// Event handler for the SaveAsFileBtn click event. Save the PDF file and set the CanSave property to false.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
             SaveFile();
             pdfViewer.PDFView.UndoManager.CanSave = false;
         }
 
+        /// <summary>
+        /// Event handler for the LeftToolPanelButton click event. Expand or collapse the left panel.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
         {
             panelState.IsLeftPanelExpand = (sender as ToggleButton).IsChecked == true;
         }
 
+        /// <summary>
+        /// Event handler for the ComboBox selection changed event. Switch between the Viewer and Digital Signature modes.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             var item = (sender as ComboBox).SelectedItem as ComboBoxItem;
@@ -384,18 +460,33 @@ namespace DigitalSignature
             currentMode = item.Content as string;
         }
         
+        /// <summary>
+        /// Event handler for ViewSignatureBtn click event. Expand the bota control and select the Signature tool.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ViewAllSignatures(object sender, EventArgs e)
         {
             LeftToolPanelButton.IsChecked = true;
             botaBarControl.SelectBotaTool(BOTATools.Signature);
         }
 
+        /// <summary>
+        /// Event handler for the SearchBtn click event. Expand the bota control and select the Search tool.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
         {
             LeftToolPanelButton.IsChecked = true;
             botaBarControl.SelectBotaTool(BOTATools.Search);
         }
 
+        /// <summary>
+        /// Event handler for the RightPanelButton click event. Expand or collapse the right panel.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void RightPanelButton_Click(object sender, RoutedEventArgs e)
         {
             panelState.RightPanel =
@@ -403,6 +494,11 @@ namespace DigitalSignature
                 PanelState.RightPanelState.PropertyPanel : PanelState.RightPanelState.None;
         }
 
+        /// <summary>
+        /// Event handler for the ViewSettingBtn click event. Expand or collapse the view setting panel.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
         {
             panelState.RightPanel =
@@ -410,6 +506,9 @@ namespace DigitalSignature
                     PanelState.RightPanelState.ViewSettings : PanelState.RightPanelState.None;
         }
         
+        /// <summary>
+        /// Close all the expanded panels.
+        /// </summary>
         private void ClearPanelState()
         {
             LeftToolPanelButtonIsChecked = false;
@@ -417,6 +516,11 @@ namespace DigitalSignature
             RightToolPanelButtonIsChecked = false;
         }
 
+        /// <summary>
+        /// Event handler for the PageInfoBtn click event. Expand the file info window.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
         {
             PasswordUI.Visibility = Visibility.Collapsed;
@@ -426,21 +530,60 @@ namespace DigitalSignature
 
         }
 
+        /// <summary>
+        /// Event handler for the CloseFileInfoBtn click event. Collapse the file info window.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
         {
             PopupBorder.Visibility = Visibility.Collapsed;
         }
 
+        /// <summary>
+        /// Event handler for the control loaded event. Load the default PDF file.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void Window_Loaded(object sender, RoutedEventArgs e)
         {
             pdfViewer = new PDFViewControl();
             LoadDefaultDocument();
         }
-
+        
+        /// <summary>
+        /// Event handler for the control unloaded event.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void Window_Unloaded(object sender, RoutedEventArgs e)
         {
 
         }
+        
+        /// <summary>
+        /// Event handler for closing the window. Prompt to save the changes.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
+        {
+            if(CanSave)
+            {
+                MessageBoxResult result = MessageBox.Show("Do you want to save the changes to the document?", 
+                    "Save", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
+                if (result == MessageBoxResult.Yes)
+                {
+                    SaveFile();
+                }
+                else if (result == MessageBoxResult.Cancel)
+                {
+                    e.Cancel = true;
+                }
+            }
+        }
+        
+        #endregion
 
         #region Save file
         /// <summary>