Explorar o código

【综合】整理代码

tangchao hai 10 meses
pai
achega
2a2f04dd64

+ 16 - 0
PDF Office/PDF Master/Class/Common/Tools/KMTools.swift

@@ -751,6 +751,22 @@ extension KMTools {
         return dateFormatter_?.string(from: date) ?? ""
     }
     
+    @objc class func isFileGreaterThan10MB(atPath filePath: String) -> Bool {
+        let fileManager = FileManager.default
+
+        do {
+            let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
+            if let fileSize = fileAttributes[.size] as? UInt64 {
+                let megabyteSize = fileSize / (1024 * 1024)
+                return megabyteSize >= 10
+            }
+        } catch {
+            KMPrint("Error: \(error)")
+        }
+
+        return false
+    }
+    
     // MARK: - Private Methods
     
     @objc fileprivate class func _documentAddWatermark(document: CPDFDocument) -> CPDFDocument? {

+ 0 - 122
PDF Office/PDF Master/Class/PDFTools/Secure/View/KMSecureEncryptSuccessTipView.swift

@@ -1,122 +0,0 @@
-//
-//  KMSecureEncryptSuccessTipView.swift
-//  PDF Reader Pro
-//
-//  Created by tangchao on 2022/11/28.
-//
-
-import Cocoa
-
-typealias KMSecureEncryptSuccessTipViewItemClick = () ->()
-class KMSecureEncryptSuccessTipView: NSView {
-
-    private var iconImageView = NSImageView()
-    private var iconSelectImageView = NSImageView()
-    private var despLabel = NSTextField(wrappingLabelWithString: "")
-    private var titleLabel = NSTextField(labelWithString: "")
-    private var closeButton = NSButton()
-    
-    private var knowButtonVC: KMDesignButton?
-    
-    var itemClick: KMSecureEncryptSuccessTipViewItemClick!
-    
-    private var knowButtonSize: NSSize = NSMakeSize(140, 32)
-    
-    override init(frame frameRect: NSRect) {
-        super.init(frame: frameRect)
-
-        self.initSubViews()
-    }
-    
-    required init?(coder: NSCoder) {
-        super.init(coder: coder)
-        
-        self.initSubViews()
-    }
-    
-    override var isFlipped: Bool {
-        return true
-    }
-    
-    func initSubViews() {
-        wantsLayer = true
-        layer?.backgroundColor = NSColor.km_init(hex: "#E8F5FF").cgColor
-        layer?.cornerRadius = 8
-        self.shadow = NSShadow()
-        self.layer?.shadowColor = NSColor.km_init(hex: "#00000029").cgColor
-        self.layer?.shadowOpacity = 1
-        self.layer?.shadowRadius = 8
-        self.layer?.shadowOffset = CGSize(width: 0, height: -3)
-        
-        self.addSubview(self.titleLabel)
-        self.addSubview(self.closeButton)
-        addSubview(iconImageView)
-        addSubview(despLabel)
-        
-        self.knowButtonVC = KMDesignButton(withType: .Text)
-        self.addSubview(self.knowButtonVC!.view)
-        
-        self.iconImageView.addSubview(self.iconSelectImageView)
-        
-        self.titleLabel.stringValue = NSLocalizedString("Set password successfully", comment: "")
-        self.titleLabel.font = NSFont.SFProTextRegularFont(14)
-        self.titleLabel.textColor = NSColor.titleColor()
-        self.closeButton.isBordered = false
-        self.closeButton.image = NSImage(named: "KMImageNameWhiteClose")
-        self.closeButton.target = self
-        self.closeButton.action = #selector(knowButtonAction)
-        iconImageView.wantsLayer = true
-        iconImageView.image = NSImage(named: "KMImageNameTipSelectedBackgroud")
-        self.iconSelectImageView.image = NSImage(named: "KMImageNameTipSelected")
-        
-        self.despLabel.isSelectable = false
-        despLabel.stringValue = NSLocalizedString("The security settings won't take effect until the document is saved. You can change the security settings before closing the file.", comment: "")
-        let ps = NSMutableParagraphStyle()
-        ps.lineSpacing = 7
-        despLabel.attributedStringValue = NSAttributedString(string: despLabel.stringValue, attributes: [.foregroundColor : NSColor.despColor(),
-            .font : NSFont.SFProTextRegularFont(14),
-            .paragraphStyle : ps
-        ])
-        
-        self.knowButtonVC?.stringValue = NSLocalizedString("Got it", comment: "")
-        self.knowButtonVC?.button(type: .Ghost, size: .m)
-        self.knowButtonVC?.target = self
-        self.knowButtonVC?.action = #selector(knowButtonAction)
-        let size = self.knowButtonVC?.stringValue.boundingRect(with: NSMakeSize(1000, self.knowButtonSize.height), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.foregroundColor : NSColor.buttonTitleColor(), .font : NSFont.SFProTextRegularFont(14)]).size
-        if (size == nil || size!.width < 40) {
-            self.knowButtonSize.width = 70
-        } else {
-            self.knowButtonSize.width = size!.width + 34
-        }
-    }
-    
-    override func layout() {
-        super.layout()
-        
-        let width: CGFloat = NSWidth(self.bounds)
-        let height: CGFloat = NSHeight(self.bounds)
-        
-        let iconSize: CGFloat = 20
-        iconImageView.frame = NSMakeRect(18, 18, iconSize, iconSize)
-        self.iconSelectImageView.frame = self.iconImageView.bounds
-        
-        self.titleLabel.frame = NSMakeRect(self.iconImageView.frame.maxX+10, 16, 295, 22)
-        self.closeButton.frame = NSMakeRect(width-34, 10, 24, 24)
-        
-        let despX: CGFloat = iconImageView.frame.maxX+12
-        let despY: CGFloat = self.titleLabel.frame.maxY+8
-        despLabel.frame = NSMakeRect(despX, despY, width-despX-8, height-despY-45)
-        
-        let knowSize = self.knowButtonSize
-        self.knowButtonVC?.view.frame = NSMakeRect(width-knowSize.width-16, height-knowSize.height-16, knowSize.width, knowSize.height)
-    }
-    
-    @objc func knowButtonAction() {
-        guard let callback = itemClick else {
-            return
-        }
-        
-        callback()
-    }
-    
-}

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

@@ -3699,7 +3699,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
     
     private func _aiTranslationPDFFileAction() {
         let isExceedsLimit = self.isPDFPageCountExceedsLimit(filePath: (self.document?.documentURL.path)!)
-        if self.isFileGreaterThan10MB(atPath: (self.document?.documentURL.path)!) {
+        if KMTools.isFileGreaterThan10MB(atPath: (self.document?.documentURL.path)!) {
             let alert = NSAlert()
             alert.alertStyle = .critical
             alert.messageText = NSLocalizedString("The uploaded file size cannot exceed 10MB", comment: "")

+ 10 - 33
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+MenuAction.swift

@@ -159,12 +159,9 @@ extension KMMainViewController: KMEditMenuProtocol {
     }
 }
 
-// MARK: View Menu
+// MARK: - View Menu
 
 extension KMMainViewController {
-    
-    // scale
-    
     @IBAction func menuItemAction_adjustWidth(_ sender: Any) {
         self.selectZoom(.width)
     }
@@ -340,7 +337,6 @@ extension KMMainViewController {
             self.exitFullScreen("")
         } else if self.canEnterPresentation(){
             self.enterPresentation()
-//            self.browserWindowController?.enterPresentation()
         }
     }
     
@@ -363,10 +359,7 @@ extension KMMainViewController {
     }
     @IBAction func chooseAutoFlowSetting(_ sender: Any?) {
         autoFlowOptionsSheetController = KMAutoFlowOptionsSheetController(windowNibName: "KMAutoFlowOptionsSheetController")
-        
-        NSWindow.currentWindow().beginSheet((autoFlowOptionsSheetController?.window)!) { responce in
-            
-        }
+        NSWindow.currentWindow().beginSheet((autoFlowOptionsSheetController?.window)!) { responce in }
     }
     
     @IBAction func toggleReadingBar(_ sender: Any?) {
@@ -395,24 +388,17 @@ extension KMMainViewController {
         guard let item = sender as? NSMenuItem else {
             return
         }
-//        let index = item.tag
-        
+
         if item.tag < 2 && IAPProductsManager.default().isAvailableAllFunction() == false {
             KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
             return
         }
-        
-//        if (toolbarViewController.splitScreenPopover != nil) {
-//            [toolbarViewController.splitScreenPopover close];
-//        }
-        
         self.splitView(withTag: item.tag)
-//        [[NSNotificationCenter defaultCenter] postNotificationName:@"kKMToolsItemSelectStateChange" object:self.pdfView];
     }
     
     @IBAction func themesColor(_ sender: Any?) {
         guard let item = sender as? NSMenuItem else {
-            __NSBeep()
+            NSSound.beep()
             return
         }
         let mode = item.tag
@@ -448,9 +434,6 @@ extension KMMainViewController {
         
         self.listView.layoutDocumentView()
         self.listView.setNeedsDisplayForVisiblePages()
-        
-//        [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:mode] forKey:@"kPDFViewModeKey"];
-//        [[NSUserDefaults standardUserDefaults] synchronize];
         UserDefaults.standard.set(mode, forKey: "kPDFViewModeKey")
         UserDefaults.standard.synchronize()
     }
@@ -464,7 +447,7 @@ extension KMMainViewController {
     }
 }
 
-// MARK: Annotation Menu
+// MARK: - Annotation Menu
 
 extension KMMainViewController {
     @IBAction func menuItemAction_highlight(_ sender: Any) {
@@ -619,11 +602,9 @@ extension KMMainViewController {
     
     private func mainMenuUpdateAnnotationStyle(identifier : String) {
         if self.toolbarController.toolbarType != .Annatiton {
-            let item : KMToolbarItemView = (self.toolbarController.mainToolBarView?.toolbarItemFindItemIdentifiers(value: KMDocumentAnnotationToolbarItemIdentifier))!
-            self.toolbarController.mainToolBarView?.delegate?.toolbarViewController?(self.toolbarController.mainToolBarView!, clickMode: .Annatiton, toolbar: item, [])
+            self.toolbarController.clickItem(KMDocumentAnnotationToolbarItemIdentifier)
         }
-        let childitem : KMToolbarItemView = (self.toolbarController.childToolBarView?.toolbarItemFindItemIdentifiers(value: identifier))!
-        self.toolbarController.mainToolBarView?.delegate?.changeAnnotationModeAction?(item: childitem.clickButton)
+        self.toolbarController.clickItem(identifier)
     }
 }
 
@@ -735,7 +716,7 @@ extension KMMainViewController: KMSystemPDFMenuProtocol {
     }
 }
 
-// MARK: goto Menu
+// MARK: - goto Menu
 
 extension KMMainViewController {
     @IBAction func menuItemAction_nextPage(_ sender: Any) {
@@ -805,9 +786,6 @@ extension KMMainViewController {
             NSSound.beep()
             return
         }
-//        if (markedPageIndex == NSNotFound || [pdfDoc isLocked] || [pdfDoc pageCount] == 0) {
-//            NSBeep();
-//        } else if (beforeMarkedPageIndex != NSNotFound) {
         if self.model.beforeMarkedPageIndex != NSNotFound {
             self.listView.goToPage(at: min(UInt(self.model.beforeMarkedPageIndex), pdfDoc.pageCount-1), point: self.model.beforeMarkedPagePoint)
         } else if (currentPageIndex != self.model.markedPageIndex) {
@@ -823,7 +801,7 @@ extension KMMainViewController {
     }
 }
 
-// MARK: tool Menu
+// MARK: - tool Menu
 
 extension KMMainViewController: KMSystemToolMenuProtocol {
     func getInfo(_ sender: Any?) {
@@ -831,7 +809,6 @@ extension KMMainViewController: KMSystemToolMenuProtocol {
     }
     
     @IBAction func menuItemAction_textTool(_ sender: Any) {
-//        self.toolbarController.selectItem(KMToolbarZoomToSelectionItemIdentifier)
         self.listView?.toolMode = .textToolMode
         self.listView?.annotationType = .unkown
     }
@@ -1241,7 +1218,7 @@ extension KMMainViewController: KMSystemToolMenuProtocol {
     }
 }
 
-// MARK: window Menu
+// MARK: - window Menu
 
 extension KMMainViewController {
     @IBAction func menuItemAction_showForwardTagPage(_ sender: Any) {

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 985 - 57
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+UI.swift


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 39 - 1090
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift


+ 0 - 8
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -3795,9 +3795,6 @@
 		BB6DD821293497B6001F0544 /* KMSecureEncryptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB6DD820293497B6001F0544 /* KMSecureEncryptModel.swift */; };
 		BB6DD822293497B6001F0544 /* KMSecureEncryptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB6DD820293497B6001F0544 /* KMSecureEncryptModel.swift */; };
 		BB6DD823293497B6001F0544 /* KMSecureEncryptModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB6DD820293497B6001F0544 /* KMSecureEncryptModel.swift */; };
-		BB6DD8252934D056001F0544 /* KMSecureEncryptSuccessTipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB6DD8242934D056001F0544 /* KMSecureEncryptSuccessTipView.swift */; };
-		BB6DD8262934D056001F0544 /* KMSecureEncryptSuccessTipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB6DD8242934D056001F0544 /* KMSecureEncryptSuccessTipView.swift */; };
-		BB6DD8272934D056001F0544 /* KMSecureEncryptSuccessTipView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB6DD8242934D056001F0544 /* KMSecureEncryptSuccessTipView.swift */; };
 		BB6EA2942B70AF48000D4490 /* KMConvertCompareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB6EA28E2B70AF43000D4490 /* KMConvertCompareViewController.xib */; };
 		BB6EA2952B70AF48000D4490 /* KMConvertCompareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB6EA28E2B70AF43000D4490 /* KMConvertCompareViewController.xib */; };
 		BB6EA2962B70AF48000D4490 /* KMConvertCompareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = BB6EA28E2B70AF43000D4490 /* KMConvertCompareViewController.xib */; };
@@ -6730,7 +6727,6 @@
 		BB6DD81729348A00001F0544 /* KMSecureEncryptComboBoxCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureEncryptComboBoxCellView.swift; sourceTree = "<group>"; };
 		BB6DD81B29348F31001F0544 /* KMSecureTextFiled.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureTextFiled.swift; sourceTree = "<group>"; };
 		BB6DD820293497B6001F0544 /* KMSecureEncryptModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureEncryptModel.swift; sourceTree = "<group>"; };
-		BB6DD8242934D056001F0544 /* KMSecureEncryptSuccessTipView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSecureEncryptSuccessTipView.swift; sourceTree = "<group>"; };
 		BB6EA28E2B70AF43000D4490 /* KMConvertCompareViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMConvertCompareViewController.xib; sourceTree = "<group>"; };
 		BB6EA28F2B70AF44000D4490 /* KMConvertCompareViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KMConvertCompareViewController.h; sourceTree = "<group>"; };
 		BB6EA2902B70AF45000D4490 /* KMConvertCompareViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KMConvertCompareViewController.m; sourceTree = "<group>"; };
@@ -12051,7 +12047,6 @@
 				BB6DD81729348A00001F0544 /* KMSecureEncryptComboBoxCellView.swift */,
 				BB6DD81B29348F31001F0544 /* KMSecureTextFiled.swift */,
 				BB8115FE2992682F0008F536 /* KMSecureLimitAlertView.swift */,
-				BB6DD8242934D056001F0544 /* KMSecureEncryptSuccessTipView.swift */,
 				BBA8B7A92935DC120097D183 /* KMRemovePasswordResultTipView.swift */,
 				BB8115FA29924A5F0008F536 /* KMSecureEncryptCheckCellView.swift */,
 				ADFA8F102B60E01C002595A4 /* KMSecureAlertView.swift */,
@@ -16452,7 +16447,6 @@
 				9F69DBBA2B55014F003D4C45 /* KMAnnotationButtonWidgetAppearanceViewController.swift in Sources */,
 				BBE9D0972AF0CECB002E83CE /* KMBatchOperateCompressViewController.swift in Sources */,
 				BB74DA772AC41182006EDFE7 /* NSFont+KMExtension.swift in Sources */,
-				BB6DD8252934D056001F0544 /* KMSecureEncryptSuccessTipView.swift in Sources */,
 				BB6B43662A04919200E02B54 /* KMBaseViewController.swift in Sources */,
 				AD3AAD412B0B7B6C00DE5FE7 /* KMCompareManager.swift in Sources */,
 				AD055EB92B8843FD0035F824 /* SKToolbarItem.m in Sources */,
@@ -16822,7 +16816,6 @@
 				ADAFDA3A2AE8EEFF00F084BC /* KMAdvertisementRequestServer.swift in Sources */,
 				BBC745EB295F067B0072C2ED /* KMCropSettingWindowController.swift in Sources */,
 				ADDEEA7B2AD3F4C800EF675D /* KMPopUpButton.swift in Sources */,
-				BB6DD8262934D056001F0544 /* KMSecureEncryptSuccessTipView.swift in Sources */,
 				BB853C702AF879C1009C20C1 /* KMBatchRemoveWatermarkOperation.swift in Sources */,
 				9FBC48B9299B44C600CA39D7 /* KMSecondaryViewController.m in Sources */,
 				ADDF832D2B391A5C00A81A4E /* NSEvent+PDFListView.m in Sources */,
@@ -18896,7 +18889,6 @@
 				BB0353CA2B2987C40048A16C /* KMSnapshotWindow.swift in Sources */,
 				BB328B6C2B565BEC00B382C6 /* iVersion.m in Sources */,
 				AD3AAD2E2B0B6FFA00DE5FE7 /* KMCompareCoveringView.swift in Sources */,
-				BB6DD8272934D056001F0544 /* KMSecureEncryptSuccessTipView.swift in Sources */,
 				ADAFDA782AEB5FCD00F084BC /* KMHomeHistoryCollectionItem.swift in Sources */,
 				ADAFDA052AE8BD5C00F084BC /* KMConvertURLToPDF.m in Sources */,
 				9FCFECAA2AD243C900EAD2CB /* KMBlankView.swift in Sources */,