Browse Source

[图片转PDF] - 功能串接

jiajie 1 year ago
parent
commit
907a0a40f4

+ 1 - 1
PDF Office/PDF Master/Class/Batch/Tools/KMImageToPDFMethod.swift

@@ -340,7 +340,7 @@ class KMImageToPDFMethod: NSObject, KMGOCRManagerDelegate {
             } else {
                 let filePath: String = photoArray?[index] as! String
                 let model = KMImageModel(filepath: filePath)
-                let tString = model.photoName.deletingPathExtension
+                let tString = model.photoName.deletingPathExtension.lastPathComponent
                 var savePath = fileSavePath.stringByAppendingPathComponent(tString).stringByAppendingPathExtension("pdf")
                 savePath = getUniqueFilePath(savePath)
                 if results == nil { results = NSMutableArray() }

+ 6 - 6
PDF Office/PDF Master/Class/Batch/WindowController/VC/KMBatchOperateImageToPDFViewController.swift

@@ -378,12 +378,12 @@ class KMBatchOperateImageToPDFViewController: KMBatchOperateBaseViewController,
     }
     
     @IBAction func buttonClicked_ChoosePlan(_ sender: NSButton) {
-        //        let popover = NSPopover()
-        //        popover.delegate = self
-        //        popover.contentViewController = KMPlanViewController(nibName: "KMPlanViewController", bundle: Bundle.main)
-        //        popover.animates = true
-        //        popover.behavior = .transient
-        //        popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minX)
+        let popover = NSPopover()
+        popover.delegate = self
+        popover.contentViewController = KMPlanViewController(nibName: "KMPlanViewController", bundle: Bundle.main)
+        popover.animates = true
+        popover.behavior = .transient
+        popover.show(relativeTo: sender.bounds, of: sender as NSView, preferredEdge: .minX)
     }
     
     @IBAction func buttonClicked_ImageToPDF(_ sender: NSButton) {

+ 4 - 4
PDF Office/PDF Master/Class/Batch/WindowController/VC/KMBatchOperateImageToPDFViewController.xib

@@ -33,7 +33,7 @@
             <rect key="frame" x="0.0" y="0.0" width="480" height="425"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="aPB-Pb-64w">
+                <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="aPB-Pb-64w">
                     <rect key="frame" x="14" y="398" width="42" height="17"/>
                     <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="dr8-xu-eZp">
                         <font key="font" metaFont="systemBold" size="14"/>
@@ -71,7 +71,7 @@
                 <customView translatesAutoresizingMaskIntoConstraints="NO" id="k0c-vv-NPP">
                     <rect key="frame" x="34" y="279" width="430" height="24"/>
                     <subviews>
-                        <textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AKV-3R-iGQ">
+                        <textField focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AKV-3R-iGQ">
                             <rect key="frame" x="1" y="1" width="400" height="22"/>
                             <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" state="on" drawsBackground="YES" id="V8A-qR-hoa">
                                 <font key="font" metaFont="system"/>
@@ -118,7 +118,7 @@
                         <action selector="buttonClicked_ImageToPDF:" target="-2" id="yfO-U1-Svw"/>
                     </connections>
                 </button>
-                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hyp-2H-elp">
+                <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hyp-2H-elp">
                     <rect key="frame" x="14" y="230" width="35" height="17"/>
                     <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="OCR" id="SLY-wg-469">
                         <font key="font" metaFont="systemBold" size="14"/>
@@ -219,7 +219,7 @@
                         <constraint firstAttribute="width" constant="204" id="eca-sg-oYC"/>
                     </constraints>
                 </box>
-                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LnK-B0-rGp">
+                <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LnK-B0-rGp">
                     <rect key="frame" x="32" y="131" width="37" height="16"/>
                     <textFieldCell key="cell" lineBreakMode="clipping" title="Label" id="Pba-1m-xRx">
                         <font key="font" metaFont="system"/>

+ 57 - 18
PDF Office/PDF Master/Class/Batch/WindowController/VC/KMPlanViewController.swift

@@ -15,7 +15,7 @@ protocol KMPlanTableCellViewDelegate: AnyObject {
 
 class KMPlanTableCellView: NSTableCellView{
     var delegate: KMPlanTableCellViewDelegate?
-    var language: Dictionary<String, Any>?
+    var language: String = ""
     @IBOutlet var planTextField: NSTextField!
     @IBOutlet var planButton: NSButton!
     
@@ -28,7 +28,10 @@ class KMPlanTableCellView: NSTableCellView{
 class KMPlanViewController: NSViewController,KMPlanTableCellViewDelegate,NSOutlineViewDelegate,NSOutlineViewDataSource{
     
     @IBOutlet var outlineView: NSOutlineView!
-    var palns: Array<Any>?
+    lazy var palns: Array<String> = {
+        let palns = [KMLocalizedString("Plan 1 (Online)",nil), KMLocalizedString("Plan 2 (Offline)",nil)]
+        return palns
+    }()
     
     override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
         super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
@@ -41,27 +44,63 @@ class KMPlanViewController: NSViewController,KMPlanTableCellViewDelegate,NSOutli
     
     override func awakeFromNib() {
         super.awakeFromNib()
-        if(self.palns == nil){
-            self.palns = [KMLocalizedString("Plan 1 (Online)",nil), KMLocalizedString("Plan 2 (Offline)",nil)]
-            self.outlineView.reloadData()
+        self.outlineView.reloadData()
+    }
+    //MARK: NSOutlineViewDataSource
+    func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
+        return self.palns.count
+    }
+    func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
+        return self.palns[index]
+    }
+    func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
+        return false
+    }
+    // NSOutlineViewDelegate
+    func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
+        let result = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("PlanDataCell"), owner: self) as! KMPlanTableCellView
+        let plan = UserDefaults.standard.integer(forKey: "KMOCRCurrentPlanKey")
+        if plan == transformCellNum(cellContent: item as! String) {
+            result.planButton.state = .on
+        } else {
+            result.planButton.state = .off
         }
+        result.planTextField.stringValue = item as! String
+        result.language = item as! String
+        result.delegate = self 
+        return result
+    }
+    func outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool {
+        return false
     }
 
     //MARK: KMPlanTableCellViewDelegate
     func tableCellViewCheckButtonDidChange(_ cell: KMPlanTableCellView) {
-//        NSUInteger plan = [self.palns indexOfObject:cell.planTextField.stringValue];
-//        if (cell.planButton.state) {
-//            [[NSUserDefaults standardUserDefaults] setInteger:plan forKey:@"KMOCRCurrentPlanKey"];
-//        } else {
-//            if(plan == 0) {
-//                [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"KMOCRCurrentPlanKey"];
-//            } else {
-//                [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"KMOCRCurrentPlanKey"];
-//            }
-//            [[NSUserDefaults standardUserDefaults] synchronize];
-//        }
-//        [self.outlineView reloadData];
-//        [[NSNotificationCenter defaultCenter] postNotificationName:@"KMOCRSelectedPlanChangeNotification" object:nil];
+        let plan = transformCellNum(cellContent: cell.planTextField.stringValue)
+        if cell.planButton.state == .on{
+            UserDefaults.standard.set(plan, forKey: "KMOCRCurrentPlanKey")
+        } else {
+            if plan == 0 {
+                UserDefaults.standard.set(1, forKey: "KMOCRCurrentPlanKey")
+            } else {
+                UserDefaults.standard.set(0, forKey: "KMOCRCurrentPlanKey")
+            }
+            UserDefaults.standard.synchronize()
+        }
+        self.outlineView.reloadData() 
+        NotificationCenter.default.post(name: NSNotification.Name("KMOCRSelectedPlanChangeNotification"), object: nil)
+    }
+    
+    func transformCellNum(cellContent:String) -> Int {
+        var index = 0
+        for i in 0..<(self.palns.count) {
+            let str: String = self.palns[i]
+            if cellContent == str {
+                index = i
+                break
+            }
+        }
+        return index
     }
     
 }

+ 1 - 1
PDF Office/PDF Master/Class/Batch/WindowController/VC/KMPlanViewController.xib

@@ -43,7 +43,7 @@
                                         </textFieldCell>
                                         <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
                                         <prototypeCellViews>
-                                            <tableCellView identifier="PlanDataCell" id="C0I-oH-B2j" customClass="KMPlanTableCellView">
+                                            <tableCellView identifier="PlanDataCell" id="C0I-oH-B2j" customClass="KMPlanTableCellView" customModule="PDF_Master" customModuleProvider="target">
                                                 <rect key="frame" x="11" y="0.0" width="155" height="24"/>
                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                 <subviews>