Explorar o código

compdfkit(win) - MainWindow 代码调整

weixiangjie hai 1 ano
pai
achega
4c1a24e8f2

+ 1 - 1
Demo/Examples/ContentEditor/MainWindow.xaml

@@ -65,7 +65,7 @@
                         </Button.ToolTip>
                     </Button>
 
-                    <Button BorderThickness="0" VerticalContentAlignment="Center" Margin="10,0,0,0" Width="30" Height="30" Style="{StaticResource LightButtonStyle}" Background="Transparent" 
+                    <Button BorderThickness="0" VerticalContentAlignment="Center" Margin="10,0,0,0" Width="30" Height="30" Style="{StaticResource LightButtonStyle}" Background="Transparent" Click="SaveFileBtn_Click" 
                         IsEnabled="{Binding CanSave,Mode=OneWay}">
                         <Button.Content>
                             <Viewbox Width="20" Height="20">

+ 68 - 78
Demo/Examples/ContentEditor/MainWindow.xaml.cs

@@ -31,6 +31,8 @@ namespace ContentEditorViewControl
     /// </summary>
    public partial class MainWindow: Window, INotifyPropertyChanged
     {
+        #region Properties
+        
         private PanelState panelState = PanelState.GetInstance();
         private CPDFDisplaySettingsControl displaySettingsControl = new CPDFDisplaySettingsControl();
         private RegularViewerControl regularViewerControl = new RegularViewerControl();
@@ -38,6 +40,7 @@ namespace ContentEditorViewControl
         private PDFViewControl passwordViewer;
         private ContentEditControl contentEditControl = new ContentEditControl();
         private CPDFBOTABarControl botaBarControl = new CPDFBOTABarControl(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search | BOTATools.Annotation);
+        public event PropertyChangedEventHandler PropertyChanged;
         private string currentMode = "Viewer";
         
         private bool _canSave = false;
@@ -87,7 +90,7 @@ namespace ContentEditorViewControl
                 OnPropertyChanged();
             }
         }
-        
+        #endregion
         public MainWindow()
         {
             InitializeComponent();
@@ -143,25 +146,44 @@ namespace ContentEditorViewControl
             panelState.PropertyChanged += PanelState_PropertyChanged;
         }
         
-        private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        private void OpenFile()
         {
-            if (e.PropertyName == "RightPanel")
+            string filePath = CommonHelper.GetExistedPathOrEmpty();
+            if (!string.IsNullOrEmpty(filePath) && contentEditControl.PdfViewControl != null)
             {
-                OnPropertyChanged(nameof(RightToolPanelButtonIsChecked));
-                OnPropertyChanged(nameof(ViewSettingBtnIsChecked));
-            }
-        }
+                if (pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
+                {
+                    string oldFilePath = pdfViewer.PDFView.Document.FilePath;
+                    if (oldFilePath.ToLower() == filePath.ToLower())
+                    {
+                        return;
+                    }
+                }
 
-        private void PdfContentEditControlRefreshAnnotList(object sender, EventArgs e)
-        {
-            botaBarControl.LoadAnnotationList();
-        }
+                passwordViewer = new PDFViewControl();
+                passwordViewer.PDFView.InitDocument(filePath);
+                if (passwordViewer.PDFView.Document == null)
+                {
+                    MessageBox.Show("Open File Failed");
+                    return;
+                }
 
-        private void ControlOnCanSaveChanged(object sender, bool e)
-        {
-           this.CanSave = e;
+                if (passwordViewer.PDFView.Document.IsLocked)
+                {
+                    PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
+                    PasswordUI.ClearPassword();
+                    PopupBorder.Visibility = Visibility.Visible;
+                    PasswordUI.Visibility = Visibility.Visible;
+                }
+                else
+                {
+                    pdfViewer.PDFView.Document.Release();
+                    pdfViewer = passwordViewer;
+                    LoadDocument();
+                }
+            }
         }
-
+        
         #endregion
         
         #region Password
@@ -203,8 +225,7 @@ namespace ContentEditorViewControl
         
         #region Load Unload custom control
 
-        
-        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
+        private void Window_Loaded(object sender, RoutedEventArgs e)
         {
             pdfViewer = new PDFViewControl();
             LoadDefaultDocument();
@@ -229,62 +250,13 @@ namespace ContentEditorViewControl
                 CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
             }
         }
-        
-        
-        
-        #endregion
-        
-        private void Window_Loaded(object sender, RoutedEventArgs e)
-        {
 
-            pdfViewer = new PDFViewControl();
-            LoadDefaultDocument();
-        }
-        
         private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
         {
             SaveFile();
             pdfViewer.PDFView.UndoManager.CanSave = false;
         }
         
-        private void OpenFile()
-        {
-            string filePath = CommonHelper.GetExistedPathOrEmpty();
-            if (!string.IsNullOrEmpty(filePath) && contentEditControl.PdfViewControl != null)
-            {
-                if (pdfViewer.PDFView != null && pdfViewer.PDFView.Document != null)
-                {
-                    string oldFilePath = pdfViewer.PDFView.Document.FilePath;
-                    if (oldFilePath.ToLower() == filePath.ToLower())
-                    {
-                        return;
-                    }
-                }
-
-                passwordViewer = new PDFViewControl();
-                passwordViewer.PDFView.InitDocument(filePath);
-                if (passwordViewer.PDFView.Document == null)
-                {
-                    MessageBox.Show("Open File Failed");
-                    return;
-                }
-
-                if (passwordViewer.PDFView.Document.IsLocked)
-                {
-                    PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " password encrypted.");
-                    PasswordUI.ClearPassword();
-                    PopupBorder.Visibility = Visibility.Visible;
-                    PasswordUI.Visibility = Visibility.Visible;
-                }
-                else
-                {
-                    pdfViewer.PDFView.Document.Release();
-                    pdfViewer = passwordViewer;
-                    LoadDocument();
-                }
-            }
-        }
-
         private void OpenFile_Click(object sender, RoutedEventArgs e)
         {
             OpenFile();
@@ -381,6 +353,36 @@ namespace ContentEditorViewControl
             LeftToolPanelButtonIsChecked = true;
             botaBarControl.SelectBotaTool(BOTATools.Search);
         }
+        
+        private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            if (e.PropertyName == "RightPanel")
+            {
+                OnPropertyChanged(nameof(RightToolPanelButtonIsChecked));
+                OnPropertyChanged(nameof(ViewSettingBtnIsChecked));
+            }
+        }
+
+        private void PdfContentEditControlRefreshAnnotList(object sender, EventArgs e)
+        {
+            botaBarControl.LoadAnnotationList();
+        }
+
+        private void ControlOnCanSaveChanged(object sender, bool e)
+        {
+            this.CanSave = e;
+        }
+        
+        private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
+        {
+            PopupBorder.Visibility = Visibility.Collapsed;
+        }
+        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+        
+        #endregion
 
         #region Save file
         /// <summary>
@@ -437,18 +439,6 @@ namespace ContentEditorViewControl
             }
         }
         #endregion
-
-        private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
-        {
-            PopupBorder.Visibility = Visibility.Collapsed;
-        }
-
-        public event PropertyChangedEventHandler PropertyChanged;
-
-        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
-        {
-            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
-        }
     }
 }
 

+ 8 - 8
Demo/Examples/DocsEditor/MainWindow.xaml.cs

@@ -56,14 +56,7 @@ namespace DocsEditor
             Loaded += MainWindow_Loaded;
             DataContext = this;
         }
-
-        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
-        {
-            BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search);
-            pdfAnnotationControl = new CPDFAnnotationControl();
-            LoadDefaultDocument();
-        }
-
+        
         #region Load document
 
         private void LoadDefaultDocument()
@@ -689,6 +682,13 @@ namespace DocsEditor
         #endregion
 
         #region Event handle
+        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
+        {
+            BotaSideTool.AddBOTAContent(BOTATools.Thumbnail | BOTATools.Outline | BOTATools.Bookmark | BOTATools.Search);
+            pdfAnnotationControl = new CPDFAnnotationControl();
+            LoadDefaultDocument();
+        }
+        
         private void CPDFPageEditBarControl_PageEditEvent(object sender, string e)
         {
             pageEditControl.PageEdit(e);