Ver Fonte

Merge branch 'develop' of git.kdan.cc:Mac_PDF/PDF_Office into develop

tangchao há 1 ano atrás
pai
commit
99d0984dc2

+ 1 - 2
PDF Office/PDF Office/Class/Home/ViewController/customViewController/KMDesignButton.swift

@@ -271,8 +271,7 @@ import Cocoa
         }
         set {
             _image = newValue
-            
-
+            updateUI()
         }
     }
     

+ 2 - 2
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMAnnotationTableRowView.swift

@@ -30,8 +30,8 @@ class KMAnnotationTableRowView: NSTableRowView {
         if self.box == nil {
             var rect = self.bounds
             rect.origin.x = self.bounds.origin.x + 8.0
-            rect.origin.y = self.bounds.origin.y + 2
-            rect.size.height = self.bounds.size.height - 4
+            rect.origin.y = self.bounds.origin.y + 8.0
+            rect.size.height = self.bounds.size.height - 16.0
             rect.size.width = self.bounds.size.width - 16.0
             
             self.box?.wantsLayer = true

+ 121 - 49
PDF Office/PDF Office/Class/PDFWindowController/Side/LeftSide/Outline/KMOutlineViewController.swift

@@ -31,6 +31,9 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
     var renamePDFOutline : CPDFOutline!
     let moreMenu = NSMenu()
     
+    //undo redo
+    private var undoRedoManager: UndoManager = UndoManager()
+    
     func dealloc() {
         
         NotificationCenter.default.removeObserver(self)
@@ -245,14 +248,12 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
         if selectedRowIndexes.count == 0 {
             __NSBeep()
         } else {
-            var selectedPDFOutlineArr = [CPDFOutline]();
+            var outlineItems: [KMOutlineItem] = []
             for index in selectedRowIndexes {
-                var outline : CPDFOutline = self.outlineView.item(atRow: index) as! CPDFOutline
-                selectedPDFOutlineArr.append(outline)
-            }
-            for tOutline in selectedPDFOutlineArr {
-                self.removePDFOutline(outline: tOutline, toIndex: NSInteger(tOutline.index), atParent: tOutline.parent)
+                var outline: CPDFOutline = self.outlineView.item(atRow: index) as! CPDFOutline
+                outlineItems.append(KMOutlineItem(toIndex: index, outline: outline, parent: outline.parent))
             }
+            self.deleteOutline(outlineItems: outlineItems)
         }
         
     }
@@ -341,19 +342,6 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
         self.renameTextField.becomeFirstResponder()
     }
     
-    func renamePDFOutline(outline : CPDFOutline! , label:String) {
-        self.renameTextField.isEditable = false
-        if outline.label == label {
-            return
-        }
-        outline.label = label
-        self.outlineView.reloadData()
-        
-        var indexSet = IndexSet()
-        indexSet.insert(self.outlineView.row(forItem: outline))
-        self.outlineView.selectRowIndexes(indexSet, byExtendingSelection: false)
-    }
-    
     func movePDFOutline(outline : CPDFOutline! , toIndex index : NSInteger , atParent parent : CPDFOutline!) {
         outline.removeFromParent()
         parent.insertChild(outline, at: UInt(index))
@@ -395,7 +383,9 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
             let outline = parent?.insertChild(at: UInt(index))
             outline?.label = string
             outline?.destination = self.listView.currentDestination
-            self.addPDFOutline(outline: outline, toIndex: index, atParent: parent)
+            
+            let outlineItem = KMOutlineItem(toIndex: index, outline: outline!, parent: parent!)
+            self.addOutline(outlineItems: [outlineItem])
         } else {
             __NSBeep()
         }
@@ -412,8 +402,8 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
             if tPage < 0 {
                 continue
             }
-            var page = self.listView.document.page(at: UInt(tPage))!
-            var tDict : [String : CPDFPage] = ["\(i)":page]
+            let page = self.listView.document.page(at: UInt(tPage))!
+            let tDict : [String : CPDFPage] = ["\(i)":page]
             arr.append(tDict)
         }
         DispatchQueue.global(qos: .utility).async{
@@ -461,38 +451,26 @@ class KMOutlineViewController: NSViewController,NSMenuItemValidation {
         self.outlineView.reloadData()
     }
     
-    func addPDFOutlineToIndex(index:NSInteger, atParent parent:CPDFOutline!) {
+    func addPDFOutlineToIndex(index: NSInteger, atParent parent: CPDFOutline!) {
         let currentPageIndex = self.listView.currentPageIndex
-        var outline = parent.insertChild(at: UInt(index))
-        outline?.label =  "\(NSLocalizedString("Page", comment: ""))\(currentPageIndex+1)"
+        
+        var destination: CPDFDestination
         let des = self.listView.currentDestination
         if "\(des?.point.x ?? 0)" != "nan" {
-            outline?.destination = self.listView.currentDestination
+            destination = self.listView.currentDestination
         } else {
-            let destination : CPDFDestination = CPDFDestination(document: self.listView.document, pageIndex: currentPageIndex, at: CGPoint(x: 0, y: 0), zoom: self.listView.scaleFactor)
-            outline?.destination = destination
+            destination = CPDFDestination(document: self.listView.document, pageIndex: currentPageIndex, at: CGPoint(x: 0, y: 0), zoom: self.listView.scaleFactor)
         }
-        self.addPDFOutline(outline:outline,toIndex: index,atParent: parent)
-    }
-    
-    func addPDFOutline(outline:CPDFOutline? , toIndex index : NSInteger , atParent parent : CPDFOutline!) {
-        self.view.window?.makeFirstResponder(self.outlineView)
-        if outline?.parent == nil {
-            parent.insertChild(outline, at: UInt(index))
-        }
-        self.outlineView.reloadData()
-        self.outlineView.expandItem(parent)
-        let indexSet : IndexSet = [self.outlineView.row(forItem: outline)]
-        self.outlineView.selectRowIndexes(indexSet, byExtendingSelection: false)
-        if(self.outlineView.selectedRow >= 0) {
-            self.renameOutlineWithRow(row: self.outlineView.selectedRow)
-        }
-        if Thread.current.isMainThread {
-            self.outlineView.scrollToVisible(self.outlineView.rect(ofRow: index))
-        } else {
-            DispatchQueue.main.async {
-                self.outlineView.scrollToVisible(self.outlineView.rect(ofRow: index))
-            }
+        
+        var outline = parent.insertChild(at: UInt(index))
+        outline?.destination = destination
+        
+        let label = "\(NSLocalizedString("Page", comment: ""))\(currentPageIndex + 1)"
+        outline?.label = label
+        
+        if outline != nil {
+            let outlineItem = KMOutlineItem(toIndex: index, outline: outline!, parent: parent)
+            self.addOutline(outlineItems: [outlineItem])
         }
     }
     
@@ -807,3 +785,97 @@ extension KMOutlineViewController : NSPopoverDelegate {
         }
     }
 }
+
+//MARK: undoRedo
+extension KMOutlineViewController {
+    func changeLocation(oldBookMark: KMBookMark, newBookMark: KMBookMark) {
+        self.listView.document.removeBookmark(forPageIndex: oldBookMark.index)
+        self.listView.document.addBookmark(newBookMark.label, forPageIndex: newBookMark.index)
+        
+        self.reloadData()
+        self.listView.setNeedsDisplayForVisiblePages()
+        
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
+            self.changeLocation(oldBookMark: newBookMark, newBookMark: oldBookMark)
+        }
+    }
+    
+    func renamePDFOutline(outline: CPDFOutline!, label: String) {
+        self.renameTextField.isEditable = false
+        if outline.label == label {
+            return
+        }
+        let temp: String = outline.label
+        outline.label = label
+        self.outlineView.reloadData()
+        
+        var indexSet = IndexSet()
+        indexSet.insert(self.outlineView.row(forItem: outline))
+        self.outlineView.selectRowIndexes(indexSet, byExtendingSelection: false)
+        
+        self.undoRedoManager.registerUndo(withTarget: self) { [unowned self] targetType in
+            self.renamePDFOutline(outline: outline, label: temp)
+        }
+    }
+    
+    func deleteOutline(outlineItems: [KMOutlineItem]) {
+        for outlineItem in outlineItems {
+            outlineItem.outline.removeFromParent()
+            self.outlineView.reloadData()
+            self.outlineView.expandItem(parent)
+        }
+
+        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+            self.addOutline(outlineItems: outlineItems)
+        }
+    }
+    
+    func addOutline(outlineItems: [KMOutlineItem]) {
+        self.view.window?.makeFirstResponder(self.outlineView)
+        for outlineItem in outlineItems {
+            if outlineItem.outline.parent == nil {
+                outlineItem.parent.insertChild(outlineItem.outline, at: UInt(outlineItem.toIndex))
+            }
+            self.outlineView.reloadData()
+            self.outlineView.expandItem(outlineItem.parent)
+        }
+        
+        if outlineItems.count == 1 {
+            let outlineItem: KMOutlineItem = outlineItems.first!
+            let indexSet : IndexSet = [self.outlineView.row(forItem: outlineItem.outline)]
+            self.outlineView.selectRowIndexes(indexSet, byExtendingSelection: false)
+            if(self.outlineView.selectedRow >= 0) {
+                self.renameOutlineWithRow(row: self.outlineView.selectedRow)
+            }
+            if Thread.current.isMainThread {
+                self.outlineView.scrollToVisible(self.outlineView.rect(ofRow: outlineItem.toIndex))
+            } else {
+                DispatchQueue.main.async {
+                    self.outlineView.scrollToVisible(self.outlineView.rect(ofRow: outlineItem.toIndex))
+                }
+            }
+        }
+        
+        self.undoRedoManager.registerUndo(withTarget: self) { targetType in
+            self.deleteOutline(outlineItems: outlineItems)
+        }
+    }
+    
+    @IBAction func undo(_ sender: Any) {
+        if (self.undoRedoManager.canUndo) {
+            self.undoRedoManager.undo()
+        }
+    }
+    
+    @IBAction func redo(_ sender: Any) {
+        if (self.undoRedoManager.canRedo) {
+            self.undoRedoManager.redo()
+        }
+    }
+    
+    struct KMOutlineItem {
+        var toIndex: Int
+        var outline: CPDFOutline
+        var parent: CPDFOutline
+    }
+}

+ 13 - 2
PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMAnnotationPropertiesViewController.m

@@ -15,6 +15,7 @@
 #import <PDF_Office-Swift.h>
 #import "KMSignatureAnnotationViewController.h"
 #import "CSelfSignAnnotation.h"
+#import "CSelfSignAnnotationFreeText.h"
 
 #define KMFromContentButtonHeightFloat 32
 
@@ -175,8 +176,7 @@
         vc.annotationModel = annotationModel;
         self.propertiesBox.contentView = vc.view;
         self.contentViewController = vc;
-    }
-    else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
+    } else if ([annotation isKindOfClass:[CPDFLinkAnnotation class]]) {
         CPDFLinkAnnotation *linkAnnotation = annotations.firstObject;
         NSString *contents = nil;
         if ([linkAnnotation URL]) {
@@ -217,6 +217,17 @@
             self.propertiesBox.contentView = vc.view;
             self.contentViewController = vc;
         }
+    } else if ([annotation isKindOfClass:[CSelfSignAnnotationFreeText class]]) {
+        CSelfSignAnnotationFreeText *newAnnotation = (CSelfSignAnnotationFreeText *)annotation;
+        if (newAnnotation.subType == CAnnotationTypeSignText ||
+            newAnnotation.subType == CAnnotationTypeSignDate) {
+            KMFillSignTextPanel *vc = [[KMFillSignTextPanel alloc] init];
+            vc.pdfView = self.pdfView;
+            vc.annotationModel = annotationModel;
+            self.propertiesBox.contentView = vc.view;
+            self.contentViewController = vc;
+        }
+        
     } else if ([annotation isKindOfClass:[CPDFStampAnnotation class]]) {
         KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
         vc.annotationModel = annotationModel;

+ 21 - 0
PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMFillSignShapePanel.swift

@@ -95,6 +95,27 @@ import Cocoa
         initLocalization()
         
         refreshUI()
+        
+        if annotationModel.stampAnnotationType() == .signTure {
+            hookVC.state = .Sel
+        } else if annotationModel.stampAnnotationType() == .signFalse {
+            forkVC.state = .Sel
+        } else if annotationModel.stampAnnotationType() == .signLine {
+            lineVC.state = .Sel
+        } else if annotationModel.stampAnnotationType() == .signDot {
+            dotVC.state = .Sel
+        } else if annotationModel.stampAnnotationType() == .signCircle {
+            rectangleVC.state = .Sel
+        }
+        if self.isTheSameColor(annotationModel.color(), anotherColor: self.colors[0]) {
+            colorVC1.state = .Sel
+        } else if self.isTheSameColor(annotationModel.color(), anotherColor: self.colors[1]) {
+            colorVC2.state = .Sel
+        } else if self.isTheSameColor(annotationModel.color(), anotherColor: self.colors[2]) {
+            colorVC3.state = .Sel
+        } else if self.isTheSameColor(annotationModel.color(), anotherColor: self.colors[3]) {
+            colorVC4.state = .Sel
+        }
     }
     
     func initializeUI() {

+ 12 - 6
PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMFillSignTextPanel.swift

@@ -53,9 +53,9 @@ class KMFillSignTextPanel: KMPropertiesPanelSubViewController {
     var fontNameVC: KMDesignSelect!
     var fontWeightVC: KMDesignSelect!
     var fontSizeVC: KMDesignSelect!
-    var leftVC: KMDesignButton!
-    var centerVC: KMDesignButton!
-    var rightVC: KMDesignButton!
+    var leftVC: KMDesignPropertySelector!
+    var centerVC: KMDesignPropertySelector!
+    var rightVC: KMDesignPropertySelector!
     var customVC1: KMDesignPropertySelector!
     var customVC2: KMDesignButton!
     
@@ -86,9 +86,9 @@ class KMFillSignTextPanel: KMPropertiesPanelSubViewController {
         fontNameVC = KMDesignSelect.init(withType: .PopButton)
         fontWeightVC = KMDesignSelect.init(withType: .PopButton)
         fontSizeVC = KMDesignSelect.init(withType: .PopButton)
-        leftVC = KMDesignButton.init(withType: .Image)
-        centerVC = KMDesignButton.init(withType: .Image)
-        rightVC = KMDesignButton.init(withType: .Image)
+        leftVC = KMDesignPropertySelector.init(withType: .Icon_Btn)
+        centerVC = KMDesignPropertySelector.init(withType: .Icon_Btn)
+        rightVC = KMDesignPropertySelector.init(withType: .Icon_Btn)
         customVC1 = KMDesignPropertySelector.init(withType: .Color_Icon_Btn)
         customVC2 = KMDesignButton.init(withType: .Image)
         
@@ -331,11 +331,17 @@ class KMFillSignTextPanel: KMPropertiesPanelSubViewController {
     // MARK: Actions
     
     @IBAction func fontAlignAction(_ sender: NSButton) {
+        leftVC.state = .Norm
+        centerVC.state = .Norm
+        rightVC.state = .Norm
         if (sender == leftVC.button) {
+            leftVC.state = .Sel
             annotationModel.setAlignment(.left)
         } else if (sender == centerVC.button) {
+            centerVC.state = .Sel
             annotationModel.setAlignment(.center)
         } else if (sender == rightVC.button) {
+            rightVC.state = .Sel
             annotationModel.setAlignment(.right)
         }
         refreshUI()

+ 36 - 0
PDF Office/PDF Office/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/KMPropertiesPanelSubViewController.swift

@@ -40,4 +40,40 @@ import Cocoa
             }
         }
     }
+    
+    func isTheSameColor(_ color1: NSColor, anotherColor color2: NSColor) -> Bool {
+        if color1.cgColor.numberOfComponents != color2.cgColor.numberOfComponents {
+            return false
+        }
+        let component = color1.cgColor.components
+        let component1 = color2.cgColor.components
+        if component == nil || component1 == nil {
+            return false
+        }
+        if component![0] != component1![0] {
+            return false
+        }
+        if component![1] != component1![1] {
+            return false
+        }
+        if color1.cgColor.numberOfComponents == 3 {
+            if component![2] != component1![2] {
+                return false
+            }
+        }
+        if color1.cgColor.numberOfComponents == 4 {
+            if component![2] != component1![2] {
+                return false
+            }
+            if component![3] != component1![3] {
+                return false
+            }
+        }
+        return true
+//        if color1.isTheSameColor(color2) {
+//            return true
+//        } else {
+//            return false
+//        }
+    }
 }

+ 2 - 0
PDF Office/PDF Office/Class/ToolsLibrary/AppKitCategories/NSColor_SKExtensions.h

@@ -88,6 +88,8 @@ enum {
 
 - (NSString *)hexString;
 
+- (BOOL)isTheSameColor:(NSColor *)color2;
+
 @end
 
 #if SDK_BEFORE(10_8)

+ 31 - 0
PDF Office/PDF Office/Class/ToolsLibrary/AppKitCategories/NSColor_SKExtensions.m

@@ -264,4 +264,35 @@
     return nil;
 }
 
+- (BOOL)isTheSameColor:(NSColor *)color2 {
+    const CGFloat *component = CGColorGetComponents(self.CGColor);
+    const CGFloat *component1 = CGColorGetComponents(color2.CGColor);
+    if (![self compareSize:component[0] :component1[0]]) {
+        return NO;
+    }
+    
+    if (![self compareSize:component[1] :component1[1]]) {
+        return NO;
+    }
+    
+    if (![self compareSize:component[2] :component1[2]]) {
+        return NO;
+    }
+    
+    if (![self compareSize:component[3] :component1[3]]) {
+        return NO;
+    }
+    return YES;
+}
+
+-(BOOL)compareSize:(CGFloat)floa1 :(CGFloat)floa2
+{
+    CGFloat t1 = [[NSString stringWithFormat:@"%.3f", floa1] floatValue];
+    CGFloat t2 = [[NSString stringWithFormat:@"%.3f", floa2] floatValue];
+    if (fabs(t1-t2)>1e-6) return NO;
+    
+    return YES;
+    
+}
+
 @end

+ 1 - 0
PDF Office/PDF Office/PDF Office-Bridging-Header.h

@@ -72,3 +72,4 @@
 #import "KMEmailSubWindowController.h"
 #import "SKInfoWindowController.h"
 #import "SKKeychain.h"
+#import "NSColor_SKExtensions.h"