Browse Source

【阅读页】- 右键裁剪

liujiajie 1 year ago
parent
commit
8d475d25d6

+ 39 - 18
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -168,19 +168,19 @@ extension KMMainViewController {
     
     func exportMenu() -> NSMenu {
         let menu = NSMenu()
-        let item1 = menu.insertItem(withTitle: NSLocalizedString("PNG", comment: ""), action:#selector(exportCorpImage), target: self, tag:0, at: 0)
-        let item2 = menu.insertItem(withTitle: NSLocalizedString("JPG", comment: ""), action:#selector(exportCorpImage), target: self, tag:1, at: 1)
-        let item3 = menu.insertItem(withTitle: NSLocalizedString("PDF", comment: ""), action:#selector(exportCorpImage), target: self, tag:2, at: 2)
+        _ = menu.insertItem(withTitle: NSLocalizedString("PNG", comment: ""), action:#selector(exportCorpImage), target: self, tag:0, at: 0)
+        _ = menu.insertItem(withTitle: NSLocalizedString("JPG", comment: ""), action:#selector(exportCorpImage), target: self, tag:1, at: 1)
+        _ = menu.insertItem(withTitle: NSLocalizedString("PDF", comment: ""), action:#selector(exportCorpImage), target: self, tag:2, at: 2)
         
         return menu
     }
     
     func cropMenu() -> NSMenu {
         let menu = NSMenu()
-        let item1 = menu.insertItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action:#selector(cropCurrentPage), target: self, at: 0)
-        let item2 = menu.insertItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action:#selector(cropAllPage), target: self, at: 1)
-        let item3 = menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
-        let item4 = menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
+        _ = menu.insertItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action:#selector(cropCurrentPage), target: self, at: 0)
+        _ = menu.insertItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action:#selector(cropAllPage), target: self, at: 1)
+        _ = menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
+        _ = menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
         return menu
     }
     
@@ -388,7 +388,7 @@ extension KMMainViewController {
     
     func setAutoScrollStype() -> NSMenuItem {
         let stypItem = NSMenuItem(title: NSLocalizedString("Auto Scroll", comment: ""), action: #selector(AutoScrollItemAction), target: self)
-        
+        stypItem.state = self.listView.isAutoFlow() ? .on : .off
         return stypItem
     }
     
@@ -427,13 +427,13 @@ extension KMMainViewController {
     func setCropStype() -> NSMenuItem {
         let stypItem = NSMenuItem(title: NSLocalizedString("Crop", comment: ""), action: nil, target: self)
         let stypeMenu = NSMenu()
-        let item1 = stypeMenu.addItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action: #selector(cropAllPageItem), target: self, tag: 0)
-        let item2 = stypeMenu.addItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action: #selector(cropCurrentPageItem), target: self, tag: 1)
-        let item3 = stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action: #selector(autoCropAllItem), target: self, tag: 2)
-        let item4 = stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action: #selector(smartAutoCropAllItem), target: self, tag: 3)
+        _ = stypeMenu.addItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action: #selector(cropAllPageItem), target: self, tag: 0)
+        _ = stypeMenu.addItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action: #selector(cropCurrentPageItem), target: self, tag: 1)
+        _ = stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action: #selector(autoCropAllItem), target: self, tag: 2)
+        _ = stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action: #selector(smartAutoCropAllItem), target: self, tag: 3)
         //        if(NSIsEmptyRect(selectionRect)) {
-        let item5 = stypeMenu.addItem(withTitle: NSLocalizedString("Select Area", comment: ""), action: #selector(selectToolModel), target: self, tag: 4)
-        let item6 = stypeMenu.addItem(withTitle: NSLocalizedString("Crop Options...", comment: ""), action: #selector(customCropModel), target: self, tag: 5)
+        _ = stypeMenu.addItem(withTitle: NSLocalizedString("Select Area", comment: ""), action: #selector(selectToolModel), target: self, tag: 4)
+        _ = stypeMenu.addItem(withTitle: NSLocalizedString("Crop Options...", comment: ""), action: #selector(customCropModel), target: self, tag: 5)
         //
         //        }
         
@@ -1838,20 +1838,40 @@ extension KMMainViewController {
         self.listView.displayBox = .cropBox
     }
     
+    func beginProgressSheet(with message: String, maxValue: UInt) { 
+        if progressController == nil {
+            progressController = SKProgressController()
+        }
+        progressController?.message = message
+        
+        if maxValue > 0 {
+            progressController?.indeterminate = false
+            progressController?.maxValue = Double(maxValue)
+        } else {
+            progressController?.indeterminate = true
+        }
+        
+        self.km_beginSheet(windowC: progressController!)
+//        progressController?.closeBlock = {
+//            
+//        }
+    }
+    
+    
    @objc func cropAllPage() {
         var size = NSZeroSize
         for i in 0 ..< self.listView.document.pageCount {
             let page = self.listView.document.page(at: i)
-            var rect = KMCropTools.getPageForegroundBox(page!)
+            let rect = KMCropTools.getPageForegroundBox(page!)
             size.width = fmax(size.width, NSWidth(rect))
             size.height = fmax(size.height, NSHeight(rect))
         }
-        
+       beginProgressSheet(withMessage: KMLocalizedString("Cropping Pages", "Message for progress sheet"), maxValue: min(18, self.listView.document.pageCount))
         var rectArray: Array<NSRect> = []
         for i in 0 ..< self.listView.document.pageCount {
             let page = self.listView.document.page(at: i)
             var rect = KMCropTools.getPageForegroundBox(page!)
-            var bounds: NSRect = (page?.bounds(for: .mediaBox))!
+            let bounds: NSRect = (page?.bounds(for: .mediaBox))!
             if (rect.minX - bounds.minX > bounds.maxX-rect.maxX) {
                 rect.origin.x = rect.maxX-size.width
             }
@@ -1891,7 +1911,7 @@ extension KMMainViewController {
         var oldRectArray: Array<NSRect> = []
         for i in 0 ..< self.listView.document.pageCount {
             let page = self.listView.document.page(at: i)
-            var rect = NSIntersectionRect(rects[Int(i)], (page?.bounds(for: .mediaBox))!)
+            let rect = NSIntersectionRect(rects[Int(i)], (page?.bounds(for: .mediaBox))!)
             let oldRect = page?.bounds(for: .cropBox)
             oldRectArray.append(oldRect!)
             
@@ -1908,6 +1928,7 @@ extension KMMainViewController {
         
         self.listView.go(to: currentPage)
         self.listView.go(to: visibleRect, on: currentPage)
+        dismissProgressSheet()
     }
     
     private func cropCustomArea() {

+ 1 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+UI.swift

@@ -678,6 +678,7 @@ extension KMMainViewController {
     }
     @objc func AutoScrollItemAction() {
         //增加判断,如果是正在滚动,就停止,否则就开始滚动
+        self.listView.autoFlow()
     }
     @objc func shareFromService(sender: NSMenuItem) {