Преглед изворни кода

【编辑工具】【压缩】- 新增压缩入口

lizhe пре 1 недеља
родитељ
комит
1cfd1f69cc

+ 18 - 3
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -451,6 +451,15 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
         self._itemSetPromptFlag(itemIdentifier: KMToolbarToolSecureItemIdentifier)
     }
     
+    @objc private func _compressAction(sender: NSMenuItem) {
+        if let data = self._currentItemView {
+            self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
+        } else {
+            self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: KMToolbarToolCompressItemIdentifier), index: sender.tag, info: nil)
+        }
+        self._itemSetPromptFlag(itemIdentifier: KMToolbarToolCompressItemIdentifier)
+    }
+    
     @objc func measureMenuAction(sender: KMToolbarClickButton) {
         self.delegate?.toolbarViewController?(self, clickChaildToolType: .measure, toolbar: sender.clickObject as! KMToolbarItemView)
         self._itemSetPromptFlag(item: sender.clickObject as? KMToolbarItemView)
@@ -2548,11 +2557,17 @@ extension KMToolbarViewController {
             item?.image = NSImage(named: "KMImageNameUXIconBatchOptimizeNor")
             item?.target = self
             item?.btnTag = KMToolbarType.compress.rawValue
-            item?.boxImagePosition = .imageLeft
+            item?.boxImagePosition = .imageExpandLeft
             item?.toolTip = NSLocalizedString("Reduce file size", comment: "")
             item?.titleName = NSLocalizedString("Compress", comment: "")
-            item?.btnAction = #selector(compressMenuAction)
-            let menuItem = NSMenuItem.init(title: NSLocalizedString("Compress", comment: ""), action: #selector(_menuItemAction), target: self)
+            item?.needExpandAction = true
+//            item?.btnAction = #selector(compressMenuAction)
+            let menuItem = NSMenuItem.init(title: NSLocalizedString("Compress", comment: ""), action: nil, target: self)
+            let subMenu = NSMenu()
+            subMenu.addItem(title: NSLocalizedString("压缩当前文件", comment: ""), action: #selector(_compressAction), target: self, tag: 1)
+            subMenu.addItem(title: NSLocalizedString("压缩多个文件", comment: ""), action: #selector(_compressAction), target: self, tag: 2)
+            subMenu.addItem(title: NSLocalizedString("压缩高级优化", comment: ""), action: #selector(_compressAction), target: self, tag: 3)
+            menuItem.submenu = subMenu
             item?.menuFormRepresentation = menuItem
             menuItem.representedObject = identifier
         } else if identifier == KMToolbarToolSecureItemIdentifier {

+ 13 - 3
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -2815,6 +2815,16 @@ extension KMMainViewController {
     // MARK: -
     // MARK: 显示窗口
     
+    internal func showCompressWindowWithIndex(index: NSInteger) {
+        if index == 1 {
+            self.showCompressWindow()
+        } else if index == 2 {
+            
+        } else if index == 3 {
+            
+        }
+    }
+        
     internal func showCompressWindow(url: URL? = nil) {
 //        if let wc = self.compressWIndowControllerNew, let _ = wc.window?.isSheet {
 //            KMPrint("压缩窗口已显示")
@@ -3902,12 +3912,12 @@ extension KMMainViewController : KMToolbarViewControllerDelegate {
                 
                 if (self.needSaveDocument()) {
                     self.saveDocumentWithProgressAlert { [unowned self] params in
-                        self.showCompressWindow()
+                        self.showCompressWindowWithIndex(index: index)
                     }
                     return
                 }
                 
-                self.showCompressWindow()
+                self.showCompressWindowWithIndex(index: index)
                 return
             }
             
@@ -5142,7 +5152,7 @@ extension KMMainViewController : KMToolbarViewControllerDelegate {
         } else if itemId == KMDocumentAIToolsToolbarItemIdentifier {
             self.showAITypeChooseView(aiConfigType: .none)
         } else if itemId == KMToolbarToolCompressItemIdentifier {
-            self.clickChildTool(type: .compress, index: 0)
+            self.clickChildTool(type: .compress, index: index)
         } else if itemId == KMToolbarPageEditSplitItemIdentifier { // 拆分
             let windowC = SplitWindowController(document: self.listView.document)
             self.km_beginSheet(windowC: windowC)