Forráskód Böngészése

【综合】resetPDFToolTipRects方法调用优化

tangchao 9 hónapja
szülő
commit
3a5c7d7047

+ 7 - 7
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -244,8 +244,7 @@ NSNotificationName const CPDFListViewDisplayModeChangeNotification = @"CPDFListV
 //
     [super setDocument:document];
     
-    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetPDFToolTipRects) object:nil];
-    [self performSelector:@selector(resetPDFToolTipRects) withObject:nil afterDelay:2];
+    [self resetPDFToolTipRectsForAfterDelay];
     
     [self.window makeFirstResponder:self];
     
@@ -318,7 +317,7 @@ NSNotificationName const CPDFListViewDisplayModeChangeNotification = @"CPDFListV
             [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewToolModeChangeNotification object:self];
         });
         [self resetPDFViewAnnotation];
-        [self resetPDFToolTipRects];
+        [self resetPDFToolTipRectsForAfterDelay];
         
         if(isDisplayAnnotationView)
             [self setNeedsDisplayAnnotationViewForVisiblePages];
@@ -1185,7 +1184,7 @@ NSNotificationName const CPDFListViewDisplayModeChangeNotification = @"CPDFListV
         [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewDidAddAnnotationNotification object:self userInfo:[NSDictionary dictionaryWithObjectsAndKeys:page, CPDFListViewPageKey, annotation, CPDFListViewAnnotationKey, nil]];
     });
     
-    [self resetPDFToolTipRects];
+    [self resetPDFToolTipRectsForAfterDelay];
     if([self.pdfListViewDelegate respondsToSelector:@selector(PDFListViewAddAnnotations:forAddAnnotations:inPage:)])
         [self.pdfListViewDelegate PDFListViewAddAnnotations:self forAddAnnotations:@[annotation] inPage:page];
 }
@@ -1216,7 +1215,7 @@ NSNotificationName const CPDFListViewDisplayModeChangeNotification = @"CPDFListV
         
         [[[self undoManager] prepareWithInvocationTarget:self] addAnnotation:wasAnnotation toPage:page];
         if ([wasAnnotation isNote]) {
-            [self resetPDFToolTipRects];
+            [self resetPDFToolTipRectsForAfterDelay];
         }
         [page removeAnnotation:wasAnnotation];
         [self annotationsChangedOnPage:page];
@@ -1613,9 +1612,10 @@ NSNotificationName const CPDFListViewDisplayModeChangeNotification = @"CPDFListV
 }
 
 - (void)handlePageChangedNotification:(NSNotification *)notification {
-    if ([self displayMode] == kPDFDisplaySinglePage || [self displayMode] == kPDFDisplayTwoUp) {
-        [self resetPDFToolTipRects];
+    if (self.isSinglePageMode || self.isTwoPageMode) {
+        [self resetPDFToolTipRectsForAfterDelay];
     }
+    
     self.copyCount = 0;
 }
 

+ 4 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Extension.h

@@ -63,7 +63,10 @@
 
 @interface CPDFView (KMExtension)
 
-@property (strong, readonly) NSUndoManager *fbUndoManager;
+@property (strong, nonatomic, readonly) NSUndoManager *fbUndoManager;
+
+@property (nonatomic, assign, readonly) BOOL isSinglePageMode;
+@property (nonatomic, assign, readonly) BOOL isTwoPageMode;
 
 - (BOOL)km_canGoBack;
 - (void)km_goBack:(id)sender;

+ 10 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Extension.m

@@ -1041,6 +1041,16 @@ CGFloat DEFAULT_SNAPSHOT_HEIGHT = 200.0;
     }
 }
 
+- (BOOL)isSinglePageMode {
+    CPDFDisplayViewMode viewM = [self displayViewMode];
+    return viewM == CPDFDisplayViewSinglePage || viewM == CPDFDisplayViewSinglePageContinuous;
+}
+
+- (BOOL)isTwoPageMode {
+    CPDFDisplayViewMode viewM = [self displayViewMode];
+    return viewM == CPDFDisplayViewTwoUp || viewM == CPDFDisplayViewTwoUpContinuous;
+}
+
 - (BOOL)km_canGoForward {
 //    if (self.canGoForward) {
 //        return YES;

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Tool.h

@@ -85,5 +85,7 @@ typedef NS_ENUM(NSInteger, CAnnotationAlignState) {
 
 + (NSUInteger)standardPDFListViewModifierFlags;
 
+- (void)resetPDFToolTipRectsForAfterDelay;
+
 @end
 

+ 8 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Tool.m

@@ -643,4 +643,12 @@
     return  [NSEvent standardPDFListViewModifierFlags];
 }
 
+- (void)resetPDFToolTipRectsForAfterDelay {
+    SEL sel = @selector(resetPDFToolTipRects);
+    if ([self respondsToSelector:sel]) {
+        [[self class] cancelPreviousPerformRequestsWithTarget:self selector:sel object:nil];
+        [self performSelector:sel withObject:nil afterDelay:1];
+    }
+}
+
 @end

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Outline/KMOutlineEditViewController.swift

@@ -73,7 +73,7 @@ class KMOutlineEditViewController: NSViewController {
             }
             if action.isKind(of: CPDFURLAction.self) {
                 var newAction : CPDFURLAction = self.outline?.action as! CPDFURLAction
-                var urlString : String = newAction.url()
+                var urlString = newAction.url() ?? ""
                 self.originalURLString = urlString
                 
                 if urlString.hasPrefix("mailto:") {
@@ -94,7 +94,7 @@ class KMOutlineEditViewController: NSViewController {
                 self.originalDestination = outL.destination
                 self.originalPageIndex = self.originalDestination?.pageIndex ?? -1
             }
-            self.originalLabel = outL.label
+            self.originalLabel = outL.label ?? ""
             self.totalPageCountLabel.stringValue = " /\(doc.pageCount)"
             self.outlineTargetPageIndexTextField.stringValue = "\(self.currentPageIndex + 1)"
         }