Przeglądaj źródła

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

liujiajie 1 rok temu
rodzic
commit
c4f758faa8

+ 2 - 2
PDF Office/PDF Master/Base.lproj/Main.storyboard

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>

+ 31 - 4
PDF Office/PDF Master/Class/ChromiumTabs/KMBrowserWindowController.swift

@@ -787,12 +787,39 @@ extension KMBrowserWindowController {
     @IBAction func toggleCaseInsensitiveNoteSearch(_ sender: Any?) {
         KMPrint("toggleCaseInsensitiveNoteSearch ...")
     }
-    @IBAction func performFindPanelAction(_ sender: Any?) {
+    @IBAction func performFindPanelAction(_ sender: NSMenuItem) {
         KMPrint("performFindPanelAction ...")
-        if let document = self.browser.activeTabContents() as? KMMainDocument {
-            if document.isHome == false {
-                document.mainViewController?.toolbarController.showFindBar()
+        
+        var forward = true
+        var findString: String?
+
+        switch sender.tag {
+        case 1:
+            if let document = self.browser.activeTabContents() as? KMMainDocument {
+                if document.isHome == false {
+                    document.mainViewController?.toolbarController.showFindBar()
+                }
+            }
+        case 3:
+            if let document = self.browser.activeTabContents() as? KMMainDocument {
+                if document.isHome == false {
+                    document.mainViewController?.toolbarController.showFindString(forward: false)
+                }
+            }
+        case 2:
+            if let document = self.browser.activeTabContents() as? KMMainDocument {
+                if document.isHome == false {
+                    document.mainViewController?.toolbarController.showFindString(forward: true)
+                }
             }
+        case 7:
+            if let document = self.browser.activeTabContents() as? KMMainDocument {
+                if document.isHome == false {
+                    document.mainViewController?.toolbarController.showAllAction()
+                }
+            }
+        default: break
+            
         }
     }
     @IBAction func scrollUp(_ sender: Any?) {

+ 3 - 3
PDF Office/PDF Master/Class/PDFTools/AddPassword/VC/KMBatchOperateAddPasswordViewController.xib

@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMBatchOperateAddPasswordViewController" customModule="PDF_Master" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMBatchOperateAddPasswordViewController" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
                 <outlet property="actionButton" destination="6pu-SN-0Ge" id="yB9-Xh-Yoi"/>
                 <outlet property="fileAuthorLabel" destination="5Ia-uJ-1zk" id="rYR-7F-PxF"/>

+ 332 - 471
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/Split/View/KMSecondaryPDFView.swift

@@ -20,20 +20,52 @@ class KMSecondaryPDFView: CPDFView {
         }
     }
     
-    var synchronizedPDFView: CPDFView?
+    private var _synchronizedPDFView: CPDFView?
+    var synchronizedPDFView: CPDFView? {
+        get {
+            return self._synchronizedPDFView
+        }
+        set {
+            if self._synchronizedPDFView != newValue {
+                if self.synchronizeZoom {
+                    self._stopObservingSynchronizedPDFView()
+                }
+                self._synchronizedPDFView = newValue
+                if self.synchronizeZoom {
+                    self._startObservingSynchronizedPDFView()
+                }
+            }
+        }
+    }
+    
     var synchronizeZoom = false
     var switching = false
-    var selectsText = false
+    private var _selectsText = false
+    var selectsText: Bool {
+        get {
+            return self._selectsText
+        }
+        set {
+            if self._selectsText != newValue {
+                self._selectsText = newValue
+                if newValue == false {
+//                    [self setCurrentSelection:RUNNING_AFTER(10_11) ? [[[PDFSelection alloc] initWithDocument:[self document]] autorelease] : nil];
+                    self.currentSelection = CPDFSelection(document: self.document)
+                }
+                self.toolModeButton?.state = self.selectsText ? .on : .off
+//                [[NSUserDefaults standardUserDefaults] setBool:selectsText forKey:SKLastSecondarySelectsTextKey];
+            }
+        }
+    }
+    
     var startScale: CGFloat = 0.0
     
     
     private var SKDefaultScaleMenuLabels = ["=", "Auto", "10%", "20%", "25%", "35%", "50%", "60%", "71%", "85%", "100%", "120%", "141%", "170%", "200%", "300%", "400%", "600%", "800%", "1000%", "1200%", "1400%", "1700%", "2000%"]
     private var SKDefaultScaleMenuFactors = [0.0, 0.0, 0.1, 0.2, 0.25, 0.35, 0.5, 0.6, 0.71, 0.85, 1.0, 1.2, 1.41, 1.7, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 17.0, 20.0]
-
     
 //    #define SKMinDefaultScaleMenuFactor (SKDefaultScaleMenuFactors[2])
     private var SKMinDefaultScaleMenuFactor = 0.1
-//    #define SKDefaultScaleMenuFactorsCount (sizeof(SKDefaultScaleMenuFactors) / sizeof(CGFloat))
     private var SKDefaultScaleMenuFactorsCount = 24
     
     
@@ -47,6 +79,12 @@ class KMSecondaryPDFView: CPDFView {
         // Drawing code here.
     }
     
+    deinit {
+        KMPrint("KMSecondaryPDFView deinit.")
+        
+        NotificationCenter.default.removeObserver(self)
+    }
+    
     override init(frame frameRect: NSRect) {
         super.init(frame: frameRect)
         
@@ -67,14 +105,12 @@ class KMSecondaryPDFView: CPDFView {
         self.synchronizedPDFView = nil
         self.synchronizeZoom = false
 //        self.selectsText = [[NSUserDefaults standardUserDefaults] boolForKey:SKLastSecondarySelectsTextKey];
-//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePageChangedNotification:)
-//                                                     name:PDFViewPageChangedNotification object:self];
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(handlePageChangedNotification), name: NSNotification.Name.CPDFViewPageChanged, object: self)
 //        if ([PDFView instancesRespondToSelector:@selector(magnifyWithEvent:)] == NO || [PDFView instanceMethodForSelector:@selector(magnifyWithEvent:)] == [NSView instanceMethodForSelector:@selector(magnifyWithEvent:)])
 //            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePDFViewScaleChangedNotification:)
 //                                                         name:PDFViewScaleChangedNotification object:self];
-//        [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
-        
-        
+        NotificationCenter.default.addObserver(self, selector: #selector(themeChanged), name: NSApplication.interfaceThemeChangedNotification, object: nil)
     }
     
     private func _initControlView() {
@@ -129,8 +165,8 @@ class KMSecondaryPDFView: CPDFView {
             self.scalePopUpButton?.refusesFirstResponder = true
 
             // hook it up
-//            [scalePopUpButton setTarget:self];
-//            [scalePopUpButton setAction:@selector(scalePopUpAction:)];
+            self.scalePopUpButton?.target = self
+            self.scalePopUpButton?.action = #selector(scalePopUpAction)
         }
         
         if (self.pagePopUpButton == nil) {
@@ -145,15 +181,14 @@ class KMSecondaryPDFView: CPDFView {
             // set a suitable font, the control size is 0, 1 or 2
             self.pagePopUpButton?.font = .toolTipsFont(ofSize: CONTROL_FONT_SIZE)
             
-//            [self reloadPagePopUpButton];
+            self.reloadPagePopUpButton()
 
             // don't let it become first responder
             self.pagePopUpButton?.refusesFirstResponder = true
 
             // hook it up
-//            [pagePopUpButton setTarget:self];
-//            [pagePopUpButton setAction:@selector(pagePopUpAction:)];
-            
+            self.pagePopUpButton?.target = self
+            self.pagePopUpButton?.action = #selector(pagePopUpAction)
         }
         
         if (self.toolModeButton == nil) {
@@ -163,15 +198,16 @@ class KMSecondaryPDFView: CPDFView {
             self.toolModeButton?.setButtonType(.onOff)
             self.toolModeButton?.bezelStyle = .texturedSquare
 //            self.toolModeButton?.image = NSImage(named: SKImageNameTextToolAdorn)
+            self.toolModeButton?.image = NSImage(named: "TextToolAdorn")
             
-//            self.toolModeButton?.state = self.selectsText
+            self.toolModeButton?.state = self.selectsText ? .on : .off
             
             // don't let it become first responder
             self.toolModeButton?.refusesFirstResponder = true
             
             // hook it up
-//            [toolModeButton setTarget:self];
-//            [toolModeButton setAction:@selector(toolModeButtonAction:)];
+            self.toolModeButton?.target = self
+            self.toolModeButton?.action = #selector(toolModeButtonAction)
         }
         
         if (self._controlView == nil) {
@@ -207,371 +243,233 @@ class KMSecondaryPDFView: CPDFView {
                     super.autoScales = false
                 }
                 super.scaleFactor = self.synchronizedPDFView != nil ? self.synchronizedPDFView!.scaleFactor : 1.0
-//                [self startObservingSynchronizedPDFView];
+                self._startObservingSynchronizedPDFView()
                 if (flag) {
                     self.scalePopUpButton?.selectItem(at: 0)
                 }
             } else {
-//                [self stopObservingSynchronizedPDFView];
-//                [self setScaleFactor:[self scaleFactor] adjustPopup:flag];
+                self._stopObservingSynchronizedPDFView()
+                self.setScaleFactor(self.scaleFactor, adjustPopup: flag)
             }
             self.switching = savedSwitching
         }
     }
     
-    /*
-     static NSString *SKDefaultScaleMenuLabels[] = {@"=", @"Auto", @"10%", @"20%", @"25%", @"35%", @"50%", @"60%", @"71%", @"85%", @"100%", @"120%", @"141%", @"170%", @"200%", @"300%", @"400%", @"600%", @"800%", @"1000%", @"1200%", @"1400%", @"1700%", @"2000%"};
-     static CGFloat SKDefaultScaleMenuFactors[] = {0.0, 0.0, 0.1, 0.2, 0.25, 0.35, 0.5, 0.6, 0.71, 0.85, 1.0, 1.2, 1.41, 1.7, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 17.0, 20.0};
-
-     #define SKMinDefaultScaleMenuFactor (SKDefaultScaleMenuFactors[2])
-     #define SKDefaultScaleMenuFactorsCount (sizeof(SKDefaultScaleMenuFactors) / sizeof(CGFloat))
-
-     #define CONTROL_FONT_SIZE 10.0
-     #define CONTROL_HEIGHT 15.0
-     #define CONTROL_WIDTH_OFFSET 20.0
-
-     - (void)commonInitialization {
-         scalePopUpButton = nil;
-         pagePopUpButton = nil;
-         synchronizedPDFView = nil;
-         synchronizeZoom = NO;
-         selectsText = [[NSUserDefaults standardUserDefaults] boolForKey:SKLastSecondarySelectsTextKey];
-         
-         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePageChangedNotification:)
-                                                      name:PDFViewPageChangedNotification object:self];
-         if ([PDFView instancesRespondToSelector:@selector(magnifyWithEvent:)] == NO || [PDFView instanceMethodForSelector:@selector(magnifyWithEvent:)] == [NSView instanceMethodForSelector:@selector(magnifyWithEvent:)])
-             [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePDFViewScaleChangedNotification:)
-                                                          name:PDFViewScaleChangedNotification object:self];
-         [NSDistributedNotificationCenter.defaultCenter addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object: nil];
-     }
-
-     - (void)themeChanged:(NSNotification *)notification {
-         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-             [self updateViewColor];
-         });
-     }
-
-     - (id)initWithFrame:(NSRect)frameRect {
-         self = [super initWithFrame:frameRect];
-         if (self) {
-             [self commonInitialization];
-         }
-         return self;
-     }
-
-     - (id)initWithCoder:(NSCoder *)decoder {
-         self = [super initWithCoder:decoder];
-         if (self) {
-             [self commonInitialization];
-         }
-         return self;
-     }
-
-     - (void)dealloc {
-         [[NSNotificationCenter defaultCenter] removeObserver:self];
-         SKDESTROY(synchronizedPDFView);
-         SKDESTROY(scalePopUpButton);
-         SKDESTROY(pagePopUpButton);
-         SKDESTROY(toolModeButton);
-         SKDESTROY(controlView);
-         [super dealloc];
-     }
-
-     - (void)setDocument:(PDFDocument *)document {
-         if ([self document])
-             [[NSNotificationCenter defaultCenter] removeObserver:self name:PDFDocumentDidUnlockNotification object:[self document]];
-         [super setDocument:document];
-         [self reloadPagePopUpButton];
-         if (document && [document isLocked])
-             [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDocumentDidUnlockNotification:)
-                                                          name:PDFDocumentDidUnlockNotification object:document];
-     }
-
-     - (void)updateViewColor {
-         self.controlView.wantsLayer = YES;
-         if([KMAppearance isDarkMode]){
-             self.controlView.layer.backgroundColor = [NSColor colorWithRed:37/255. green:37/255. blue:38/255. alpha:1].CGColor;
-         } else {
-             self.controlView.layer.backgroundColor = [NSColor colorWithRed:250/255. green:250/255. blue:250/255. alpha:1].CGColor;
-         }
-         self.controlView.layer.backgroundColor = [KMAppearance KMColor_Layout_L0].CGColor;
-     }
-
-     #pragma mark Popup buttons
-
-
-
-     - (void)reloadPagePopUpButton {
-         NSArray *labels = [[self document] pageLabels];
-         NSUInteger count = [pagePopUpButton numberOfItems];
-         NSSize size = NSMakeSize(1000.0, 1000.0);
-         NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[pagePopUpButton font], NSFontAttributeName, nil];
-         __block CGFloat maxWidth = 0.0;
-         __block NSUInteger maxIndex = 0;
-         
-         while (count--)
-             [pagePopUpButton removeItemAtIndex:count];
-         
-         if ([labels count] > 0) {
-             [labels enumerateObjectsUsingBlock:^(id label, NSUInteger i, BOOL *stop) {
-                 CGFloat width = NSWidth([label boundingRectWithSize:size options:0 attributes:attrs]);
-                 if (width > maxWidth) {
-                     maxWidth = width;
-                     maxIndex = i;
-                 }
-                 [pagePopUpButton addItemWithTitle:label];
-             }];
-             
-             sizePopUpToItemAtIndex(pagePopUpButton, maxIndex);
-             
-             [pagePopUpButton selectItemAtIndex:[[self currentPage] pageIndex]];
-             
-             if (controlView)
-                 [controlView setFrameSize:NSMakeSize(NSWidth([toolModeButton frame]) + NSWidth([pagePopUpButton frame]) + NSWidth([scalePopUpButton frame]), NSHeight([controlView frame]))];
-         }
-     }
-
-     - (NSView *)controlView {
-         
-         if (scalePopUpButton == nil) {
-
-             // create it
-             scalePopUpButton = [[NSPopUpButton allocWithZone:[self zone]] initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
-             
-             [[scalePopUpButton cell] setControlSize:NSSmallControlSize];
-             [scalePopUpButton setBordered:NO];
-             [scalePopUpButton setEnabled:YES];
-             [scalePopUpButton setRefusesFirstResponder:YES];
-             [[scalePopUpButton cell] setUsesItemFromMenu:YES];
-
-             // set a suitable font, the control size is 0, 1 or 2
-             [scalePopUpButton setFont:[NSFont toolTipsFontOfSize:CONTROL_FONT_SIZE]];
-
-             NSUInteger cnt, numberOfDefaultItems = SKDefaultScaleMenuFactorsCount;
-             id curItem;
-             NSString *label;
-             CGFloat width, maxWidth = 0.0;
-             NSSize size = NSMakeSize(1000.0, 1000.0);
-             NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:[scalePopUpButton font], NSFontAttributeName, nil];
-             NSUInteger maxIndex = 0;
-             
-             // fill it
-             for (cnt = 0; cnt < numberOfDefaultItems; cnt++) {
-                 label = [[NSBundle mainBundle] localizedStringForKey:SKDefaultScaleMenuLabels[cnt] value:@"" table:@"ZoomValues"];
-                 width = NSWidth([label boundingRectWithSize:size options:0 attributes:attrs]);
-                 if (width > maxWidth) {
-                     maxWidth = width;
-                     maxIndex = cnt;
-                 }
-                 [scalePopUpButton addItemWithTitle:label];
-                 curItem = [scalePopUpButton itemAtIndex:cnt];
-                 [curItem setRepresentedObject:(SKDefaultScaleMenuFactors[cnt] > 0.0 ? [NSNumber numberWithDouble:SKDefaultScaleMenuFactors[cnt]] : nil)];
-             }
-             // select the appropriate item, adjusting the scaleFactor if necessary
-             if([self synchronizeZoom])
-                 [self setSynchronizeZoom:YES adjustPopup:YES];
-             else if([self autoScales])
-                 [self setScaleFactor:0.0 adjustPopup:YES];
-             else
-                 [self setScaleFactor:[self scaleFactor] adjustPopup:YES];
-
-             // Make sure the popup is big enough to fit the largest cell
-             sizePopUpToItemAtIndex(scalePopUpButton, maxIndex);
-
-             // don't let it become first responder
-             [scalePopUpButton setRefusesFirstResponder:YES];
-
-             // hook it up
-             [scalePopUpButton setTarget:self];
-             [scalePopUpButton setAction:@selector(scalePopUpAction:)];
-             
-         }
-         
-         if (pagePopUpButton == nil) {
-             
-             // create it
-             pagePopUpButton = [[NSPopUpButton allocWithZone:[self zone]] initWithFrame:NSMakeRect(0.0, 0.0, 1.0, 1.0) pullsDown:NO];
-             
-             [[pagePopUpButton cell] setControlSize:NSSmallControlSize];
-             [pagePopUpButton setBordered:NO];
-             [pagePopUpButton setEnabled:YES];
-             [pagePopUpButton setRefusesFirstResponder:YES];
-             [[pagePopUpButton cell] setUsesItemFromMenu:YES];
-
-             // set a suitable font, the control size is 0, 1 or 2
-             [pagePopUpButton setFont:[NSFont toolTipsFontOfSize:CONTROL_FONT_SIZE]];
-             
-             [self reloadPagePopUpButton];
-
-             // don't let it become first responder
-             [pagePopUpButton setRefusesFirstResponder:YES];
-
-             // hook it up
-             [pagePopUpButton setTarget:self];
-             [pagePopUpButton setAction:@selector(pagePopUpAction:)];
-             
-         }
-         
-         if (toolModeButton == nil) {
-             
-             // create it
-             toolModeButton = [[NSButton alloc] initWithFrame:NSMakeRect(0.0, 0.0, 17.0, 15.0)];
-             
-             [toolModeButton setButtonType:NSOnOffButton];
-             [toolModeButton setBezelStyle:NSBezelStyleTexturedSquare];
-             [toolModeButton setImage:[NSImage imageNamed:SKImageNameTextToolAdorn]];
-             
-             [toolModeButton setState:[self selectsText]];
-             
-             // don't let it become first responder
-             [toolModeButton setRefusesFirstResponder:YES];
-             
-             // hook it up
-             [toolModeButton setTarget:self];
-             [toolModeButton setAction:@selector(toolModeButtonAction:)];
-             
-         }
-         
-         if (controlView == nil) {
-             
-             NSRect toolRect = [toolModeButton frame], pageRect = [pagePopUpButton frame], scaleRect = [scalePopUpButton frame], tmpRect;
-             
-             controlView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, NSWidth(toolRect) + NSWidth(pageRect) + NSWidth(scaleRect), CONTROL_HEIGHT)];
-             
-             [toolModeButton setAutoresizingMask:NSViewMaxXMargin | NSViewMaxYMargin];
-             [pagePopUpButton setAutoresizingMask:NSViewMaxXMargin | NSViewMaxYMargin];
-             [scalePopUpButton setAutoresizingMask:NSViewMinXMargin | NSViewMaxYMargin];
-             NSDivideRect([controlView bounds], &toolRect, &tmpRect, NSWidth(toolRect), NSMinXEdge);
-             NSDivideRect(tmpRect, &pageRect, &scaleRect, NSWidth(pageRect), NSMinXEdge);
-             [toolModeButton setFrame:toolRect];
-             [pagePopUpButton setFrame:pageRect];
-             [scalePopUpButton setFrame:scaleRect];
-             [controlView addSubview:toolModeButton];
-             [controlView addSubview:pagePopUpButton];
-             [controlView addSubview:scalePopUpButton];
-             controlView.wantsLayer = YES;
-             
-         }
-
-         return controlView;
-     }
-
-     - (void)scalePopUpAction:(id)sender {
-         NSNumber *selectedFactorObject = [[sender selectedItem] representedObject];
-         if (selectedFactorObject)
-             [self setScaleFactor:[selectedFactorObject doubleValue] adjustPopup:NO];
-         else if ([sender indexOfSelectedItem] == 0)
-             [self setSynchronizeZoom:YES adjustPopup:NO];
-         else
-             [self setAutoScales:YES adjustPopup:NO];
-     }
-
-     - (void)pagePopUpAction:(id)sender {
-         [self goToPage:[[self document] pageAtIndex:[sender indexOfSelectedItem]]];
-     }
-
-     - (void)toolModeButtonAction:(id)sender {
-         [self setSelectsText:[(NSButton *)sender state]];
-     }
-
-     - (void)setSynchronizedPDFView:(PDFView *)newSynchronizedPDFView {
-         if (synchronizedPDFView != newSynchronizedPDFView) {
-             if ([self synchronizeZoom])
-                 [self stopObservingSynchronizedPDFView];
-             [synchronizedPDFView release];
-             synchronizedPDFView = [newSynchronizedPDFView retain];
-             if ([self synchronizeZoom])
-                 [self startObservingSynchronizedPDFView];
-         }
-     }
-
-     - (void)setSynchronizeZoom:(BOOL)newSync {
-         [self setSynchronizeZoom:newSync adjustPopup:YES];
-     }
-
-     - (void)setSynchronizeZoom:(BOOL)newSync adjustPopup:(BOOL)flag {
-         if (synchronizeZoom != newSync) {
-             BOOL savedSwitching = switching;
-             switching = YES;
-             synchronizeZoom = newSync;
-             if (newSync) {
-                 if ([self autoScales])
-                     [super setAutoScales:NO];
-                 [super setScaleFactor:synchronizedPDFView ? [synchronizedPDFView scaleFactor] : 1.0];
-                 [self startObservingSynchronizedPDFView];
-                 if (flag)
-                     [scalePopUpButton selectItemAtIndex:0];
-             } else {
-                 [self stopObservingSynchronizedPDFView];
-                 [self setScaleFactor:[self scaleFactor] adjustPopup:flag];
-             }
-             switching = savedSwitching;
-         }
-     }
-
-
-
-
-
-     - (void)setSelectsText:(BOOL)newSelectsText {
-         if (newSelectsText != selectsText) {
-             selectsText = newSelectsText;
-             if (selectsText == NO)
-                 [self setCurrentSelection:RUNNING_AFTER(10_11) ? [[[PDFSelection alloc] initWithDocument:[self document]] autorelease] : nil];
-             [toolModeButton setState:selectsText ? NSOnState : NSOffState];
-             [[NSUserDefaults standardUserDefaults] setBool:selectsText forKey:SKLastSecondarySelectsTextKey];
-         }
-     }
-
-     - (IBAction)zoomIn:(id)sender{
-         NSUInteger numberOfDefaultItems = SKDefaultScaleMenuFactorsCount;
-         NSUInteger i = [self lowerIndexForScaleFactor:[self scaleFactor]];
-         if (i < numberOfDefaultItems - 1) i++;
-         [self setScaleFactor:SKDefaultScaleMenuFactors[i] adjustPopup:YES];
-     }
-
-     - (IBAction)zoomOut:(id)sender{
-         NSUInteger i = [self upperIndexForScaleFactor:[self scaleFactor]];
-         if (i > 2) i--;
-         [self setScaleFactor:SKDefaultScaleMenuFactors[i] adjustPopup:YES];
-     }
-
-     - (BOOL)canZoomIn{
-         if ([super canZoomIn] == NO)
-             return NO;
-         NSUInteger numberOfDefaultItems = SKDefaultScaleMenuFactorsCount;
-         NSUInteger i = [self lowerIndexForScaleFactor:[self scaleFactor]];
-         return i < numberOfDefaultItems - 1;
-     }
-
-     - (BOOL)canZoomOut{
-         if ([super canZoomOut] == NO)
-             return NO;
-         NSUInteger i = [self upperIndexForScaleFactor:[self scaleFactor]];
-         return i > 2;
-     }
-
-     - (BOOL)performKeyEquivalent:(NSEvent *)theEvent { return NO; }
-
-     - (IBAction)toggleDisplayAsBookFromMenu:(id)sender {
-         [self setDisplaysAsBook:[self displaysAsBook] == NO];
-     }
+    @objc func themeChanged(_ notification: Notification) {
+        DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
+            self.updateViewColor()
+        }
+    }
+    
+    override var document: CPDFDocument! {
+        get {
+            return super.document
+        }
+        set {
+            if super.document != nil {
+                NotificationCenter.default.removeObserver(self, name: NSNotification.Name.CPDFDocumentDidUnlock, object: self.document)
+            }
+            super.document = newValue
+            self.reloadPagePopUpButton()
+            
+            if newValue != nil && newValue.isLocked {
+                NotificationCenter.default.addObserver(self, selector: #selector(handleDocumentDidUnlockNotification), name: NSNotification.Name.CPDFDocumentDidUnlock, object: newValue)
+            }
+        }
+    }
+    
+    func updateViewColor() {
+        self.controlView?.wantsLayer = true
+        if KMAppearance.isDarkMode() {
+            self.controlView?.layer?.backgroundColor = NSColor(red: 37/255.0, green: 37/255.0, blue: 38/255.0, alpha: 1).cgColor
+        } else {
+            self.controlView?.layer?.backgroundColor = NSColor(red: 250/255.0, green: 250/255.0, blue: 250/255.0, alpha: 1).cgColor
+        }
+        self.controlView?.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
+    }
+    
+    // MARK: - Popup buttons
+    
+    func reloadPagePopUpButton() {
+        let labels = self.document?.pageLabels() ?? []
+        var count = self.pagePopUpButton?.numberOfItems ?? 0
+        var size = NSMakeSize(1000, 1000)
+        var attrs = [NSAttributedString.Key.font : self.pagePopUpButton?.font ?? NSFont.toolTipsFont(ofSize: CONTROL_FONT_SIZE)]
+        var maxWidth = 0.0
+        var maxIndex = 0
+        
+//        while (count--)
+//            [pagePopUpButton removeItemAtIndex:count];
+        while count > 0 {
+            count -= 1
+            self.pagePopUpButton?.removeItem(at: count)
+        }
+        
+        if labels.count > 0 {
+            for (i, label) in labels.enumerated() {
+                var width = NSWidth(label.boundingRect(with: size, options: NSString.DrawingOptions(rawValue: 0), attributes: attrs))
+                if (width > maxWidth) {
+                    maxWidth = width;
+                    maxIndex = i
+                }
+                self.pagePopUpButton?.addItem(withTitle: label)
+            }
+            
+            self.sizePopUpToItemAtIndex(self.pagePopUpButton, anIndex: UInt(maxIndex))
+            self.pagePopUpButton?.selectItem(at: self.currentPageIndex)
+            if (self.controlView != nil) {
+                //                [controlView setFrameSize:NSMakeSize(NSWidth([toolModeButton frame]) + NSWidth([pagePopUpButton frame]) + NSWidth([scalePopUpButton frame]), NSHeight([controlView frame]))];
+                let w = NSWidth(self.toolModeButton?.frame ?? .zero) + NSWidth(self.pagePopUpButton?.frame ?? .zero) + NSWidth(self.scalePopUpButton?.frame ?? .zero)
+                let h = NSHeight(self.controlView?.frame ?? .zero)
+                self.controlView?.setFrameSize(NSMakeSize(w, h))
+            }
+        }
+    }
 
-     - (IBAction)toggleDisplayPageBreaksFromMenu:(id)sender {
-         [self setDisplaysPageBreaks:[self displaysPageBreaks] == NO];
+    @objc func scalePopUpAction(_ sender: NSPopUpButton) {
+        let selectedFactorObject = sender.selectedItem?.representedObject
+        if (selectedFactorObject != nil) {
+            self.setScaleFactor(selectedFactorObject as! CGFloat, adjustPopup: false)
+        } else if (sender.indexOfSelectedItem == 0) {
+            self.setSynchronizeZoom(true, adjustPopup: false)
+        } else {
+            self.setAutoScales(true, adjustPopup: false)
+        }
      }
 
-     - (void)doActualSize:(id)sender {
-         [self setScaleFactor:1.0];
+    @objc func pagePopUpAction(_ sender: NSPopUpButton) {
+        self.go(toPageIndex: sender.indexOfSelectedItem, animated: false)
      }
 
-     - (void)doPhysicalSize:(id)sender {
-         [self setPhysicalScaleFactor:1.0];
+    @objc func toolModeButtonAction(_ sender: NSButton) {
+        self.selectsText = sender.state == .on
      }
+    
+    override var canZoomIn: Bool {
+        if super.canZoomIn == false {
+            return false
+        }
+        
+        let numberOfDefaultItems = SKDefaultScaleMenuFactorsCount
+        let i = self.lowerIndex(for: self.scaleFactor)
+        return i < numberOfDefaultItems - 1
+    }
+    
+    override func zoomIn(_ sender: Any!) {
+        let numberOfDefaultItems = SKDefaultScaleMenuFactorsCount
+        var i = self.lowerIndex(for: self.scaleFactor)
+        if i < numberOfDefaultItems-1 {
+           i += 1
+        }
+        self.setScaleFactor(SKDefaultScaleMenuFactors[Int(i)], adjustPopup: true)
+    }
+    
+    override var canZoomOut: Bool {
+        if super.canZoomOut == false {
+            return false
+        }
+        let i = self.upperIndex(for: self.scaleFactor)
+        return i > 2
+    }
+    
+    override func zoomOut(_ sender: Any!) {
+        var i = self.upperIndex(for: self.scaleFactor)
+        if i > 2 {
+           i -= 1
+        }
+        self.setScaleFactor(SKDefaultScaleMenuFactors[Int(i)], adjustPopup: true)
+    }
+    
+    override func performKeyEquivalent(with event: NSEvent) -> Bool {
+        return false
+    }
+    
+    @IBAction func toggleDisplayAsBookFromMenu(_ sender: AnyObject?) {
+        self.displaysAsBook = !self.displaysAsBook
+    }
+    
+    @IBAction func toggleDisplayPageBreaksFromMenu(_ sender: AnyObject?) {
+        self.displaysPageBreaks = !self.displaysPageBreaks
+    }
+    
+    @objc func doActualSize(_ sender: AnyObject?) {
+        self.scaleFactor = 1.0
+    }
+    
+    @objc func doPhysicalSize(_ sender: AnyObject?) {
+//        [self setPhysicalScaleFactor:1.0];
+    }
+    
+    @objc func changeToolMode(_ sender: NSMenuItem?) {
+        self.selectsText = ((sender?.tag ?? 0) == 1)
+    }
+    
+    override func menu(for event: NSEvent) -> NSMenu? {
+//        static NSSet *selectionActions = nil;
+//        if (selectionActions == nil)
+//            selectionActions = [[NSSet alloc] initWithObjects:@"copy:", @":", @":", @":", @":", nil];
+        var selectionActions = ["copy:", "_searchInSpotlight:", "_searchInGoogle:", "_searchInDictionary:", "_revealSelection:"]
+        var menu = super.menu(for: event)
+        var item: NSMenuItem?
+        
+        if self.selectsText == false {
+            self.currentSelection = CPDFSelection(document: self.document)
+            while let cnt = menu?.numberOfItems, cnt > 0 {
+//            while ([menu numberOfItems]) {
+//                item = [menu itemAtIndex:0];
+                item = menu?.item(at: 0)
+                if item!.isSeparatorItem || selectionActions.contains(NSStringFromSelector(item!.action!)) {
+                    //                if ([item isSeparatorItem] || [self validateMenuItem:item] == NO || [selectionActions containsObject:NSStringFromSelector([item action])])
+                    //                    [menu removeItemAtIndex:0];
+                    menu?.removeItem(at: 0)
+                } else {
+                    break
+                }
+            }
+        }
+        
+        var i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("_setDoublePageScrolling:"))
+        if (i == -1) {
+            i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("_toggleContinuous:"))
+        }
+        if let data = i, data != -1 {
+//            var displayMode = self.displayViewMode()
+//            [menu insertItem:[NSMenuItem separatorItem] atIndex:++i];
+            i! += 1
+            menu?.insertItem(.separator(), at: i!)
+//            if (displayMode == kPDFDisplayTwoUp || displayMode == kPDFDisplayTwoUpContinuous) {
+//                item = [menu insertItemWithTitle:NSLocalizedString(@"Book Mode", @"Menu item title") action:@selector(toggleDisplayAsBookFromMenu:) keyEquivalent:@"" atIndex:++i];
+//                [item setTarget:self];
+//            }
+//            item = [menu insertItemWithTitle:NSLocalizedString(@"Page Breaks", @"Menu item title") action:@selector(toggleDisplayPageBreaksFromMenu:) keyEquivalent:@"" atIndex:++i];
+            i! += 1
+            item = menu?.insertItem(withTitle: KMLocalizedString("Page Breaks", "Menu item title"), action: #selector(toggleDisplayPageBreaksFromMenu), target: self, at: i!)
+        }
+        
+        i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("_setActualSize:"))
+        if let data = i, data != -1 {
+            menu?.item(at: i!)?.action = #selector(doActualSize)
+            item = menu?.insertItem(withTitle: KMLocalizedString("Physical Size", "Menu item title"), action: #selector(doPhysicalSize), target: self, at: i! + 1)
+//            [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
+//            [item setAlternate:YES];
+        }
+        
+//        i = i == NSNotFound || i == 0 ? [menu numberOfItems] : i - 1;
+        i = menu?.indexOfItem(withTarget: self, andAction: NSSelectorFromString("goToNextPage:"))
+        if i == NSNotFound || i == 0 {
+            i = menu?.numberOfItems
+        } else if i != nil {
+            i = i! - 1
+        }
 
-     - (void)changeToolMode:(id)sender {
-         [self setSelectsText:(BOOL)[sender tag]];
-     }
+        menu?.insertItem(withTitle: KMLocalizedString("Scroll Tool", "Menu item title"), action: #selector(changeToolMode), target: self, at: i!)
+        menu?.insertItem(withTitle: KMLocalizedString("Text Tool", "Menu item title"), action: #selector(changeToolMode), target: self, at: i!)
+        menu?.insertItem(.separator(), at: i!)
+        
+        return menu
+    }
+    
+    /*
 
      // we don't want to steal the printDocument: action from the responder chain
      - (void)printDocument:(id)sender{}
@@ -580,77 +478,6 @@ class KMSecondaryPDFView: CPDFView {
          return aSelector != @selector(printDocument:) && [super respondsToSelector:aSelector];
      }
 
-     - (NSMenu *)menuForEvent:(NSEvent *)theEvent {
-         static NSSet *selectionActions = nil;
-         if (selectionActions == nil)
-             selectionActions = [[NSSet alloc] initWithObjects:@"copy:", @"_searchInSpotlight:", @"_searchInGoogle:", @"_searchInDictionary:", @"_revealSelection:", nil];
-         NSMenu *menu = [super menuForEvent:theEvent];
-         NSMenuItem *item;
-         
-         if ([self selectsText] == NO) {
-             [self setCurrentSelection:RUNNING_AFTER(10_11) ? [[[PDFSelection alloc] initWithDocument:[self document]] autorelease] : nil];
-             while ([menu numberOfItems]) {
-                 item = [menu itemAtIndex:0];
-                 if ([item isSeparatorItem] || [self validateMenuItem:item] == NO || [selectionActions containsObject:NSStringFromSelector([item action])])
-                     [menu removeItemAtIndex:0];
-                 else
-                     break;
-             }
-         }
-         
-         NSInteger i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"_setDoublePageScrolling:")];
-         if (i == -1)
-             i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"_toggleContinuous:")];
-         if (i != -1) {
-             PDFDisplayMode displayMode = [self displayMode];
-             [menu insertItem:[NSMenuItem separatorItem] atIndex:++i];
-             if (displayMode == kPDFDisplayTwoUp || displayMode == kPDFDisplayTwoUpContinuous) {
-                 item = [menu insertItemWithTitle:NSLocalizedString(@"Book Mode", @"Menu item title") action:@selector(toggleDisplayAsBookFromMenu:) keyEquivalent:@"" atIndex:++i];
-                 [item setTarget:self];
-             }
-             item = [menu insertItemWithTitle:NSLocalizedString(@"Page Breaks", @"Menu item title") action:@selector(toggleDisplayPageBreaksFromMenu:) keyEquivalent:@"" atIndex:++i];
-             [item setTarget:self];
-         }
-         i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"_setActualSize:")];
-         if (i != -1) {
-             [[menu itemAtIndex:i] setAction:@selector(doActualSize:)];
-             item = [menu insertItemWithTitle:NSLocalizedString(@"Physical Size", @"Menu item title") action:@selector(doPhysicalSize:) target:self atIndex:i + 1];
-             [item setKeyEquivalentModifierMask:NSAlternateKeyMask];
-             [item setAlternate:YES];
-         }
-         
-         i = [menu indexOfItemWithTarget:self andAction:NSSelectorFromString(@"goToNextPage:")];
-         i = i == NSNotFound || i == 0 ? [menu numberOfItems] : i - 1;
-         
-         [menu insertItemWithTitle:NSLocalizedString(@"Scroll Tool", @"Menu item title") action:@selector(changeToolMode:) target:self tag:0 atIndex:i];
-         [menu insertItemWithTitle:NSLocalizedString(@"Text Tool", @"Menu item title") action:@selector(changeToolMode:) target:self tag:1 atIndex:i];
-         [menu insertItem:[NSMenuItem separatorItem]atIndex:i];
-
-         return menu;
-     }
-
-     - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
-         if ([menuItem action] == @selector(toggleDisplayAsBookFromMenu:)) {
-             [menuItem setState:[self displaysAsBook] ? NSOnState : NSOffState];
-             return YES;
-         } else if ([menuItem action] == @selector(toggleDisplayPageBreaksFromMenu:)) {
-             [menuItem setState:[self displaysPageBreaks] ? NSOnState : NSOffState];
-             return YES;
-         } else if ([menuItem action] == @selector(doActualSize:)) {
-             [menuItem setState:fabs([self scaleFactor] - 1.0) < 0.1 ? NSOnState : NSOffState];
-             return YES;
-         } else if ([menuItem action] == @selector(doPhysicalSize:)) {
-             [menuItem setState:([self autoScales] || fabs([self physicalScaleFactor] - 1.0 ) > 0.01) ? NSOffState : NSOnState];
-             return YES;
-         } else if ([menuItem action] == @selector(changeToolMode:)) {
-             [menuItem setState:[self selectsText] == (BOOL)[menuItem tag] ? NSOnState : NSOffState];
-             return YES;
-         } else if ([[SKSecondaryPDFView superclass] instancesRespondToSelector:_cmd]) {
-             return [super validateMenuItem:menuItem];
-         }
-         return YES;
-     }
-
      #pragma mark Gestures
 
      - (void)beginGestureWithEvent:(NSEvent *)theEvent {
@@ -750,40 +577,42 @@ class KMSecondaryPDFView: CPDFView {
          else
              [super setCursorForAreaOfInterest:area];
      }
-
-     #pragma mark Notification handling
-
-     - (void)startObservingSynchronizedPDFView {
-         if (synchronizedPDFView)
-             [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSynchronizedScaleChangedNotification:)
-                                                          name:PDFViewScaleChangedNotification object:synchronizedPDFView];
-     }
-
-     - (void)stopObservingSynchronizedPDFView {
-         if (synchronizedPDFView)
-             [[NSNotificationCenter defaultCenter] removeObserver:self name:PDFViewScaleChangedNotification object:synchronizedPDFView];
-     }
-
-     - (void)handlePageChangedNotification:(NSNotification *)notification {
-         [pagePopUpButton selectItemAtIndex:[[self document] indexForPage:[self currentPage]]];
-     }
-
-     - (void)handleSynchronizedScaleChangedNotification:(NSNotification *)notification {
-         if ([self synchronizeZoom])
-             [self setScaleFactor:[synchronizedPDFView scaleFactor]];
-     }
-
-     - (void)handleDocumentDidUnlockNotification:(NSNotification *)notification {
-         [self reloadPagePopUpButton];
-     }
-
-     - (void)handlePDFViewScaleChangedNotification:(NSNotification *)notification {
-         if ([self autoScales] == NO && [self synchronizeZoom] == NO)
-             [self setScaleFactor:fmax([self scaleFactor], SKMinDefaultScaleMenuFactor) adjustPopup:YES];
-     }
-
      */
     
+    // MARK: - mark Notification handling
+    
+    private func _startObservingSynchronizedPDFView() {
+        if self.synchronizedPDFView != nil {
+            NotificationCenter.default.addObserver(self, selector: #selector(handleSynchronizedScaleChangedNotification), name: NSNotification.Name.CPDFViewScaleChanged, object: self.synchronizedPDFView)
+        }
+    }
+     
+    private func _stopObservingSynchronizedPDFView() {
+        if self.synchronizedPDFView != nil {
+            NotificationCenter.default.removeObserver(self, name: NSNotification.Name.CPDFViewScaleChanged, object: self.synchronizedPDFView)
+        }
+    }
+    
+    @objc func handlePageChangedNotification(_ notification: Notification) {
+        self.pagePopUpButton?.selectItem(at: self.currentPageIndex)
+    }
+    
+    @objc func handleSynchronizedScaleChangedNotification(_ notification: Notification) {
+        if self.synchronizeZoom {
+            self.scaleFactor = self.synchronizedPDFView?.scaleFactor ?? 0.0
+        }
+    }
+    
+    @objc func handleDocumentDidUnlockNotification(_ notification: Notification) {
+        self.reloadPagePopUpButton()
+    }
+    
+    @objc func handlePDFViewScaleChangedNotification(_ notification: Notification) {
+        if self.autoScales == false && self.synchronizeZoom == false {
+            self.setScaleFactor(fmax(self.scaleFactor, SKMinDefaultScaleMenuFactor), adjustPopup: true)
+        }
+    }
+    
     func sizePopUpToItemAtIndex(_ popUpButton: NSPopUpButton?, anIndex: UInt) {
         var i = popUpButton?.indexOfSelectedItem
         popUpButton?.selectItem(at: Int(anIndex))
@@ -821,7 +650,7 @@ class KMSecondaryPDFView: CPDFView {
             _newScaleFactor = SKDefaultScaleMenuFactors[Int(i)];
         }
         if self.autoScales {
-//            [self setAutoScales:NO adjustPopup:NO];
+            self.setAutoScales(false, adjustPopup: false)
         }
         super.scaleFactor = _newScaleFactor
         self.switching = savedSwitching
@@ -891,3 +720,35 @@ class KMSecondaryPDFView: CPDFView {
         return upper
     }
 }
+
+extension KMSecondaryPDFView: NSMenuItemValidation {
+    func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
+        let action = menuItem.action
+        if action == #selector(toggleDisplayAsBookFromMenu) {
+            menuItem.state = self.displaysAsBook ? .on : .off
+            return true
+        } else if action == #selector(toggleDisplayPageBreaksFromMenu) {
+            menuItem.state = self.displaysPageBreaks ? .on : .off
+            return true
+        } else if action == #selector(doActualSize) {
+//            [menuItem setState:fabs([self scaleFactor] - 1.0) < 0.1 ? NSOnState : NSOffState];
+            menuItem.state = (self.scaleFactor-1.0) < 0.1 ? .on : .off
+            return true
+        } else if action == #selector(doPhysicalSize) {
+//            [menuItem setState:([self autoScales] || fabs([self physicalScaleFactor] - 1.0 ) > 0.01) ? NSOffState : NSOnState];
+//            return YES;
+        } else if action == #selector(changeToolMode) {
+//            [menuItem setState:[self selectsText] == (BOOL)[menuItem tag] ? NSOnState : NSOffState];
+            if self.selectsText {
+                menuItem.state = menuItem.tag == 1 ? .on : .off
+            } else {
+                menuItem.state = menuItem.tag == 0 ? .on : .off
+            }
+            return true
+        }
+//            else if ([[SKSecondaryPDFView superclass] instancesRespondToSelector:_cmd]) {
+//            return [super validateMenuItem:menuItem];
+//        }
+        return true
+    }
+}

Plik diff jest za duży
+ 29 - 29
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/LeftSideView.xib


+ 19 - 6
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarController.swift

@@ -46,7 +46,8 @@ extension CAnnotationType {
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, scanOCRModel selectedTag:Int)
     
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, itemDidClick toolbarItem: KMToolbarItemView)
-    @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String)
+    @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String, forward: Bool)
+    @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAllAction searchString: String, forward: Bool)
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
 }
 
@@ -523,19 +524,27 @@ extension KMToolbarController {
         
         self.findSearchView.searchAction = { view, searchString, forward in
             print("searchAction")
-            self.toolbarViewController(self.mainToolBarView!, searchAction: searchString)
+            self.toolbarViewController(self.mainToolBarView!, searchAction: searchString, forward: forward)
             return true
         }
         
         self.findSearchView.showAllAction = { [unowned self] view, searchString, forward in
-            self.toolbarViewController(self.mainToolBarView!, searchAction: searchString)
+            self.toolbarViewController(self.mainToolBarView!, searchAllAction: searchString, forward: forward)
             print("showAllAction: \(searchString)")
         }
     }
     
+    func showFindString(forward: Bool) {
+        self.toolbarViewController(self.mainToolBarView!, searchAction: self.findSearchView.findString ?? "", forward: forward)
+    }
+    
+    func showAllAction() {
+        self.toolbarViewController(self.mainToolBarView!, searchAllAction: self.findSearchView.findString ?? "", forward: true)
+    }
+    
     func exitFindBar() {
         print("exitFindBar")
-        var height: Float = self.fetchHeight(type: _toolbarType)
+        var height: Float = self.fetchHeight(type: _toolbarType, isShow: false)
 
         self.delegate?.toolbarController?(self, heightOffsetChange: height)
     }
@@ -786,8 +795,12 @@ extension KMToolbarController: KMToolbarViewControllerDelegate {
         self.delegate?.toolbarViewController?(viewController, itemDidClick: toolbarItem)
     }
     
-    func toolbarViewController(_ viewController: KMToolbarViewController, searchAction searchString: String) {
-        self.delegate?.toolbarViewController?(viewController, searchAction: searchString)
+    func toolbarViewController(_ viewController: KMToolbarViewController, searchAction searchString: String, forward: Bool) {
+        self.delegate?.toolbarViewController?(viewController, searchAction: searchString, forward: forward)
+    }
+    
+    func toolbarViewController(_ viewController: KMToolbarViewController, searchAllAction searchString: String, forward: Bool) {
+        self.delegate?.toolbarViewController?(viewController, searchAllAction: searchString, forward: forward)
     }
     
     func toolbarViewController(_ viewController: KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?) {

+ 85 - 74
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarView.swift

@@ -525,80 +525,80 @@ private let KMToolbarItemSpace = 8.0
         let leftW = NSWidth(self.leftView.frame)
         let contentW = NSWidth(self.contentView.frame)
         let rightW = NSWidth(self.rightView.frame)
-//        KMPrint("width: \(leftW), \(contentW), \(rightW)")
-//        KMPrint("\(self.frame.size.width)")
+        KMPrint("width: \(leftW), \(contentW), \(rightW)")
+        KMPrint("\(self.frame.size.width)")
         
         let contentLength = leftW + contentW + rightW
-//        if (contentLength <= 0) {
-//            return
-//        }
-//        if contentLength <= self.frame.size.width {
-//            self.leftView.mas_remakeConstraints { make in
-//                make?.top.bottom().equalTo()(self)
-//                make?.left.equalTo()(self)
-//                make?.width.mas_equalTo()(leftW)
-//            }
-//            if self.centerView.superview != nil {
-//                self.centerView.mas_remakeConstraints { make in
-//                    make?.top.bottom().equalTo()(self)
-//                    make?.left.equalTo()(self.leftView.mas_right)
-////                    make?.width.mas_equalTo()(contentW)
-//                }
-//            } else {
-//                self.contentView.mas_remakeConstraints { make in
-//                    make?.top.bottom().equalTo()(self)
-//                    make?.left.equalTo()(self.leftView.mas_right)
-////                    make?.width.mas_equalTo()(contentW)
-//                }
-//            }
-//            self.rightView.mas_remakeConstraints { make in
-//                make?.top.bottom().equalTo()(self)
-//                make?.right.mas_equalTo()(0)
-////                make?.width.mas_equalTo()(rightW)
-//                if self.centerView.superview != nil {
-//                    make?.left.equalTo()(self.centerView.mas_right)
-//                } else {
-//                    make?.left.equalTo()(self.contentView.mas_right)
-//                }
-//            }
-//
-//            self.moreButton.isHidden = true
-//        } else {
-//            self.moreButton.isHidden = false
-//            self.moreButton.mas_remakeConstraints { make in
-//                make?.top.bottom().equalTo()(0)
-//                make?.width.mas_equalTo()(moreButtonWidth)
-//                make?.right.mas_equalTo()(0)
-//            }
-//
-//            if self.frame.size.width > leftW + contentW { // 能显示 left + content, right 显示不下
-//                if self.centerView.superview != nil {
-//                    self.centerView.mas_remakeConstraints { make in
-//                        make?.top.bottom().equalTo()(self)
-//                        make?.left.equalTo()(self.leftView.mas_right)
-//                        make?.width.mas_equalTo()(contentW)
-//                    }
-//                } else {
-//                    self.contentView.mas_remakeConstraints { make in
-//                        make?.top.bottom().equalTo()(self)
-//                        make?.left.equalTo()(self.leftView.mas_right)
-//                        make?.width.mas_equalTo()(contentW)
-//                    }
-//                }
-//
-//                self.rightView.mas_remakeConstraints { make in
-//                    make?.top.bottom().equalTo()(self)
-////                    make?.right.mas_equalTo()(0)
-////                    make?.width.mas_equalTo()(contentLength-self.frame.size.width)
-//
-//                    if self.centerView.superview != nil {
-//                        make?.left.equalTo()(self.centerView.mas_right)
-//                    } else {
-//                        make?.left.equalTo()(self.contentView.mas_right)
-//                    }
-//                }
-//            }
-//        }
+        if (contentLength <= 0) {
+            return
+        }
+        if contentLength <= self.frame.size.width { // 能正常显示
+            self.leftView.mas_remakeConstraints { make in
+                make?.top.bottom().equalTo()(self)
+                make?.left.equalTo()(self)
+                make?.width.mas_equalTo()(leftW)
+            }
+            if self.centerView.superview != nil {
+                self.centerView.mas_remakeConstraints { make in
+                    make?.top.bottom().equalTo()(self)
+                    make?.left.equalTo()(self.leftView.mas_right)
+//                    make?.width.mas_equalTo()(contentW)
+                }
+            } else {
+                self.contentView.mas_remakeConstraints { make in
+                    make?.top.bottom().equalTo()(self)
+                    make?.left.equalTo()(self.leftView.mas_right)
+//                    make?.width.mas_equalTo()(contentW)
+                }
+            }
+            self.rightView.mas_remakeConstraints { make in
+                make?.top.bottom().equalTo()(self)
+                make?.right.mas_equalTo()(0)
+//                make?.width.mas_equalTo()(rightW)
+                if self.centerView.superview != nil {
+                    make?.left.equalTo()(self.centerView.mas_right)
+                } else {
+                    make?.left.equalTo()(self.contentView.mas_right)
+                }
+            }
+
+            self.moreButton.isHidden = true
+        } else { // 需要显示更多
+            self.moreButton.isHidden = false
+            self.moreButton.mas_remakeConstraints { make in
+                make?.top.bottom().equalTo()(0)
+                make?.width.mas_equalTo()(moreButtonWidth)
+                make?.right.mas_equalTo()(0)
+            }
+
+            if self.frame.size.width > leftW + contentW { // 能显示 left + content, right 显示不下
+                if self.centerView.superview != nil {
+                    self.centerView.mas_remakeConstraints { make in
+                        make?.top.bottom().equalTo()(self)
+                        make?.left.equalTo()(self.leftView.mas_right)
+                        make?.width.mas_equalTo()(contentW)
+                    }
+                } else {
+                    self.contentView.mas_remakeConstraints { make in
+                        make?.top.bottom().equalTo()(self)
+                        make?.left.equalTo()(self.leftView.mas_right)
+                        make?.width.mas_equalTo()(contentW)
+                    }
+                }
+
+                self.rightView.mas_remakeConstraints { make in
+                    make?.top.bottom().equalTo()(self)
+//                    make?.right.mas_equalTo()(0)
+//                    make?.width.mas_equalTo()(contentLength-self.frame.size.width)
+
+                    if self.centerView.superview != nil {
+                        make?.left.equalTo()(self.centerView.mas_right)
+                    } else {
+                        make?.left.equalTo()(self.contentView.mas_right)
+                    }
+                }
+            }
+        }
         
 //        var frame = self.contentView.frame
 
@@ -606,7 +606,8 @@ private let KMToolbarItemSpace = 8.0
         var count = allItems.count
         var idx = count-1
         for item in allItems.reversed() {
-            if (CGRectGetMaxX(item.frame) <= self.frame.size.width-moreButtonWidth-leftButtonWidth) {
+            let tempFrame = item.superview?.convert(item.frame, to: item.superview!.superview) ?? .zero
+            if (CGRectGetMaxX(tempFrame) <= self.frame.size.width) {
                 count = idx
                 break
             }
@@ -646,13 +647,23 @@ private let KMToolbarItemSpace = 8.0
         self._invisibleItems.removeAll()
         for item in  allItems.reversed() {
             let tempFrame = item.superview?.convert(item.frame, to: item.superview!.superview) ?? .zero
-            if (CGRectGetMaxX(tempFrame) <= self.frame.size.width-moreButtonWidth-leftButtonWidth+20+20) {
+            if (CGRectGetMaxX(tempFrame) <= self.frame.size.width) {
                 item.isHidden = false
             } else {
                 item.isHidden = true
                 self._invisibleItems.append(item)
             }
         }
+        
+        if self._invisibleItems.isEmpty {
+            KMPrint("无更多菜单")
+        } else {
+            for item in self._invisibleItems {
+                KMPrint(item.itemIdentifier)
+            }
+        }
+
+//        KMPrint(self._visibleItems)
     }
     
     func reloadData() {

+ 22 - 10
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -111,7 +111,7 @@ import Cocoa
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, scanOCRModel selectedTag:Int)
     
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, itemDidClick toolbarItem: KMToolbarItemView)
-    @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String)
+    @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, searchAction searchString: String, forward: Bool)
     @objc optional func toolbarViewController(_ viewController:KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?)
 }
 
@@ -223,6 +223,14 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
         }
     }
     
+    @objc private func _menuItemAction(_ item: NSMenuItem) {
+        guard let itemId = item.representedObject as? String else {
+            NSSound.beep()
+            return
+        }
+        self.delegate?.toolbarViewController?(self, menuItemDidClick: self.toolbarItemFindItemIdentifiers(value: itemId), index: 0, info: nil)
+    }
+    
     @objc private func _comparisonAction(sender: NSMenuItem) {
         if let data = self._currentItemView {
             self.delegate?.toolbarViewController?(self, menuItemDidClick: data, index: sender.tag, info: nil)
@@ -474,7 +482,7 @@ class KMToolbarViewController: NSViewController, NSTextFieldDelegate {
                     KMPrint("按下 enter")
                     self.delegate?.toolbarViewController?(self, zoomSting: self.zoomTextField.stringValue)
                 } else if let _ = control as? NSSearchField {
-                    self.delegate?.toolbarViewController?(self, searchAction: control.stringValue)
+                    self.delegate?.toolbarViewController?(self, searchAction: control.stringValue, forward: true)
                 }
             }
             return true
@@ -1051,7 +1059,7 @@ extension KMToolbarViewController {
             item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
             
-            let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_itemAction), target: self)
+            let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_menuItemAction), target: self)
             menuItem.tag = item!.btnTag
             item?.menuFormRepresentation = menuItem
         } else if identifier == KMToolbarToolEnhancedScanIdentifier {
@@ -1153,8 +1161,8 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
-            let menuItem = NSMenuItem.init(title: NSLocalizedString("Page Display", comment: ""), action: #selector(_itemAction), target: self)
-            menuItem.tag = item!.btnTag
+            let menuItem = NSMenuItem.init(title: NSLocalizedString("Page Display", comment: ""), action: #selector(_menuItemAction), target: self)
+            menuItem.representedObject = identifier
             item?.menuFormRepresentation = menuItem
         } else if identifier == KMDocumentShareToolbarItemIdentifier {
             item?.image = NSImage(named: "KMImageNameUXIconToolbarShareNor")
@@ -1200,6 +1208,10 @@ extension KMToolbarViewController {
             titleLabel.font = KMToolbarMainItemView.textFont
             
             item?.customizeView = view
+            
+            let menuItem = NSMenuItem.init(title: NSLocalizedString("Search", comment: ""), action: #selector(_menuItemAction), target: self)
+            menuItem.representedObject = identifier
+            item?.menuFormRepresentation = menuItem
         } else if identifier == KMRightControlToolbarItemIdentifier {
             item?.image = NSImage(named: "KMImageNameUXIconBtnTriRightNor")
             item?.titleName = NSLocalizedString("Properties", comment: "")
@@ -1208,8 +1220,8 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.selectBackgroundType = .imageBox
             item?.btnAction = #selector(_itemAction)
-            let menuItem = NSMenuItem.init(title: NSLocalizedString("Properties", comment: ""), action: #selector(_itemAction), target: self)
-            menuItem.tag = item!.btnTag
+            let menuItem = NSMenuItem.init(title: NSLocalizedString("Properties", comment: ""), action: #selector(_menuItemAction), target: self)
+            menuItem.representedObject = identifier
             item?.menuFormRepresentation = menuItem
         } else if identifier == KMToolbarToolRedactItemIdentifier {
             item?.image = NSImage(named: "KMImageNameMainToolsRedact")
@@ -1233,7 +1245,7 @@ extension KMToolbarViewController {
             item?.boxImagePosition = .imageAbove
             item?.btnAction = #selector(_itemAction)
             
-            let menuItem = NSMenuItem.init(title: NSLocalizedString("Digital Sign", comment: ""), action: #selector(_itemAction), target: self)
+            let menuItem = NSMenuItem.init(title: NSLocalizedString("Digital Sign", comment: ""), action: #selector(_menuItemAction), target: self)
             menuItem.tag = item!.btnTag
             item?.menuFormRepresentation = menuItem
         }
@@ -1548,7 +1560,7 @@ extension KMToolbarViewController {
             item?.toolTip = NSLocalizedString("Recognize text from Image-based or Scanned PDF with OCR", comment: "")
             item?.btnAction = #selector(_itemAction)
             
-            let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_itemAction), target: self)
+            let menuItem = NSMenuItem.init(title: NSLocalizedString("OCR", comment: ""), action: #selector(_menuItemAction), target: self)
             menuItem.tag = item!.btnTag
             item?.menuFormRepresentation = menuItem
         } else if item?.itemIdentifier == KMToolbarConversionCreatePDFItemIdentifier {
@@ -1841,7 +1853,7 @@ extension KMToolbarViewController {
             item?.needExpandAction = true
 //            item?.btnAction = #selector(_itemAction)
             
-            let menuItem = NSMenuItem.init(title: "Bates Number", action: #selector(_itemAction), target: self)
+            let menuItem = NSMenuItem.init(title: "Bates Number", action: #selector(_menuItemAction), target: self)
             let subMenu = NSMenu()
             subMenu.addItem(title: NSLocalizedString("Side-by-Side View", comment: ""), action: #selector(_comparisonAction), target: self, tag: 1)
             subMenu.addItem(title: NSLocalizedString("Compare by File Overlay", comment: ""), action: #selector(_comparisonAction), target: self, tag: 2)

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

@@ -4124,7 +4124,10 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                 } else if toolbarItem.itemIdentifier == KMDocumentNextPageToolbarItemIdentifier {
                     self.changePDFViewGotoNextPageAction()
                 } else if toolbarItem.itemIdentifier == KMDocumentViewDisplayToolbarItemIdentifier {
-                    Swift.debugPrint("KMDocumentViewDisplayToolbarItemIdentifier ...")
+//                    Swift.debugPrint("KMDocumentViewDisplayToolbarItemIdentifier ...")
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
+                        self.toolbarController.clickItem(KMToolbarViewSettingIdentifier)
+                    }
                 } else if toolbarItem.itemIdentifier == KMLeftControlToolbarItemIdentifier {
                     toolbarItem.isSelected = !toolbarItem.isSelected
                     self.toggleLeftPane()
@@ -4138,7 +4141,6 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                 } else if itemID == KMDocumentScanOCRToolbarItemIdentifier {
                     showOCRWindow()
                 } else if itemID == KMDocumentDigitalSignToolbarItemIdentifier {
-                    Swift.debugPrint("KMDocumentDigitalSignToolbarItemIdentifier ...")
                     self.showDigitalSignWindow(withFilePathURL: self.listView.document.documentURL)
                 }
             } else {
@@ -4223,23 +4225,17 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
     
     func toolbarViewController(_ viewController: KMToolbarViewController, menuItemDidClick toolbarItem: KMToolbarItemView, index: Int, info: Any?) {
         if (toolbarItem.itemIdentifier == KMToolbarToolWatermarkItemIdentifier) {
-            KMPrint("KMToolbarToolWatermarkItemIdentifier \(index)")
             self.clickChildTool(type: .watermark, index: index)
         } else if (toolbarItem.itemIdentifier == KMToolbarToolBackgroundItemIdentifier) {
             self.clickChildTool(type: .background, index: index)
         } else if (toolbarItem.itemIdentifier == KMToolbarToolHeaderFooterItemIdentifier) {
-            KMPrint("KMToolbarToolHeaderFooterItemIdentifier \(index)")
             self.clickChildTool(type: .headerAndFooter, index: index)
         } else if (toolbarItem.itemIdentifier == KMToolbarToolBatesItemIdentifier) {
-            KMPrint("KMToolbarToolBatesItemIdentifier \(index)")
             self.clickChildTool(type: .bates, index: index)
         } else if (toolbarItem.itemIdentifier == KMToolbarComparisonItemIdentifier) {
-            KMPrint("KMToolbarComparisonItemIdentifier \(index)")
             self.clickChildTool(type: .comparison, index: index)
         } else if (toolbarItem.itemIdentifier == KMToolbarToolFormAlignIdentifier) {
-            KMPrint("KMToolbarToolFormAlignIdentifier \(index)")
         } else if (toolbarItem.itemIdentifier == KMToolbarConversionImageItemIdentifier) {
-            KMPrint("KMToolbarConversionImageItemIdentifier \(index)")
             convertToImg(index: index)
         } else if (toolbarItem.itemIdentifier == KMToolbarConversionExportImageItemIdentifier) {
             extractImageAction(num: index)
@@ -4256,8 +4252,14 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                 self.toolbarController.clickItem(KMToolbarSelectToolModeItemIdentifier)
             }
         } else if (toolbarItem.itemIdentifier == KMToolbarToolSecureItemIdentifier) {
-            KMPrint("KMToolbarToolSecureItemIdentifier \(index)")
             self.clickChildTool(type: .secure, index: index)
+        } else if toolbarItem.itemIdentifier == KMDocumentSearchToolbarItemIdentifier {
+            KMPrint("KMDocumentSearchToolbarItemIdentifier ...")
+        } else if toolbarItem.itemIdentifier == KMRightControlToolbarItemIdentifier {
+            toolbarItem.isSelected = !toolbarItem.isSelected
+            self.toggleRightPane()
+        } else if toolbarItem.itemIdentifier == KMDocumentViewDisplayToolbarItemIdentifier {
+            self.toolbarController.toolbarType = .viewSetting
         }
     }
     
@@ -4284,8 +4286,46 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
         showAllConvertWindow(convertT: convertT)
     }
     
-    func toolbarViewController(_ viewController: KMToolbarViewController, searchAction searchString: String) {
-        self.leftSideViewController.showSearchMode(searchString)
+    func toolbarViewController(_ viewController: KMToolbarViewController, searchAction searchString: String, forward: Bool) {
+        if self.searchResults.count == 0 {
+            self.search(searchString: searchString, isCase: true)
+        }
+        
+        var row = max(searchIndex - 1, 0)
+        if forward {
+            row = searchIndex + 1
+        }
+        if row >= 0 && row < self.searchResults.count && self.searchResults.count != 0 {
+            let model = self.searchResults[row]
+            if model.selection != nil {
+                self.listView.go(to: model.selection, animated: true)
+                self.listView.setHighlightedSelection(model.selection, animated: true)
+                self.listView.setNeedsDisplayAnnotationViewForVisiblePages()
+                
+                searchIndex = row
+            }
+        }
+    }
+    
+    func toolbarViewController(_ viewController: KMToolbarViewController, searchAllAction searchString: String, forward: Bool) {
+//        if self.searchResults.count == 0 {
+            self.leftSideViewController.showSearchMode(searchString)
+//        }
+        
+//        var row = max(searchIndex - 1, 0)
+//        if forward {
+//            row = searchIndex + 1
+//        }
+//        if row >= 0 && row < self.searchResults.count && self.searchResults.count != 0 {
+//            let model = self.searchResults[row]
+//            if model.selection != nil {
+//                self.listView.go(to: model.selection, animated: true)
+//                self.listView.setHighlightedSelection(model.selection, animated: true)
+//                self.listView.setNeedsDisplayAnnotationViewForVisiblePages()
+//                
+//                searchIndex = row
+//            }
+//        }
     }
 }
 

+ 38 - 15
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -71,6 +71,9 @@ let LOCKED_KEY  = "locked"
     //自动滚动
     var autoFlowOptionsSheetController: KMAutoFlowOptionsSheetController?
     
+    //Search
+    var searchIndex: Int = 0
+    
     private var _needSave = false
     var needSave: Bool {
         set {
@@ -1285,22 +1288,42 @@ let LOCKED_KEY  = "locked"
 
         controller.doneAction = { [unowned self] controller, options, attribute in
 //            let windowController_secure = self.currentWindowController as! KMSecureEncryptWindowController
-            self.view.window?.endSheet((self.currentWindowController.window)!)
-            self.currentWindowController = nil
-
-            self._secureOptions = options
-            self.documentAttribute = attribute
-            self.needSave = true
-            self.recordIsPDFDocumentEdited(type: .setPassword)
-
-            if (options.count != 0) {
-                self.showSecureSuccessTip()
-                self.recordSaveWatermarkFlag(type: .setPassword)
-            } else {
-                let alert = NSAlert()
-                alert.messageText = NSLocalizedString("Failure", comment: "")
-                alert.runModal()
+            let openPanel = NSOpenPanel()
+            openPanel.canChooseFiles = false
+            openPanel.canChooseDirectories = true
+            openPanel.canCreateDirectories = true
+            openPanel.beginSheetModal(for: NSWindow.currentWindow()) { (result) in
+                if result == NSApplication.ModalResponse.OK {
+                    for fileURL in openPanel.urls {
+                        let document = CPDFDocument(url: self.document?.documentURL)
+                        if document != nil {
+                            document!.setDocumentAttributes(attribute)
+                            let success = document!.write(to: url, withOptions: options)
+                            if success {
+                                self.view.window?.endSheet((self.currentWindowController.window)!)
+                                self.currentWindowController = nil
+                                
+                                
+                                NSWorkspace.shared.activateFileViewerSelecting([fileURL])
+                            }
+                        }
+                    }
+                }
             }
+
+//            self._secureOptions = options
+//            self.documentAttribute = attribute
+//            self.needSave = true
+//            self.recordIsPDFDocumentEdited(type: .setPassword)
+//
+//            if (options.count != 0) {
+//                self.showSecureSuccessTip()
+//                self.recordSaveWatermarkFlag(type: .setPassword)
+//            } else {
+//                let alert = NSAlert()
+//                alert.messageText = NSLocalizedString("Failure", comment: "")
+//                alert.runModal()
+//            }
         }
 
         controller.cancelAction = { [unowned self] controller in

+ 16 - 0
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -68,5 +68,21 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "2A7BEE24-DCB8-4598-B755-39E36835F0F5"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/Toolbar/KMToolbarView.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "690"
+            endingLineNumber = "690"
+            landmarkName = "toolbarCustomChangeNotification()"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>

Plik diff jest za duży
+ 1822 - 884
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/lizhe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist