Sfoglia il codice sorgente

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

ZhouJieSheng 2 anni fa
parent
commit
f02b78dce1

+ 114 - 0
PDF Office/Helper/CropPageUndoManager.cs

@@ -0,0 +1,114 @@
+using ComPDFKitViewer;
+using ComPDFKitViewer.PdfViewer;
+using Microsoft.Office.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PDF_Office.Helper
+{
+    public enum CropPageEnum
+    {
+        CropCurrentPageWM,
+        CropAllPagesWM
+    }
+
+    public class CropPageUndoManager : IHistory
+    {
+        public List<int> cropPageList = new List<int>();
+
+        private List<CropPageEnum> cropPageEnumList = new List<CropPageEnum>();
+
+        private int cropPageEnumIndex = -1;
+
+        private int cropPageListInterval = 0;
+
+        private CPDFViewer pdfviewer = null;
+
+        public CropPageUndoManager()
+        {
+
+        }
+
+        public void setPDFViewer(CPDFViewer pDFViewer)
+        {
+            pdfviewer = pDFViewer;
+        }
+
+        public void ADDCropCurrentPageWM()
+        {
+            cropPageEnumIndex++;
+            cropPageEnumList.Insert(cropPageEnumIndex, CropPageEnum.CropCurrentPageWM);
+            if (cropPageEnumIndex != cropPageEnumList.Count - 1)
+            {
+                cropPageEnumList.RemoveRange(cropPageEnumIndex + 1, cropPageEnumList.Count - cropPageEnumIndex-1);
+                cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval-1, cropPageListInterval);
+                cropPageListInterval = 0;
+            }
+
+
+
+        }
+        public void ADDCropAllPagesWM()
+        {
+            cropPageEnumIndex++;
+            cropPageEnumList.Insert(cropPageEnumIndex, CropPageEnum.CropAllPagesWM);
+            if (cropPageEnumIndex != cropPageEnumList.Count - 1)
+            {
+                cropPageEnumList.RemoveRange(cropPageEnumIndex+1, cropPageEnumList.Count - cropPageEnumIndex-1);
+                cropPageList.RemoveRange(cropPageList.Count - cropPageListInterval-37, cropPageListInterval);
+                cropPageListInterval = 0;
+            }
+            
+        }
+
+        public void setPageList(List<int> CropPageList)
+        {
+            cropPageList = CropPageList;
+        }
+
+        public bool Redo()
+        {
+            cropPageEnumIndex++;
+            if (cropPageEnumIndex < cropPageEnumList.Count )
+            {
+                
+                if (cropPageEnumList[cropPageEnumIndex] == CropPageEnum.CropAllPagesWM) { cropPageListInterval -= pdfviewer.Document.PageCount; } else { cropPageListInterval--; }
+                
+                if (cropPageList.Count - cropPageListInterval == 0) { pdfviewer.SetCropMode(false); } else { pdfviewer.SetCropMode(true, cropPageList.GetRange(0, cropPageList.Count - cropPageListInterval)); }
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        public bool Undo()
+        {
+            if (cropPageEnumIndex > -1)
+            {
+                if (cropPageEnumList[cropPageEnumIndex] == CropPageEnum.CropAllPagesWM)
+                {
+                    cropPageListInterval += pdfviewer.Document.PageCount;
+                }
+                else
+                {
+                    cropPageListInterval++;
+                }
+                if (cropPageList.Count - cropPageListInterval == 0) { pdfviewer.SetCropMode(false); } else { pdfviewer.SetCropMode(true, cropPageList.GetRange(0, cropPageList.Count - cropPageListInterval)); }
+
+                cropPageEnumIndex--;
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+
+
+        }
+    }
+}

+ 1 - 0
PDF Office/PDF Office.csproj

@@ -328,6 +328,7 @@
     <Compile Include="EventAggregators\SplitEvent.cs" />
     <Compile Include="Helper\CacheFilePath.cs" />
     <Compile Include="Helper\ConverterHelper.cs" />
+    <Compile Include="Helper\CropPageUndoManager.cs" />
     <Compile Include="Helper\Win32Helper.cs" />
     <Compile Include="Helper\DpiHelpers.cs" />
     <Compile Include="Helper\EditToolsHelper.cs" />

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

@@ -21,6 +21,7 @@ using System.Threading.Tasks;
 using static PDF_Office.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
 using Task = System.Threading.Tasks.Task;
 using PDF_Office.Model.Dialog.ToolsDialogs;
+using ComPDFKitViewer;
 
 namespace PDF_Office.ViewModels.Tools
 {
@@ -31,13 +32,13 @@ namespace PDF_Office.ViewModels.Tools
         private ViewContentViewModel viewContentViewModel;
 
         public IDialogService dialogs;
-
+        public CropPageUndoManager UndoManager=new CropPageUndoManager();
         public IEventAggregator eventAggregator;
-
+        List<int> cropCurrentPageList = new List<int>();
+        List<int> cropPagesList = new List<int>();
        
-
         private CPDFDocument.GetPageIndexDelegate indexDelegate = null;
-    
+
 
         public string unicode = null;
 
@@ -60,8 +61,8 @@ namespace PDF_Office.ViewModels.Tools
         //        App.mainWindowViewModel.Value = int.Parse(PageIndex);
         //    }
         //}
-    //private CPDFDocument tempDocument;
-    //private IntPtr compressingIntpr = IntPtr.Zero;
+        //private CPDFDocument tempDocument;
+        //private IntPtr compressingIntpr = IntPtr.Zero;
         //private string _pageNumber = "";
         ///// <value>
         ///// 总页数
@@ -81,7 +82,8 @@ namespace PDF_Office.ViewModels.Tools
         public DelegateCommand CancelPasswordCommand { get; set; }
         public DelegateCommand<object> SetEditToolsCommand { get; set; }
         public DelegateCommand SetWatermarkCommand { get; set; }
-
+        public DelegateCommand CropCurrentPageWMCommand { get; set; }
+        public DelegateCommand CropAllPagesWMCommand { get; set; }
         public ToolsBarContentViewModel(IDialogService dialogService, IEventAggregator eventAggregator)
         {
             dialogs = dialogService;
@@ -92,6 +94,8 @@ namespace PDF_Office.ViewModels.Tools
             SetPasswordCommand = new DelegateCommand(OpenSetPasswordDialog);
             CancelPasswordCommand = new DelegateCommand(OpenCancelPasswordDialog);
             SetEditToolsCommand = new DelegateCommand<object>(SetEditTools);
+            CropCurrentPageWMCommand = new DelegateCommand(CropCurrentPageWM);
+            CropAllPagesWMCommand = new DelegateCommand(CropAllPagesWM);
         }
 
         private void SetEditTools(object e)
@@ -112,7 +116,7 @@ namespace PDF_Office.ViewModels.Tools
             {
                 CompressDialogModel compressDialogModel = new CompressDialogModel();
                 compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
-               // OnOpened((Prism.Services.Dialogs.DialogResult)e);
+                // OnOpened((Prism.Services.Dialogs.DialogResult)e);
             });
         }
 
@@ -221,6 +225,36 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
+        private void CropCurrentPageWM()
+        {
+            if (PDFViewer.CurrentIndex > 0)
+            {
+                UndoManager.cropPageList.Add(PDFViewer.CurrentIndex);
+            }
+            UndoManager.ADDCropCurrentPageWM();
+            PDFViewer?.SetCropMode(true, UndoManager.cropPageList);
+            PDFViewer.UndoManager.AddHistory(UndoManager);
+            PDFViewer.UndoManager.CanSave = true;
+        }
+        private void CropAllPagesWM()
+        {
+            
+            for (int i = 0; i < PDFViewer.Document.PageCount; i++)
+            {
+                cropPagesList.Add(i);
+            }
+            
+            UndoManager.cropPageList.AddRange(cropPagesList);
+            UndoManager.ADDCropAllPagesWM();
+            PDFViewer?.SetCropMode(true, UndoManager.cropPageList);
+            PDFViewer.UndoManager.AddHistory(UndoManager);
+            PDFViewer.UndoManager.CanSave = true;
+            
+            //PDFViewer.UndoManager.AddHistory();
+        }
+
+        
+            
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;
@@ -236,6 +270,8 @@ namespace PDF_Office.ViewModels.Tools
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             if (PDFViewer != null)
             {
+                UndoManager.setPDFViewer(PDFViewer);
+                //DFViewer.UndoManager.AddHistory(UndoManager);
                 isFirstLoad = false;
             }
         }

+ 13 - 1
PDF Office/Views/Tools/ToolsBarContent.xaml

@@ -202,11 +202,23 @@
                             </Path>
                         </StackPanel>
                     </Button>
-                    <Button Style="{StaticResource InsideBarBtnStyle}" Visibility="Visible">
+                    <Button Style="{StaticResource InsideBarBtnStyle}" Visibility="Visible" IsEnabled="{Binding ElementName=SecurityMenuMore, Path=IsOpen, Converter={StaticResource InvertBoolConvert}}" Click="CropPageMore_Click" Initialized="CropPageMore_Initialized" Name="CropPageMenuMore">
                         <StackPanel Orientation="Horizontal" Margin="4,0,4,0">
                             <Path Data="M13 16L5 16C4.44771 16 4 15.5523 4 15V7L4 2V0H2L2 2H0V4H2L2 15C2 16.6569 3.34315 18 5 18L16 18V20H18V18H20V16H18H16H13ZM16 14V5C16 4.44771 15.5523 4 15 4H6V2H15C16.6569 2 18 3.34315 18 5V14H16Z" Fill="#273C62"></Path>
                             <TextBlock VerticalAlignment="Center" Text="裁剪" />
+                            <Path
+                        Width="12"
+                        Height="12"
+                        Margin="4,0"
+                        Data="M6.5 10L11.5 4H1.5L6.5 10Z"
+                        Fill="{StaticResource color.icon.base.neutral.norm.lv1}" />
                         </StackPanel>
+                        <Button.ContextMenu>
+                            <ContextMenu Name="CropPageMenu" Placement="Bottom">
+                                <MenuItem Header="Crop Current Page - White Margins" Command="{Binding CropCurrentPageWMCommand}"/>
+                                <MenuItem Header="Crop All Pages - White Margins" Command="{Binding CropAllPagesWMCommand}" />
+                            </ContextMenu>
+                        </Button.ContextMenu>
                     </Button>
                 </StackPanel>
             </Grid>

+ 11 - 0
PDF Office/Views/Tools/ToolsBarContent.xaml.cs

@@ -21,6 +21,17 @@ namespace PDF_Office.Views.Tools
         private void SecurityButtonMore_Initialized(object sender, System.EventArgs e)
         {
             this.SecurityButtonMore.ContextMenu = null;
+        }
+
+        private void CropPageMore_Click(object sender, System.Windows.RoutedEventArgs e)
+        {
+            CropPageMenu.PlacementTarget = this.SecurityButtonMore;
+            CropPageMenu.IsOpen = true;
+        }
+
+        private void CropPageMore_Initialized(object sender, System.EventArgs e)
+        {
+            this.CropPageMenuMore.ContextMenu = null;
         }
     }
 }